:root {
  --bg: #f5f6f8; --card: #ffffff; --ink: #1d2330; --muted: #5d6676; --line: #dfe3ea;
  --accent: #1f6feb; --accent-ink: #ffffff; --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e;
  --chip: #eef2f8; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --card: #171b23; --ink: #e6e9ef; --muted: #98a1b3; --line: #2a3140;
          --accent: #4c8dff; --chip: #212837; --ok: #3fb950; --warn: #d29922; --bad: #f85149; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
header { display: flex; gap: 12px; align-items: center; padding: 8px 16px; background: var(--card);
         border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-size: 18px; letter-spacing: .5px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav button { background: none; border: 0; padding: 6px 10px; border-radius: 6px; color: var(--muted); cursor: pointer; font: inherit; }
nav button.active, nav button:hover { background: var(--chip); color: var(--ink); }
main { padding: 16px; max-width: 1280px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 12px; } h2 { font-size: 16px; margin: 0 0 8px; } h3 { font-size: 14px; margin: 12px 0 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.narrow { max-width: 360px; margin: 12vh auto; display: grid; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.tile .k { color: var(--muted); font-size: 12px; } .tile .v { font-size: 22px; font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--chip); }
.table-wrap { overflow-x: auto; }
button { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.ghost { border-color: transparent; background: none; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; }
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 70px; resize: vertical; }
textarea.long { min-height: 260px; }
input[type=checkbox] { width: auto; }
label { display: grid; gap: 4px; font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; }
.help { color: var(--muted); font-size: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; display: grid; gap: 10px;
           grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
fieldset > legend { font-weight: 600; padding: 0 6px; }
fieldset .wide { grid-column: 1 / -1; }
.chip { display: inline-block; background: var(--chip); border-radius: 999px; padding: 1px 8px; font-size: 12px; margin: 1px 2px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); } .muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.banner { background: #fff4ce; color: #5c4400; padding: 8px 16px; border-bottom: 1px solid #e8d48a; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2f0b; color: #f0d98a; border-color: #5c4a12; } }
.transcript { display: grid; gap: 6px; max-height: 52vh; overflow-y: auto; padding: 4px; }
.msg { padding: 6px 10px; border-radius: 8px; max-width: 85%; white-space: pre-wrap; }
.msg.user { background: var(--chip); justify-self: start; } .msg.assistant { background: color-mix(in srgb, var(--accent) 16%, transparent); justify-self: end; }
.msg .t { color: var(--muted); font-size: 11px; display: block; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); width: min(1000px, 96vw); max-height: 92vh; padding: 14px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.toast { position: fixed; bottom: 16px; right: 16px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 520px; z-index: 50; white-space: pre-wrap; }
.toast.bad { background: var(--bad); color: #fff; }
.error { color: var(--bad); min-height: 1em; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.dot.off { background: var(--bad); }
@media (max-width: 640px) { main { padding: 10px; } header { padding: 8px 10px; } }
