:root {
  --bg: #ffffff;
  --surface: #f4f4f2;
  --composer: #ffffff;
  --text: #1d1f21;
  --muted: #6b6f76;
  --line: #e2e2de;
  --accent: #1f6feb;
  --user: #f0f0ed;
  --error: #b42318;
  --error-soft: #fdecea;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --bar0: #1f6feb;
  --bar1: #2e9d6a;
  --bar2: #c27c0e;
  --negative: #b42318;
  --send: #1d1f21;
  --send-text: #ffffff;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #222326;
    --composer: #26272b;
    --text: #ececea;
    --muted: #a0a3a8;
    --line: #36383d;
    --accent: #6ea8ff;
    --user: #2c2d31;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --bar0: #6ea8ff;
    --bar1: #5cc493;
    --bar2: #e2a74a;
    --negative: #ff8a80;
    --send: #ececea;
    --send-text: #17181a;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
      stroke-linejoin: round; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }

/* ------------------------------------------------------------------ top bar */
.top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: 0.2px; }
.new-chat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
}
.new-chat:hover { background: var(--surface); }
body.empty .new-chat { visibility: hidden; }

/* ------------------------------------------------------------------ layout: centered when empty, docked after */
.main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; }
.thread {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.dock {
  flex: none;
  width: 100%;
  max-width: 792px;
  margin: 0 auto;
  padding: 0 16px 10px;
}
.hero { display: none; text-align: center; margin-bottom: 22px; }
.hero h1 { font-size: 28px; line-height: 1.25; margin: 0 0 8px; font-weight: 600; }
.hero p { margin: 0; color: var(--muted); }

body.empty .scroll { display: none; }
body.empty .dock { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 12vh; }
body.empty .hero { display: block; }

/* ------------------------------------------------------------------ composer */
.composer {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--composer);
  box-shadow: var(--shadow);
  padding: 10px 12px 8px 16px;
}
.composer:focus-within { border-color: var(--muted); }
.composer textarea {
  display: block;
  width: 100%;
  min-height: 28px;
  max-height: 220px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 4px 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}
.row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.hint { flex: 1; color: var(--muted); font-size: 12px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin-left: -6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin-left: auto;
  border: 0;
  border-radius: 50%;
  background: var(--send);
  color: var(--send-text);
}

.chips { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chips li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.chips svg { width: 14px; height: 14px; color: var(--muted); }

.notice { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
.status { margin: 4px 0 0; min-height: 1.2em; text-align: center; color: var(--error); font-size: 13px; }

/* ------------------------------------------------------------------ messages */
.msg { max-width: 100%; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  max-width: 80%;
  padding: 9px 16px;
  border-radius: 20px;
  background: var(--user);
}
.msg.user.file { display: inline-flex; align-items: center; gap: 8px; }
.msg.user.file svg { color: var(--muted); flex: none; }
.msg.assistant { align-self: stretch; }
.msg.error .msg-text {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--error-soft);
  color: var(--error);
}

/* same file again: two choices under the question */
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.choice {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
}
.choice:hover:not(:disabled) { background: var(--surface); }
.choice.primary { background: var(--send); border-color: var(--send); color: var(--send-text); }
.choice.primary:hover:not(:disabled) { background: var(--send); opacity: 0.9; }
.chosen { color: var(--muted); font-size: 13px; }

/* activity: the live progress list of one turn */
.activity { align-self: stretch; color: var(--muted); font-size: 14px; }
.activity summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 8px; }
.activity summary::-webkit-details-marker { display: none; }
.activity.running summary { cursor: default; }
.activity ol { margin: 6px 0 0; padding-left: 22px; }
.activity li.current { color: var(--text); }
.activity .track { height: 3px; margin-top: 8px; border-radius: 2px; background: var(--line); overflow: hidden;
                   max-width: 260px; }
.activity .fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.activity:not(.running) .track { display: none; }
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
.activity:not(.running) .dot { animation: none; background: var(--muted); }
@keyframes pulse { 50% { opacity: 0.25; transform: scale(0.8); } }

/* answer layout: headline, chart, points, notes (collapsed) */
.msg-text.headline { font-weight: 600; font-size: 16px; line-height: 1.5; }
.points { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.points li {
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--surface);
  overflow-wrap: anywhere;
}
.notes { margin-top: 10px; color: var(--muted); font-size: 13px; }
.notes summary { cursor: pointer; width: fit-content; }
.notes summary:hover { color: var(--text); }
.notes ul { margin: 6px 0 0; padding-left: 18px; }
.notes li + li { margin-top: 4px; }

/* chart */
.chart { margin: 12px 0 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; }
.chart figcaption { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.chart-svg { width: 100%; height: auto; display: block; stroke: none; }
.chart-svg * { stroke: none; }
.chart-label { fill: var(--text); font-size: 13px; }
.chart-value { fill: var(--muted); font-size: 12px; }
.bar-s0 { fill: var(--bar0); }
.bar-s1 { fill: var(--bar1); }
.bar-s2 { fill: var(--bar2); }
.negative { fill: var(--negative); }

/* drop overlay */
.dropzone {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 111, 235, 0.12);
  z-index: 10;
}
.dropzone[hidden] { display: none; }
.dropzone-box {
  padding: 28px 36px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: var(--bg);
  font-weight: 600;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; }
}

@media (max-width: 560px) {
  .hero h1 { font-size: 22px; }
  .msg.user { max-width: 90%; }
  .hint { display: none; }
}
