:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b42c2c;
  --meter-track: #cde2fb;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-1-wash: rgba(57, 135, 229, 0.12);
    --good-text: #0ca30c;
    --critical-text: #e66767;
    --meter-track: #184f95;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-1-wash: rgba(57, 135, 229, 0.12);
  --good-text: #0ca30c;
  --critical-text: #e66767;
  --meter-track: #184f95;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}

code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.92em; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { display: block; width: 26px; height: 26px; flex: none; margin-right: -6px; }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live[data-state="live"] .live-dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); animation: pulse 2s infinite; }
.live[data-state="stale"] .live-dot { background: var(--warning); }
.live[data-state="down"] .live-dot { background: var(--critical); }
.live[data-state="paused"] .live-dot { background: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none !important; } }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select, .icon-btn, .segmented button {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  height: 32px; padding: 0 10px; cursor: pointer;
}
select { padding-right: 28px; max-width: 220px; }
.icon-btn:hover, .segmented button:hover { background: var(--surface-2); }
.icon-btn[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; border-radius: 0; height: 30px; padding: 0 12px; background: transparent; color: var(--ink-2); }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-checked="true"] { background: var(--ink); color: var(--surface); font-weight: 600; }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* ---------- nav tabs (shared look with detail page) ---------- */
.tabs { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--surface-2); }
.tabs a { color: var(--ink-2); text-decoration: none; font-size: 13px; padding: 4px 10px; border-radius: 6px; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

/* ---------- layout ---------- */
main { max-width: 1600px; margin: 0 auto; padding: 20px 24px 40px; display: grid; gap: 16px; }

.banner {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--warning);
  color: var(--ink-2);
}

.card {
  margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  min-width: 0;
}
.card-title { font-weight: 600; }
.card-sub { color: var(--muted); font-size: 12px; }
.card-head, figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 12px 16px 0; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.kpi-label { color: var(--ink-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; white-space: nowrap; }
.kpi-hero .kpi-value { font-size: 34px; }
.kpi-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub .bad, .bad { color: var(--critical-text); }
.status-icon { font-weight: 700; margin-right: 3px; }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.chart-wide { grid-column: span 2; }
.chart-card .chart { position: relative; height: 170px; margin: 6px 8px 8px; }
.chart canvas { display: block; width: 100%; height: 100%; }
.legend { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12px; }
.key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; margin-left: 6px; }
.key-1 { background: var(--series-1); }
.key-err { background: var(--critical); }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  font-variant-numeric: tabular-nums; min-width: 120px;
}
.tooltip .tt-time { color: var(--muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .tt-swatch { width: 10px; height: 2px; border-radius: 1px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; padding: 6px 4px 8px; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.table td { padding: 7px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table td.wrap { white-space: normal; word-break: break-word; }
#t-services tbody tr { cursor: pointer; }
#t-services tbody tr:hover, #t-services tbody tr.selected { background: var(--surface-2); }
.svc-name { font-weight: 600; }
.ver { color: var(--muted); font-size: 12px; margin-left: 6px; }
.dots { display: inline-flex; gap: 3px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--series-1); }
.dot.stale { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.dots-count { margin-left: 6px; color: var(--ink-2); }
.spark { display: block; width: 120px; height: 24px; }
.dim { color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.badge.stale::before { background: var(--warning); }
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter-track { width: 70px; height: 6px; border-radius: 3px; background: var(--meter-track); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 3px; background: var(--series-1); }
.meter-fill.warn { background: var(--warning); }
.meter-fill.crit { background: var(--critical); }
.meter-val { min-width: 42px; text-align: right; }
.empty { padding: 14px 16px 18px; color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; }
.method { color: var(--muted); font-size: 11px; font-weight: 600; margin-right: 6px; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }

.foot { color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .charts { grid-template-columns: minmax(0, 1fr); }
  .chart-wide { grid-column: auto; }
}
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  main { padding: 16px 16px 32px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-hero { grid-column: span 2; }
}
