:root {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 8px;
  --row-h: 26px;
  --head-h: 32px;
  color-scheme: dark;
  --bg: #0e1015;
  --panel: #14171f;
  --panel-2: #1a1e28;
  --panel-3: #222736;
  --border: #272c3a;
  --border-strong: #353c4f;
  --text: #d8dce6;
  --text-strong: #f2f4f8;
  --muted: #8a92a6;
  --faint: #5d6478;
  --accent: #7aa7ff;
  --accent-2: #86e1b9;
  --accent-soft: rgba(122, 167, 255, 0.14);
  --warn: #f1b75f;
  --danger: #ff7a85;
  --ok: #6fd3a1;
  --sel: rgba(122, 167, 255, 0.22);
  --row-alt: rgba(255, 255, 255, 0.018);
  --row-hover: rgba(122, 167, 255, 0.07);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --kw: #c792ea;
  --str: #c3e88d;
  --num: #f78c6c;
  --cmt: #637089;
  --fn: #82aaff;
  --ident: #ffcb6b;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f9;
  --panel: #ffffff;
  --panel-2: #f3f5f9;
  --panel-3: #e9edf4;
  --border: #e1e5ed;
  --border-strong: #cbd2de;
  --text: #1f2532;
  --text-strong: #0d1220;
  --muted: #5f6779;
  --faint: #9aa2b4;
  --accent: #2f6fec;
  --accent-2: #138a5b;
  --accent-soft: rgba(47, 111, 236, 0.1);
  --warn: #b26b00;
  --danger: #d33a4a;
  --ok: #138a5b;
  --sel: rgba(47, 111, 236, 0.16);
  --row-alt: rgba(15, 30, 60, 0.025);
  --row-hover: rgba(47, 111, 236, 0.06);
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.15);
  --kw: #8e3ec8;
  --str: #2f7d32;
  --num: #c2410c;
  --cmt: #8a94a8;
  --fn: #1d5fd1;
  --ident: #9a6700;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.45 var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--font-mono); }
::selection { background: var(--sel); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--side-w, 272px) 1fr;
  grid-template-rows: 48px 1fr;
  height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text-strong); white-space: nowrap; }
.brand svg { width: 20px; height: 20px; }
.dbpick { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); }
.dbpick select { max-width: 260px; }
.dbname { color: var(--text-strong); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 2px; background: var(--panel-2); padding: 3px; border-radius: 9px; border: 1px solid var(--border); }
.tabs button {
  border: 0; background: transparent; padding: 5px 14px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 550;
  display: flex; align-items: center; gap: 6px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--panel); color: var(--text-strong); box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.tabs kbd { font-size: 10px; color: var(--faint); }
.spacer { flex: 1; }
.pill { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.busy::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-right: 6px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.sidebar .search { margin: 10px 10px 6px; }
.side-scroll { overflow: auto; flex: 1; padding-bottom: 16px; }
.side-section { margin-top: 6px; }
.side-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--faint); font-weight: 650; cursor: pointer; user-select: none;
}
.side-head .count { margin-left: auto; font-weight: 500; letter-spacing: 0; }
.side-head .chev { transition: transform .15s; }
.side-section.collapsed .chev { transform: rotate(-90deg); }
.side-section.collapsed .side-list { display: none; }
.side-list { list-style: none; margin: 0; padding: 0 6px; }
.side-item {
  display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 7px; padding: 4px 8px; border-radius: 6px;
  cursor: pointer; color: var(--text); min-width: 0;
}
.side-item:hover { background: var(--panel-2); }
.side-item.active { background: var(--accent-soft); color: var(--text-strong); }
.side-item .ic { color: var(--faint); display: flex; }
.side-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .meta { font-size: 11px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.side-item .acts { display: none; gap: 2px; }
.side-item:hover .acts { display: flex; }
.side-item:hover .acts + .meta { display: none; }
.side-empty { padding: 4px 18px; color: var(--faint); font-size: 12px; }
.resizer-x { position: absolute; right: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 5; }

main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 7px; border: 1px solid var(--border-strong);
  background: var(--panel-2); color: var(--text); cursor: pointer; white-space: nowrap; font-weight: 520; line-height: 1.35;
}
.btn:hover { background: var(--panel-3); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root:not([data-theme="light"]) .btn.primary { color: #0b1020; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.icon { padding: 5px 7px; }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn kbd { font-size: 10.5px; opacity: .65; font-family: var(--font-ui); }
input[type="text"], input[type="search"], input:not([type]), select, textarea {
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: 7px; padding: 5px 9px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { padding-right: 4px; }
.mono-input { font-family: var(--font-mono); font-size: 12.5px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--panel-2); padding: 4px 10px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--text-strong); }
.sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--panel-3);
  color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge.accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.badge.warn { color: var(--warn); }
.badge.ok { color: var(--ok); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.err { color: var(--danger); }
.small { font-size: 12px; }

/* ---------- object header / toolbars ---------- */
.objhead {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px 8px; flex-wrap: wrap; border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.objhead h2 { margin: 0; font-size: 16px; font-weight: 650; color: var(--text-strong); display: flex; align-items: center; gap: 8px; }
.objhead .badges { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap;
}
.toolbar label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.toolbar .grow { flex: 1; min-width: 180px; display: flex; }
.toolbar .grow input { flex: 1; }
.statusbar {
  display: flex; align-items: center; gap: 12px; padding: 5px 14px; border-top: 1px solid var(--border); background: var(--panel);
  color: var(--muted); font-size: 12px; min-height: 30px; white-space: nowrap; overflow: hidden;
}
.statusbar .sql { overflow: hidden; text-overflow: ellipsis; font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); cursor: pointer; }
.statusbar .sql:hover { color: var(--muted); }
.statusbar .error { color: var(--danger); white-space: normal; }

/* ---------- grid ---------- */
.grid-wrap { flex: 1; min-height: 0; position: relative; background: var(--bg); }
.grid { position: absolute; inset: 0; overflow: auto; outline: none; font-family: var(--font-mono); font-size: 12.5px; }
.grid .sizer { position: relative; }
.grid .ghead {
  position: sticky; top: 0; z-index: 3; height: var(--head-h); background: var(--panel-2); border-bottom: 1px solid var(--border-strong);
}
.grid .hc {
  position: absolute; top: 0; height: var(--head-h); padding: 0 8px; display: flex; align-items: center; gap: 5px;
  font-family: var(--font-ui); font-weight: 600; font-size: 12px; color: var(--text-strong); border-right: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap; overflow: hidden;
}
.grid .hc:hover { background: var(--panel-3); }
.grid .hc .t { overflow: hidden; text-overflow: ellipsis; }
.grid .hc .ty { color: var(--faint); font-weight: 500; font-size: 10.5px; }
.grid .hc .ix { color: var(--accent-2); font-size: 10px; }
.grid .hc .so { color: var(--accent); font-size: 10px; }
.grid .hc.doc .t { text-decoration: underline dotted var(--faint); text-underline-offset: 3px; }
.grid .hc .rz { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.grid .rn-head, .grid .rn {
  position: sticky; left: 0; z-index: 2; background: var(--panel-2); color: var(--faint);
  text-align: right; padding: 0 8px; border-right: 1px solid var(--border-strong); font-size: 11px;
}
.grid .ghead .rn-head { z-index: 4; height: var(--head-h); display: flex; align-items: center; justify-content: flex-end; }
.grid .gbody { position: absolute; left: 0; top: var(--head-h); }
.grid .r { position: absolute; left: 0; height: var(--row-h); }
.grid .r:nth-child(even) .c { background: var(--row-alt); }
.grid .r:hover .c { background: var(--row-hover); }
.grid .r .rn { height: var(--row-h); line-height: var(--row-h); cursor: pointer; border-bottom: 1px solid var(--border); }
.grid .r.sel .rn { color: var(--accent); }
.grid .c {
  position: absolute; top: 0; height: var(--row-h); line-height: var(--row-h); padding: 0 8px; white-space: pre; overflow: hidden;
  text-overflow: ellipsis; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); color: var(--text);
}
.grid .c.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .c.null { color: var(--faint); font-style: italic; }
.grid .c.date { color: var(--accent-2); }
.grid .c.blob, .grid .c.trunc { color: var(--warn); }
.grid .c.cur { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--sel) !important; z-index: 1; }
.grid .loading-row { position: absolute; left: 0; height: var(--row-h); line-height: var(--row-h); padding-left: 70px; color: var(--muted); font-family: var(--font-ui); }
.grid-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); flex-direction: column; gap: 8px; pointer-events: none; text-align: center; padding: 20px; }
.grid-empty .big { font-size: 15px; color: var(--text); }
.grid-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.08); display: flex; align-items: flex-start; justify-content: center; padding-top: 70px; z-index: 6; pointer-events: none; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-card { pointer-events: auto; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); }

/* ---------- schema panel ---------- */
.schema-panel { max-height: 40vh; overflow: auto; border-bottom: 1px solid var(--border); background: var(--panel); padding: 8px 14px 12px; }
.schema-panel table { border-collapse: collapse; width: 100%; font-size: 12px; }
.schema-panel th { text-align: left; color: var(--faint); font-weight: 600; padding: 4px 8px; position: sticky; top: -8px; background: var(--panel); }
.schema-panel td { padding: 3px 8px; border-top: 1px solid var(--border); vertical-align: top; }
.schema-panel td.mono { white-space: nowrap; }
.schema-panel pre { white-space: pre-wrap; background: var(--panel-2); padding: 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 12px; max-height: 240px; overflow: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--font-mono); font-size: 11.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--panel-2); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text-strong); }

/* ---------- SQL editor ---------- */
.sqlpane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.editor-wrap { position: relative; height: var(--editor-h, 34vh); min-height: 90px; border-bottom: 1px solid var(--border); background: var(--panel); }
.editor { position: absolute; inset: 0; }
.editor pre, .editor textarea {
  position: absolute; inset: 0; margin: 0; padding: 12px 14px 12px 52px; font: 13.5px/1.6 var(--font-mono); white-space: pre; overflow: auto;
  tab-size: 2; border: 0; border-radius: 0; letter-spacing: 0; word-spacing: 0;
}
.editor pre { pointer-events: none; color: var(--text); background: transparent; overflow: hidden; }
.editor textarea { color: transparent; caret-color: var(--text-strong); background: transparent; resize: none; outline: none; box-shadow: none !important; }
.editor textarea::selection { background: var(--sel); color: transparent; }
.editor .gutter {
  position: absolute; left: 0; top: 0; bottom: 0; width: 42px; padding: 12px 8px 12px 0; text-align: right; color: var(--faint);
  font: 13.5px/1.6 var(--font-mono); overflow: hidden; border-right: 1px solid var(--border); user-select: none; background: var(--panel);
}
.editor .gutter div.cur { color: var(--text); }
.tok-kw { color: var(--kw); font-weight: 600; }
.tok-fn { color: var(--fn); }
.tok-str { color: var(--str); }
.tok-num { color: var(--num); }
.tok-cmt { color: var(--cmt); font-style: italic; }
.tok-id { color: var(--ident); }
.tok-tbl { color: var(--accent-2); }
.tok-active { background: var(--accent-soft); border-radius: 3px; box-shadow: 0 0 0 1px var(--accent-soft); }
.resizer-y { height: 6px; margin-top: -3px; cursor: row-resize; position: relative; z-index: 4; }
.complete {
  position: absolute; z-index: 20; min-width: 220px; max-width: 420px; max-height: 240px; overflow: auto; background: var(--panel);
  border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); font: 12.5px var(--font-mono); padding: 3px;
}
.complete div { padding: 3px 8px; border-radius: 5px; display: flex; gap: 10px; justify-content: space-between; cursor: pointer; white-space: nowrap; }
.complete div.on { background: var(--accent-soft); color: var(--text-strong); }
.complete .k { color: var(--faint); font-family: var(--font-ui); font-size: 11px; }
.docname { font-weight: 600; color: var(--text-strong); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dirty::after { content: " ●"; color: var(--warn); }
.plan { padding: 14px 18px; overflow: auto; flex: 1; font-family: var(--font-mono); font-size: 12.5px; }
.plan ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed var(--border-strong); }
.plan > ul { border-left: 0; padding-left: 0; }
.plan li { padding: 3px 0; }
.plan .scan { color: var(--warn); }
.plan .search { color: var(--ok); }

/* ---------- record drawer ---------- */
.drawer {
  position: fixed; top: 48px; right: 0; bottom: 0; width: min(720px, 92vw); background: var(--panel); border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow); z-index: 30; display: flex; flex-direction: column; transform: translateX(105%); transition: transform .18s ease;
}
.drawer.open { transform: none; }
.drawer header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.drawer header h3 { margin: 0; font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer .body { overflow: auto; flex: 1; padding: 8px 12px 30px; }
.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.kv td { padding: 4px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv td.k { width: 36%; color: var(--muted); font-family: var(--font-mono); word-break: break-all; }
.kv td.k .d { display: block; font-family: var(--font-ui); color: var(--faint); font-size: 11px; margin-top: 2px; word-break: normal; }
.kv td.v { font-family: var(--font-mono); white-space: pre-wrap; word-break: break-word; }
.kv td.v.null { color: var(--faint); font-style: italic; }
.kv td.v .raw { color: var(--faint); font-size: 11px; margin-left: 8px; }
.pivot { margin: 14px 0; }
.pivot h4 { margin: 0 0 6px; font-size: 12.5px; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.pivot .pv-scroll { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.pivot table { border-collapse: collapse; font-family: var(--font-mono); font-size: 12px; width: 100%; }
.pivot th { position: sticky; top: 0; background: var(--panel-2); text-align: right; padding: 4px 8px; font-weight: 600; color: var(--text-strong); border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.pivot th:first-child, .pivot td:first-child { text-align: right; color: var(--faint); position: sticky; left: 0; background: var(--panel-2); }
.pivot td { padding: 2px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pivot td.null { color: var(--faint); }
.pivot td.date { color: var(--accent-2); }

/* ---------- chat ---------- */
.ask { display: grid; grid-template-columns: 240px 1fr; min-height: 0; flex: 1; }
.chatlist { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chatlist .top { padding: 10px; display: flex; gap: 6px; }
.chatlist ul { list-style: none; margin: 0; padding: 0 6px 10px; overflow: auto; flex: 1; }
.chatlist li { padding: 7px 9px; border-radius: 7px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; position: relative; }
.chatlist li:hover { background: var(--panel-2); }
.chatlist li.active { background: var(--accent-soft); }
.chatlist li .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); padding-right: 18px; }
.chatlist li .m { font-size: 11px; color: var(--faint); }
.chatlist li .x { position: absolute; right: 6px; top: 7px; display: none; }
.chatlist li:hover .x { display: block; }
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-scroll { flex: 1; overflow: auto; padding: 18px 0 30px; }
.chat-inner { max-width: 920px; margin: 0 auto; padding: 0 22px; display: flex; flex-direction: column; gap: 14px; }
.msg-user { align-self: flex-end; max-width: 80%; background: var(--accent-soft); border: 1px solid var(--border); padding: 9px 13px; border-radius: 12px 12px 3px 12px; white-space: pre-wrap; color: var(--text-strong); }
.msg-ai { line-height: 1.6; }
.msg-ai .who { font-size: 11.5px; color: var(--faint); margin-bottom: 2px; display: flex; gap: 8px; align-items: center; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 16px 0 8px; color: var(--text-strong); line-height: 1.3; }
.md h1 { font-size: 18px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14.5px; } .md h4 { font-size: 13.5px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { background: var(--panel-3); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.md blockquote { margin: 0 0 10px; padding: 2px 12px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md table { border-collapse: collapse; margin: 6px 0 12px; font-size: 12.5px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 9px; text-align: left; }
.md th { background: var(--panel-2); color: var(--text-strong); }
.md td.n { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.codeblock { margin: 0 0 12px; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--panel); }
.codeblock .cb-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; background: var(--panel-2); border-bottom: 1px solid var(--border); font-size: 11.5px; color: var(--faint); }
.codeblock .cb-head .lang { flex: 1; }
.codeblock pre { margin: 0; padding: 10px 12px; overflow: auto; font-size: 12.5px; line-height: 1.55; max-height: 420px; }
.toolcard { border: 1px solid var(--border); border-radius: 10px; background: var(--panel); font-size: 12.5px; overflow: hidden; }
.toolcard .tc-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer; }
.toolcard .tc-head .nm { font-weight: 600; color: var(--text-strong); font-family: var(--font-mono); font-size: 12px; }
.toolcard .tc-head .sum { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolcard .tc-body { border-top: 1px solid var(--border); padding: 8px 10px; display: none; }
.toolcard.open .tc-body { display: block; }
.toolcard pre { margin: 0 0 8px; white-space: pre-wrap; font-size: 12px; max-height: 260px; overflow: auto; }
.toolcard .preview { overflow: auto; max-height: 240px; border: 1px solid var(--border); border-radius: 6px; }
.toolcard .preview table { border-collapse: collapse; font-family: var(--font-mono); font-size: 11.5px; }
.toolcard .preview th, .toolcard .preview td { padding: 2px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
.toolcard .preview th { background: var(--panel-2); position: sticky; top: 0; }
.toolcard .acts { display: flex; gap: 6px; margin-top: 8px; }
.tc-icon { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; flex: none; }
.tc-icon.ok { background: rgba(111, 211, 161, .15); color: var(--ok); }
.tc-icon.bad { background: rgba(255, 122, 133, .15); color: var(--danger); }
.thinking { border-left: 2px solid var(--border-strong); padding: 2px 10px; color: var(--faint); font-size: 12px; white-space: pre-wrap; max-height: 160px; overflow: auto; }
.thinking-head { font-size: 11.5px; color: var(--faint); cursor: pointer; user-select: none; }
.notice { font-size: 12px; color: var(--muted); padding: 6px 10px; border-radius: 8px; background: var(--panel-2); border: 1px dashed var(--border-strong); }
.notice.warn { color: var(--warn); }
.notice.error { color: var(--danger); border-style: solid; }
.turn-usage { font-size: 11px; color: var(--faint); display: flex; gap: 10px; flex-wrap: wrap; }
.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 10px 14px 12px; }
.composer-inner { max-width: 920px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { width: 100%; resize: none; min-height: 46px; max-height: 240px; padding: 10px 12px; border-radius: 10px; line-height: 1.5; }
.composer .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.composer select { max-width: 230px; }
.ctxbar { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--faint); }
.ctxbar .bar { width: 110px; height: 6px; border-radius: 3px; background: var(--panel-3); overflow: hidden; }
.ctxbar .bar i { display: block; height: 100%; background: var(--accent); width: 0; }
.starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 10px; }
.starter { border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 10px 12px; cursor: pointer; color: var(--text); text-align: left; }
.starter:hover { border-color: var(--accent); }
.hero { text-align: center; padding: 40px 10px 10px; color: var(--muted); }
.hero h2 { color: var(--text-strong); margin: 0 0 6px; font-size: 20px; }
.typing::after { content: "▍"; animation: pulse 1s infinite; color: var(--accent); }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(5, 8, 15, .55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { width: min(1000px, 100%); }
.modal header { padding: 14px 16px 6px; font-weight: 650; font-size: 15px; color: var(--text-strong); }
.modal .mbody { padding: 6px 16px 10px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal .mbody label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; }
.modal footer { padding: 10px 16px 14px; display: flex; gap: 8px; justify-content: flex-end; }
.modal pre.brief { white-space: pre-wrap; font-size: 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin: 0; }
.modal textarea.notes { min-height: 320px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; }
.toasts { position: fixed; bottom: 16px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel); border: 1px solid var(--border-strong); box-shadow: var(--shadow); border-radius: 9px; padding: 9px 13px; max-width: 420px; animation: rise .15s ease-out; }
.toast.err { border-color: var(--danger); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.menu { position: absolute; z-index: 40; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 9px; box-shadow: var(--shadow); padding: 4px; min-width: 200px; }
.menu button { display: flex; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; cursor: pointer; gap: 8px; }
.menu button:hover { background: var(--panel-2); }
.menu .mi-sep { height: 1px; background: var(--border); margin: 4px 0; }
.popover { position: fixed; z-index: 45; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 9px; box-shadow: var(--shadow); padding: 10px 12px; max-width: min(640px, 90vw); max-height: 60vh; overflow: auto; font-family: var(--font-mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }

/* ---------- auth pages ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background:
  radial-gradient(1200px 600px at 10% -10%, rgba(122,167,255,.12), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(134,225,185,.08), transparent 60%), var(--bg); }
.auth-card { width: min(560px, 100%); background: var(--panel); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: var(--shadow); padding: 26px 28px; }
.auth-card h1 { margin: 0 0 4px; font-size: 20px; color: var(--text-strong); display: flex; align-items: center; gap: 10px; }
.auth-card h1 svg { width: 26px; height: 26px; }
.auth-card p { color: var(--muted); margin: 8px 0; }
.auth-card .big-btn { width: 100%; justify-content: center; padding: 10px; font-size: 14px; margin-top: 14px; }
.auth-card .status { min-height: 22px; margin-top: 12px; font-size: 12.5px; }
.auth-card .opts { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.auth-card .opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; }
.auth-card .opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.auth-card .opt input { margin-top: 3px; }
.auth-card .opt b { color: var(--text-strong); font-weight: 600; }
.auth-card .opt span { display: block; color: var(--muted); font-size: 12px; }
.auth-card label.field { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; margin-top: 10px; }
.cmd { position: relative; margin-top: 10px; }
.cmd pre { background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: 9px; padding: 12px; white-space: pre-wrap; word-break: break-all; font-size: 12px; max-height: 220px; overflow: auto; margin: 0; }
.cmd .btn { position: absolute; top: 8px; right: 8px; }
.steps { margin: 12px 0 0; padding-left: 20px; color: var(--muted); }
.steps li { margin: 4px 0; }
.warnbox { border: 1px solid var(--warn); color: var(--warn); border-radius: 9px; padding: 8px 12px; font-size: 12.5px; margin-top: 10px; }
.footer-links { margin-top: 18px; display: flex; justify-content: space-between; font-size: 12.5px; }
