:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --ink: #1d2230;
  --ink-2: #4a5165;
  --ink-3: #7a8094;
  --line: #e3e0d6;
  --accent: #27407a;
  --accent-ink: #ffffff;
  --accent-soft: #e8ecf6;
  --gold: #a07a2c;
  --ok: #2f7d4f;
  --warn: #a8662a;
  --err: #b0413e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 4px 16px rgba(20, 24, 40, .05);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141b;
    --surface: #1a1d27;
    --surface-2: #222634;
    --ink: #e9eaf0;
    --ink-2: #b6bacb;
    --ink-3: #868ba0;
    --line: #2e3344;
    --accent: #8ea6e8;
    --accent-ink: #10131c;
    --accent-soft: #232b45;
    --gold: #d2ad62;
    --ok: #5fbf87;
    --warn: #e0a15e;
    --err: #e57b77;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, select, textarea { font: inherit; color: inherit; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.hidden { display: none !important; }

.app { display: flex; flex-direction: column; min-height: 100vh; max-width: 860px; margin: 0 auto; padding: 0 16px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--accent); color: var(--accent-ink); font-size: 21px;
}
h1 { font: 600 20px/1.2 var(--serif); margin: 0; letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--ink-3); font-size: 13px; }
.status {
  display: flex; align-items: center; gap: 7px; flex: none;
  padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); font-size: 12.5px; color: var(--ink-2); white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.status.ok .dot { background: var(--ok); }
.status.busy .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.status.err .dot { background: var(--err); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- intro ---------- */
.chat { flex: 1; padding: 22px 0 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.model-card { padding: 18px 20px; display: grid; gap: 14px; }
.model-card h2 { font: 600 17px/1.3 var(--serif); margin: 0 0 4px; }
.model-card p { margin: 0; color: var(--ink-2); font-size: 14px; }
.model-card.loaded { display: none; }
.model-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.model-actions select { flex: 1 1 240px; min-width: 0; }
select {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); max-width: 100%;
}
.progress { position: relative; height: 26px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-soft); transition: width .3s; }
.progress span { position: relative; display: block; padding: 0 10px; font-size: 12px; line-height: 26px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.section-label { font: 600 12px/1 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 26px 0 10px; }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.doc-list li {
  display: flex; gap: 12px; align-items: baseline; justify-content: space-between;
  padding: 11px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
}
.doc-title { font-weight: 500; }
.doc-meta { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.doc-list a { color: inherit; text-decoration: none; }
.doc-list a:hover .doc-title { text-decoration: underline; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px;
  padding: 7px 13px; font-size: 13.5px; cursor: pointer; text-align: left; color: var(--ink-2);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- messages ---------- */
.msg { margin: 22px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 85%; background: var(--accent); color: var(--accent-ink);
  padding: 10px 15px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.bot .answer { padding: 2px 2px 0; overflow-wrap: anywhere; }
.answer p { margin: 0 0 10px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer h4 { font: 600 15px/1.4 var(--serif); margin: 14px 0 6px; }
.answer .thinking { color: var(--ink-3); font-style: italic; }
.answer .note { color: var(--ink-2); font-size: 14px; background: var(--surface-2); border-radius: 10px; padding: 10px 13px; }
.cursor::after { content: "▍"; color: var(--accent); animation: pulse 1s infinite; }
a.cite {
  display: inline-block; min-width: 20px; padding: 0 5px; margin: 0 1px;
  border-radius: 6px; background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 600; line-height: 18px; text-align: center; text-decoration: none; vertical-align: 1px;
}
.sources { margin-top: 12px; display: grid; gap: 8px; }
.sources-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; margin-top: 6px; }
.source { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 10px 13px; transition: border-color .3s, box-shadow .3s; }
.source.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.source summary { cursor: pointer; list-style: none; display: flex; gap: 10px; align-items: baseline; }
.source summary::-webkit-details-marker { display: none; }
.source .n { flex: none; color: var(--accent); font-weight: 600; font-size: 13px; }
.source .s-title { font-weight: 500; font-size: 14px; }
.source .s-meta { color: var(--ink-3); font-size: 12.5px; }
.source .s-snippet { color: var(--ink-2); font-size: 13.5px; margin: 4px 0 0; }
.source[open] .s-snippet { display: none; }
.source .s-full { color: var(--ink-2); font-size: 13.5px; margin: 8px 0 4px; white-space: pre-wrap; }
.source .s-open { font-size: 13px; color: var(--accent); }
.meta-line { color: var(--ink-3); font-size: 12px; margin-top: 8px; }

/* ---------- composer ---------- */
.composer { position: sticky; bottom: 0; background: linear-gradient(to bottom, transparent, var(--bg) 18px); padding: 18px 0 10px; }
.composer-inner { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 10px; }
.scope { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-3); padding: 0 4px 8px; }
.scope select { padding: 4px 8px; font-size: 12.5px; border-radius: 8px; flex: 1; min-width: 0; max-width: 520px; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  padding: 8px 6px; max-height: 180px; line-height: 1.5; min-width: 0;
}
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 9px 15px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink); display: inline-block;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.send { width: 42px; height: 40px; padding: 0; display: grid; place-items: center; flex: none; }
.stop { height: 40px; flex: none; }
.foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 8px 4px 0; font-size: 12px; color: var(--ink-3); }
.admin summary { cursor: pointer; }
.admin-body { max-width: 340px; padding-top: 6px; }
.admin-body p { margin: 0 0 8px; }
.hint { font-size: 11.5px; }

@media (max-width: 560px) {
  h1 { font-size: 17px; }
  .tagline { display: none; }
  .doc-list li { flex-direction: column; gap: 2px; }
  .foot { flex-direction: column; }
}
