/* ---------- tokens ----------
   Categorical series slots are the dataviz reference palette, validated against these surfaces
   (dark #15171a, light #ffffff). Slot 9+ reuses the hues with a dash pattern (set in app.js). */
:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --surface: #15171a;
  --surface-2: #1d2024;
  --surface-3: #262a2f;
  --ink: #eceef1;
  --ink-2: #b4b8be;
  --muted: #8b9097;
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .14);
  --grid: #24272c;
  --axis: #3a3e44;
  --accent: #338ced;
  --accent-wash: rgba(51, 140, 237, .16);
  --good: #0aac23;
  --bad: #dc3c3d;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05;
  --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
  --heat-0: #1b2230;
  --heat-1: #0e3d7e;
  --heat-2: #84b9f3;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 12px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e8eaee;
  --ink: #191919;
  --ink-2: #444a52;
  --muted: #666b72;
  --line: rgba(11, 11, 11, .08);
  --line-2: rgba(11, 11, 11, .16);
  --grid: #ececec;
  --axis: #c2c2c2;
  --accent: #257de0;
  --accent-wash: rgba(37, 125, 224, .12);
  --good: #008a17;
  --bad: #dc3c3d;
  --shadow: 0 10px 30px rgba(15, 20, 30, .12);
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600;
  --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647;
  --heat-0: #eef4fc;
  --heat-1: #b6d5f8;
  --heat-2: #0f4a96;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f3f4f6;
    --surface-3: #e8eaee;
    --ink: #191919;
    --ink-2: #444a52;
    --muted: #666b72;
    --line: rgba(11, 11, 11, .08);
    --line-2: rgba(11, 11, 11, .16);
    --grid: #ececec;
    --axis: #c2c2c2;
    --accent: #257de0;
    --accent-wash: rgba(37, 125, 224, .12);
    --good: #008a17;
    --bad: #dc3c3d;
    --shadow: 0 10px 30px rgba(15, 20, 30, .12);
    --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600;
    --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647;
    --heat-0: #eef4fc;
    --heat-1: #b6d5f8;
    --heat-2: #0f4a96;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 640px) { .wrap { padding: 0 16px; } }
.num { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.top-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; }
.brand-bg { fill: var(--surface-3); }
.brand-line { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 13px; }
@media (max-width: 520px) { .brand-sub { display: none; } }
.top-right { display: flex; align-items: center; gap: 10px; }
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.ok .dot { background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); animation: pulse 2.4s infinite; }
.live.stale .dot { background: var(--bad); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .live.ok .dot { animation: none; } }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--line-2); border-radius: 9px; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 16px; height: 16px; fill: var(--ink-2); }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 20px 0 14px; }
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  overflow-x: auto; max-width: 100%; scrollbar-width: none;
}
.seg button {
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer;
  padding: 6px 11px; border-radius: 7px; font-size: 13px; font-weight: 550; white-space: nowrap;
}
.seg button:hover { background: var(--surface-2); color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg button:disabled { opacity: .4; cursor: default; background: transparent; }
.seg.small button { padding: 4px 9px; font-size: 12px; }
.btn {
  border: 1px solid var(--line-2); background: var(--surface-3); color: var(--ink);
  padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 550;
}
.btn:hover { border-color: var(--muted); }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px;
}
@media (max-width: 640px) { .card { padding: 14px; } }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- chart ---------- */
.totals { display: flex; gap: 22px; }
.total { text-align: right; }
.total .v { font-size: 22px; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.total .k { font-size: 12px; color: var(--muted); }
@media (max-width: 640px) { .totals { width: 100%; justify-content: flex-start; } .total { text-align: left; } }
.chart-box { position: relative; min-height: 300px; transition: opacity .2s; }
.chart-box.loading { opacity: .55; }
.chart { width: 100%; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.uplot { font-family: var(--font); }
.u-select { background: var(--accent-wash); border-left: 1px solid var(--accent); border-right: 1px solid var(--accent); }
.u-cursor-x { border-right: 1px dashed var(--muted) !important; }
.u-cursor-y { display: none; }
.u-over { cursor: crosshair; }

.tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 200px; max-width: 300px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 12px; font-size: 13px;
}
.tooltip .tt-time { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.tooltip .tt-row { display: grid; grid-template-columns: 16px 44px 1fr; align-items: center; gap: 8px; padding: 2px 0; }
.tooltip .tt-row.focus .tt-name { color: var(--ink); }
.tooltip .tt-val { font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
.tooltip .tt-name { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tooltip .tt-off .tt-val { color: var(--muted); font-weight: 500; }
.tooltip .tt-sum { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }

.key { width: 16px; height: 4px; display: block; overflow: visible; }

/* ---------- legend ---------- */
.legend {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px;
}
.legend li { position: relative; }
.legend .item {
  width: 100%; display: grid; grid-template-columns: 18px 32px 1fr auto; align-items: center; gap: 10px;
  padding: 9px 12px; text-align: left; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  transition: opacity .15s, border-color .15s, background .15s;
}
.legend .item:hover { border-color: var(--line-2); background: var(--surface-3); }
.legend .item[aria-pressed="false"] { opacity: .42; }
.legend .item[aria-pressed="false"] .key { opacity: .5; }
.legend .icon, .profile .icon {
  width: 32px; height: 32px; border-radius: 8px; object-fit: cover; background: var(--surface-3);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; color: var(--muted);
}
.legend .meta { min-width: 0; }
.legend .name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend .detail { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend .count { text-align: right; }
.legend .count .v { display: block; font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.legend .count .k { display: block; font-size: 11px; color: var(--muted); }
.legend .off .v { font-size: 13px; color: var(--muted); font-weight: 550; }
.legend .remove {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); cursor: pointer;
  font-size: 13px; line-height: 1; display: grid; place-items: center;
}
.legend .remove:hover { color: var(--bad); border-color: var(--bad); }
.manage { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.manage input {
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 6px 10px; min-width: 0;
  flex: 1 1 200px;
}
.manage-msg { color: var(--muted); font-size: 13px; }

/* ---------- stats table ---------- */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
table.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats th, .stats td { padding: 9px 10px; text-align: right; white-space: nowrap; }
.stats th.l, .stats td.l { text-align: left; }
.stats th {
  font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line-2);
  cursor: pointer; user-select: none;
}
.stats th:hover { color: var(--ink); }
.stats th[aria-sort]::after { content: " ↓"; }
.stats th[aria-sort="ascending"]::after { content: " ↑"; }
.stats tbody tr { border-bottom: 1px solid var(--line); cursor: pointer; }
.stats tbody tr:last-child { border-bottom: 0; }
.stats tbody tr:hover { background: var(--surface-2); }
.stats .srv { display: flex; align-items: center; gap: 10px; max-width: 320px; }
.stats .srv span { overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.stats .muted { color: var(--muted); }
.bar { display: inline-block; vertical-align: middle; height: 6px; border-radius: 3px; background: var(--surface-3); width: 54px; margin-left: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--muted); border-radius: 3px; }
@media (max-width: 640px) { .hide-sm { display: none; } }

/* ---------- details ---------- */
.details select {
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 6px 10px; max-width: 100%;
}
.details-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 24px 32px; }
.changes-wrap { grid-column: 1 / -1; }
@media (max-width: 900px) { .details-body { grid-template-columns: 1fr; } }
.profile-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.profile .icon { width: 52px; height: 52px; border-radius: 12px; font-size: 16px; }
.profile .pname { font-size: 17px; font-weight: 650; }
.profile .host { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.profile .desc { color: var(--ink-2); margin: 0 0 10px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); }
.chip.warn { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--ink); }
.links { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; font-size: 13px; font-weight: 550; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 16px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.facts dd small { color: var(--muted); font-weight: 450; }

.sub-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; margin-top: 10px; }
.heat .lbl { font-size: 11px; color: var(--muted); display: flex; align-items: center; }
.heat .hlbl { grid-column: span 6; font-size: 11px; color: var(--muted); white-space: nowrap; }
.heat .cell { aspect-ratio: 1 / 1; border-radius: 3px; background: var(--heat-0); min-height: 10px; }
.heat .cell.none { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.heat .cell:hover { outline: 2px solid var(--ink); outline-offset: -1px; }
.heat-scale { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.heat-scale .ramp { height: 8px; width: 140px; border-radius: 4px; background: linear-gradient(90deg, var(--heat-0), var(--heat-1), var(--heat-2)); }

.changes { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow-y: auto; }
.changes li { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.changes li:last-child { border-bottom: 0; }
.changes time { color: var(--muted); font-variant-numeric: tabular-nums; }
.changes .what { overflow-wrap: anywhere; }
.changes .old { color: var(--muted); text-decoration: line-through; }
.changes .none { color: var(--muted); display: block; }
@media (max-width: 640px) { .changes li { grid-template-columns: 1fr; gap: 2px; } }

.foot { color: var(--muted); font-size: 12px; padding-bottom: 32px; }
