/* Quản trị 1579 v2 — nền tối cố định, điện thoại là chính (1 cột), máy tính 2 cột. Không thư viện ngoài. */
:root {
  color-scheme: dark;
  --page: #0e0e0e;
  --surface: #1b1b1a;
  --surface-2: #242423;
  --ink: #f3f2ee;
  --ink-2: #c9c8bf;
  --muted: #9b9a92;
  --grid: #2e2e2c;
  --axis: #44443f;
  --border: rgba(255, 255, 255, 0.11);
  --s1: #4a90e2; /* 3D Card */
  --s2: #f07a3a; /* MathIQ */
  --s3: #2ec48c; /* Song Gift */
  --good: #3ccf5a;
  --warn: #f3b23e;
  --critical: #ff6464;
  --good-text: #5be07a;
  --accent: #4a90e2;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
a { color: var(--accent); }
button, select, input, .btn {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; cursor: pointer; text-decoration: none; display: inline-block; min-height: 40px;
}
button:hover, .btn:hover { border-color: var(--axis); }
button:focus-visible, select:focus-visible, input:focus-visible, .btn:focus-visible, .tab:focus-visible, .q:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn.small, button.small { min-height: 34px; padding: 5px 10px; font-size: 14px; }

/* ---------- Đầu trang ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px 6px; }
.brand { display: flex; flex-direction: column; line-height: 1.25; }
.brand b { font-size: 18px; }
.brand span { color: var(--muted); font-size: 12px; }
.controls { padding: 4px 16px 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--border); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { min-height: 36px; padding: 6px 12px; border-radius: 999px; background: var(--surface); font-size: 15px; }
.chips button.is-on { background: var(--ink); color: var(--page); border-color: var(--ink); font-weight: 600; }
.row2 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row2 select { min-height: 36px; padding: 5px 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; cursor: pointer; }
.switch input { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--accent); }
.rangewrap { position: relative; display: inline-block; }

/* Lịch (giữ từ bản cũ) */
.pop[hidden] { display: none; }
.pop { position: absolute; left: 0; top: calc(100% + 6px); z-index: 20; display: flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); overflow: hidden; }
.pop__cal { padding: 10px 12px 10px; width: 300px; }
.cal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal__head button { border: 0; background: none; font-size: 20px; line-height: 1; padding: 2px 10px; color: var(--ink-2); min-height: 0; }
.cal__months { font-weight: 600; }
.cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px 0; font-variant-numeric: tabular-nums; }
.cal__grid .dow { text-align: center; color: var(--muted); font-size: 11px; padding: 2px 0 4px; }
.cal__grid button { border: 0; background: none; padding: 0; height: 36px; min-height: 0; color: var(--ink); border-radius: 0; font-size: 14px; }
.cal__grid button.other { color: var(--muted); opacity: 0.55; }
.cal__grid button.future { color: var(--muted); opacity: 0.35; cursor: default; }
.cal__grid button:not(.future):hover { background: var(--surface-2); }
.cal__grid button.in { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.cal__grid button.start, .cal__grid button.end { background: var(--accent); color: #fff; font-weight: 600; }
.cal__grid button.start { border-radius: 8px 0 0 8px; }
.cal__grid button.end { border-radius: 0 8px 8px 0; }
.cal__grid button.start.end { border-radius: 8px; }
.cal__grid button.today { text-decoration: underline; text-underline-offset: 3px; }
.cal__foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.cal__foot .hint { font-size: 12px; }
@media (max-width: 640px) { .pop { position: fixed; left: 8px; right: 8px; top: 130px; } .pop__cal { width: auto; } }

/* ---------- Tab chính ---------- */
.tabs { display: flex; gap: 4px; padding: 6px 16px 0; border-bottom: 1px solid var(--border); background: var(--page); position: sticky; top: 0; z-index: 5; }
.tab { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--ink-2); white-space: nowrap; font-size: 15px; }
.tab.is-on { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }

main { padding: 12px 16px 40px; max-width: 1100px; margin: 0 auto; }
.note { color: var(--muted); margin: 0 0 10px; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

/* ---------- Dải trạng thái ---------- */
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--border); font-size: 15px; cursor: pointer; }
.banner::before { content: ""; width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--muted); }
.banner.ok::before { background: var(--good); }
.banner.warn::before { background: var(--warn); }
.banner.bad::before { background: var(--critical); }
.banner.bad { border-color: color-mix(in srgb, var(--critical) 50%, transparent); }
.banner small { color: var(--muted); margin-left: auto; font-size: 13px; white-space: nowrap; }

/* ---------- 5 khối ---------- */
.blocks { display: grid; grid-template-columns: 1fr; gap: 12px; }
.block { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px 12px; }
.block h2 { font-size: 14px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.02em; margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.block h2 .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); color: var(--ink); font-size: 12px; }
.big { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 38px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.big .unit { font-size: 16px; font-weight: 500; color: var(--ink-2); }
.say { margin: 4px 0 8px; color: var(--ink-2); font-size: 15px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 2px 0 6px; }
.pair > div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.pair .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; display: flex; align-items: baseline; gap: 6px; }
.pair .l { font-size: 13px; color: var(--ink-2); }
.pair .v.good { color: var(--good-text); }
.pair .v.bad { color: var(--critical); }
.apps { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; color: var(--ink-2); margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.apps b { color: var(--ink); font-weight: 600; }
.facts { list-style: none; margin: 4px 0 0; padding: 0; border-top: 1px solid var(--grid); }
.facts li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.facts li:last-child { border-bottom: 0; }
.facts li span:first-child { color: var(--ink-2); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.facts li b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.facts li.sub { padding-left: 14px; font-size: 13px; }
.delta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.q { display: inline-grid; place-items: center; width: 24px; height: 24px; min-height: 0; padding: 0; border-radius: 50%; border: 1px solid var(--axis); background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 700; line-height: 1; vertical-align: middle; flex: none; }
.q:hover { color: var(--ink); border-color: var(--ink-2); }
.big .q { align-self: center; }

/* Phễu */
.funnel { margin: 6px 0 2px; }
.funnel-row { display: grid; grid-template-columns: 92px 1fr 88px; gap: 8px; align-items: center; margin: 5px 0; font-size: 14px; }
.funnel-row > span:first-child { color: var(--ink-2); }
.funnel-row > div { background: var(--surface-2); border-radius: 4px; height: 16px; overflow: hidden; }
.funnel-bar { height: 100%; background: var(--s1); border-radius: 4px; min-width: 2px; }
.funnel-row > span:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.funnel-row > span:last-child small { color: var(--muted); }

/* Có gì hỏng */
.health { list-style: none; margin: 0; padding: 0; }
.health li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 15px; }
.health li:last-child { border-bottom: 0; }
.health li::before { content: ""; flex: none; width: 12px; height: 12px; border-radius: 50%; margin-top: 5px; background: var(--muted); }
.health li.ok::before { background: var(--good); }
.health li.warn::before { background: var(--warn); }
.health li.bad::before { background: var(--critical); }
.health li.info::before { background: var(--axis); }
.health li .t { color: var(--ink-2); font-size: 13px; display: block; }

/* ---------- Thẻ, biểu đồ, bảng (tab Theo ngày) ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
.card__head { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.card__head h2 { margin: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--ink-2); font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; vertical-align: 3px; width: 14px; }
.chart { width: 100%; min-height: 220px; position: relative; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--grid); fill-opacity: 0.5; }

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; font-size: 12px; }
td.n, th.n { text-align: right; }
td.hint { white-space: normal; }

/* Danh sách thay bảng rộng trên điện thoại */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.rows li:last-child { border-bottom: 0; }
.rows li span:first-child { color: var(--ink-2); display: flex; flex-direction: column; }
.rows li small { color: var(--muted); font-size: 12px; font-weight: 400; }
.rows li b { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; line-height: 1.3; }
.rows li b small { margin-left: 3px; }
.rows li.hint { display: block; }

/* ---------- Kỹ thuật (gập) ---------- */
.tech { margin-top: 20px; border: 1px dashed var(--border); border-radius: 14px; padding: 0 16px; }
.tech > summary { cursor: pointer; padding: 12px 0; color: var(--ink-2); font-size: 14px; list-style: none; display: flex; align-items: center; gap: 8px; }
.tech > summary::-webkit-details-marker { display: none; }
.tech > summary::before { content: "▸"; color: var(--muted); }
.tech[open] > summary::before { content: "▾"; }
.tech .card { background: var(--surface); }
.tech code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink-2); word-break: break-all; }
.rawfilters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin: 10px 0; }
.rawfilters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.rawfilters label.chk { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 7px; }
.rawfilters .rawbtns { display: flex; gap: 8px; align-items: center; }
.rawpager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 12px 0 0; }
.rawrow-detail td { white-space: normal; background: var(--page); }
.rawrow-detail pre { margin: 0; max-height: 320px; overflow: auto; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); font-size: 12px; }
.tag.bad { color: var(--critical); border-color: var(--critical); }
.tag.out { color: var(--accent); border-color: var(--accent); }
.status-ok::before, .status-bad::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-ok::before { background: var(--good); }
.status-bad::before { background: var(--critical); }
.status-bad { color: var(--critical); }

/* ---------- Tooltip biểu đồ & tấm giải thích "?" ---------- */
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface-2); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); min-width: 140px; }
.tip b { display: block; margin-bottom: 4px; }
.tip div { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.sheet[hidden] { display: none; }
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet__box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 0 0; padding: 16px 18px 24px; width: 100%; max-width: 560px; max-height: 80vh; overflow: auto; }
.sheet__box h3 { margin: 0 0 10px; font-size: 17px; padding-right: 40px; }
.sheet__box p { margin: 0 0 10px; font-size: 15px; line-height: 1.5; }
.sheet__box p b { color: var(--ink-2); font-weight: 600; }
.sheet__box .close { position: absolute; right: 14px; top: 10px; }
.sheet__box { position: relative; }
@media (min-width: 640px) { .sheet { align-items: center; } .sheet__box { border-radius: 16px; } }

/* ---------- Máy tính: 2 cột ---------- */
@media (min-width: 900px) {
  .blocks { grid-template-columns: 1fr 1fr; }
  .block.wide { grid-column: 1 / -1; }
  .big { font-size: 42px; }
  .controls { flex-direction: row; align-items: center; justify-content: space-between; }
}
@media (max-width: 380px) {
  .big { font-size: 32px; }
  .funnel-row { grid-template-columns: 80px 1fr 80px; }
}
