:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #e2e0d8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --series-1: #2a78d6;   /* chi */
  --series-2: #eb6834;   /* doanh thu */
  --good: #0f7b3e;
  --good-bg: #e3f3e8;
  --bad: #b42318;
  --bad-bg: #fbe7e5;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --sample: #6b4a00;
  --sample-bg: #ffe9a8;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 14px rgb(0 0 0 / .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #5598e7;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #5fd08a;
    --good-bg: #13301f;
    --bad: #ff8a80;
    --bad-bg: #3a1714;
    --warn: #f3c562;
    --warn-bg: #352a10;
    --sample: #ffe3a0;
    --sample-bg: #4a3600;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #5598e7;
  --series-1: #3987e5; --series-2: #d95926;
  --good: #5fd08a; --good-bg: #13301f; --bad: #ff8a80; --bad-bg: #3a1714;
  --warn: #f3c562; --warn-bg: #352a10; --sample: #ffe3a0; --sample-bg: #4a3600; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }

/* Đầu trang */
header.top { background: var(--surface); border-bottom: 1px solid var(--line); }
header.top .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding-top: 14px; padding-bottom: 10px; }
.brand { text-decoration: none; color: var(--text); margin-right: auto; }
.brand b { display: block; font-size: 19px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 13px; color: var(--text-2); }
nav.tabs { display: flex; gap: 4px; width: 100%; overflow-x: auto; }
nav.tabs a {
  flex: none; padding: 7px 12px; border-radius: 999px; text-decoration: none;
  color: var(--text-2); font-size: 14px; font-weight: 600;
}
nav.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.lang { display: flex; gap: 4px; }
.lang button {
  border: 1px solid var(--line); background: transparent; color: var(--text-2);
  border-radius: 8px; padding: 3px 8px; font: inherit; font-size: 13px; cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

.sample-banner {
  background: var(--sample-bg); color: var(--sample); font-weight: 600; font-size: 14px;
  padding: 10px 16px; text-align: center;
}
.sample-banner a { color: inherit; margin-left: 6px; }

main { padding: 20px 0 40px; }
section { margin: 0 0 22px; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 12px; letter-spacing: -.005em; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }

/* Dòng trạng thái */
.status-line { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--text-2);
}
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* Ô số */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .k { font-size: 13px; color: var(--text-2); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin: 2px 0; overflow-wrap: anywhere; }
.kpi .n { font-size: 12px; color: var(--text-3); }
.kpi .v.pos { color: var(--good); }
.kpi .v.neg { color: var(--bad); }
.kpi .v.unk { color: var(--text-3); font-size: 18px; font-weight: 600; }

/* Thước tỷ lệ so mục tiêu */
.ratio-card { margin-top: 10px; }
.ratio-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.ratio-side { max-width: 320px; }
@media (min-width: 720px) { .ratio-side { text-align: right; } }
.ratio-big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.meter { position: relative; height: 12px; background: var(--surface-2); border-radius: 999px; margin: 14px 0 26px; }
.meter .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--series-1); }
.meter .fill.win { background: var(--good); }
.meter .goal { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--text); }
.meter .goal span { position: absolute; top: 24px; transform: translateX(-50%); font-size: 12px; white-space: nowrap; color: var(--text-2); font-weight: 600; }
.meter .tick { position: absolute; top: 18px; font-size: 11px; color: var(--text-3); transform: translateX(-50%); }

.mini { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini div { min-width: 0; }
.mini .k { font-size: 12px; color: var(--text-2); }
.mini .v { font-weight: 700; overflow-wrap: anywhere; }
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--series-1); border-radius: 999px; }

/* Biểu đồ */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover, .chart .hit.on { fill: var(--surface-2); }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .12); white-space: nowrap; z-index: 2;
}
.tip b { display: block; margin-bottom: 2px; }
.tip i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }
details.table-view { margin-top: 10px; }
details.table-view summary { cursor: pointer; font-size: 14px; color: var(--accent); }

/* Bảng */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
@media (max-width: 480px) { table { font-size: 13px; } th, td { padding: 6px 6px; } }
th { font-size: 12px; color: var(--text-2); font-weight: 600; }
td.l, th.l { text-align: left; }
td.wrap-text { white-space: normal; min-width: 140px; }
tr.prov td { color: var(--text-2); font-style: italic; }

/* Quyết định */
.decisions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.decision { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.decision .top { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-bottom: 4px; }
.act { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text); }
.act.TAT, .act.PHANH, .act.GIAM { background: var(--bad-bg); color: var(--bad); }
.act.SCALE, .act.NHAN_BAN, .act.LEN_MOI { background: var(--good-bg); color: var(--good); }
.act.CANH_BAO, .act.XIN_AP, .act.CHO_DATA { background: var(--warn-bg); color: var(--warn); }
.decision .target { font-weight: 600; font-size: 14px; }
.decision .when { font-size: 12px; color: var(--text-3); margin-left: auto; }
.decision p { margin: 0; }
.decision .codes { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.decision .codes code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; background: var(--surface-2); border-radius: 4px; padding: 1px 4px; }

/* Chờ bắt đầu */
.waiting { text-align: center; padding: 28px 16px; }
.waiting h1 { font-size: 26px; }
.waiting p { max-width: 520px; margin: 8px auto 0; }
.countdown { display: flex; justify-content: center; gap: 8px; margin: 22px 0 6px; }
.countdown div { background: var(--surface-2); border-radius: 12px; padding: 10px 6px; min-width: 66px; }
.countdown b { display: block; font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.countdown span { font-size: 12px; color: var(--text-2); }

/* Luật chơi */
.rules { margin: 0; padding-left: 20px; }
.rules li { margin: 6px 0; }

/* Nhật ký */
.days { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
.days a {
  flex: none; text-decoration: none; text-align: center; padding: 6px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); font-size: 13px; line-height: 1.25;
}
.days a b { display: block; color: var(--text); font-size: 15px; }
.days a[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.grid2 { display: grid; gap: 14px; }
/* Ô lưới không được giãn theo bề rộng tối thiểu của bảng bên trong: bảng tự cuộn ngang trong .tbl-wrap */
.grid2 > *, .card, section { min-width: 0; }
@media (min-width: 820px) { .grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.funnel { display: grid; gap: 6px; }
.funnel .row { display: grid; grid-template-columns: minmax(0, 120px) minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 14px; }
.funnel .row .track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.funnel .row .track i { display: block; height: 100%; background: var(--series-1); border-radius: 999px; }
.funnel .row .num { text-align: right; font-weight: 600; }
.story { border-left: 3px solid var(--accent); }
.story p { margin: 6px 0; }

footer { border-top: 1px solid var(--line); padding: 18px 0 30px; font-size: 13px; color: var(--text-3); }

.empty { color: var(--text-3); font-size: 14px; padding: 8px 0; }
.err { background: var(--bad-bg); color: var(--bad); padding: 12px 14px; border-radius: 10px; }
@media (prefers-reduced-motion: no-preference) { .meter .fill, .bar i { transition: width .4s ease; } }
