:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e7e6df;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #0ca30c; --good-ink: #006300; --warn: #fab219; --warn-ink: #8a5b00; --serious: #ec835a; --crit: #d03b3b;
  --seq-0: #eef4fc; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: rgba(57, 135, 229, 0.16);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --good-ink: #0ca30c; --warn-ink: #fab219;
  --seq-0: #1d2633; --seq-1: #104281; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #9ec5f4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: rgba(57, 135, 229, 0.16);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --good-ink: #0ca30c; --warn-ink: #fab219;
    --seq-0: #1d2633; --seq-1: #104281; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #9ec5f4;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 18px 12px; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand b { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-wash); color: var(--accent-ink); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); display: grid; gap: 8px; }
.side-foot button { justify-self: start; }

.main { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 28px;
  background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.top h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.top .crumbs { color: var(--muted); font-size: 13px; }
.top .spacer { flex: 1; }
.content { padding: 22px 28px 60px; max-width: 1480px; }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--crit); }
.btn.danger.solid { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12.5px; border-radius: 6px; }
.btn svg { width: 15px; height: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 5px 11px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
input[type=text], input[type=password], input[type=search], select {
  height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface);
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------------- cards */
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card > header { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; }
.card > header h2, .card > header h3 { font-size: 14px; margin: 0; font-weight: 600; }
.card > header .sub { color: var(--muted); font-size: 12.5px; }
.card > header .spacer { flex: 1; }
.card .body { padding: 14px 16px 16px; }
.card .body.flush { padding: 10px 0 4px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; margin: 26px 0 10px; }

.tile { padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 12.5px; font-weight: 500; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .value small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.tile .foot { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* ---------------------------------------------------------------- tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border-strong);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface); user-select: none;
}
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--ink); }
.tbl th .arrow { color: var(--accent); margin-left: 3px; }
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tr.click { cursor: pointer; }
.tbl tfoot td { font-weight: 600; border-top: 1px solid var(--border-strong); border-bottom: 0; }
.tbl .name { font-weight: 600; color: var(--ink); }
.tbl .sub { color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- pills */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 2px 8px 2px 7px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface); white-space: nowrap; color: var(--ink-2); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.pill.running i, .pill.good i, .pill.matched i, .pill.available i { background: var(--good); }
.pill.stopped i { background: transparent; border: 1.5px solid var(--muted); }
.pill.pending i, .pill.stopping i, .pill.warn i, .pill.rebooting i { background: var(--warn); animation: pulse 1.2s infinite; }
.pill.warn i { animation: none; }
.pill.crit i, .pill.high i, .pill.over-billed i { background: var(--crit); }
.pill.medium i, .pill.under-billed i, .pill.serious i { background: var(--serious); }
.pill.info i { background: var(--accent); }
.pill.low i, .pill.billed-only i, .pill.not-billed i { background: var(--warn); }
.pill.lock { color: var(--ink-2); }
.pill svg { width: 12px; height: 12px; }
@keyframes pulse { 50% { opacity: .35; } }
.tag.new { background: var(--accent); color: #fff; font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: .04em; vertical-align: 2px; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); color: var(--ink-2); margin: 1px 3px 1px 0; }

/* ---------------------------------------------------------------- spec lists */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.spec-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.big-spec { display: flex; gap: 22px; flex-wrap: wrap; padding: 4px 0 2px; }
.big-spec div b { display: block; font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big-spec div span { color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .12; }
.chart .xhair { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.tip {
  position: absolute; pointer-events: none; z-index: 30; min-width: 140px; max-width: 320px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
}
.tip .t { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 8px; }
.tip .r b { margin-left: auto; font-variant-numeric: tabular-nums; padding-left: 12px; }
.sw { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.sw.ln { height: 3px; border-radius: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); margin: 0 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.chart-title b { font-size: 13px; }
.chart-title .now { margin-left: auto; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

.meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.meter.warn > i { background: var(--warn); }
.meter.crit > i { background: var(--crit); }
.meter-row { display: grid; grid-template-columns: 70px 1fr 120px; gap: 12px; align-items: center; font-size: 13px; margin: 8px 0; }
.meter-row .num { color: var(--ink-2); }

.heat { display: grid; gap: 2px; font-size: 11.5px; }
.heat .hl { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px; align-self: center; }
.heat .hc { height: 18px; border-radius: 3px; background: var(--seq-0); }
.heat .hx { color: var(--muted); font-size: 10.5px; text-align: center; }

.spark { display: block; }

/* ---------------------------------------------------------------- findings */
.finding { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; padding: 12px 16px; border-top: 1px solid var(--grid); }
.finding:first-child { border-top: 0; }
.finding .ttl { font-weight: 600; }
.finding .det { grid-column: 2; color: var(--ink-2); font-size: 13px; }
.finding .save { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.finding .save small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }

/* ---------------------------------------------------------------- modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .38); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); border: 1px solid var(--border); }
.modal.wide { width: min(920px, 100%); }
.modal header { padding: 18px 20px 6px; }
.modal header h3 { margin: 0; font-size: 17px; }
.modal .mb { padding: 8px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }
.callout { border-radius: 8px; padding: 10px 12px; font-size: 13px; background: var(--surface-2); border-left: 3px solid var(--muted); margin: 10px 0; }
.callout.warn { border-left-color: var(--warn); }
.callout.crit { border-left-color: var(--crit); }
.callout.info { border-left-color: var(--accent); }
.field { display: grid; gap: 6px; margin: 12px 0; font-size: 13px; }
.field input { width: 100%; }
.type-list { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.type-list tr.sel td { background: var(--accent-wash) !important; }
.steps { list-style: none; padding: 0; margin: 10px 0; font-size: 13px; }
.steps li { padding: 4px 0; display: flex; gap: 10px; }
.steps li span { color: var(--muted); font-variant-numeric: tabular-nums; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: grid; gap: 8px; }
.toast div { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: 420px; }
.toast div.err { background: var(--crit); color: #fff; }

.loading { padding: 40px; text-align: center; color: var(--muted); }
.loading::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 10px; vertical-align: -2px; border: 2px solid var(--axis); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.err-box { padding: 14px 16px; color: var(--crit); }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); padding: 28px; }
.login h1 { font-size: 20px; margin: 14px 0 4px; }
.login p { margin: 0 0 18px; color: var(--muted); }
.login .btn { width: 100%; justify-content: center; height: 38px; margin-top: 8px; }
.login .msg { color: var(--crit); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--ink-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tabs button .count { color: var(--muted); font-weight: 400; margin-left: 4px; }

details.method { font-size: 13px; color: var(--ink-2); }
details.method summary { cursor: pointer; font-weight: 600; color: var(--ink); }
details.method li { margin: 4px 0; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .g-main, .g3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 4px 8px; }
  .nav { display: flex; overflow-x: auto; width: 100%; }
  .nav a { padding: 6px 10px; }
  .side-foot { display: none; }
  .top { padding: 10px 16px; position: static; }
  .content { padding: 16px 16px 40px; }
  .g2 { grid-template-columns: minmax(0, 1fr); }
  .charts { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------------------------- print */
@media print {
  :root { color-scheme: light; --page: #fff; --surface: #fff; --shadow: none; }
  .side, .top, .no-print, .btn { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { break-inside: avoid; box-shadow: none; }
  .tbl th { position: static; }
  body { font-size: 11.5px; }
}
