:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-1-soft: rgba(42, 120, 214, 0.14);
  --meter-track: #e7e6e1;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b02a2a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --line: #2f2f2c;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #95948c;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-1-soft: rgba(57, 135, 229, 0.2);
    --meter-track: #2c2c29;
    --good-ink: #3fc43f;
    --critical-ink: #ef7d7d;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --line: #2f2f2c;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #95948c;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-1-soft: rgba(57, 135, 229, 0.2);
  --meter-track: #2c2c29;
  --good-ink: #3fc43f;
  --critical-ink: #ef7d7d;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text-primary); font: 16px/1.45 var(--font);
  -webkit-text-size-adjust: 100%; padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 0.86em; }

/* ---------- top bar */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: -0.01em; }
.top .updated { font-size: 13px; color: var(--text-muted); }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface-1); border-radius: 10px; width: 40px; height: 40px;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 24px; }
.view > h2 { font-size: 22px; margin: 6px 0 12px; letter-spacing: -0.01em; }

/* ---------- cards */
.card {
  background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 12px;
}
.card h3 { font-size: 15px; margin: 0 0 10px; color: var(--text-secondary); font-weight: 600; }
.card h3 .aside { float: right; font-weight: 400; color: var(--text-muted); font-size: 13px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- status */
.verdict { display: flex; gap: 14px; align-items: center; }
.verdict .badge-big {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff;
}
.verdict .badge-big svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 2.5; }
.verdict .headline { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.s-ok { background: var(--good); }
.s-warn { background: var(--warning); color: #3a2a00 !important; }
.s-critical { background: var(--critical); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-secondary); white-space: nowrap;
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--good); }
.dot.warn { background: var(--warning); }
.dot.critical { background: var(--critical); }
.dot.off { background: var(--text-muted); }
.problems { list-style: none; padding: 0; margin: 12px 0 0; }
.problems li { display: flex; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.problems li .tag { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; min-width: 62px; }
.tag.critical { color: var(--critical-ink); }
.tag.warn { color: var(--text-secondary); }
.problems li button { margin-left: auto; }

/* ---------- meters (stat tiles) */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.tile .label { font-size: 13px; color: var(--text-secondary); }
.tile .value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); }
.meter { height: 8px; border-radius: 4px; background: var(--meter-track); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; border-radius: 4px; background: var(--series-1); width: 0; }
.meter.warn > span { background: var(--warning); }
.meter.critical > span { background: var(--critical); }

/* ---------- lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .title { font-weight: 600; }
.svc { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.svc .nums { text-align: right; font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: 4px 10px; align-items: center; padding: 6px 0; }
.bar-row .name { font-size: 14px; }
.bar-row .num { font-size: 13px; text-align: right; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.bar-row .meter { grid-column: 1 / -1; margin-top: 0; height: 6px; }

details.group { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; box-shadow: var(--shadow); }
details.group > summary {
  list-style: none; cursor: pointer; padding: 13px 16px; display: flex; align-items: center; gap: 10px; font-weight: 600;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted); transform: rotate(45deg); margin-left: auto; transition: transform 0.15s; }
details.group[open] > summary::after { transform: rotate(225deg); }
details.group > .body { padding: 0 16px 10px; }

/* ---------- buttons, forms */
.btn {
  border: 1px solid var(--line); background: var(--surface-1); border-radius: 10px; padding: 9px 14px; cursor: pointer;
  font-weight: 600; min-height: 40px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--critical-ink); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 14px; color: var(--text-secondary); margin-bottom: 4px; }
input[type="text"], input[type="number"], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-1);
}
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.check b { display: block; font-weight: 600; }
.check small { color: var(--text-muted); }
.switch-box { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.switch-box.on { border-color: var(--serious); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-1); padding: 5px 12px; cursor: pointer; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- chart */
.chart { position: relative; margin-top: 6px; }
.chart + .chart, .chart + div > .chart { margin-top: 18px; }
.scope-chips + .btns { margin-top: 12px; }
.chart svg { display: block; width: 100%; height: 130px; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1-soft); stroke: none; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; }
.chart .marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .tip {
  position: absolute; top: -6px; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-1);
  font-size: 12px; padding: 3px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap;
}
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chart-head .now { font-size: 13px; color: var(--text-secondary); }

/* ---------- logs, code */
pre.logs {
  background: var(--surface-2); border-radius: 10px; padding: 10px; font: 12px/1.5 var(--mono); overflow-x: auto;
  max-height: 50vh; white-space: pre; margin: 8px 0 0;
}
.code {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font: 13px/1.5 var(--mono); overflow-x: auto;
  white-space: pre; word-break: normal;
}
.secret { word-break: break-all; white-space: normal; font-weight: 600; }

/* ---------- bottom nav */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--surface-1);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs a {
  flex: 1; text-align: center; padding: 8px 0 9px; font-size: 12px; color: var(--text-muted); text-decoration: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
nav.tabs a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; }
nav.tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ---------- dialogs */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--surface-1); color: var(--text-primary); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog .d-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface-1); }
dialog .d-head h3 { margin: 0; font-size: 18px; flex: 1; }
dialog .d-body { padding: 14px 16px 18px; }

/* ---------- sign in */
.signin { max-width: 420px; margin: 12vh auto 0; text-align: center; padding: 0 16px; }
.signin .logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 14px; display: block; }
.signin h2 { margin: 0 0 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--text-primary); color: var(--surface-1); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.toast.bad { background: var(--critical); color: #fff; }
.empty { color: var(--text-muted); text-align: center; padding: 18px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.scope-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.scope-chips .pill.change { background: transparent; border: 1px solid var(--serious); color: var(--text-primary); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; font-weight: 600; color: var(--text-muted); font-size: 12px; padding: 4px 6px 4px 0; }
table.tbl td { padding: 7px 6px 7px 0; border-top: 1px solid var(--line); vertical-align: top; }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll-x { overflow-x: auto; }
@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
