:root {
  --bg: #ffffff;
  --surface: #f4f4f5;
  --text: #18181b;
  --muted: #8b8b93;
  --line: #e7e7ea;
  --accent: #18181b;
  --accent-text: #ffffff;
  --code-bg: #f6f6f7;
  --danger: #c2412d;
  --ok: #3fa672;
  --column: 720px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101011;
    --surface: #1d1d20;
    --text: #ececee;
    --muted: #85858d;
    --line: #29292d;
    --accent: #ececee;
    --accent-text: #101011;
    --code-bg: #18181b;
    --danger: #f0806c;
    --ok: #58c08a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* Header */
.top {
  flex: none;
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-inner {
  max-width: var(--column);
  margin: 0 auto;
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.title { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.target { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.icon-button {
  margin-left: auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
}
.icon-button:hover { background: var(--surface); }
.icon-button svg { width: 20px; height: 20px; }

/* Message list */
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.list {
  max-width: var(--column);
  margin: 0 auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100%;
}
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.row { display: flex; flex-direction: column; min-width: 0; }
.row.user { align-items: flex-end; }
.bubble {
  max-width: 82%;
  background: var(--surface);
  padding: 9px 14px;
  border-radius: 18px;
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.meta { font-size: 11px; color: var(--muted); margin-top: 4px; padding: 0 4px; }
.who { display: flex; align-items: baseline; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.who b { font-weight: 600; color: var(--text); font-size: 13px; }
.row.system { align-items: center; }
.row.system span { font-size: 13px; color: var(--muted); text-align: center; max-width: 90%; overflow-wrap: anywhere; }
.actions { margin-top: 6px; display: flex; gap: 4px; }
.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 3px 8px;
  margin-left: -8px;
  border-radius: 6px;
}
.text-button:hover { background: var(--surface); color: var(--text); }

/* Rendered replies */
.md { min-width: 0; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.75em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.2em 0 0.5em; line-height: 1.35; font-weight: 600; }
.md h1 { font-size: 1.3em; }
.md h2 { font-size: 1.18em; }
.md h3 { font-size: 1.06em; }
.md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.md li { margin: 0.2em 0; }
.md li > p { margin: 0; }
.md a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--muted); }
.md strong { font-weight: 600; }
.md blockquote { margin: 0 0 0.75em; padding: 0 0 0 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md code {
  font: 0.88em/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--code-bg);
  padding: 0.12em 0.36em;
  border-radius: 5px;
}
.md .codebox { margin: 0 0 0.85em; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.md .codebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 4px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--code-bg);
  border-bottom: 1px solid var(--line);
}
.md .codebar .text-button { margin-left: 0; }
.md pre { margin: 0; padding: 12px; overflow-x: auto; background: var(--code-bg); }
.md pre code { background: transparent; padding: 0; font-size: 13px; line-height: 1.55; white-space: pre; }
.md .tablebox { margin: 0 0 0.85em; overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 6px 12px 6px 0; text-align: left; vertical-align: top; }
.md th { font-weight: 600; white-space: nowrap; }

/* Thinking indicator */
.typing { display: flex; align-items: center; gap: 5px; height: 24px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: 0.6; } }

/* Empty state */
.empty { margin: auto 0; padding: 24px 0 40px; text-align: center; }
.empty h2 { font-size: 22px; font-weight: 600; margin: 0 0 6px; }
.empty p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
}
.chip:hover { background: var(--surface); }

/* Composer */
.bottom { flex: none; padding: 0 16px calc(12px + env(safe-area-inset-bottom)); position: relative; }
.bottom-inner { max-width: var(--column); margin: 0 auto; }
.status { font-size: 13px; color: var(--danger); min-height: 0; padding: 0 4px 6px; }
.status:empty { display: none; }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 6px 6px 6px 16px;
}
.composer:focus-within { border-color: var(--muted); }
.composer textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  padding: 6px 0;
  height: 36px;
  max-height: 168px;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
}
.send svg { width: 18px; height: 18px; }
.send:disabled { opacity: 0.25; cursor: default; }
.jump {
  position: absolute;
  left: 50%;
  top: -48px;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.jump svg { width: 18px; height: 18px; }

/* Token screen */
.login {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
}
.login h2 { font-size: 18px; font-weight: 600; margin: 0; }
.login input {
  font: inherit;
  width: min(380px, 100%);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  outline: 0;
}
.login input:focus { border-color: var(--muted); }
.login button {
  border: 0;
  border-radius: 12px;
  padding: 9px 28px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

@media (max-width: 520px) {
  .list { gap: 16px; padding-top: 16px; }
  .bubble { max-width: 88%; }
}
