/* kbcinha design system — "Ghost Protocol". Spec: DESIGN.md (repo root).
   Dark-first, system fonts only, no framework, no animation beyond short transitions. */

/* ---------- tokens ---------- */
:root {
  color-scheme: dark;
  /* surface */
  --bg: #0B0E13;          /* page */
  --bg-raised: #11151C;   /* table header, hover row, inputs */
  --line: #1F2530;        /* hairline divider */
  --line-strong: #2A3140; /* input border, meter track, chart gridline */
  /* text */
  --text: #E6E9EF;        /* 15.9:1 on --bg */
  --text-muted: #A1A9B8;  /* 8.2:1  secondary text, table cells */
  --text-faint: #7D8696;  /* 5.3:1  section labels, axis ticks */
  /* interaction (ultraviolet) */
  --uv: #9B7BFF;          /* 6.1:1  active tab, links, focus, hover, selection */
  --uv-fill: #7050F0;     /* solid UI fills (active bar under tab), never text */
  --uv-wash: rgb(155 123 255 / .12); /* hover/selected background */
  /* data (cyan) — series only */
  --data: #4FD8EB;        /* 11.4:1 bars, lines, sparklines, numbers in tables */
  --data-dim: rgb(79 216 235 / .35); /* secondary series / area under line */
  /* status — errors and rate limits only */
  --ok: #3FB950;
  --warn: #F2B84B;        /* 429, retries, quota >= 80% */
  --err: #FF7B72;         /* 5xx, ERROR, quota >= 95% */

  /* type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: .75rem;    /* 12  labels, footer, axis */
  --fs-sm: .8125rem;  /* 13  table, meta */
  --fs-md: .9375rem;  /* 15  body, tabs */
  --fs-lg: 1.25rem;   /* 20  page title */
  --fs-xl: 2rem;      /* 32  KPI value */
  --lh-tight: 1.15;
  --lh: 1.5;
  --tracking-label: .12em;

  /* space (4px base) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;
  /* shape */
  --radius-sm: 4px;   /* badges, meters, inputs */
  --radius-md: 8px;   /* route nodes, search */
  --hairline: 1px solid var(--line);
  /* motion */
  --t-fast: 120ms ease-out;
  /* layout */
  --page-max: 1440px;
  --gutter: var(--s-5);
}

/* optional light theme: <html data-theme="light"> */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F6F7F9; --bg-raised: #ECEEF2; --line: #DDE1E7; --line-strong: #C9CED7;
  --text: #14181F; --text-muted: #4A5262; --text-faint: #5D6574;
  --uv: #6D4AE0; --uv-fill: #6D4AE0; --uv-wash: rgb(109 74 224 / .10);
  --data: #0B7C8C; --data-dim: rgb(11 124 140 / .30);
  --ok: #1A7F37; --warn: #9A6400; --err: #C4322B;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: var(--fs-md)/var(--lh) var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, ol, ul, figure { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: var(--uv); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--uv); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--uv-wash); }
code, kbd, .mono, .num { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.icon {
  width: 1.25em; height: 1.25em; flex: none; vertical-align: -.25em;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- layout ---------- */
.page { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--gutter); min-height: 100vh; display: flex; flex-direction: column; }
.page > main { flex: 1; }
.page > *, .split > *, .kpi { min-width: 0; } /* let tables/route scroll inside, never the page */
.section { padding: var(--s-5) 0; border-top: var(--hairline); }
.label {
  font: 500 var(--fs-xs)/1 var(--font-mono); color: var(--text-faint);
  text-transform: uppercase; letter-spacing: var(--tracking-label);
}
h2.label, h3.label { display: block; margin-bottom: var(--s-4); }
.split { display: grid; grid-template-columns: 1fr 1fr; }
.split > * + * { border-left: var(--hairline); padding-left: var(--s-5); }
.split > :first-child { padding-right: var(--s-5); }
@media (max-width: 860px) {
  :root { --gutter: var(--s-4); }
  .split { grid-template-columns: 1fr; }
  .split > * + * { border-left: 0; padding-left: 0; border-top: var(--hairline); padding-top: var(--s-5); margin-top: var(--s-5); }
}

/* ---------- top bar + tabs ---------- */
.topbar { display: flex; align-items: center; gap: var(--s-6); height: 64px; }
.brand { display: block; line-height: 0; }
.brand img { height: 28px; width: auto; }
.tabs { display: flex; gap: var(--s-1); margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  position: relative; display: block; padding: var(--s-2) var(--s-3);
  color: var(--text-muted); font-size: var(--fs-md); white-space: nowrap; text-decoration: none;
  transition: color var(--t-fast);
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--uv); }
.tabs a[aria-current="page"]::after {
  content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -2px; height: 2px; background: var(--uv-fill);
}
.search {
  display: flex; align-items: center; gap: var(--s-2); height: 36px; padding: 0 var(--s-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-md); color: var(--text-faint);
  background: transparent; transition: border-color var(--t-fast);
}
.search:focus-within { border-color: var(--uv); }
.search input { width: 10ch; border: 0; background: none; color: var(--text); font: inherit; font-size: var(--fs-sm); }
.search input:focus { outline: none; }
kbd { font-size: var(--fs-xs); color: var(--text-faint); }
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: var(--s-3) 0; gap: var(--s-3); }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .search { margin-left: auto; }
  .search input { width: 6ch; }
}

/* ---------- KPI strip ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); border-top: var(--hairline); }
.kpi { padding: var(--s-4) var(--s-5) var(--s-4) 0; }
.kpi + .kpi { padding-left: var(--s-5); border-left: var(--hairline); }
.kpi__value {
  display: block; margin: var(--s-2) 0 var(--s-3);
  font: 400 var(--fs-xl)/var(--lh-tight) var(--font-mono); font-variant-numeric: tabular-nums; color: var(--data);
}
.kpi__unit { font-size: .6em; color: var(--text-muted); margin-left: .1em; }
.kpi__delta { font: var(--fs-xs) var(--font-mono); color: var(--text-faint); }
.spark { display: block; width: 100%; height: 28px; }
@media (max-width: 860px) {
  .kpi + .kpi { border-left: 0; padding-left: 0; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--s-4); }
  .kpi { padding-right: 0; }
}

/* ---------- charts (inline SVG, server-rendered) ---------- */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.viz-bar { fill: var(--data); transition: fill var(--t-fast); }
.viz-bar:hover, .viz-bar.is-active { fill: var(--uv); }
.viz-line { fill: none; stroke: var(--data); stroke-width: 1.5; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.viz-line--2 { stroke: var(--data-dim); }
.viz-area { fill: var(--data-dim); opacity: .35; }
.viz-grid { stroke: var(--line); stroke-dasharray: 2 4; vector-effect: non-scaling-stroke; }
.viz-cursor { stroke: var(--uv); stroke-width: 1; vector-effect: non-scaling-stroke; }
.viz-tick { fill: var(--text-faint); font: 11px var(--font-mono); font-variant-numeric: tabular-nums; }
.viz-err { fill: var(--err); }
.viz-warn { fill: var(--warn); }

/* ---------- route row ---------- */
.route { display: flex; align-items: flex-start; gap: var(--s-3); overflow-x: auto; }
.route__node { display: grid; justify-items: center; gap: var(--s-1); min-width: 88px; text-align: center; }
.route__icon {
  display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: var(--s-1);
  border: 1px solid var(--uv); border-radius: var(--radius-md); color: var(--uv);
}
.route__icon .icon { width: 24px; height: 24px; }
.route__name { font: var(--fs-sm) var(--font-mono); color: var(--text); white-space: nowrap; }
.route__arrow { flex: 1; min-width: 24px; max-width: 72px; height: 1px; margin-top: 28px; background: var(--uv); position: relative; }
.route__arrow::after {
  content: ""; position: absolute; right: 0; top: -3px; width: 6px; height: 6px;
  border-top: 1px solid var(--uv); border-right: 1px solid var(--uv); transform: rotate(45deg);
}
.route__node.is-down .route__icon { border-color: var(--err); color: var(--err); }

/* ---------- quota bar ---------- */
.quota { display: grid; grid-template-columns: minmax(96px, auto) 1fr 5ch; align-items: center; gap: var(--s-3) var(--s-4); }
.quota__name { font-size: var(--fs-md); color: var(--text); }
.quota__value { font: var(--fs-sm) var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--text); }
.meter { height: 4px; border-radius: var(--radius-sm); background: var(--line-strong); overflow: hidden; }
.meter > span { display: block; height: 100%; width: var(--v, 0%); background: var(--data); border-radius: inherit; }
.meter.is-warn > span { background: var(--warn); }
.meter.is-err > span { background: var(--err); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; border-top: var(--hairline); border-bottom: var(--hairline); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  position: sticky; top: 0; background: var(--bg); text-align: left; white-space: nowrap;
  padding: var(--s-2) var(--s-3); border-bottom: var(--hairline);
  font: 500 var(--fs-xs)/1.4 var(--font-mono); color: var(--text-faint); text-transform: uppercase; letter-spacing: var(--tracking-label);
}
.table td { padding: var(--s-2) var(--s-3); border-bottom: var(--hairline); color: var(--text-muted); white-space: nowrap; font-family: var(--font-mono); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--t-fast); }
.table tbody tr:hover { background: var(--bg-raised); }
.table tbody tr[aria-selected="true"] { background: var(--uv-wash); }
.table .num, .table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.is-data { color: var(--data); }
.table td.is-strong { color: var(--text); }

/* ---------- status dot + badges + log levels ---------- */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); vertical-align: .05em; }
.dot--ok { background: var(--ok); }
.dot--warn { background: var(--warn); }
.dot--err { background: var(--err); }
.badge {
  display: inline-flex; align-items: center; gap: var(--s-1); padding: 1px var(--s-2);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: 500 var(--fs-xs)/1.5 var(--font-mono); color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em;
}
.badge--uv { border-color: var(--uv); color: var(--uv); }
.badge--warn { border-color: var(--warn); color: var(--warn); }
.badge--err { border-color: var(--err); color: var(--err); }
/* .table prefix wins over `.table td` */
.lvl--info, .table .lvl--info { color: var(--text-muted); }
.lvl--warn, .st--4xx, .table .lvl--warn, .table .st--4xx { color: var(--warn); }
.lvl--error, .st--5xx, .table .lvl--error, .table .st--5xx { color: var(--err); }
.st--2xx, .table .st--2xx { color: var(--text); }

/* ---------- empty / error / loading ---------- */
.state { display: grid; justify-items: start; gap: var(--s-2); padding: var(--s-6) 0; color: var(--text-muted); font-size: var(--fs-sm); }
.state .icon { width: 20px; height: 20px; color: var(--text-faint); }
.state__title { color: var(--text); font-size: var(--fs-md); }
.state--error .icon, .state--error .state__title { color: var(--err); }
.skeleton { display: block; height: 12px; border-radius: var(--radius-sm); background: var(--bg-raised); } /* static: no shimmer */
.skeleton + .skeleton { margin-top: var(--s-2); }

/* ---------- button (minimal) ---------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--s-2); height: 32px; padding: 0 var(--s-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: none;
  color: var(--text); font: inherit; font-size: var(--fs-sm); cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast);
}
.btn:hover { border-color: var(--uv); color: var(--uv); }
.btn--primary { background: var(--uv-fill); border-color: var(--uv-fill); color: #fff; }
.btn--primary:hover { color: #fff; filter: brightness(1.1); }

/* ---------- footer ---------- */
.footer {
  display: grid; grid-template-columns: repeat(4, auto); justify-content: space-between; gap: var(--s-3) var(--s-5);
  padding: var(--s-4) 0; border-top: var(--hairline);
  font: var(--fs-xs) var(--font-mono); color: var(--text-faint); text-transform: uppercase; letter-spacing: var(--tracking-label);
}
.footer b { font-weight: 400; color: var(--data); margin-left: var(--s-2); }
.footer .dot { margin-right: var(--s-2); }
@media (max-width: 600px) { .footer { grid-template-columns: 1fr 1fr; } }
