@font-face {
  font-family: "Playfair Display";
  src: url("fonts/playfair-display.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/inter.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f4f5f2;
  --white: #ffffff;
  --blue: #143e9e;
  --deep: #0c2b73;
  --ink: #17233b;
  --muted: #6e7686;
  --line: rgba(20, 62, 158, 0.18);
  --user-bg: #e9eef8;
  --display: "Playfair Display", "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", serif;
  --body: "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.7;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, p, figure, dl, dd { margin: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.mono { font-family: var(--mono); letter-spacing: 0.05em; }
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
::selection { background: rgba(20, 62, 158, 0.16); }
.eyebrow {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--blue);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0.04;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}

.app {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr) 288px;
  height: 100vh;
  height: 100dvh;
}

/* ---------- rail ---------- */
.rail {
  display: flex;
  flex-direction: column;
  padding: 20px 16px 18px;
  background: rgba(255, 255, 255, 0.55);
  border-right: 1px solid var(--line);
  min-height: 0;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 6px; }
.brand-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--blue);
  flex: none;
}
.brand-name {
  font-family: var(--display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.rail-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 34px; }
.rail-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  transition: color 0.18s, border-color 0.18s, background 0.18s;
}
.rail-link:hover { color: var(--blue); background: rgba(20, 62, 158, 0.04); }
.rail-link.is-active {
  color: var(--blue);
  border-left-color: var(--blue);
  background: rgba(20, 62, 158, 0.05);
}
.rail-link b {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 400;
  color: var(--muted);
}
.rail-plate {
  margin-top: 28px;
  padding: 6px;
  background: var(--white);
  border: 1px solid var(--line);
}
.rail-plate img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  filter: contrast(1.03) saturate(0.96);
}
.rail-plate figcaption {
  font-size: 8px;
  color: var(--muted);
  padding: 6px 2px 1px;
  letter-spacing: 0.1em;
}
.rail-foot { margin-top: auto; padding: 14px 6px 2px; border-top: 1px solid var(--line); }
.rail-foot .status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
}
.rail-foot .mono { font-size: 8.5px; color: var(--muted); margin-top: 5px; }
.rail-logout {
  display: block;
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 8.5px;
  color: var(--muted);
  letter-spacing: 0.06em;
  transition: color 0.18s;
}
.rail-logout:hover { color: var(--blue); }
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #2f7d4f;
  box-shadow: 0 0 0 3px rgba(47, 125, 79, 0.12);
  flex: none;
}

/* ---------- main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 30px 18px;
  border-bottom: 1px solid var(--line);
}
.mobile-brand { display: none; }
.topbar-title h1 {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin-top: 5px;
}
.topbar-actions { display: flex; align-items: center; gap: 14px; padding-bottom: 3px; }
.thread { font-size: 9px; color: var(--muted); letter-spacing: 0.1em; }
.ghost-btn {
  height: 32px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 11.5px;
  text-decoration: none;
  white-space: nowrap;
  flex: none;
  transition: border-color 0.18s, color 0.18s;
}
.ghost-btn:hover { border-color: var(--blue); color: var(--blue); }

.stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 30px 10px;
}
.stream-inner { max-width: 820px; margin: 0 auto; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 2vh 0 4vh; }
.empty-plate {
  max-width: 560px;
  margin: 0 auto 24px;
  padding: 7px;
  background: var(--white);
  border: 1px solid var(--line);
}
.empty-plate img {
  width: 100%;
  height: 190px;
  object-fit: cover;
  object-position: center 58%;
  filter: contrast(1.03) saturate(0.96);
}
.empty-plate figcaption {
  font-size: 8px;
  color: var(--muted);
  text-align: left;
  padding: 7px 3px 1px;
  letter-spacing: 0.1em;
}
.empty h2 {
  font-family: var(--display);
  font-size: 34px;
  font-weight: 500;
  line-height: 1.16;
  margin: 10px 0 8px;
  letter-spacing: -0.02em;
}
.empty p {
  max-width: 480px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}
.chips button {
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: #3d4658;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}
.chips button:hover { border-color: var(--blue); color: var(--blue); background: var(--white); }

/* ---------- messages ---------- */
.messages { display: flex; flex-direction: column; gap: 22px; }
.messages[hidden] { display: none; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
.msg.user { align-self: flex-end; align-items: flex-end; max-width: 78%; }
.msg-meta {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 5px;
}
.msg.user .msg-meta { color: var(--blue); }
.tts-replay {
  margin-left: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8.5px;
  text-decoration: underline;
  cursor: pointer;
}
.tts-replay:hover { color: var(--blue); }
.ghost-btn.is-on {
  border-color: var(--blue);
  color: var(--blue);
  background: rgba(20, 62, 158, 0.06);
}
.composer input[type="file"] { display: none; }
.icon-btn.is-recording {
  color: #b3261e;
  border-color: #b3261e;
  background: rgba(179, 38, 30, 0.08);
  animation: voicePulse 1.2s ease-in-out infinite;
}
@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.28); }
  50% { box-shadow: 0 0 0 6px rgba(179, 38, 30, 0); }
}
.msg-image {
  display: block;
  max-width: 280px;
  max-height: 200px;
  margin-bottom: 8px;
  padding: 4px;
  object-fit: cover;
  background: var(--white);
  border: 1px solid var(--line);
}
.bubble {
  max-width: 92%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13.5px;
  line-height: 1.8;
}
.msg.assistant .bubble {
  padding: 11px 15px;
  background: rgba(255, 255, 255, 0.6);
  border-left: 2px solid var(--blue);
}
.msg.user .bubble {
  max-width: 100%;
  padding: 10px 14px;
  background: var(--user-bg);
  border: 1px solid rgba(20, 62, 158, 0.2);
}

/* ---------- typing ---------- */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 13px 16px;
  background: rgba(255, 255, 255, 0.6);
  border-left: 2px solid var(--blue);
}
.typing span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--blue);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- confirmation card ---------- */
.confirm-card {
  margin-top: 11px;
  width: 100%;
  max-width: 560px;
  background: var(--white);
  border: 1px solid var(--line);
  border-top: 3px solid var(--blue);
  padding: 14px 16px 15px;
  box-shadow: 0 18px 30px -30px rgba(12, 43, 115, 0.55);
}
.confirm-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.confirm-head .mono { font-size: 8.5px; color: var(--blue); letter-spacing: 0.12em; }
.confirm-kind { font-size: 10px; color: var(--muted); }
.confirm-summary { font-size: 13px; line-height: 1.7; margin: 9px 0 13px; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.choice {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 11.5px;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.choice b { font-family: var(--mono); font-weight: 500; margin-right: 5px; }
.choice-a { background: var(--blue); border-color: var(--blue); color: var(--white); }
.choice-a:hover { background: var(--deep); }
.choice-b:hover { border-color: var(--blue); color: var(--blue); }
.choice-c { border-color: transparent; color: var(--muted); }
.choice-c:hover { color: var(--blue); }
.choice:disabled { opacity: 0.45; cursor: not-allowed; }
.edit-box { margin-top: 11px; }
.edit-box textarea {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 9px 10px;
  font-size: 12.5px;
  line-height: 1.6;
  outline: none;
}
.edit-box textarea:focus { border-color: var(--blue); }
.edit-row { display: flex; justify-content: flex-end; gap: 7px; margin-top: 7px; }
.confirm-status { margin-top: 9px; font-family: var(--mono); font-size: 9px; color: var(--muted); letter-spacing: 0.06em; }
.confirm-card.is-done .confirm-actions,
.confirm-card.is-done .edit-box { display: none; }

/* ---------- sms cards ---------- */
.sms-cards {
  margin-top: 11px;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sms-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--line);
}
.sms-head .mono { font-size: 8.5px; color: var(--blue); letter-spacing: 0.12em; }
.sms-count { font-size: 10px; color: var(--muted); }
.sms-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  padding: 10px 12px;
}
.sms-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sms-to { font-size: 11px; color: var(--muted); }
.sms-badge {
  flex: none;
  font-size: 9.5px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.sms-badge.is-ok { color: var(--blue); border-color: rgba(20, 62, 158, 0.35); }
.sms-badge.is-bad { color: #a3342f; border-color: rgba(163, 52, 47, 0.35); }
.sms-badge.is-warn { color: #8a6d1f; border-color: rgba(138, 109, 31, 0.35); }
.sms-content {
  margin: 7px 0 0;
  font-size: 12.5px;
  line-height: 1.7;
  word-break: break-word;
  color: var(--ink);
}
.sms-link {
  display: inline-block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--blue);
}
.sms-link:hover { color: var(--deep); }

/* ---------- composer ---------- */
.composer { padding: 10px 30px 16px; border-top: 1px solid var(--line); background: var(--paper); }
.composer-box {
  max-width: 820px;
  margin: 0 auto;
  background: var(--white);
  border: 1px solid var(--line);
  padding: 10px 12px 9px;
  transition: border-color 0.18s;
}
.composer-box:focus-within { border-color: rgba(20, 62, 158, 0.45); }
.composer-box textarea {
  width: 100%;
  min-height: 26px;
  max-height: 150px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 13.5px;
  line-height: 1.65;
  padding: 2px 2px 0;
}
.composer-box textarea::placeholder { color: #9aa1ad; }
.composer-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px dashed var(--line);
}
.icon-btn {
  width: 29px; height: 29px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  transition: color 0.18s, border-color 0.18s;
}
.icon-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { color: var(--blue); border-color: var(--blue); }
.hint { margin-left: auto; font-size: 8px; color: var(--muted); letter-spacing: 0.08em; }
.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 31px;
  padding: 0 12px;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: var(--white);
  font-size: 11.5px;
  transition: background 0.18s, opacity 0.18s;
}
.send-btn svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.send-btn:hover { background: var(--deep); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- side ---------- */
.side {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 20px;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
  overflow-y: auto;
}
.side-head h2 {
  font-family: var(--display);
  font-size: 26px;
  font-weight: 500;
  line-height: 1.15;
  margin: 7px 0 8px;
  letter-spacing: -0.01em;
}
.side-head p { font-size: 12px; color: var(--muted); line-height: 1.75; }
.side-metrics { border-top: 1px solid var(--line); }
.side-metrics > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.side-metrics dt {
  font-family: var(--display);
  font-size: 28px;
  line-height: 1;
  color: var(--blue);
  letter-spacing: -0.02em;
}
.side-metrics dd { font-size: 10.5px; color: var(--muted); }
.side-note { border-top: 1px dashed var(--line); padding-top: 13px; }
.side-note .mono { font-size: 8px; color: var(--blue); letter-spacing: 0.12em; }
.side-note p { font-size: 11.5px; color: var(--muted); line-height: 1.7; margin-top: 5px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%) translateY(6px);
  z-index: 60;
  padding: 8px 13px;
  background: var(--ink);
  color: var(--white);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .typing span { animation: none; opacity: 1; }
}

/* ---------- responsive ---------- */
/* 移动端底部导航：桌面端隐藏，窄屏时替代左侧 rail */
.mobile-nav { display: none; }

@media (max-width: 1180px) {
  .app { grid-template-columns: 216px minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 840px) {
  .app {
    grid-template-columns: 1fr;
    /* 给底部导航留位，避免遮挡输入框和页面内容 */
    padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  }
  .rail { display: none; }
  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: rgba(244, 245, 242, 0.94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 8px 0 7px;
    font-size: 11px;
    color: var(--muted);
    transition: color 0.18s;
  }
  .mobile-nav a b {
    font-family: var(--mono);
    font-size: 8.5px;
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--muted);
  }
  .mobile-nav a.is-active { color: var(--blue); }
  .mobile-nav a.is-active b { color: var(--blue); }
  .mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--display);
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
  }
  .topbar { align-items: flex-start; padding: 16px 18px 14px; }
  .topbar-title h1 { font-size: 24px; }
  .topbar-actions { padding-top: 2px; }
  .thread { display: none; }
  .stream { padding: 18px 16px 8px; }
  .empty { padding-top: 0; }
  .empty-plate { margin-bottom: 18px; }
  .empty-plate img { height: 140px; }
  .empty h2 { font-size: 28px; }
  .chips button { font-size: 11px; }
  .composer { padding: 9px 14px 13px; }
  .hint { display: none; }
  .msg.user { max-width: 88%; }
  .confirm-card { padding: 12px 13px 13px; }
}
