:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --side: #10151f;
  --side-text: #c9d1dd;
  --side-muted: #7d8899;
  --side-hover: #1b2331;
  --text: #161b24;
  --muted: #5d6676;
  --line: #e2e6ec;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --accent-soft: #e8eefc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #067647;
  --user-bubble: #e8eefc;
  --code-bg: #0f1520;
  --code-text: #e4e9f1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 21, 31, 0.06), 0 4px 16px rgba(16, 21, 31, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --panel: #151b24;
    --side: #090c12;
    --side-hover: #161d29;
    --text: #e6eaf0;
    --muted: #9aa4b2;
    --line: #273040;
    --accent: #5b8def;
    --accent-text: #0b1020;
    --accent-soft: #1c2840;
    --danger: #ff8a7f;
    --danger-soft: #3a1b1b;
    --ok: #4cc38a;
    --user-bubble: #1c2840;
    --code-bg: #0a0e15;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 10px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 8px 12px; }
.error { color: var(--danger); font-size: 14px; min-height: 0; margin: 6px 0; }
.error:empty { display: none; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.spread { justify-content: space-between; }
.stack { display: grid; gap: 6px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.stop { border-color: var(--danger); color: var(--danger); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
.danger-text { color: var(--danger); }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 8px; height: 34px; min-width: 34px; cursor: pointer; color: inherit; font-size: 16px; }
.icon-btn:hover { border-color: var(--line); }
.icon-btn.small { height: 26px; min-width: 26px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit;
}
textarea.input { height: auto; padding: 10px 11px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.input.small { height: 32px; font-size: 13px; padding: 0 8px; width: auto; max-width: 100%; }
.label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0; cursor: pointer; }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 6px; margin: 16px 0 0; }
.fieldset legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.form .btn[type="submit"] { margin-top: 14px; }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.auth-card h1 { margin-top: 14px; }
.switch { margin-top: 16px; font-size: 14px; color: var(--muted); }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: none; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; top: 9px; width: 5px; height: 5px; border-radius: 50%; background: #fff; }
.brand-mark::before { left: 7px; }
.brand-mark::after { right: 7px; }
.brand-mark.big { width: 44px; height: 44px; border-radius: 12px; }
.brand-mark.big::before, .brand-mark.big::after { top: 15px; width: 8px; height: 8px; }
.brand-mark.big::before { left: 11px; }
.brand-mark.big::after { right: 11px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 272px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 14px 12px; gap: 12px; min-height: 0; }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px 4px; }
.brand { font-weight: 700; color: #fff; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .btn.primary { color: #fff; }
.nav { display: grid; gap: 2px; }
.nav a, .chat-list a { color: var(--side-text); padding: 7px 10px; border-radius: 8px; display: block; }
.nav a:hover, .chat-list a:hover { background: var(--side-hover); }
.nav a.on, .chat-list a.on { background: var(--side-hover); color: #fff; }
.chat-list-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--side-muted); padding: 4px 10px 0; }
.chat-list { overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 1px; }
.chat-list a { min-width: 0; }
.chat-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-meta { display: block; font-size: 12px; color: var(--side-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .muted { color: var(--side-muted); }
.sidebar-foot { border-top: 1px solid #222b3a; padding-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot .link { color: var(--side-muted); }
.me { display: flex; align-items: center; gap: 8px; color: var(--side-text); min-width: 0; }
.me span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #2a3546; color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; }
.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 58px; }
.topbar-title { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; }
.topbar-title .picker { max-width: 340px; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.menu-btn { display: none; }
.chat-head { display: flex; gap: 10px; align-items: center; min-width: 0; flex-wrap: wrap; }
.chat-name { background: none; border: 0; font: inherit; font-weight: 650; color: var(--text); cursor: pointer; padding: 4px 6px; border-radius: 6px; max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-name:hover { background: var(--bg); }
.pill { font-size: 13px; background: var(--accent-soft); color: var(--accent); padding: 3px 10px; border-radius: 99px; font-weight: 600; }
.tag { font-size: 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 0 7px; margin-left: 6px; color: var(--muted); font-weight: 500; }

/* ---------- chat thread ---------- */
.thread { flex: 1; overflow-y: auto; padding: 24px max(18px, calc((100% - 820px) / 2)); min-height: 0; }
.thread.centered { display: flex; flex-direction: column; justify-content: center; text-align: center; }
.intro h2 { font-size: 24px; }
.starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 18px auto 0; max-width: 760px; width: 100%; }
.starter { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font: inherit; color: var(--text); cursor: pointer; }
.starter:hover { border-color: var(--accent); }
.msg { margin: 0 0 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); padding: 10px 14px; border-radius: 14px 14px 4px 14px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-head { font-size: 12px; font-weight: 650; color: var(--muted); margin-bottom: 4px; text-transform: none; }
.msg-actions { display: flex; gap: 14px; align-items: center; margin-top: 4px; opacity: 0.85; }
.error-msg { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius); padding: 12px 14px; }
.error-msg p { margin-bottom: 8px; }

.md { overflow-wrap: anywhere; }
.md p, .md ul, .md ol, .md blockquote, .md .table-wrap, .md .code { margin: 0 0 12px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 3px 0; }
.md h3, .md h4, .md h5, .md h6 { margin: 18px 0 8px; }
.md code { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 0.92em; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.code { border-radius: var(--radius); overflow: hidden; background: var(--code-bg); border: 1px solid var(--line); }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-size: 12px; color: #9aa4b2; border-bottom: 1px solid #1f2836; }
.copy-code { background: none; border: 0; color: #c9d1dd; cursor: pointer; font: inherit; }
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; color: var(--code-text); font-size: 13px; line-height: 1.5; }
.code pre code { background: none; border: 0; padding: 0; color: inherit; }
.table-wrap { overflow-x: auto; }
.md table, .table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td, .table th, .table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.md th, .table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; }
.table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.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; } }

/* ---------- composer ---------- */
.composer-wrap { padding: 10px max(18px, calc((100% - 820px) / 2)) 14px; background: linear-gradient(to bottom, transparent, var(--bg) 30%); }
.composer { display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: var(--accent); }
.composer-input { flex: 1; border: 0; resize: none; background: transparent; color: var(--text); font: inherit; padding: 7px 8px; max-height: 260px; outline: none; }
.notice { font-size: 12px; color: var(--muted); margin: 8px 4px 0; text-align: center; }

/* ---------- compare ---------- */
.compare-bar { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: var(--panel); }
.compare-pick { display: grid; gap: 2px; }
.compare-area { flex: 1; min-height: 0; overflow: auto; padding: 16px 18px; }
.compare-cols { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(260px, 1fr)); gap: 14px; min-height: 100%; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; min-width: 0; }
.col-head { font-weight: 650; font-size: 14px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.col .md { flex: 1; }
.col-foot { display: flex; gap: 12px; align-items: center; padding-top: 10px; }
.col-foot:empty { display: none; }

/* ---------- pages ---------- */
.page { flex: 1; overflow-y: auto; padding: 22px max(18px, calc((100% - 1100px) / 2)); min-height: 0; }
.card.narrow { max-width: 760px; }
.page.narrow { padding-left: max(18px, calc((100% - 760px) / 2)); padding-right: max(18px, calc((100% - 760px) / 2)); }
.empty { text-align: center; padding: 60px 20px; max-width: 520px; margin: 0 auto; }
.small-empty { grid-column: 1 / -1; padding: 40px 10px; }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 14px; }
.agent-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.agent-card h3 { margin: 0; }
.agent-top { display: flex; gap: 10px; align-items: center; }
.agent-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.agent-desc { flex: 1; }
.files { display: grid; gap: 8px; }
.file-input { display: none; }
.file-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.file-list li { display: flex; gap: 10px; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.file-list li span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }

.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--panel); overflow-x: auto; }
.tabs a { padding: 11px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 550; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.card.highlight { border-color: var(--accent); }
.pending-row { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-check { display: inline-flex; gap: 5px; align-items: center; font-size: 13px; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px 3px 7px; cursor: pointer; white-space: nowrap; }
.chip-check:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.catalog { margin-top: 10px; max-height: 460px; overflow-y: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 8px 0; }
.stat { background: var(--bg); border-radius: var(--radius); padding: 12px; display: grid; gap: 2px; }
.stat strong { font-size: 20px; font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; margin: 12px 0 8px; color: var(--muted); }

/* ---------- modal & toast ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(5, 8, 14, 0.5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 14px; padding: 20px; width: 100%; max-width: 440px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); display: grid; gap: 12px; }
.modal .label { margin-top: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); background: var(--side); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: 0.25s; z-index: 60; max-width: calc(100% - 32px); font-size: 14px; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar-open .sidebar { transform: none; }
  .sidebar-open .scrim { display: block; position: fixed; inset: 0; background: rgba(5, 8, 14, 0.45); z-index: 30; }
  .menu-btn { display: inline-block; }
  .topbar { padding: 8px 12px; }
  .compare-cols { grid-template-columns: 1fr; }
  .pending-row { grid-template-columns: 1fr; }
  .chat-name { max-width: 200px; }
  .msg.user .bubble { max-width: 92%; }
}
