/* Server Monitor — one stylesheet, no build step. Light and dark are both selected palettes. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --axis-text: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #7a5200;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #a32626;
  --good-wash: rgba(12, 163, 12, 0.10);
  --warning-wash: rgba(250, 178, 25, 0.16);
  --critical-wash: rgba(208, 59, 59, 0.10);
  --track: #cde2fb;
  --shadow: 0 8px 28px rgba(11, 11, 11, 0.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #a3a199;
    --axis-text: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-ink: #0ca30c;
    --warning-ink: #fab219;
    --critical-ink: #ec7a7a;
    --good-wash: rgba(12, 163, 12, 0.16);
    --warning-wash: rgba(250, 178, 25, 0.14);
    --critical-wash: rgba(208, 59, 59, 0.18);
    --track: #184f95;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #a3a199;
  --axis-text: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good-ink: #0ca30c;
  --warning-ink: #fab219;
  --critical-ink: #ec7a7a;
  --good-wash: rgba(12, 163, 12, 0.16);
  --warning-wash: rgba(250, 178, 25, 0.14);
  --critical-wash: rgba(208, 59, 59, 0.18);
  --track: #184f95;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 var(--font);
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-secondary); }
a { color: var(--accent-ink); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Top bar, tabs, filters ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topbar__row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1440px; margin: 0 auto; padding: 10px 20px 4px;
}
.topbar__actions { display: flex; align-items: center; gap: 6px; }
.topbar__actions form { margin: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.brand--lg { font-size: 20px; }
.brand__mark {
  width: 14px; height: 14px; border-radius: 4px;
  background: var(--accent);
  box-shadow: 4px 4px 0 -1px var(--series-3);
}
.tabs {
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  max-width: 1440px; margin: 0 auto; padding: 0 14px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: none;
  padding: 10px 10px 11px; border: 0; background: none; cursor: pointer;
  color: var(--text-secondary); font: inherit; font-weight: 500; text-decoration: none;
}
.tab:hover { color: var(--text-primary); }
.tab[aria-current="page"] { color: var(--text-primary); }
.tab[aria-current="page"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0;
  height: 2px; border-radius: 2px; background: var(--accent);
}
.tab__badge {
  display: inline-block; min-width: 18px; margin-left: 4px; padding: 0 5px;
  border-radius: 9px; background: var(--critical); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
}

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  max-width: 1440px; margin: 0 auto; padding: 14px 20px 0;
}
.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
.segmented button {
  border: 0; background: none; border-radius: 6px; padding: 5px 12px;
  font: inherit; font-weight: 500; color: var(--text-secondary); cursor: pointer;
}
.segmented button[aria-checked="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 13px; }
.status-dot { color: var(--text-muted); font-size: 12px; margin-right: 6px; white-space: nowrap; }

/* ── Buttons & fields ───────────────────────────────────────────────── */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.select-field select {
  appearance: none; min-width: 190px; padding: 6px 30px 6px 12px;
  border: 1px solid var(--border); border-radius: 8px; background-color: var(--surface-1); color: var(--text-primary);
  font: inherit; font-weight: 550; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%), linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.app-tag {
  display: inline-block; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top;
  padding: 1px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2);
  color: var(--text-primary); font: 550 12px/1.5 var(--font); cursor: pointer;
}
.app-tag:hover { border-color: var(--baseline); }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  border-radius: 8px; padding: 6px 12px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn--ghost { border-color: transparent; background: none; color: var(--text-secondary); }
.btn--ghost:hover { color: var(--text-primary); background: var(--surface-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-ink); }
.btn--sm { padding: 3px 9px; font-size: 12.5px; }
.field { display: grid; gap: 6px; font-weight: 500; }
input[type="text"], input[type="search"], input[type="password"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--baseline); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); font: inherit;
}

/* ── Layout ─────────────────────────────────────────────────────────── */
.view { max-width: 1440px; margin: 0 auto; padding: 14px 20px 48px; transition: opacity .15s; }
.view.is-loading { opacity: .55; }
.view > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--kpi { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
@media (max-width: 560px) {
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .view, .filters, .topbar__row { padding-left: 12px; padding-right: 12px; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  min-width: 0;
}
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card__sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.card--flush { padding: 0; }
.card--flush > .card__head { padding: 16px 16px 0; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 24px 0 -4px; }
.section-title h2 { font-size: 16px; }

/* ── Stat tiles ─────────────────────────────────────────────────────── */
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: grid; gap: 4px; align-content: start; min-width: 0;
}
.tile--link { cursor: pointer; text-align: left; font: inherit; color: inherit; }
.tile--link:hover { border-color: var(--baseline); }
.tile__label { color: var(--text-secondary); font-size: 12.5px; }
.tile__value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.tile__sub { color: var(--text-muted); font-size: 12px; }
.tile__foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 4px; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter--warning > span { background: var(--warning); }
.meter--critical > span { background: var(--critical); }

/* ── Status chips (icon + label, never color alone) ─────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550;
  background: var(--surface-2); color: var(--text-secondary);
}
.chip__icon { font-size: 10px; line-height: 1; }
.chip--good { background: var(--good-wash); color: var(--good-ink); }
.chip--warning { background: var(--warning-wash); color: var(--warning-ink); }
.chip--critical { background: var(--critical-wash); color: var(--critical-ink); }
.chip--info { background: var(--surface-2); color: var(--text-secondary); }

.status-code { font-variant-numeric: tabular-nums; font-weight: 600; }
.status-code--5 { color: var(--critical-ink); }
.status-code--4 { color: var(--warning-ink); }
.status-code--3 { color: var(--text-secondary); }
.status-code--2 { color: var(--good-ink); }
.status-code--0 { color: var(--critical-ink); }

.callout {
  border-radius: 10px; padding: 10px 14px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary);
}
.callout--warning { background: var(--warning-wash); }
.callout--critical { background: var(--critical-wash); }
.callout--good { background: var(--good-wash); }
.callout code { background: var(--surface-1); padding: 1px 5px; border-radius: 4px; }
.alert-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.alert-list li { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── Tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
th {
  color: var(--text-secondary); font-weight: 550; font-size: 12px; white-space: nowrap;
  position: sticky; top: 0; background: var(--surface-1);
}
th.num, td.num { text-align: right; }
th[aria-sort] { cursor: pointer; user-select: none; }
th[aria-sort]:hover { color: var(--text-primary); }
th[aria-sort="ascending"]::after { content: " ↑"; }
th[aria-sort="descending"]::after { content: " ↓"; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.is-clickable { cursor: pointer; }
tbody tr.is-clickable:hover td, tbody tr.is-clickable:focus-visible td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }
.cell-main { font-weight: 500; overflow-wrap: anywhere; }
.cell-sub { color: var(--text-muted); font-size: 12px; overflow-wrap: anywhere; }
.truncate { display: block; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.method { font-family: var(--mono); font-size: 11.5px; color: var(--text-secondary); margin-right: 6px; }
.empty { padding: 28px 16px; text-align: center; color: var(--text-muted); }
.share { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.share__bar { width: 60px; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.share__bar > span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { max-width: 320px; }
.load-more { display: flex; justify-content: center; padding: 12px; }

/* ── Charts ─────────────────────────────────────────────────────────── */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--axis-text); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { stroke: none; opacity: .10; }
.chart .dot { stroke: var(--surface-1); stroke-width: 2; }
.chart .crosshair { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:focus { outline: none; }
.chart .bar:hover, .chart .bar.is-active { filter: brightness(1.12); }
.s1 { stroke: var(--series-1); } .f1 { fill: var(--series-1); }
.s2 { stroke: var(--series-2); } .f2 { fill: var(--series-2); }
.s3 { stroke: var(--series-3); } .f3 { fill: var(--series-3); }
.chart-empty {
  position: absolute; inset: 0 0 22px 44px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13px; pointer-events: none;
}
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.key--bar { width: 10px; height: 10px; border-radius: 2px; }
.key.s1, .key.f1 { background: var(--series-1); }
.key.s2, .key.f2 { background: var(--series-2); }
.key.s3, .key.f3 { background: var(--series-3); }
.chart-table { max-height: 240px; overflow: auto; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 12px; min-width: 140px;
}
.tooltip__title { color: var(--text-muted); margin-bottom: 4px; }
.tooltip__row { display: flex; align-items: center; gap: 8px; }
.tooltip__row strong { font-variant-numeric: tabular-nums; font-size: 13px; }
.tooltip__row span:last-child { color: var(--text-secondary); }

/* ── Drawer (details) ───────────────────────────────────────────────── */
.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(760px, 100vw);
  border: 0; border-left: 1px solid var(--border); padding: 0;
  background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow);
}
.drawer::backdrop { background: rgba(0, 0, 0, .35); }
.drawer__head {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-1);
}
.drawer__head h2 { font-size: 16px; overflow-wrap: anywhere; }
.drawer__body { padding: 16px 18px 40px; }
.drawer__body > * + * { margin-top: 18px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
pre.code {
  margin: 0; padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
  font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow: auto;
}

/* ── Login ──────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(380px, 100%); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.login-card > * + * { margin-top: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 9px; }

@media (forced-colors: active) {
  .meter > span, .share__bar > span, .key { forced-color-adjust: none; }
}
@media (prefers-reduced-motion: reduce) {
  .view { transition: none; }
}
