/* nguon1-api admin UI — vanilla CSS, dark theme by default, light via html[data-theme=light] */

:root {
  color-scheme: dark;
  --bg: #0e1015;
  --surface: #161920;
  --surface-2: #1c2029;
  --surface-3: #252a35;
  --border: #2a303c;
  --border-strong: #3a4150;
  --text: #e8eaef;
  --text-2: #b0b6c3;
  --muted: #7d8496;
  --accent: #4d8dff;
  --accent-2: #3a78ea;
  --accent-soft: rgba(77, 141, 255, .14);
  --accent-ink: #ffffff;
  --ok: #34c37a;
  --ok-soft: rgba(52, 195, 122, .14);
  --warn: #e3a516;
  --warn-soft: rgba(227, 165, 22, .14);
  --err: #f06464;
  --err-soft: rgba(240, 100, 100, .13);
  --info: #4ca3ff;
  --info-soft: rgba(76, 163, 255, .13);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-err: #e66767;
  --grid: #262b36;
  --code-bg: #0b0d11;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --radius: 10px;
  --radius-sm: 7px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f3f4f7;
  --surface-3: #e9ebf0;
  --border: #dfe2e8;
  --border-strong: #c9ced8;
  --text: #14161b;
  --text-2: #4b5263;
  --muted: #767d8f;
  --accent: #2a6ae0;
  --accent-2: #1f5bcc;
  --accent-soft: rgba(42, 106, 224, .10);
  --ok: #138a4b;
  --ok-soft: rgba(19, 138, 75, .10);
  --warn: #a87400;
  --warn-soft: rgba(168, 116, 0, .11);
  --err: #cf3434;
  --err-soft: rgba(207, 52, 52, .09);
  --info: #1f6fd1;
  --info-soft: rgba(31, 111, 209, .10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-err: #e34948;
  --grid: #e8eaef;
  --code-bg: #f6f7f9;
  --shadow: 0 10px 30px rgba(20, 25, 40, .14);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre, .mono { font-family: var(--mono); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1 1 auto; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.ic { width: 16px; height: 16px; flex: none; vertical-align: -3px; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px; height: 56px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand .logo {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8a5cff); color: #fff; font-size: 13px; font-weight: 800;
}
.brand small { color: var(--muted); font-weight: 500; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; height: 100%; align-items: stretch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: flex; align-items: center; gap: 7px; padding: 0 12px; color: var(--text-2);
  border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500;
}
.tabs a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

main#view { max-width: 1400px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-h h2, .card-h h3 { font-size: 15px; font-weight: 650; }
.card-h .spacer { flex: 1; }
.card.flush { padding: 0; }
.card.flush > .card-h { padding: 14px 16px 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid > .card + .card, .chat-layout > .card + .card { margin-top: 0; }
.grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
@media (max-width: 960px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); } }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px; min-width: 0;
}
.stat .lbl { color: var(--muted); font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .val { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .sub { color: var(--text-2); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .sub .ok { color: var(--ok); } .stat .sub .err { color: var(--err); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  cursor: pointer; font-weight: 550; white-space: nowrap; user-select: none;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:focus-visible, .input:focus-visible, select:focus-visible, textarea:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger:hover { filter: brightness(.95); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn.block { width: 100%; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.seg button {
  border: 0; background: transparent; padding: 0 11px; height: 28px; border-radius: 5px;
  color: var(--text-2); cursor: pointer; font-weight: 550; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }

/* ---------- Forms ---------- */
.input, select.input, textarea.input {
  width: 100%; height: 34px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  min-width: 0;
}
textarea.input { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 26px; }
.input::placeholder, textarea.input::placeholder { color: var(--muted); }
.input.mono { font-size: 12.5px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .lbl { font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.field .hint { font-size: 12px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid .span-2 { grid-column: 1 / -1; } }
.input-group { display: flex; gap: 0; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; }
.form-error { color: var(--err); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }
fieldset.group { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; min-width: 0; }
fieldset.group + fieldset.group { margin-top: 14px; }
fieldset.group legend { padding: 0 6px; font-weight: 650; font-size: 13.5px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 36px; height: 20px; border-radius: 20px; background: var(--surface-3); border: 1px solid var(--border-strong);
  position: relative; transition: background .15s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-2); transition: transform .15s, background .15s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }

.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 12px; max-height: 190px; overflow: auto; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.checklist label { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; min-width: 0; }
.checklist label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.err { background: var(--err); } .dot.warn { background: var(--warn); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,195,122,.5); } 70% { box-shadow: 0 0 0 7px rgba(52,195,122,0); } 100% { box-shadow: 0 0 0 0 rgba(52,195,122,0); } }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.card.flush .tbl-wrap { border-radius: 0 0 var(--radius) var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.tbl th, table.tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
table.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; z-index: 1; }
table.tbl td.num, table.tbl th.num { text-align: right; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.row-err { background: var(--err-soft); }
table.tbl tr.row-err:hover { background: color-mix(in srgb, var(--err-soft) 100%, var(--surface-2)); }
table.tbl tr.row-dim td { opacity: .6; }
table.tbl td.wrap { white-space: normal; min-width: 180px; }
table.tbl .actions { display: flex; gap: 4px; justify-content: flex-end; }
table.tbl tfoot td { font-weight: 650; border-top: 1px solid var(--border-strong); border-bottom: 0; }

/* ---------- States ---------- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%; display: inline-block; flex: none;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 36px 16px; color: var(--muted); text-align: center; }
.state .title { color: var(--text-2); font-weight: 600; }
.state.err .title { color: var(--err); }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.notice.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.notice.err { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.notice.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.skel { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 9px; max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 13.5px;
  animation: toastIn .18s ease-out;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--err); }
.toast.info { border-left: 3px solid var(--info); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(5, 7, 12, .55); display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fadeIn .12s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 480px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow);
}
.modal.wide { max-width: 720px; }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-h h3 { font-size: 16px; font-weight: 650; flex: 1; }
.modal-b { padding: 16px; overflow: auto; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.secret-box { display: flex; gap: 6px; align-items: center; padding: 8px 10px; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.secret-box span { flex: 1; }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(5, 7, 12, .45); animation: fadeIn .12s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 71; width: min(640px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border-strong); box-shadow: var(--shadow);
  display: flex; flex-direction: column; animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-h h3 { flex: 1; font-size: 16px; }
.drawer-b { flex: 1; overflow: auto; padding: 16px; }
dl.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 6px 12px; margin: 0 0 16px; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { dl.kv { grid-template-columns: 120px minmax(0, 1fr); } }
.pre-block { position: relative; margin: 0 0 14px; }
.pre-block .pre-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }
pre.code {
  margin: 0; padding: 10px 12px; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12px; line-height: 1.5; overflow: auto; max-height: 360px; white-space: pre-wrap; word-break: break-word;
}

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; min-height: 200px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart .hover-band { fill: var(--text); opacity: .05; pointer-events: none; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 140px;
  background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 12px; color: var(--text); transform: translate(-50%, -100%); white-space: nowrap;
}
.chart-tip .t { color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.chart-tip .r { display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; }
.chart-tip .r b { margin-left: auto; padding-left: 12px; font-weight: 650; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend .sw, .chart-tip .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.legend span.item { display: inline-flex; align-items: center; gap: 6px; }

/* queue widget */
.queue { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.queue .q { min-width: 0; }
.queue .q .lbl { font-size: 12px; color: var(--muted); }
.queue .q .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--surface-3); border-radius: 6px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .4s; }
.bar.warn > i { background: var(--warn); } .bar.err > i { background: var(--err); }

/* pricing */
.avail { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; }
.calc-result { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 12px; padding: 12px; background: var(--surface-2); border-radius: var(--radius-sm); }
.calc-result .total { font-size: 18px; font-weight: 700; color: var(--accent); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 11.5px; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }

/* pagination */
.pager { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager .info { color: var(--muted); font-size: 13px; }
.pager .spacer { flex: 1; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.filters .field.q { grid-column: span 2; }
@media (max-width: 560px) { .filters .field.q { grid-column: 1 / -1; } }

/* ---------- Docs ---------- */
.docs-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 24px; align-items: start; }
.toc { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto; font-size: 13px; padding: 4px 0; }
.toc .toc-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; margin: 0 0 8px 10px; }
.toc a { display: block; padding: 4px 10px; color: var(--text-2); border-left: 2px solid var(--border); line-height: 1.35; }
.toc a.l3 { padding-left: 22px; font-size: 12.5px; }
.toc a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }
@media (max-width: 900px) {
  .docs-layout { grid-template-columns: minmax(0, 1fr); }
  .toc { position: static; max-height: 260px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 0; }
}
.docs { line-height: 1.65; font-size: 14.5px; max-width: 920px; }
.docs section { padding-bottom: 8px; scroll-margin-top: 72px; }
.docs h1 { font-size: 26px; margin: 0 0 12px; }
.docs h2 { font-size: 21px; margin: 30px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); scroll-margin-top: 72px; }
.docs h3 { font-size: 16.5px; margin: 22px 0 8px; scroll-margin-top: 72px; }
.docs h4 { font-size: 14.5px; margin: 16px 0 6px; }
.docs > :first-child, .docs section:first-child > h2:first-child { margin-top: 0; }
.docs p { margin: 8px 0; }
.docs ul, .docs ol { padding-left: 22px; margin: 8px 0; }
.docs li { margin: 3px 0; }
.docs code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: .88em; }
.docs pre { position: relative; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; overflow: auto; margin: 10px 0 14px; font-size: 12.8px; line-height: 1.55; }
.docs pre code { background: none; padding: 0; font-size: inherit; border-radius: 0; }
.docs pre[data-lang]::before, .docs pre.has-lang::before {
  content: attr(data-lang); position: absolute; top: 6px; left: 12px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); font-family: var(--font); font-weight: 700;
}
.docs pre[data-lang] { padding-top: 26px; }
.docs pre .copy-btn { position: absolute; top: 6px; right: 6px; opacity: .65; }
.docs pre:hover .copy-btn { opacity: 1; }
.docs .tbl-wrap { margin: 10px 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.docs table.tbl { width: 100%; }
.docs table.tbl td { white-space: normal; vertical-align: top; }
.docs table.tbl th { position: static; background: var(--surface-2); }
.docs .callout { padding: 10px 14px; border-radius: var(--radius-sm); margin: 12px 0; border: 1px solid var(--border); border-left-width: 4px; background: var(--surface-2); }
.docs .callout.info { border-left-color: var(--info); background: var(--info-soft); }
.docs .callout.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.docs .callout.tip { border-left-color: var(--ok); background: var(--ok-soft); }
.docs .callout > :first-child { margin-top: 0; } .docs .callout > :last-child { margin-bottom: 0; }
.docs kbd { display: inline-block; padding: 0 6px; font-size: 12px; line-height: 20px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); }
.docs img { max-width: 100%; }
.docs blockquote { margin: 10px 0; padding: 4px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }

/* ---------- Chat ---------- */
.chat-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.chat-side { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto; }
.chat-side .stack { gap: 11px; }
.chat-main { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 460px; padding: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 380px; }
.chat-empty .big { font-size: 18px; color: var(--text-2); font-weight: 650; margin-bottom: 6px; }
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg .bubble { padding: 10px 14px; border-radius: 12px; max-width: min(820px, 100%); min-width: 0; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--surface-2); border: 1px solid var(--border); width: 100%; }
.msg.error .bubble { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 40%, transparent); color: var(--text); }
.msg .who { font-size: 11.5px; color: var(--muted); font-weight: 600; display: flex; gap: 8px; align-items: center; }
.msg .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.msg .meta .chip { font-variant-numeric: tabular-nums; }
.msg .thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.msg .thumbs img { max-width: 160px; max-height: 120px; border-radius: 8px; border: 1px solid var(--border); }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.gen-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 4px; }
.gen-images figure { margin: 0; position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--code-bg); }
.gen-images img { display: block; width: 100%; height: auto; }
.gen-images figcaption { display: flex; justify-content: flex-end; gap: 6px; padding: 6px; }
.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { min-height: 52px; max-height: 240px; resize: none; }
.composer .bar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; }
.attachments:empty { display: none; }
.att { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border-strong); }
.att img { width: 100%; height: 100%; object-fit: cover; }
.att button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; font-size: 13px; line-height: 20px; padding: 0; }
.chat-main.drag { outline: 2px dashed var(--accent); outline-offset: -6px; }
@media (max-width: 900px) {
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .chat-side { position: static; max-height: none; }
  .chat-main { height: calc(100vh - 90px); }
}

/* markdown inside chat bubbles */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 6px 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 12px 0 6px; font-size: 15px; }
.md h1 { font-size: 18px; } .md h2 { font-size: 16.5px; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: .88em; }
.md blockquote { margin: 6px 0; padding: 2px 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.md th { background: var(--surface-3); }
.codeblock { margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--code-bg); }
.codeblock .codebar { display: flex; align-items: center; justify-content: space-between; padding: 3px 6px 3px 12px; background: var(--surface-3); font-size: 11.5px; color: var(--muted); font-weight: 600; }
.codeblock pre { margin: 0; padding: 10px 12px; overflow: auto; font-size: 12.5px; line-height: 1.5; }
.codeblock pre code { background: none; padding: 0; font-size: inherit; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; font-size: 18px; margin-bottom: 4px; }
.login-card .brand .logo { width: 34px; height: 34px; font-size: 16px; border-radius: 9px; }
.login-card .lead { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card .btn.primary { height: 40px; font-size: 15px; }
.login-card .remember { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: -2px; }
.login-foot { position: fixed; top: 12px; right: 12px; }

/* ---------- Responsive shell ---------- */
@media (max-width: 760px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .brand small { display: none; }
  .brand .name { display: none; }
  .tabs a { padding: 0 9px; }
  .tabs a svg { display: none; }
  main#view { padding: 14px 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .val { font-size: 19px; }
  .queue { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
