/* Watcher — dark only (owner's choice, 30/10/2026). Palette: dataviz reference instance, dark steps
   (surfaces, ink, blue accent, fixed status colors). */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.04);
  --accent: #3987e5;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #0ca30c;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.4 var(--font); }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 650; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 20px; height: 20px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--good); box-shadow: 0 0 0 3px color-mix(in oklab, var(--good) 25%, transparent); }
.live.off i { background: var(--critical); }
.spacer { flex: 1; }
.ghost { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; cursor: pointer; color: var(--ink-2); }
.ghost:hover { background: var(--hover); color: var(--ink); }
.top form { margin: 0; }

main { padding: 20px 24px 40px; max-width: 1500px; margin: 0 auto; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: minmax(220px, 1.3fr) repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 12px; }
.tile .value { font-size: 28px; font-weight: 600; margin-top: 2px; }
.tile .value.hero { font-size: 48px; line-height: 1.05; letter-spacing: -0.5px; }
.tile .value small { font-size: 0.45em; font-weight: 500; color: var(--ink-2); }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- status chips (color + icon + label, never color alone) ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 550; white-space: nowrap; }
.chip svg { width: 12px; height: 12px; flex: none; }
.chip.ok svg { color: var(--good); }
.chip.pending svg { color: var(--warning); }
.chip.alert svg, .chip.down svg { color: var(--critical); }
.chip.connecting svg, .chip.disabled svg { color: var(--muted); }
.chip.connecting, .chip.disabled { color: var(--ink-2); font-weight: 500; }

/* ---------- alert list ---------- */
.alerts { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px 0; margin-bottom: 16px; }
.alerts h2 { font-size: 13px; font-weight: 600; margin: 6px 16px 4px; color: var(--ink-2); }
.alerts ul { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 12px; align-items: baseline; padding: 6px 16px; border-top: 1px solid var(--border); }
.alerts li:first-child { border-top: 0; }
.alerts li b { font-weight: 600; }

/* ---------- fleet table ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 550; color: var(--ink-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th button { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; font-weight: inherit; }
th button:hover { color: var(--ink); }
th button[aria-sort]::after { content: " ↓"; }
td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr.host { cursor: pointer; }
tr.host:hover td { background: var(--hover); }
tr.host.dim td { color: var(--ink-2); }
tr.group td { background: var(--page); font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 6px 12px; }
.name { font-weight: 600; white-space: nowrap; }
.name small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.reason { display: block; font-size: 11px; color: var(--ink-2); max-width: 240px; white-space: normal; }

.metric { display: grid; grid-template-columns: 84px 46px 120px; align-items: center; gap: 8px; }
.metric .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }
.metric .s { font-size: 11px; color: var(--muted); grid-column: 1 / 3; margin-top: -4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric.nospark { grid-template-columns: 84px 46px; }

/* Meter (SVG, CSP-safe): fill carries severity; track is a light step of the fill's own hue; tick = alert threshold. */
svg.meter { width: 84px; height: 14px; display: block; overflow: visible; --fill: var(--accent); }
svg.meter .track { fill: color-mix(in oklab, var(--fill) 18%, var(--surface)); }
svg.meter .fill { fill: var(--fill); }
svg.meter .tick { fill: var(--ink-2); stroke: var(--surface); stroke-width: 1px; }
svg.meter.warn { --fill: var(--warning); }
svg.meter.crit { --fill: var(--critical); }
svg.meter.none { --fill: var(--muted); }
.disks svg.meter { width: 120px; }

svg.spark { width: 120px; height: 28px; display: block; overflow: visible; }
svg.spark path.line { fill: none; stroke: var(--accent); stroke-width: 2px; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
svg .thr { stroke: var(--muted); stroke-width: 1px; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
svg .base { stroke: var(--axis); stroke-width: 1px; vector-effect: non-scaling-stroke; }
svg .grid { stroke: var(--grid); stroke-width: 1px; vector-effect: non-scaling-stroke; }
svg .xh { stroke: var(--ink-2); stroke-width: 1px; vector-effect: non-scaling-stroke; }
svg .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2px; }
svg text { fill: var(--muted); font-size: 10px; font-family: var(--font); }

/* ---------- details ---------- */
tr.details > td { background: var(--page); padding: 14px 16px 18px; cursor: default; }
.det { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.4fr); gap: 20px; }
.det h3 { font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; margin-bottom: 14px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }
.disks { display: grid; grid-template-columns: minmax(80px, max-content) 120px 44px max-content; gap: 6px 10px; align-items: center; font-size: 13px; }
.disks .mnt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }
.charts { display: grid; gap: 10px; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 6px; }
.chart .ct { font-size: 12px; font-weight: 600; color: var(--ink-2); display: flex; justify-content: space-between; }
svg.big { width: 100%; height: 110px; display: block; overflow: visible; }
svg.big path.line { fill: none; stroke: var(--accent); stroke-width: 2px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }

/* ---------- tooltip ---------- */
.tip { position: fixed; pointer-events: none; z-index: 20; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); white-space: nowrap; }
.tip b { font-variant-numeric: tabular-nums; }

.foot { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- view tabs ---------- */
.tabs { display: inline-flex; background: var(--page); border: 1px solid var(--border); border-radius: 9px; padding: 2px; margin-left: 8px; }
.tabs button { background: none; border: 0; padding: 4px 12px; border-radius: 7px; cursor: pointer; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.10); }

/* ---------- map view: hub -> cluster links, one node per server ---------- */
.map { position: relative; padding: 6px 0 4px; }
.map svg.links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.links .link { fill: none; stroke: var(--axis); stroke-width: 2px; }
.links .flow { fill: none; stroke: var(--accent); stroke-width: 2.5px; stroke-linecap: round; stroke-dasharray: 1 15; animation: flow 1.4s linear infinite; }
.links .warn .flow { stroke: var(--warning); }
.links .crit .link { stroke: var(--critical); stroke-dasharray: 6 5; }
.links .crit .flow { stroke: var(--critical); }
@keyframes flow { to { stroke-dashoffset: -16; } }
@media (prefers-reduced-motion: reduce) { .links .flow { animation: none; } }

.hub { position: relative; z-index: 1; margin: 0 auto 46px; width: fit-content; display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 7px 18px 7px 8px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06); }
.hub-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in oklab, var(--accent) 14%, var(--surface)); color: var(--accent); }
.hub-icon svg { width: 18px; height: 18px; }
.hub.crit .hub-icon { background: color-mix(in oklab, var(--critical) 16%, var(--surface)); color: var(--critical); }
.hub b { display: block; font-size: 14px; }
.hub small { color: var(--ink-2); font-size: 12px; }

.clusters { position: relative; z-index: 1; display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 26px 22px; }
.cluster { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cl-head { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px 4px 9px; font-size: 12px; white-space: nowrap; }
.cl-head svg { width: 12px; height: 12px; }
.cl-head.ok svg { color: var(--good); }
.cl-head.pending svg { color: var(--warning); }
.cl-head.alert svg, .cl-head.down svg { color: var(--critical); }
.cl-head b { font-weight: 600; }
.cl-tiles { display: grid; gap: 8px; grid-template-columns: 148px; }
.cl-tiles.cols-2 { grid-template-columns: repeat(2, 148px); }
.cl-tiles.cols-3 { grid-template-columns: repeat(3, 148px); }
.cl-tiles.cols-4 { grid-template-columns: repeat(4, 148px); }
.cl-tiles.cols-5 { grid-template-columns: repeat(5, 148px); }
.cl-tiles.cols-6 { grid-template-columns: repeat(6, 148px); }

.node { all: unset; box-sizing: border-box; display: grid; align-content: start; gap: 4px; width: 148px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px 9px; cursor: pointer; font-size: 12px; color: var(--ink); transition: border-color 0.15s, box-shadow 0.15s; }
.node:hover { border-color: color-mix(in oklab, var(--ink) 28%, transparent); }
.node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.node.selected { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
.node.st-alert, .node.st-down { border-color: var(--critical); box-shadow: inset 0 0 0 1px var(--critical); background: color-mix(in oklab, var(--critical) 5%, var(--surface)); }
.node.st-pending { border-color: var(--warning); box-shadow: inset 0 0 0 1px var(--warning); }
.node.st-disabled { opacity: 0.6; }
.n-head { display: flex; align-items: center; gap: 5px; min-width: 0; }
.n-head > svg { width: 12px; height: 12px; flex: none; }
.st-ok .n-head > svg { color: var(--good); }
.st-pending .n-head > svg { color: var(--warning); }
.st-alert .n-head > svg, .st-down .n-head > svg { color: var(--critical); }
.st-connecting .n-head > svg, .st-disabled .n-head > svg { color: var(--muted); }
.n-head b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-state { font-size: 11px; font-weight: 650; color: var(--ink-2); margin-top: -2px; }
.n-body { display: grid; gap: 3px; min-height: 54px; align-content: start; }
.n-row { display: grid; grid-template-columns: 26px 1fr 34px; align-items: center; gap: 6px; }
.n-row svg.meter { width: 100%; }
.n-k { color: var(--muted); font-size: 10.5px; letter-spacing: 0.3px; }
.n-v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; font-size: 11.5px; }
.n-msg { font-size: 11.5px; color: var(--ink-2); line-height: 1.35; overflow-wrap: anywhere; }

/* ---------- details drawer ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(580px, 100vw); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -10px 0 32px rgba(0, 0, 0, 0.14); z-index: 10; overflow-y: auto; padding: 16px 20px 28px; }
.drawer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.drawer-head h2 { font-size: 17px; margin: 0; flex: 1; display: flex; align-items: center; gap: 10px; }
.drawer .det { grid-template-columns: 1fr; }
.det-gap { margin-top: 16px !important; }
.kills { margin: 0; padding-left: 18px; font-size: 13px; display: grid; gap: 4px; }
.det p.muted { margin: 0; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; }
.login h1 { font-size: 20px; margin: 0; display: flex; gap: 8px; align-items: center; }
.login h1 svg { width: 22px; height: 22px; }
.login input[type="password"] { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--axis); background: var(--page); color: var(--ink); font: inherit; }
.login button { padding: 10px 12px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login .err { color: var(--critical); font-size: 13px; min-height: 1em; }
.hidden { display: none !important; }

@media (max-width: 1100px) {
  .col-load, .col-up { display: none; }
}
@media (max-width: 820px) {
  .top { padding: 12px 14px; }
  main { padding: 14px 10px 30px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .tile .value.hero { font-size: 38px; }
  svg.spark, .col-seen { display: none; }
  .metric, .metric.nospark { grid-template-columns: 44px 38px; gap: 6px; }
  .metric svg.meter { width: 44px; }
  .metric .s, .name small, .reason { display: none; }
  .top { gap: 6px; }
  .top .ghost { padding: 3px 7px; font-size: 12px; }
  .tabs button { padding: 3px 9px; }
  .live span { display: none; }
  .ghost { padding: 4px 8px; font-size: 13px; }
  .kv dd { overflow-wrap: anywhere; }
  .tabs { margin-left: 0; }
  .brand { font-size: 0; gap: 0; }
  .map svg.links { display: none; }
  .hub { margin-bottom: 16px; }
  .clusters { flex-direction: column; align-items: stretch; }
  .cluster { align-items: stretch; }
  .cl-head { align-self: flex-start; }
  .cl-tiles[class] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .node { width: auto; }
  .det { grid-template-columns: 1fr; }
  td, th { padding: 7px 8px; }
}
