:root {
  color-scheme: light;
  --page: #f6f6f4;
  --surface: #ffffff;
  --ink: #191919;
  --ink-2: #666666;
  --line: rgba(11, 11, 11, 0.10);
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --accent: #257de0;
  --accent-ink: #ffffff;
  --series: #257de0;
  --hover-wash: rgba(37, 125, 224, 0.08);
  --good: #0aac23;
  --good-ink: #006c10;
  --critical: #dc3c3d;
  --warn-bg: #fff4e5;
  --seq-0: #f1f5fa;
  --seq-1: #cce3fd; --seq-2: #9dc8f7; --seq-3: #6aabf1; --seq-4: #338ced;
  --seq-5: #2370cd; --seq-6: #1757ac; --seq-7: #0e3d7e;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --ink: #efefef;
    --ink-2: #9c9c9c;
    --line: rgba(255, 255, 255, 0.10);
    --grid: #303030;
    --axis: #474747;
    --accent: #338ced;
    --series: #338ced;
    --hover-wash: rgba(51, 140, 237, 0.14);
    --good-ink: #53c556;
    --warn-bg: #2b2112;
    --seq-0: #222426;
    --seq-1: #0e3d7e; --seq-2: #0f4a96; --seq-3: #1757ac; --seq-4: #1b64be;
    --seq-5: #257de0; --seq-6: #519ced; --seq-7: #9dc8f7;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1rem; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* ---------- controls */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 0.45rem 0.85rem; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--hover-wash); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--critical); }
button.link { border: 0; background: none; padding: 0.2rem 0.4rem; color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
input, select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.45rem 0.6rem;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 0.85rem; color: var(--ink-2); margin-bottom: 0.25rem; }
.field { margin-bottom: 0.9rem; }
.field input { width: 100%; }
.error { color: var(--critical); min-height: 1.3em; font-size: 0.9rem; }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: 0.05em; word-break: break-all; }

/* ---------- sign-in pages */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.6rem;
}
.auth-card h1 { margin-bottom: 0.3rem; }
.auth-card p { margin: 0 0 1.1rem; }
.auth-card button.primary { width: 100%; justify-content: center; padding: 0.6rem; }
.qr { display: block; margin: 0.5rem auto 0.75rem; width: 200px; height: 200px; border-radius: 8px; background: #fff; padding: 6px; }

/* ---------- app shell */
header.top {
  display: flex; align-items: center; gap: 1rem; padding: 0.7rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
header.top nav { display: flex; gap: 0.25rem; }
header.top nav button { border: 0; background: none; }
header.top nav button[aria-current="page"] { background: var(--hover-wash); color: var(--accent); font-weight: 600; }
header.top .spacer { flex: 1; }
main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.filters .presets { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.filters .presets button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.filters .custom { display: flex; align-items: center; gap: 0.35rem; }

.notice {
  display: flex; gap: 0.6rem; align-items: flex-start; background: var(--warn-bg);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.9rem; margin-bottom: 1rem;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem 1rem; }
.tile .label { font-size: 0.8rem; color: var(--ink-2); }
.tile .value { font-size: 1.6rem; font-weight: 600; line-height: 1.2; margin-top: 0.15rem; }
.tile .sub { font-size: 0.8rem; color: var(--ink-2); margin-top: 0.1rem; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 0.75rem; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.6rem; }
.card-head .muted { font-size: 0.8rem; }

/* ---------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .bar { fill: var(--series); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .bar, .chart g.col:hover .bar { filter: brightness(1.15); }
.chart g.col:hover .hit { fill: var(--hover-wash); }
.chart .tick { stroke: var(--series); stroke-width: 2; stroke-linecap: round; }
.chart .cell { stroke: var(--surface); stroke-width: 2; }
.chart .cell:hover { stroke: var(--ink); stroke-width: 1.5; }
.chart .empty { fill: var(--ink-2); font-size: 13px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--surface);
  font-size: 0.8rem; padding: 0.35rem 0.55rem; border-radius: 6px; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px)); z-index: 10;
}
.legend { display: flex; align-items: center; gap: 0.4rem; font-size: 0.75rem; color: var(--ink-2); margin-top: 0.4rem; }
.legend .swatches { display: flex; }
.legend .swatches span { width: 18px; height: 10px; }

/* ---------- tables */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); }
th { font-size: 0.8rem; color: var(--ink-2); font-weight: 500; }
td.actions { text-align: right; width: 1%; white-space: nowrap; }
.pager { display: flex; align-items: center; gap: 0.5rem; justify-content: flex-end; margin-top: 0.6rem; }

.status { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; }
.status.online .dot { background: var(--good); }
.status.online { color: var(--good-ink); }
.status.offline .dot { background: var(--critical); }
.status.offline { color: var(--critical); }
.status.never .dot { background: var(--axis); }

.token-box {
  background: var(--page); border: 1px dashed var(--accent); border-radius: 8px; padding: 0.75rem; margin: 0.6rem 0;
}
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; min-width: 180px; }
.form-narrow { max-width: 360px; }
.center { text-align: center; }
