:root {
  --bg: #f4f5f8; --panel: #ffffff; --ink: #1a1d29; --muted: #656b7d; --line: #e2e5ee;
  --side: #161a2b; --side-ink: #c9cee0; --side-active: #2a3050;
  --accent: #5b4bdb; --accent-ink: #ffffff;
  --good: #1b8a4b; --warn: #b36b00; --bad: #c0352b; --good-bg: #e3f5ea; --warn-bg: #fff2d9; --bad-bg: #fde6e4;
  --chart-a: #5b4bdb; --chart-b: #e08a1e; --grid: #e6e8f0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1220; --panel: #181c2e; --ink: #e8eaf4; --muted: #9aa1b8; --line: #2a2f47;
    --side: #0b0d19; --side-ink: #aab0c8; --side-active: #222844;
    --accent: #8b7dff; --accent-ink: #10122a;
    --good: #55d08a; --warn: #f0b04a; --bad: #ff7b70; --good-bg: #12301f; --warn-bg: #3a2a0c; --bad-bg: #3d1a17;
    --chart-a: #8b7dff; --chart-b: #f0b04a; --grid: #262b43;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1220; --panel: #181c2e; --ink: #e8eaf4; --muted: #9aa1b8; --line: #2a2f47;
  --side: #0b0d19; --side-ink: #aab0c8; --side-active: #222844;
  --accent: #8b7dff; --accent-ink: #10122a;
  --good: #55d08a; --warn: #f0b04a; --bad: #ff7b70; --good-bg: #12301f; --warn-bg: #3a2a0c; --bad-bg: #3d1a17;
  --chart-a: #8b7dff; --chart-b: #f0b04a; --grid: #262b43;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 16px; letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; color: var(--side-ink); font-size: 12px; }
.nav a { display: block; color: var(--side-ink); padding: 8px 10px; border-radius: 8px; }
.nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav a.on { background: var(--side-active); color: #fff; font-weight: 600; }
.side .spacer { flex: 1; }
.side .who { padding: 8px 10px; font-size: 12px; }
.main { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* surfaces */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile .k { color: var(--muted); font-size: 12px; }
.tile .v { font-size: 22px; font-weight: 650; margin-top: 2px; }
.tile .s { color: var(--muted); font-size: 12px; }
.tile.good .v { color: var(--good); } .tile.bad .v { color: var(--bad); } .tile.warn .v { color: var(--warn); }
.two { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* form controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 70px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.field-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline select, .inline input { width: auto; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ink); font-size: 14px; }
.checks input { width: auto; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }

/* dialogs, toasts */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 20px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 7, 18, .55); }
dialog h2 { margin-top: 0; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.secret { display: flex; gap: 6px; }
.secret input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 12px; margin: 10px 0; font-size: 13px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; max-width: 380px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 26px; }
.login h1 { margin-bottom: 14px; }
.err { color: var(--bad); min-height: 20px; margin-top: 8px; }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .bar { fill: var(--chart-a); opacity: .85; }
.chart .line { fill: none; stroke: var(--chart-b); stroke-width: 2; }
.chart .target { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.chart .dot { fill: var(--chart-b); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
pre.json { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 12px; max-height: 180px; overflow: auto; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 0 10px 0 0; } .brand small { display: none; }
  .nav { display: flex; flex-wrap: wrap; } .side .spacer { display: none; }
  .main { padding: 16px 16px 50px; }
  .two, .field-row { grid-template-columns: 1fr; }
}
