:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #e9e8e3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300; --warn-text: #8a5a00; --crit-text: #b02a2a;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c; --grid: #282826;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --good-text: #3fcf3f; --warn-text: #fab219; --crit-text: #ff7a7a; --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c; --grid: #282826;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --good-text: #3fcf3f; --warn-text: #fab219; --crit-text: #ff7a7a; --accent: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 13px; margin: 0 0 10px; font-weight: 600; color: var(--text); }
.muted { color: var(--text-3); font-weight: 450; }
.small { font-size: 12px; }
.center { text-align: center; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
button, input { font: inherit; color: inherit; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.controls form { margin: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.live { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); animation: pulse 2s infinite; }
.dot.stale { background: var(--critical); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--good) 0%, transparent); } }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; cursor: pointer; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.ghost { border: 1px solid var(--border); background: transparent; border-radius: 8px; padding: 4px 10px; cursor: pointer; color: var(--text-2); }
.ghost:hover, .seg button:hover { color: var(--text); }

main { padding: 16px 20px 40px; max-width: 1680px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.banner { border: 1px solid var(--critical); color: var(--crit-text); background: color-mix(in srgb, var(--critical) 10%, var(--surface)); border-radius: 10px; padding: 8px 12px; font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin: 0; min-width: 0; }
figcaption { font-size: 13px; font-weight: 600; margin-bottom: 6px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 1380px) { .kpis { grid-template-columns: repeat(8, minmax(0, 1fr)); } .kpi .value { font-size: 26px; } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.kpi .label { font-size: 12px; color: var(--text-2); }
.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi .sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 4px 0 4px; }
.meter i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--s1); transition: width .4s; }
.meter i.warning { background: var(--warning); } .meter i.critical { background: var(--critical); }

/* status chips (icon + label, never color alone) */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st.good { color: var(--good-text); } .st.warning { color: var(--warn-text); } .st.critical { color: var(--crit-text); }
.st.neutral { color: var(--text-3); }
.val-warning { color: var(--warn-text); } .val-critical { color: var(--crit-text); } .val-good { color: var(--good-text); }

/* grids */
.grid { display: grid; gap: 16px; }
.charts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.charts .wide { grid-column: span 3; }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .charts, .three { grid-template-columns: repeat(2, minmax(0, 1fr)); } .charts .wide { grid-column: span 2; } }
@media (max-width: 720px) {
  .charts, .three, .two { grid-template-columns: minmax(0, 1fr); } .charts .wide { grid-column: auto; }
  main { padding: 12px 16px 32px; } .topbar { padding: 10px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi .value { font-size: 22px; }
}

/* charts */
.chart { position: relative; height: 200px; }
.wide .chart { height: 230px; }
.chart canvas { display: block; width: 100%; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.dash { background-image: linear-gradient(90deg, currentColor 50%, transparent 50%) !important; background-size: 6px 3px; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); font-size: 12px; text-align: center; padding: 12px; pointer-events: none; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 8px 10px; font-size: 12px;
}
.tooltip .tt-time { color: var(--text-3); 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(--text-2); }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* tables */
.scroll { overflow: auto; max-height: 360px; }
.scroll.tall { max-height: 440px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2); padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
td.msg { word-break: break-word; color: var(--text-2); }
td.nowrap { white-space: nowrap; }
.mini { display: inline-block; width: 70px; height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; vertical-align: middle; margin-right: 8px; }
.mini i { display: block; height: 100%; background: var(--s1); border-radius: 4px; }
.mini i.warning { background: var(--warning); } .mini i.critical { background: var(--critical); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.none { color: var(--text-3); font-size: 12px; padding: 10px 8px; }

/* login */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 24px; }
.login-card label { font-size: 12px; color: var(--text-2); margin-top: 6px; }
.login-card input { padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card button { padding: 9px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.err { color: var(--crit-text); min-height: 1em; margin: 0; }
