:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76756f;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e9e8e4;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --warning-bg: #fff4d6;
  --serious-bg: #fde6dc;
  --critical-bg: #f9dcdc;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #33322f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2a2a28;
    --warning-bg: #3a2f10;
    --serious-bg: #3d2318;
    --critical-bg: #421a1a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 1280px; margin: 0 auto; padding-inline: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); }

.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top .wrap { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; justify-content: space-between; padding-block: 14px; }
h1 { font-size: 20px; margin: 0; }
.meta { text-align: right; }
@media (max-width: 640px) { .meta { text-align: left; } }

section { margin-block: 28px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 12px; }
.section-head h2 { font-size: 17px; margin: 0; }
.section-head p { margin: 0; }

.banner { margin-top: 16px; padding: 10px 14px; border-radius: 8px; background: var(--critical-bg); border: 1px solid var(--critical); }

/* Thẻ hồ */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; cursor: pointer; text-align: left; font: inherit; color: inherit;
  display: flex; flex-direction: column; gap: 8px;
}
.card:hover, .card:focus-visible { border-color: var(--accent); outline: none; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-head h3 { font-size: 15px; margin: 0; }
.card .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.htl { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.htl small { font-size: 14px; font-weight: 400; color: var(--text-2); }
.delta { font-size: 13px; color: var(--text-2); margin-left: 6px; }
.meter { position: relative; height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.meter > span { position: absolute; inset: 0 auto 0 0; background: var(--series-1); border-radius: 4px; }
.meter.over > span { background: var(--critical); }
.meter-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 13px; }
.kv div { display: flex; justify-content: space-between; gap: 6px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-variant-numeric: tabular-nums; }
.spill { font-size: 12px; color: var(--text-2); white-space: pre-line; border-left: 3px solid var(--border); padding: 2px 0 2px 8px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; border: 1px solid var(--border); color: var(--text-2); }
.badge.stale { border-color: var(--warning); }

/* Bảng */
.table-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.data { border-collapse: collapse; width: 100%; min-width: 640px; }
table.data th, table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--bg); }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
tr.alert-1 { background: var(--warning-bg); }
tr.alert-2 { background: var(--serious-bg); }
tr.alert-3 { background: var(--critical-bg); }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--dot, var(--muted)); }
.status.s0 { --dot: var(--good); font-weight: 400; }
.status.s1 { --dot: var(--warning); }
.status.s2 { --dot: var(--serious); }
.status.s3 { --dot: var(--critical); }
.gate-state { display: inline-block; padding: 2px 10px; border-radius: 10px; font-weight: 600; font-size: 13px; }
.gate-state.open { background: color-mix(in srgb, var(--series-1) 18%, transparent); }
.gate-state.closed { background: var(--grid); }

/* Biểu đồ */
.picker select { font: inherit; padding: 4px 8px; margin-left: 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); max-width: 100%; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 12px; }
.chart-box { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.chart-box figcaption { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.chart-area { position: relative; height: 300px; }

footer { margin-block: 32px; }
