.viz-root {
  color-scheme: light;
  --surface-0: #f6f6f4;
  --surface-1: #ffffff;
  --surface-2: #f1f1ef;
  --border: #e3e3df;
  --grid: #ececea;
  --text-primary: #191919;
  --text-secondary: #666666;
  --series-1: #257de0;
  --series-2: #f47230;
  --good: #0aac23; --good-ink: #006c10;
  --warning: #fbb315; --warning-ink: #8a5a00;
  --serious: #f18a59; --serious-ink: #9a3d12;
  --critical: #dc3c3d; --critical-ink: #b42324;
  --off: #9a9a96;
  --qa: #6a4ce2; --prod: #ec4647;
  --focus: #257de0;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-0: #111111; --surface-1: #191919; --surface-2: #222222;
    --border: #2f2f2f; --grid: #2a2a2a;
    --text-primary: #efefef; --text-secondary: #9c9c9c;
    --series-1: #338ced; --series-2: #e76624;
    --good-ink: #5fd06f; --warning-ink: #fbb315; --serious-ink: #f18a59; --critical-ink: #f07a7b;
    --off: #6f6f6b; --qa: #9887ef; --prod: #eb6263;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.viz-root { min-height: 100vh; background: var(--surface-0); color: var(--text-primary); }
.muted { color: var(--text-secondary); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code { font: 12px/1.3 ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: var(--surface-1); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; white-space: nowrap; }
.brand svg { width: 20px; height: 20px; fill: var(--series-1); }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--text-secondary); font-weight: 550; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text-primary); }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 13px; }
.user { display: flex; align-items: center; gap: 6px; }
.role { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-secondary); }
.btn { border: 1px solid var(--border); background: var(--surface-1); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 550; }
.btn:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.banner { margin: 16px 24px 0; padding: 10px 14px; border-radius: 10px; background: var(--surface-1); border: 1px solid var(--warning); }

main { padding: 20px 24px 48px; max-width: 1440px; margin: 0 auto; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: 12px; color: var(--text-secondary); font-weight: 550; }
.tile .v { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.tile .s { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 7px; cursor: pointer; color: var(--text-secondary); font-weight: 550; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text-primary); }
.filters select, .filters input { background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px; }
.filters input { min-width: 220px; }

/* project groups */
.group { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 18px; box-shadow: var(--shadow); overflow: hidden; }
.group-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.group-head h2 { margin: 0; font-size: 15px; }
.env-badge { font-size: 11px; font-weight: 700; letter-spacing: .05em; padding: 2px 8px; border-radius: 6px; color: #fff; }
.env-badge.QA { background: var(--qa); }
.env-badge.PROD { background: var(--prod); }
.group-head .sum { margin-left: auto; color: var(--text-secondary); font-size: 13px; font-variant-numeric: tabular-nums; }
.group-head .bulk { display: flex; gap: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; color: var(--text-secondary); font-weight: 600; background: var(--surface-1); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.proj:hover td { background: var(--surface-2); }
.pname { font-weight: 600; }
.pid { font-size: 12px; color: var(--text-secondary); }
.where { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.expand { border: 0; background: none; cursor: pointer; color: var(--text-secondary); width: 22px; padding: 0; font-size: 12px; }
tr.detail td { background: var(--surface-2); padding: 8px 16px 12px 48px; }
.res { display: grid; gap: 4px; font-size: 12.5px; }
.res .r { display: flex; gap: 10px; flex-wrap: wrap; }
.res .r b { font-weight: 600; }
.res .svc { color: var(--text-secondary); }
.err { color: var(--critical-ink); }

/* status pill: icon + label, never colour alone */
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.status.on { color: var(--good-ink); } .status.on .dot { background: var(--good); }
.status.off { color: var(--text-secondary); }
.status.partial { color: var(--serious-ink); } .status.partial .dot { background: var(--serious); }
.status.starting, .status.stopping { color: var(--warning-ink); }
.status.starting .dot, .status.stopping .dot { background: var(--warning); animation: pulse 1.1s ease-in-out infinite; }
.status.error { color: var(--critical-ink); } .status.error .dot { background: var(--critical); border-radius: 2px; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .status .dot { animation: none !important; } }

/* switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; border-radius: 99px; background: var(--off); transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--good); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled + .track { opacity: .45; }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch.busy .track { background: var(--warning); }

/* costs */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin: 0; box-shadow: var(--shadow); min-width: 0; }
.card.wide { grid-column: 1 / -1; }
figcaption { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
figcaption h3 { margin: 0; font-size: 14px; }
.legend { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.sw.s1 { background: var(--series-1); } .sw.s2 { background: var(--series-2); }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .lbl { fill: var(--text-primary); font-size: 11.5px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: .10; }
.chart .b1 { fill: var(--series-1); } .chart .b2 { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .cross { stroke: var(--text-secondary); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .hl { opacity: 1; } .chart.hovering .bar:not(.hl) { opacity: .45; }
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.14); max-width: 280px; }
.tooltip b { font-variant-numeric: tabular-nums; }
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.bar-cell .track2 { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; position: relative; overflow: hidden; }
.bar-cell .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-cell .ghost24 { position: absolute; left: 0; top: 0; bottom: 0; border-right: 2px solid var(--series-2); }
.save { color: var(--good-ink); font-weight: 600; }

/* toast + dialog */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-1);
  padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.bad { background: var(--critical); color: #fff; }
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 20px 22px; background: var(--surface-1); color: var(--text-primary); width: min(460px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 8px; }
dialog label { display: grid; gap: 6px; margin: 12px 0 4px; font-size: 13px; }
dialog input { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-0); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.note { color: var(--text-secondary); font-size: 12.5px; max-width: 900px; }
.empty { padding: 24px; text-align: center; color: var(--text-secondary); }
.skeleton { height: 120px; border-radius: 12px; background: linear-gradient(90deg, var(--surface-1), var(--surface-2), var(--surface-1)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }

.of { font-size: 15px; }
.s2ink { color: var(--series-2); font-weight: 600; }

@media (max-width: 960px) {
  .grid2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  main { padding: 14px; }
  .hide-sm { display: none; }
}
