/* Devcode Console. Tokens first: every color is a role, light and dark are each chosen (not flipped).
   Series colors follow the dataviz reference palette (validated: blue/orange/aqua all-pairs, both modes). */
:root {
  color-scheme: light;
  --bg: #f2f2ef;
  --card: #fcfcfb;
  --card-2: #f4f4f1;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6b6a65;
  --axis-ink: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.09);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --accent-ink: #1c5cab;
  --s-new: #2a78d6;
  --s-churn: #eb6834;
  --s-active: #1baf7a;
  --s-rev: #6250d6;
  --good: #0ca30c;
  --good-text: #006300;
  --bad-text: #b8312f;
  --warning: #fab219;
  --critical: #d03b3b;
  --info: #6b6a65;
  --warn-soft: #fff6e0;
  --crit-soft: #fdecec;
  --good-soft: #e9f6e9;
  --skel: #e8e8e3;
  --radius: 16px;
}
:root[data-scheme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --card: #1a1a19;
  --card-2: #222220;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #a3a198;
  --axis-ink: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: none;
  --accent: #3987e5;
  --accent-soft: #1b2a3d;
  --accent-ink: #9ec5f4;
  --s-new: #3987e5;
  --s-churn: #d95926;
  --s-active: #199e70;
  --s-rev: #9085e9;
  --good: #0ca30c;
  --good-text: #3fc23f;
  --bad-text: #f07a7a;
  --warning: #fab219;
  --critical: #e05252;
  --info: #a3a198;
  --warn-soft: #2e2715;
  --crit-soft: #321b1b;
  --good-soft: #162a16;
  --skel: #262624;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px calc(28px + env(safe-area-inset-bottom)); }
.num { font-variant-numeric: normal; }
.star { font-size: 0.72em; margin-right: 0.25em; vertical-align: 0.08em; }
.tab { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  margin: 0 -16px; padding: 12px 16px 10px;
}
.top-row { display: flex; align-items: center; gap: 10px; }
.brand { width: 34px; height: 34px; border-radius: 10px; flex: none; display: block; }
.title { flex: 1; min-width: 0; }
.title h1 { margin: 0; font-size: 18px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
.updated { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--card);
  display: grid; place-items: center; cursor: pointer; flex: none; color: var(--ink-2);
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.seg {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; margin-top: 10px; padding: 3px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 12px;
}
.seg.two { grid-template-columns: repeat(2, 1fr); }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg button {
  border: 0; background: transparent; border-radius: 9px; padding: 7px 4px; font-size: 13px; font-weight: 600;
  color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
:root[data-scheme="dark"] .seg button.on { background: #33332f; }

/* ---------- sections & cards ---------- */
.sec-h { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 2px 8px; }
.sec-h h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); }
.sec-h .aside { font-size: 12px; color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px;
}
.card + .card { margin-top: 10px; }
.busy .live { opacity: 0.55; transition: opacity 0.2s; }
.live { transition: opacity 0.2s; }

/* hero */
.hero-label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.hero { font-size: 48px; line-height: 1.05; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 4px; }
.hero-sub { font-size: 13px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.hero-sub b { color: var(--ink); font-weight: 600; }
.note { margin-top: 10px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: flex-start; }
.note svg { width: 14px; height: 14px; flex: none; margin-top: 1px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.tile { background: var(--card-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile .lab { font-size: 12px; color: var(--ink-2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .val { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; margin-top: 2px; white-space: nowrap; }
.tile .val small { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-left: 4px; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.delta svg { width: 11px; height: 11px; stroke-width: 3; }
.delta.good { color: var(--good-text); }
.delta.bad { color: var(--bad-text); }
.delta.flat { color: var(--muted); }

/* insights */
.ins { list-style: none; margin: 0; padding: 0; }
.ins li { display: flex; gap: 10px; padding: 10px 2px; align-items: flex-start; font-size: 14px; line-height: 1.4; }
.ins li + li { border-top: 1px solid var(--border); }
.ins li[data-bot] { cursor: pointer; }
.ins .ic { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; flex: none; margin-top: 0; }
.ins .ic svg { width: 14px; height: 14px; }
.ins .critical .ic { background: var(--crit-soft); color: var(--critical); }
.ins .warning .ic { background: var(--warn-soft); color: #b37400; }
:root[data-scheme="dark"] .ins .warning .ic { color: var(--warning); }
.ins .info .ic { background: var(--card-2); color: var(--info); }
.ins .good .ic { background: var(--good-soft); color: var(--good-text); }
.ins .lvl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); display: block; margin-bottom: 1px; }

/* bot cards */
.bot { cursor: pointer; position: relative; }
.bot:active { transform: scale(0.995); }
.bot-h { display: flex; align-items: center; gap: 10px; }
.logo { width: 40px; height: 40px; border-radius: 12px; flex: none; object-fit: cover; background: var(--card-2); }
.logo.ini { display: grid; place-items: center; font-weight: 700; font-size: 17px; color: var(--ink-2); border: 1px solid var(--border); }
.logo.lg { width: 56px; height: 56px; border-radius: 16px; font-size: 22px; }
.bot-n { flex: 1; min-width: 0; }
.bot-n b { display: block; font-size: 16px; line-height: 1.2; }
.bot-n span { font-size: 12px; color: var(--muted); }
.pill { font-size: 12px; font-weight: 600; padding: 3px 8px 3px 7px; border-radius: 99px; display: inline-flex; gap: 5px; align-items: center; white-space: nowrap; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--good-soft); color: var(--good-text); }
.pill.offline { background: var(--crit-soft); color: var(--bad-text); }
.pill.unconfigured { background: var(--card-2); color: var(--muted); }
.pill svg { width: 12px; height: 12px; }
.chev { width: 18px; height: 18px; color: var(--muted); flex: none; }
.stale { margin-top: 10px; font-size: 12px; color: var(--ink-2); background: var(--warn-soft); border-radius: 10px; padding: 7px 10px; }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.trio .k { font-size: 12px; color: var(--muted); white-space: nowrap; }
.trio .v { font-size: 18px; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.trio .d { min-height: 16px; }
.divider { border-top: 1px solid var(--border); margin: 12px 0; }
.spark-h { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.legend i.box { width: 10px; height: 10px; border-radius: 3px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: 13px; }
.facts .k { color: var(--muted); font-size: 12px; }
.facts .v { font-weight: 600; }
.facts .v small { color: var(--muted); font-weight: 500; }
.reasons { margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.reasons b { color: var(--ink); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.kpi { background: var(--card-2); border-radius: 10px; padding: 7px 8px; min-width: 0; }
.kpi .v { font-weight: 700; font-size: 15px; white-space: nowrap; }
.kpi .k { font-size: 11px; color: var(--muted); line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* charts */
.chart { position: relative; margin-top: 4px; outline: none; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: 8px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart text { fill: var(--axis-ink); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart text.end { fill: var(--ink-2); font-weight: 600; font-size: 11px; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 9px; font-size: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14); min-width: 108px; z-index: 2; display: none;
}
.tip .t { color: var(--muted); margin-bottom: 3px; }
.tip .r { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tip .r b { font-variant-numeric: tabular-nums; min-width: 28px; }
.tip .r i { width: 12px; height: 2px; border-radius: 2px; display: inline-block; }
.tip .r span { color: var(--ink-2); }
.chart-card h3 { margin: 0; font-size: 15px; font-weight: 700; }
.chart-card .cap { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.chart-card .legend { margin-bottom: 6px; }
details.table { margin-top: 8px; font-size: 12px; }
details.table summary { cursor: pointer; color: var(--accent-ink); font-weight: 600; padding: 4px 0; }
details.table .scroll { max-height: 260px; overflow: auto; margin-top: 6px; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--card-2); font-weight: 600; color: var(--ink-2); }

/* meters */
.meters { display: grid; gap: 10px; }
.meter .row { display: flex; justify-content: space-between; font-size: 13px; }
.meter .row b { font-weight: 700; }
.meter .track { height: 8px; border-radius: 99px; background: var(--accent-soft); margin-top: 4px; overflow: hidden; }
.meter .fill { height: 100%; border-radius: 99px; background: var(--accent); }
.hbars { display: grid; gap: 8px; }
.hbar .row { display: flex; justify-content: space-between; font-size: 13px; gap: 8px; }
.hbar .bar { height: 8px; background: var(--card-2); border-radius: 4px; margin-top: 3px; }
.hbar .bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--s-churn); min-width: 2px; }

/* detail */
.back { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--accent-ink); font-weight: 600; padding: 6px 0; cursor: pointer; }
.back svg { width: 18px; height: 18px; }
.d-head { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.d-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.d-head .u { font-size: 13px; color: var(--muted); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* skeleton */
.sk { background: var(--skel); border-radius: 10px; position: relative; overflow: hidden; }
.sk::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent); animation: sh 1.3s infinite;
}
:root[data-scheme="dark"] .sk::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent); }
@keyframes sh { to { transform: translateX(100%); } }

/* empty / denied */
.empty { text-align: center; padding: 70px 24px; color: var(--ink-2); }
.empty svg { width: 44px; height: 44px; color: var(--muted); }
.empty h2 { font-size: 18px; color: var(--ink); margin: 12px 0 6px; }

/* footer, sheet, toast */
.foot { margin-top: 24px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 4px 0 2px; font-size: 17px; }
.sheet .lab { font-size: 13px; color: var(--ink-2); margin-top: 16px; font-weight: 600; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--card); padding: 9px 14px; border-radius: 12px; font-size: 13px; transition: 0.2s; pointer-events: none; z-index: 30;
  max-width: calc(100% - 32px);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (forced-colors: active) { .legend i, .tip .r i { forced-color-adjust: none; } }
