:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dddcd7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --grid: #e6e5e0;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 8px 30px rgba(0,0,0,.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34342f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #95948c; --accent: #3987e5;
    --series-1: #3987e5; --grid: #2c2c29; --shadow: 0 8px 30px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34342f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #95948c; --accent: #3987e5;
  --series-1: #3987e5; --grid: #2c2c29; --shadow: 0 8px 30px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h2 { font-size: 16px; margin: 28px 0 12px; }
h3 { margin: 0; font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--critical); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.badge { font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin-left: 6px; vertical-align: middle; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 6px 12px; border-radius: 6px; color: var(--text-2); cursor: pointer; font: inherit; }
.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.btn {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 1px solid transparent;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.warn { background: transparent; color: var(--critical); border-color: var(--critical); }
.btn.small { padding: 3px 8px; font-size: 12px; }

main { padding: 16px; max-width: 1600px; margin: 0 auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.kpi .label { color: var(--text-2); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: var(--accent); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 12px; }
.card { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.card .tenant { font-size: 11px; color: var(--muted); word-break: break-all; }
.card .stats { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 0; }
.card .stats div { font-variant-numeric: tabular-nums; }
.card .stats b { display: block; font-size: 20px; }
.card .stats span { font-size: 12px; color: var(--text-2); }
.card ul.subs { list-style: none; padding: 0; margin: 8px 0; font-size: 12px; color: var(--text-2); }
.card .alert { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--text); border-left: 3px solid var(--critical); padding: 8px 10px; border-radius: 4px; font-size: 12px; margin-top: 8px; word-break: break-word; }

.bars { margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 36px; gap: 8px; align-items: center; font-size: 12px; margin: 3px 0; color: var(--text-2); }
.bar-row .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--series-1); border-radius: 4px; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.filters input[type=search], .filters select, .modal input, .tag-editor input {
  font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); }

.bulkbar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.grid th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 12px; cursor: default; }
table.grid th[data-sort] { cursor: pointer; }
table.grid th.sorted::after { content: " ▾"; }
table.grid th.sorted.asc::after { content: " ▴"; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid td.cb, table.grid th.cb { width: 32px; }
table.grid th.num, table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.type { color: var(--text-2); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); margin-right: 4px; color: var(--text-2); }

.state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state.running::before { background: var(--good); }
.state.stopped::before { background: var(--critical); }
.state.transitioning::before { background: var(--warning); }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 12px 0; font-size: 13px; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 30;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  overflow-y: auto; padding: 16px;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.drawer-head h3 { word-break: break-all; }
.drawer dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; margin: 0 0 16px; }
.drawer dt { color: var(--text-2); }
.drawer dd { margin: 0; word-break: break-all; }
.drawer .actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }
.drawer pre { background: var(--surface-2); padding: 10px; border-radius: 6px; overflow: auto; max-height: 360px; font-size: 11px; }
.drawer h4 { font-size: 13px; margin: 18px 0 8px; }
.tag-editor .row { display: flex; gap: 6px; margin-bottom: 6px; }
.tag-editor input { flex: 1; min-width: 0; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 12px; padding: 20px; width: min(440px, 100%); box-shadow: var(--shadow); }
.modal-box p { color: var(--text-2); word-break: break-word; }
.modal-box input { width: 100%; margin: 6px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.toast { position: fixed; bottom: 16px; right: 16px; z-index: 60; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: min(480px, calc(100vw - 32px)); font-size: 13px; }
.toast.err { background: var(--critical); color: #fff; }

.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.chart-card .hero { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
.chart-card svg { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart-card .axis text { fill: var(--muted); font-size: 10px; }
.chart-card .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-card .bar { fill: var(--series-1); }
.chart-card .bar.hover { opacity: .75; }
.chart-card .hit { fill: transparent; }
.tooltip { position: fixed; z-index: 70; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: 12px; box-shadow: var(--shadow); }
.cost-block { margin-bottom: 16px; }
.cost-block h3 { margin-bottom: 8px; }

@media (max-width: 700px) {
  .topbar-right { margin-left: 0; width: 100%; }
  .filters input[type=search] { min-width: 0; max-width: none; width: 100%; }
  .bar-row { grid-template-columns: 110px 1fr 30px; }
  .cards { grid-template-columns: 1fr; }
}

/* ---------- v2: accounts, insights, settings ---------- */
.alert-banner { background: color-mix(in srgb, var(--warning) 18%, var(--surface)); border: 1px solid var(--warning); color: var(--text); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: 12px; padding: 28px; text-align: center; margin-bottom: 16px; }
.empty h2 { margin-top: 0; }
.flush { margin: 0; }
.ok-text { color: var(--good); }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head p { margin: 4px 0 0; }

.scan-form { display: flex; gap: 8px; }
.scan-form input { flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.scan-log { margin: 12px 0 0; padding: 10px 10px 10px 30px; background: var(--surface-2); border-radius: 6px; font-size: 12px; max-height: 220px; overflow: auto; }
.scan-log li { margin: 2px 0; color: var(--text-2); }
.scan-log li.tool { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; }
.scan-log li.error { color: var(--critical); }

.insights-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.list-title { margin: 0 0 8px; font-size: 13px; color: var(--text-2); }
.report-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.report-item { all: unset; box-sizing: border-box; width: 100%; display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; }
.report-item:hover, .report-item.active { border-color: var(--accent); }
.report-item:focus-visible { outline: 2px solid var(--accent); }
.ri-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ri-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; background: var(--muted); }
.dot.good { background: var(--good); } .dot.attention { background: var(--warning); } .dot.critical, .dot.error { background: var(--critical); }
.dot.running { background: var(--accent); }

.report-view { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; min-width: 0; }
.report-view h2 { font-size: 18px; margin: 8px 0; }
.report-view h4 { margin: 18px 0 8px; font-size: 13px; color: var(--text-2); }
.report-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.good::before { background: var(--good); }
.status-pill.attention::before { background: var(--warning); }
.status-pill.critical::before { background: var(--critical); }
.changes { margin: 0; padding-left: 20px; font-size: 13px; color: var(--text-2); }
.finding { border: 1px solid var(--border); border-left: 4px solid var(--muted); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.finding.critical { border-left-color: var(--critical); }
.finding.warning { border-left-color: var(--warning); }
.finding.saving { border-left-color: var(--good); }
.finding h3 { margin: 6px 0; font-size: 14px; }
.finding p { margin: 6px 0; font-size: 13px; color: var(--text-2); }
.finding .rec { color: var(--text); }
.finding-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sev { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-2); }
.sev::before { content: "● "; }
.sev.critical::before { color: var(--critical); } .sev.warning::before { color: var(--warning); } .sev.saving::before { color: var(--good); } .sev.info::before { color: var(--accent); }
.saving-amt { margin-left: auto; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tag.link { border: 0; cursor: pointer; font: inherit; font-size: 11px; }
.tag.link:hover { color: var(--accent); }

.insight-banner { all: unset; box-sizing: border-box; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; width: 100%; margin-top: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.insight-banner:hover { border-color: var(--accent); }
.insight-banner:focus-visible { outline: 2px solid var(--accent); }
.ib-text { flex: 1; min-width: 200px; font-size: 13px; }

.modal-box.wide { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal-box label, .settings label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); margin: 10px 0; }
.modal-box label.check, .settings label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; }
.modal-box select, .settings input, .settings select, .settings textarea {
  font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.settings textarea { resize: vertical; }
.hint { font-size: 11px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; }
.modal-actions.left { justify-content: flex-start; }
.settings { max-width: 720px; }
.settings fieldset { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 16px 12px; margin: 0 0 16px; }
.settings legend { font-weight: 600; padding: 0 6px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.howto { margin-top: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-size: 13px; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto pre { background: var(--surface-2); padding: 8px 10px; border-radius: 6px; overflow: auto; font-size: 12px; }
.howto li { margin: 8px 0; }

@media (max-width: 900px) {
  .insights-layout { grid-template-columns: 1fr; }
  .scan-form { flex-direction: column; }
}
.modal-box input[type=checkbox], .settings input[type=checkbox] { width: auto; margin: 0; flex: none; }
.card-head > div:last-child { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.card-head .badge { margin-left: 0; }
