:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --bar: #2a78d6;
  --st-block: #d03b3b;   /* status: critical */
  --st-suspect: #fab219; /* status: warning */
  --st-clear: #0ca30c;   /* status: good */
  --st-block-ink: #b42828;
  --st-clear-ink: #006300;
  --st-suspect-ink: #8a5d00;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --bar: #3987e5;
    --st-block-ink: #e66767;
    --st-clear-ink: #0ca30c;
    --st-suspect-ink: #fab219;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --bar: #3987e5;
  --st-block-ink: #e66767;
  --st-clear-ink: #0ca30c;
  --st-suspect-ink: #fab219;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.brand-logo { width: 22px; height: 22px; display: block; flex: none; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2);
}
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; }

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

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.field.inline { flex-direction: row; }
.field.grow { flex: 1 1 320px; }
.field.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 8px; }
select, input[type="text"], input[type="date"], input[type="search"], input[type="password"] {
  height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 14px;
}
input[type="search"] { width: 100%; }
.presets { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.presets button { border: 0; background: var(--surface); padding: 0 12px; height: 32px; cursor: pointer; color: var(--text-2); }
.presets button + button { border-left: 1px solid var(--border); }
.presets button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.btn {
  height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; }
.meta { color: var(--muted); font-size: 12px; }

.alert {
  border: 1px solid color-mix(in srgb, var(--st-block) 40%, transparent);
  background: color-mix(in srgb, var(--st-block) 10%, var(--surface));
  color: var(--text); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
}

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 650; margin-top: 4px; }
.kpi-sub { color: var(--text-2); font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.st-block { background: var(--st-block); }
.st-suspect { background: var(--st-suspect); }
.st-clear { background: var(--st-clear); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card h2 { font-size: 14px; margin: 0; font-weight: 600; }
.sub-h { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); margin: 8px 0; }
.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--text-2); }
.legend span { display: flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; height: 300px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 16px; }

/* ---------- bar lists (HTML horizontal bars) ---------- */
.barlist { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.bar-name small { color: var(--muted); margin-left: 4px; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-val { color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; min-width: 64px; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; text-align: center; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-2); font-weight: 600; border-bottom: 1px solid var(--axis); padding: 8px; white-space: nowrap; }
td { border-bottom: 1px solid var(--grid); padding: 8px; vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; white-space: nowrap; }
.badge.block { color: var(--st-block-ink); }
.badge.suspect { color: var(--st-suspect-ink); }
.badge.clear { color: var(--st-clear-ink); }
.chip {
  display: inline-block; margin: 0 4px 4px 0; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 12px; white-space: nowrap;
}
.tx-table td:nth-child(1), .tx-table td:nth-child(2), .tx-table td:nth-child(6), .tx-table td:nth-child(7) { white-space: nowrap; }
.copy { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; }
.copy:hover { color: var(--accent); }
.tx-summary { margin-bottom: 8px; }
.tx-summary a, td a { color: var(--accent); }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 12px; color: var(--text-2); }

/* ---------- login screen ---------- */
body.signed-out .topbar, body.signed-out main { display: none; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card input { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 14px; }
.login-card .btn { height: 38px; }
.login-brand { margin-bottom: 4px; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }

/* ---------- modal / loading ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 12px; padding: 24px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; }
.modal-card h2 { margin: 0; font-size: 18px; }
.loading { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 60; overflow: hidden; }
.loading .spinner { height: 100%; width: 30%; background: var(--accent); animation: slide 1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(400%); } }
[hidden] { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .chart-wrap { height: 240px; }
  .topbar-right { margin-left: 0; }
}
