:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #17202a;
  --muted: #64707d;
  --line: #e2e7ec;
  --brand: #0f766e;
  --brand-soft: #e6f4f2;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info: #1d4ed8;
  --info-soft: #e8eefc;
  --chart-a: #94a3b8;
  --chart-b: #0f766e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418; --card: #171e24; --text: #e6ebef; --muted: #94a0ab; --line: #2a333b;
    --brand: #2dd4bf; --brand-soft: #123532; --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #3a2c0d;
    --bad: #f87171; --bad-soft: #3a1515; --info: #93b4ff; --info-soft: #172446; --chart-a: #55626e; --chart-b: #2dd4bf;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }
small, .muted { color: var(--muted); }
a { color: var(--brand); }

/* đăng nhập */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; }
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.err { color: var(--bad); margin: 0; min-height: 1em; font-size: 13px; }

/* khung */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.top-right { display: flex; align-items: center; gap: 10px; }
.tabs { position: sticky; top: 53px; z-index: 19; display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs a { white-space: nowrap; padding: 6px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-size: 14px; }
.tabs a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.view { max-width: 1180px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

/* thành phần */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { display: grid; gap: 2px; }
.kpi b { font-size: 22px; line-height: 1.2; }
.kpi span { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row > select, .row > input { width: auto; max-width: 100%; }
.row.between { justify-content: space-between; }
.btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; }
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.callout { border-radius: 8px; padding: 10px 12px; font-size: 14px; background: var(--info-soft); color: var(--text); }
.callout.warn { background: var(--warn-soft); }

/* bảng */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.nw { white-space: nowrap; }
td .txt { max-width: 460px; white-space: pre-wrap; word-break: break-word; }

/* công tắc */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }

/* biểu đồ */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 9px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.legend .a { background: var(--chart-a); }
.legend .b { background: var(--chart-b); }
.bar-a { fill: var(--chart-a); }
.bar-b { fill: var(--chart-b); }
.ci-line { stroke: var(--text); stroke-width: 1.5; }
.ci-track { fill: var(--line); }

/* câu mẫu */
.tpl { display: grid; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.tpl:last-child { border-bottom: 0; }
.tpl .orig { font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.errs { margin: 0; padding-left: 18px; color: var(--bad); font-size: 13px; }

/* hộp thoại + thông báo */
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--card); color: var(--text); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dlg { padding: 20px; display: grid; gap: 12px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .view { padding: 12px; gap: 12px; }
  .card { padding: 12px; }
  .kpi b { font-size: 19px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
  .hide-m { display: none; }
}

/* hướng dẫn */
.guide details { border-bottom: 1px solid var(--line); padding: 4px 0; }
.guide details:last-child { border-bottom: 0; }
.guide summary { cursor: pointer; font-weight: 600; padding: 10px 0; list-style: none; display: flex; justify-content: space-between; gap: 8px; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "＋"; color: var(--muted); }
.guide details[open] summary::after { content: "－"; }
.guide .body { padding: 0 0 14px; display: grid; gap: 10px; }
.guide p, .guide ul, .guide ol { margin: 0; }
.guide ul, .guide ol { padding-left: 20px; display: grid; gap: 4px; }
.guide .q { border-left: 3px solid var(--brand); background: var(--brand-soft); padding: 8px 12px; border-radius: 0 8px 8px 0; white-space: pre-wrap; }
.guide .step { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.guide .step > b { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; }
.guide code { background: var(--line); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* ⓘ giải thích – di chuột (máy tính) hoặc chạm (điện thoại) */
.tip { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--line); color: var(--muted);
  font-size: 11px; font-weight: 700; font-style: normal; cursor: help; margin-left: 5px; vertical-align: 1px; text-transform: none; letter-spacing: 0;
  user-select: none; flex: none; }
.tip:hover, .tip:focus { background: var(--brand); color: #fff; outline: none; }
#tipbox { position: fixed; z-index: 70; max-width: min(320px, calc(100vw - 24px)); background: var(--text); color: var(--bg); padding: 9px 12px;
  border-radius: 8px; font-size: 13px; line-height: 1.5; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); pointer-events: none; white-space: pre-line; }
.summary { margin-top: 6px; padding: 6px 10px; border-radius: 6px; background: var(--ok-soft); font-size: 13px; }
.group-title { display: flex; align-items: center; gap: 4px; margin: 4px 0 8px; font-size: 13px; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .03em; }
.use { font-size: 12px; color: var(--muted); }
