:root {
  --red: #c8102e; --red-d: #9e0b23; --ink: #1d2433; --muted: #6b7385; --line: #e4e7ee;
  --bg: #f5f6f8; --card: #fff; --ok: #138a4b; --ok-bg: #e6f5ec; --warn: #a86400; --warn-bg: #fff4dc;
  --bad: #c42b2b; --bad-bg: #fde8e8; --blue: #2f5bd3; --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
button, input, select { font: inherit; }
a { color: var(--blue); }

/* ---------- khung ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--red); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-weight: 700; font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #fff; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 14px; opacity: .85; }
.topbar nav a.on, .topbar nav a:hover { background: rgba(255,255,255,.18); opacity: 1; }
main { max-width: 1180px; margin: 0 auto; padding: 14px 14px 90px; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 14px; }
.controls label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; flex: 1 1 160px; }
.controls select, .controls input, .field input, .field select {
  height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: #fff; color: var(--ink); }
.controls .btns { display: flex; gap: 8px; flex: 0 0 auto; }

.btn { height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  color: var(--ink); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.meta { color: var(--muted); font-size: 13px; margin: -4px 2px 12px; }

/* ---------- thẻ số ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700;
  display: flex; justify-content: space-between; align-items: center; }
.big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.big small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.ok { background: var(--ok-bg); } .pill.bad { background: var(--bad-bg); } .pill.warn { background: var(--warn-bg); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin-top: 10px; font-size: 14px; }
.kv > span:nth-child(odd) { color: var(--muted); }
.kv > span:nth-child(even) { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: #eef0f4; border-radius: 99px; overflow: hidden; margin: 6px 0 2px; position: relative; }
.bar > i { display: block; height: 100%; background: var(--red); border-radius: 99px; }
.bar > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); }
.shift { margin-top: 8px; font-size: 14px; }
.shift .row { display: flex; justify-content: space-between; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

.flags { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.flags li { padding: 9px 12px; border-radius: 10px; font-size: 14px; }
.flags li.red { background: var(--bad-bg); color: #7a1515; }
.flags li.amber { background: var(--warn-bg); color: #6b4000; }
.flags li.green { background: var(--ok-bg); color: #0b5a30; }

.section-title { margin: 22px 2px 10px; font-size: 16px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #e9ebf0; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.chart-box { position: relative; height: 260px; }

/* ---------- bảng ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { background: #fafbfc; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
th:first-child, td:first-child { text-align: left; }
tr.click { cursor: pointer; } tr.click:hover td { background: #fafbfc; }

/* ---------- đăng nhập / form ---------- */
.login { max-width: 380px; margin: 12vh auto; background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 28px 24px; }
.login .logo { width: 56px; height: 56px; border-radius: 14px; background: var(--red); color: #fff; font-weight: 800;
  display: grid; place-items: center; font-size: 20px; margin-bottom: 14px; }
.login h1 { font-size: 20px; margin: 0 0 18px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; display: flex; gap: 6px; align-items: center; cursor: pointer; }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: grid; place-items: center; z-index: 50; padding: 14px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; padding: 18px; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px; }
.status-ok { color: var(--ok); font-weight: 700; } .status-partial { color: var(--warn); font-weight: 700; }
.status-error { color: var(--bad); font-weight: 700; } .status-running { color: var(--blue); font-weight: 700; }
td.msg { white-space: pre-wrap; text-align: left; min-width: 260px; font-size: 13px; color: var(--muted); }

@media (max-width: 640px) {
  .topbar nav a { padding: 6px 7px; font-size: 13px; }
  .big { font-size: 30px; }
  .controls .btns { width: 100%; }
  .controls .btns .btn { flex: 1; }
}
code.copy { cursor: pointer; background: var(--bg, #f4f5f7); padding: 2px 6px; border-radius: 6px; font-size: 12px; word-break: break-all; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.chips input { width: auto !important; height: auto !important; margin: 0; padding: 0; flex: none; }
.chips label { white-space: nowrap; }
