:root {
  --bg: #f4f5f7; --surface: #ffffff; --line: #dfe2e7; --ink: #1c2330; --muted: #5b6577;
  --accent: #1f5fa8; --accent-ink: #ffffff; --track: #e7e9ee;
  --red-bg: #fbe3e1; --red-ink: #93211a; --red-mark: #c8372d;
  --yellow-bg: #fdf0c8; --yellow-ink: #6e4f00; --yellow-mark: #d39a0a;
  --green-bg: #dcf1e2; --green-ink: #1b5e33; --green-mark: #2f8f53;
  --blue-bg: #dbe9fb; --blue-ink: #174c8c; --blue-mark: #2d73c7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f; --surface: #1d232c; --line: #333c49; --ink: #e8ebf0; --muted: #a2acba;
    --accent: #6ea8ea; --accent-ink: #10161e; --track: #2d3542;
    --red-bg: #4a211f; --red-ink: #ffc9c4; --red-mark: #e5645a;
    --yellow-bg: #453711; --yellow-ink: #fbe09a; --yellow-mark: #e0b23a;
    --green-bg: #1d3b29; --green-ink: #b4e8c6; --green-mark: #4fb377;
    --blue-bg: #1e3553; --blue-ink: #bcd8fb; --blue-mark: #5b9be0;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, "Segoe UI", Roboto, Arial, sans-serif; }
h1 { font-size: 1.3rem; margin: 0; line-height: 1.3; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
.muted { color: var(--muted); margin: 0; font-size: .875rem; }
.error { color: var(--red-ink); background: var(--red-bg); padding: 8px 12px; border-radius: 6px; }
.top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: center; padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-actions { display: flex; gap: 8px; }
.btn { font: inherit; font-size: .875rem; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--red-mark); border-color: var(--red-mark); color: #ffffff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.delete-list { max-height: 180px; overflow-y: auto; margin: 10px 0; padding-left: 20px; font-size: .875rem; }
#delete_form label, #final_form label { display: block; font-weight: 600; margin-bottom: 4px; }
input.pin { font: inherit; font-size: 1.2rem; letter-spacing: .3em; width: 11em; max-width: 100%; display: block; margin-bottom: 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }
.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 12px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.count { background: var(--red-bg); color: var(--red-ink); border-radius: 10px; padding: 0 7px; font-size: .75rem; }
.wrap { padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.kpi.hero { grid-column: span 2; }
.kpi b { display: block; font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi.hero b { font-size: 2.2rem; }
.kpi span { color: var(--muted); font-size: .8125rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
input[type=search], input[type=password], select { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); max-width: 100%; }
.reminders { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.reminders .card { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.unit-line { font-size: .875rem; }
.unit-line strong { font-weight: 600; }
.unit-line .muted { display: block; }
.card .btn { align-self: flex-start; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8125rem; white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
th.first, td.first { position: sticky; left: 0; background: var(--surface); }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; font-weight: 600; }
.tree details { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.tree summary { cursor: pointer; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tree summary::before { content: "▸"; color: var(--muted); }
.tree details[open] > summary::before { content: "▾"; }
.tree summary::-webkit-details-marker { display: none; }
.tree-list { list-style: none; margin: 0; padding: 0 12px 8px 28px; border-left: 2px solid var(--line); margin-left: 18px; }
.tree-item { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) auto; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: .875rem; }
.tree-item:last-child { border-bottom: 0; }
.tree-item code { word-break: break-all; font-size: .8125rem; }
.tree-warn { margin: 0 12px 8px 18px; padding: 4px 8px; border-radius: 5px; background: var(--red-bg); color: var(--red-ink); font-size: .8125rem; }
.tree-unit > .btn { margin: 0 0 10px 18px; }
@media (max-width: 640px) { .tree-item { grid-template-columns: 1fr; } }
.team-name { min-width: 260px; }
.btn.small { font-size: .75rem; padding: 2px 8px; }
.cell { font: inherit; font-size: .8125rem; display: block; width: 100%; min-width: 74px; border: 0; border-radius: 5px; padding: 3px 6px; cursor: pointer; text-align: center; white-space: nowrap; font-weight: 600; }
.badge { font-size: .8125rem; border-radius: 5px; padding: 2px 8px; white-space: nowrap; font-weight: 600; display: inline-block; }
.s-chua_gui, .s-thieu { background: var(--red-bg); color: var(--red-ink); }
.s-chua_kiem_soat, .s-dang_cap_nhat { background: var(--yellow-bg); color: var(--yellow-ink); }
.s-da_kiem_soat, .s-hoan_thanh { background: var(--green-bg); color: var(--green-ink); }
.s-moi { background: var(--blue-bg); color: var(--blue-ink); }
.none { color: var(--muted); text-align: center; display: block; }
.bar { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; min-width: 90px; }
.bar i { display: block; height: 100%; background: var(--green-mark); border-radius: 4px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: 12px; align-items: center; margin: 12px 0; }
.bar-row .bar { height: 12px; grid-column: 1 / -1; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .875rem; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(760px, calc(100vw - 32px)); max-height: 85vh; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
#detail_body { padding: 16px 18px; }
.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.file-name { word-break: break-word; }
.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px)); background: var(--blue-bg); color: var(--blue-ink); border: 1px solid var(--blue-mark); border-radius: 8px; padding: 10px 14px; font-size: .875rem; font-weight: 600; }
.live { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green-mark); margin-right: 6px; }
.live.off { background: var(--red-mark); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login .btn { align-self: stretch; padding: 8px; }
