:root {
  --bg: #141311;
  --bg-2: #191815;
  --surface: #1e1d1a;
  --surface-2: #24231f;
  --border: #2f2e2a;
  --border-strong: #3c3b36;
  --text: #eceae4;
  --text-2: #9c9890;
  --text-3: #6f6b64;
  --accent: #8b8578;
  --accent-2: #c4bbaa;
  --up: #3f7d58;
  --up-bg: #1c2a21;
  --down: #a14b46;
  --down-bg: #2a1c1b;
  --warn: #a4843c;
  --warn-bg: #2a2418;
  --focus: #c4bbaa;
  --paper: #c4b89a;
  --radius: 4px;
  --sans: "IBM Plex Sans", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top: 44px;
  --strip: 28px;
  --nav: 196px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 13px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 1px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 50; }

.num, table td.num, .metric-v, .eq-value { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.mono { font-family: var(--mono); font-size: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--top);
  display: flex; align-items: center; gap: 16px;
  padding: 0 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 168px; }
.brand .name { font-weight: 600; letter-spacing: 0.04em; font-size: 14px; }
.mode-badge {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em;
  border: 1px solid var(--paper); color: var(--paper);
  padding: 2px 6px;
}
.status-cluster { display: flex; gap: 14px; flex: 1; min-width: 0; }
.stat { display: flex; flex-direction: column; min-width: 72px; }
.stat .label { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.stat .value { font-family: var(--mono); font-size: 12px; }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--down); }
.stat.ok .value { color: var(--up); }
.top-actions { display: flex; gap: 8px; align-items: center; }
.mode-toggle { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.mode-toggle button {
  background: transparent; border: 0; border-right: 1px solid var(--border);
  color: var(--text-2); padding: 5px 10px; cursor: pointer; font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
}
.mode-toggle button:last-child { border-right: 0; }
.mode-toggle button[aria-pressed="true"] { background: var(--surface-2); color: var(--paper); }
.mode-toggle button.live-on[aria-pressed="true"] { color: #e0b8b5; background: var(--down-bg); }
.mode-badge.live { border-color: var(--down); color: #e0b8b5; }

.paper-strip {
  height: var(--strip);
  display: flex; align-items: center;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--paper);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.shell { display: grid; grid-template-columns: var(--nav) 1fr; min-height: calc(100vh - var(--top) - var(--strip)); }
.nav {
  border-right: 1px solid var(--border);
  background: var(--bg-2);
  padding: 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.nav a {
  color: var(--text-2);
  padding: 7px 10px;
  border-radius: var(--radius);
  text-decoration: none;
}
.nav a:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); border: 1px solid var(--border); }

main { padding: 16px 18px 40px; min-width: 0; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.page-head h1 { font-size: 16px; font-weight: 600; margin: 0; }
.page-head .meta { color: var(--text-2); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card h2, .card h3 {
  margin: 0; padding: 8px 12px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-2); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.card .body { padding: 10px 12px; }
.card .link { font-size: 11px; letter-spacing: 0; text-transform: none; font-weight: 500; }

.metrics { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 8px; margin-bottom: 12px; }
.metric {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px;
}
.metric .k { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.metric .v { font-size: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric .s { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.metric.up .v { color: var(--up); }
.metric.down .v { color: var(--down); }
.metric.muted .v { color: var(--text-2); }

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.danger { border-color: var(--down); color: #e0b8b5; }
.btn.primary { border-color: var(--accent-2); color: var(--accent-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { padding: 3px 8px; font-size: 12px; }

.seg { display: inline-flex; border: 1px solid var(--border); }
.seg button {
  background: transparent; border: 0; border-right: 1px solid var(--border);
  color: var(--text-2); padding: 4px 9px; cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

.table-wrap { overflow: auto; max-height: 520px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-3); font-weight: 500; position: sticky; top: 0; background: var(--surface-2); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.selected { background: #26251f; }
td.right, th.right { text-align: right; }
.up { color: var(--up); }
.down { color: var(--down); }
.pill { font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; border: 1px solid var(--border); padding: 1px 6px; color: var(--text-2); }
.pill.on { border-color: var(--warn); color: var(--warn); }
.pill.ok { border-color: var(--up); color: var(--up); }
.pill.bad { border-color: var(--down); color: var(--down); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.filters input, .filters select {
  background: var(--bg); border: 1px solid var(--border); padding: 5px 8px; min-width: 140px;
}
.empty, .loading, .stale-note {
  color: var(--text-2); padding: 18px 12px; font-size: 13px;
}
.loading { font-family: var(--mono); }
.stale-note { background: var(--warn-bg); border-top: 1px solid var(--border); }
.hierarchy .child.muted { color: var(--text-3); }

.chart-box { position: relative; height: 320px; }
.chart-box.short { height: 120px; }
.chart-legend { display: flex; gap: 14px; color: var(--text-2); font-size: 11px; padding: 0 12px 8px; }
.swatch { display: inline-block; width: 10px; height: 2px; background: var(--text); vertical-align: middle; margin-right: 4px; }
.swatch.base { background: var(--accent); }
.swatch.up { background: var(--up); }
.swatch.down { background: var(--down); }
.tooltip {
  position: absolute; pointer-events: none;
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 6px 8px; font-size: 11px; font-family: var(--mono);
  white-space: nowrap; z-index: 5;
}

.alerts { display: flex; flex-direction: column; gap: 6px; }
.alert { border: 1px solid var(--border); padding: 8px 10px; }
.alert.warning { border-color: var(--warn); }
.alert .t { font-weight: 600; }
.alert .d { color: var(--text-2); margin-top: 2px; }

.hierarchy { font-size: 12px; }
.hierarchy .node { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.hierarchy .child { padding-left: 24px; }
.live-feed { font-family: var(--mono); font-size: 11px; max-height: 360px; overflow: auto; }
.live-feed .row { display: grid; grid-template-columns: 72px 70px 1fr; gap: 8px; padding: 4px 10px; border-bottom: 1px solid var(--border); }
.live-feed .k { color: var(--text-3); }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; font-size: 12px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

pre.payload { font-family: var(--mono); font-size: 11px; white-space: pre-wrap; margin: 0; max-height: 280px; overflow: auto; }

.drawer, .modal {
  position: fixed; inset: 0; background: rgba(10,10,9,0.55); z-index: 40;
  display: flex; justify-content: flex-end;
}
.drawer[hidden], .modal[hidden] { display: none !important; }
.modal { justify-content: center; align-items: center; }
.drawer-panel, .modal-panel {
  background: var(--bg-2); border-left: 1px solid var(--border);
  width: min(520px, 100%); height: 100%; display: flex; flex-direction: column;
}
.modal-panel { width: min(440px, 92vw); height: auto; border: 1px solid var(--border); padding: 16px; }
.drawer-panel header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.drawer-panel h2, .modal-panel h2 { margin: 0; font-size: 14px; }
.drawer-body { padding: 12px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
body.login main {
  width: min(380px, 92vw);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 24px;
}
body.login .kicker { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3); margin: 0 0 6px; }
body.login h1 { margin: 0 0 8px; font-size: 20px; }
body.login .sub { color: var(--text-2); margin: 0 0 16px; }
body.login label { display: flex; flex-direction: column; gap: 6px; }
body.login input { background: var(--bg); border: 1px solid var(--border); padding: 8px; font-family: var(--mono); }
body.login button { margin-top: 14px; width: 100%; padding: 8px; background: var(--surface-2); border: 1px solid var(--accent-2); color: var(--accent-2); cursor: pointer; }
body.login .err { color: var(--down); }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .chart-box { height: 240px; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .nav { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
  .status-cluster { display: none; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}
