:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1b1f24;
  --muted: #6a737d;
  --line: #dde1e6;
  --accent: #c2185b;
  --accent-text: #ffffff;
  --user: #fbe4ee;
  --code: #eef0f3;
  --error: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d23;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --line: #2c3139;
    --accent: #ec5f95;
    --accent-text: #160a10;
    --user: #3a1f2b;
    --code: #23272f;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
button {
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
button.ghost:hover { color: var(--text); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.5em; margin: 0; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  display: grid;
  gap: 10px;
}
.card h1 { margin: 0; font-size: 1.5rem; }
.card p { margin: 0 0 8px; }
.card input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

/* chat */
.app { height: 100%; display: flex; flex-direction: column; max-width: 820px; margin: 0 auto; }
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.title span { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  font-size: .8rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; text-align: center; color: var(--muted); }
.msg { max-width: 100%; }
.msg.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--user);
  border-radius: 14px 14px 4px 14px;
  padding: 8px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .body pre {
  background: var(--code);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
  white-space: pre;
  font: .9em/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.msg.assistant .body.waiting::after { content: "…"; color: var(--muted); }
.msg .error { margin-top: 4px; }
.stats {
  margin-top: 8px;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0 12px;
  font: .78rem/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--muted);
}
.stats .warn { color: var(--error); font-weight: 600; }
.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 40vh;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
@media (max-width: 520px) {
  .bar { flex-wrap: wrap; }
  .title { flex-basis: 100%; }
}
