:root {
  --bg: #f4ede1;
  --panel: rgba(255, 250, 245, 0.8);
  --panel-strong: rgba(255, 252, 248, 0.94);
  --line: rgba(35, 41, 53, 0.12);
  --line-strong: rgba(35, 41, 53, 0.22);
  --text: #202330;
  --muted: #676d7d;
  --accent: #c35c41;
  --accent-deep: #9f442e;
  --success: #1f7b59;
  --shadow: 0 24px 60px rgba(58, 36, 24, 0.12);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(218, 128, 92, 0.24), transparent 26%),
    radial-gradient(circle at 84% 12%, rgba(52, 116, 165, 0.14), transparent 24%),
    linear-gradient(180deg, #f9f1e3 0%, #f4eee6 42%, #eef4f4 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(31, 35, 48, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 35, 48, 0.03) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at center, black 46%, transparent 88%);
  pointer-events: none;
}

.backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 80%, rgba(27, 120, 104, 0.1), transparent 24%),
    radial-gradient(circle at 85% 65%, rgba(198, 91, 63, 0.1), transparent 28%);
  filter: blur(30px);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1320px, calc(100% - 40px));
  margin: 24px auto 48px;
}

.panel {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  border-radius: var(--radius-xl);
}

.eyebrow,
.section-kicker {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.74rem;
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Songti SC", serif;
  font-weight: 700;
}

h1 {
  margin-top: 12px;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.02;
  max-width: 12ch;
}

h2 {
  font-size: 1.24rem;
}

.summary-copy,
.helper-text,
.message-meta,
.message-preview,
.muted {
  color: var(--muted);
}

.page-stack,
.workspace {
  display: grid;
  gap: 22px;
}

.page-stack {
  margin-top: 0;
}

.summary-panel,
.detail-panel,
.workspace > .panel,
.workspace-grid > .panel,
.query-panel {
  padding: 24px;
}

.query-panel {
  display: grid;
  display: grid;
  gap: 16px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 22px;
}

.list-heading {
  display: grid;
  gap: 4px;
}

.section-title-row,
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.field {
  display: grid;
  gap: 10px;
}

.field span {
  font-size: 0.92rem;
  font-weight: 600;
}

input,
textarea {
  width: 100%;
  padding: 15px 17px;
  font: inherit;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

textarea {
  min-height: 168px;
  resize: vertical;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(195, 92, 65, 0.55);
  box-shadow: 0 0 0 4px rgba(195, 92, 65, 0.12);
  transform: translateY(-1px);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.button,
.tab-button,
.message-item {
  font: inherit;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease,
    background-color 180ms ease;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.button-compact {
  padding: 10px 14px;
  white-space: nowrap;
}

.button:hover,
.message-item:hover,
.tab-button:hover {
  transform: translateY(-1px);
}

.button:disabled,
.tab-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.button-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff9f5;
  box-shadow: 0 18px 30px rgba(159, 68, 46, 0.2);
}

.button-secondary {
  background: rgba(31, 35, 48, 0.08);
  color: var(--text);
}

.button-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.helper-text {
  margin: 0;
  line-height: 1.6;
  min-height: 1.6em;
}

.helper-text.is-error {
  color: #a3412b;
}

.helper-text.is-success {
  color: var(--success);
}

.hero-copy {
  margin: 0;
  max-width: 62ch;
  line-height: 1.75;
  color: var(--muted);
}

.section-stack {
  display: grid;
  gap: 16px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 22px;
}

.admin-grid.auth-guest {
  grid-template-columns: minmax(320px, 560px);
  justify-content: center;
}

.admin-grid.auth-ready {
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
}

.admin-grid > .panel {
  padding: 24px;
}

.login-panel {
  min-height: min(78vh, 760px);
  align-content: center;
}

.login-form-shell {
  width: min(100%, 360px);
  margin: 0 auto;
}

body:not(.is-authenticated) .auth-only {
  display: none !important;
}

body:not(.is-authenticated) #loginSection {
  text-align: center;
}

body:not(.is-authenticated) #loginSection .section-title-row {
  flex-direction: column;
  align-items: center;
}

body:not(.is-authenticated) #loginSection .button-row {
  justify-content: center;
}

body:not(.is-authenticated) #loginStatusText {
  margin-top: 12px;
  text-align: center;
}

.admin-form {
  display: grid;
  gap: 16px;
}

.meta-card {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.45);
}

.field-hint {
  display: inline-block;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.password-rules {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.password-rules li + li {
  margin-top: 4px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid var(--line);
}

.stat-card strong {
  font-size: 1.1rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.86rem;
}

.checkbox-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.45);
}

.checkbox-row input {
  width: auto;
  margin: 3px 0 0;
  transform: none;
  box-shadow: none;
}

.checkbox-row span {
  line-height: 1.7;
}

.panel[hidden] {
  display: none !important;
}

.list-container {
  display: grid;
  gap: 12px;
  max-height: 58vh;
  overflow: auto;
  padding-right: 6px;
}

.list-container.empty {
  padding: 22px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.4);
}

.message-item {
  width: 100%;
  padding: 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.62);
  text-align: left;
  cursor: pointer;
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

.message-item.is-selected {
  border-color: rgba(198, 91, 63, 0.42);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 239, 232, 0.9));
}

.message-subject {
  font-weight: 700;
}

.message-preview {
  margin-top: 8px;
  font-size: 0.92rem;
  line-height: 1.55;
}

.message-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.message-time {
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.82rem;
}

.tab-row {
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(31, 35, 48, 0.06);
}

.tab-button {
  border: 0;
  background: transparent;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}

.tab-button.is-active {
  background: #fff8f4;
  color: var(--accent-deep);
}

.message-meta {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.45);
  line-height: 1.7;
}

.message-body {
  margin-top: 16px;
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.76);
  overflow: hidden;
}

.message-body.placeholder {
  display: grid;
  place-items: center;
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

.message-text {
  margin: 0;
  padding: 24px;
  white-space: pre-wrap;
  line-height: 1.75;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.96rem;
}

.html-preview {
  width: 100%;
  min-height: 460px;
  border: 0;
  background: #ffffff;
}

.reveal {
  animation: float-in 680ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(22px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1120px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .admin-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .list-container {
    max-height: 360px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 24px, 100%);
    margin: 18px auto 28px;
  }

  .query-panel,
  .summary-panel,
  .workspace-grid > .panel {
    padding: 20px;
  }

  .section-title-row,
  .detail-header,
  .message-topline {
    flex-direction: column;
    align-items: flex-start;
  }

  .button-row {
    flex-direction: column;
  }

  .button {
    width: 100%;
  }
}
