:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #1c2430;
  --muted: #6b7684;
  --nav: #1f2a37;
  --nav-text: #c9d1db;
  --accent: #d97706;
  --accent-strong: #b45309;
  --accent-soft: #fef3e2;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
a { color: var(--info); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--nav); color: var(--nav-text); flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { padding: 18px 18px 14px; color: #fff; display: flex; gap: 10px; align-items: center; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 15px; }
.brand span { font-size: 12px; color: var(--nav-text); }
.nav-group { padding: 10px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8793a3; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: var(--nav-text); font-size: 14px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: rgba(245,158,11,.12); color: #fff; border-left-color: #f59e0b; }
.nav .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar-foot a { color: var(--nav-text); }
.main { flex: 1; min-width: 0; }
.topbar {
  display: none; position: sticky; top: 0; z-index: 20; background: var(--nav); color: #fff;
  padding: 10px 14px; align-items: center; gap: 10px;
}
.topbar button { background: none; border: 0; color: #fff; font-size: 22px; padding: 4px 8px; cursor: pointer; }
.content { padding: 22px 26px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
  .layout.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .layout.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .topbar { display: flex; }
  .content { padding: 16px 16px 60px; }
}

/* ---------- Driver layout ---------- */
.driver { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: 80px; }
.driver-head { background: var(--nav); color: #fff; padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); display: flex; align-items: center; gap: 12px; }
.driver-head .who { flex: 1; }
.driver-head .who b { display: block; }
.driver-head .who span { font-size: 13px; color: var(--nav-text); }
.driver-head button { background: rgba(255,255,255,.1); color: #fff; border: 0; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.driver .content { padding: 16px; }
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.big-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 10px; min-height: 112px;
  font-weight: 600; font-size: 15px; color: var(--text); box-shadow: var(--shadow); cursor: pointer;
}
.big-btn .ic { font-size: 30px; }
.big-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Cards / panels ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.card-head h2 { margin-right: auto; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.attn { border-color: #f5c27a; background: var(--warn-soft); }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.two-col > * { min-width: 0; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 500;
  cursor: pointer; min-height: 38px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f2c4c4; }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.lg { padding: 12px 18px; min-height: 48px; font-size: 16px; }
.btn.block { width: 100%; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 4px 6px; color: var(--muted); font-size: 16px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field .req { color: var(--bad); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: #fff; border: 1px solid #cfd5dd; border-radius: 8px;
  padding: 8px 10px; min-height: 40px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #fcd9a4; border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; vertical-align: middle; accent-color: var(--accent); }
input[readonly] { background: var(--surface-2); }
.driver input, .driver select, .driver textarea { min-height: 46px; font-size: 16px; }
.seg { display: flex; border: 1px solid #cfd5dd; border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 10px 6px; font: inherit; cursor: pointer; border-right: 1px solid #cfd5dd; min-height: 42px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.calc-box { background: var(--accent-soft); border: 1px solid #f7d29b; border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.calc-box b { font-size: 16px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 140px; }
.filters .field.wide { min-width: 220px; }
.filters input, .filters select { min-height: 38px; padding: 6px 10px; }
.search { max-width: 280px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.tbl th { background: var(--surface-2); font-weight: 600; color: #4a5562; font-size: 13px; position: sticky; top: 0; white-space: nowrap; }
.tbl tbody tr:hover { background: #fbfaf7; }
.tbl tr.click { cursor: pointer; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); }
.tbl tr.inactive td { color: #9aa3ad; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.cho_duyet, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.da_duyet, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.tu_choi, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.count { background: #f59e0b; color: #1f2a37; }

/* ---------- Entry cards (driver list, approval) ---------- */
.entry { padding: 14px; display: flex; gap: 12px; }
.entry + .entry { border-top: 1px solid var(--border); }
.entry .body { flex: 1; min-width: 0; }
.entry .title { font-weight: 600; }
.entry .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.entry .reason { background: var(--bad-soft); color: var(--bad); border-radius: 6px; padding: 6px 10px; margin-top: 8px; font-size: 13px; }
.entry .warns { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { width: 72px; height: 72px; border-radius: 8px; object-fit: cover; background: #e9ecf0; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.thumb.lg { width: 120px; height: 150px; }
.thumb-wrap { position: relative; }
.thumb-wrap .x {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--bad);
  color: #fff; font-size: 14px; line-height: 22px; text-align: center; cursor: pointer; padding: 0;
}
.photo-add {
  width: 72px; height: 72px; border-radius: 8px; border: 2px dashed #c7ced8; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--muted); font-size: 12px; cursor: pointer; background: #fff;
}
.photo-add .ic { font-size: 22px; }
.approve-card { display: grid; grid-template-columns: auto 1fr; gap: 16px; padding: 16px; }
.approve-card + .approve-card { border-top: 1px solid var(--border); }
.approve-card .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 10px; align-items: end; }
.approve-card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
@media (max-width: 700px) { .approve-card { grid-template-columns: 1fr; } }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- Chart ---------- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column-reverse; min-width: 4px; height: 100%; position: relative; }
.bars .b span { display: block; width: 100%; }
.bars .b .m1 { background: #d97706; border-radius: 0 0 2px 2px; }
.bars .b .m2 { background: #4b6584; border-radius: 2px 2px 0 0; }
.bars .b:hover { filter: brightness(1.1); }
.bars-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15, 23, 32, .5); z-index: 100; display: flex; align-items: flex-start;
  justify-content: center; padding: 30px 12px; overflow-y: auto;
}
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 900px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 560px) {
  .modal-back { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; }
  .modal-foot { position: sticky; bottom: 0; background: var(--surface); }
}
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 200; }
.lb-stage { position: absolute; inset: 0 0 56px 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; transition: transform .15s; }
.lb-stage img.sideways { max-width: calc(100vh - 56px); max-height: 100vw; }
.lb-stage.zoomed { overflow: auto; display: block; text-align: center; }
.lb-stage.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox > button { position: absolute; background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 50%; width: 46px; height: 46px; font-size: 22px; cursor: pointer; z-index: 2; }
.lightbox .close { top: 14px; right: 14px; }
.lightbox .prev { left: 10px; top: 50%; }
.lightbox .next { right: 10px; top: 50%; }
.lb-tools { position: absolute; left: 0; right: 0; bottom: 0; height: 56px; display: flex; gap: 8px; align-items: center; justify-content: center; color: #fff; font-size: 14px; }
.lb-tools button { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; min-width: 44px; }
.lb-tools button:disabled { opacity: .35; }

/* ---------- Duyệt phiếu dạng đối chiếu ---------- */
.cmp-card { display: grid; grid-template-columns: minmax(280px, 440px) 1fr; gap: 20px; padding: 18px; }
.cmp-card + .cmp-card { border-top: 6px solid var(--bg); }
.viewer { background: #20262e; border-radius: 10px; height: 460px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; transition: transform .15s; }
.empty-photo { color: #c9d1db; font-size: 14px; }
.viewer-tools { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.mini-thumbs { display: flex; gap: 6px; margin-left: auto; }
.mini-thumbs img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.mini-thumbs img.on { border-color: var(--accent); }
.photo-meta { margin-top: 6px; }
.cmp-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.cmp-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.cmp-table th { text-align: left; font-weight: 500; color: var(--muted); width: 140px; padding: 6px 10px 6px 0; vertical-align: top; border-bottom: 1px dashed var(--border); }
.cmp-table td { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.cmp-table td.big { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.checks { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.checks li { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border-radius: 8px; font-size: 14px; }
.checks li > span { font-weight: 700; width: 16px; text-align: center; }
.checks li.ok { background: var(--ok-soft); color: var(--ok); }
.checks li.warn { background: var(--warn-soft); color: var(--warn); }
.checks li.bad { background: var(--bad-soft); color: var(--bad); }
.verify { margin-top: 12px; display: grid; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.verify label { display: flex; gap: 10px; align-items: center; font-weight: 500; cursor: pointer; }
.verify input { width: 20px; height: 20px; }
.cmp-card .fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.cmp-card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid #cfd5dd; background: #fff; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--bad-soft); border-color: #f2b8b8; color: var(--bad); }
@media (max-width: 860px) {
  .cmp-card { grid-template-columns: 1fr; padding: 12px; }
  .viewer { height: 60vh; }
  .cmp-card .fields { grid-template-columns: 1fr 1fr; }
}

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: 92vw; }
.toast { background: #1f2a37; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 14px; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }
.progress { height: 6px; background: #e8ebef; border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #1f2a37 0%, #2c3b4e 60%, #3a2d18 100%); }
.login .card { width: 100%; max-width: 380px; padding: 28px 24px; }
.login .logo { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login .logo img { width: 48px; height: 48px; }
.login input { min-height: 46px; font-size: 16px; }

/* ---------- Statement (bảng kê) ---------- */
.statement { background: #fff; padding: 28px 32px; border: 1px solid var(--border); border-radius: var(--radius); }
.statement .co { font-size: 13px; }
.statement .co b { font-size: 15px; }
.statement h2.title { text-align: center; font-size: 19px; margin: 18px 0 4px; }
.statement .period { text-align: center; font-style: italic; margin-bottom: 16px; }
.statement table { width: 100%; border-collapse: collapse; font-size: 13px; }
.statement th, .statement td { border: 1px solid #b9c0c9; padding: 5px 7px; vertical-align: top; }
.statement th { background: #eef1f5; }
.statement .info td { border: 0; padding: 2px 6px 2px 0; }
.statement .sum td { font-weight: 700; }
.statement .balance { width: auto; margin-left: auto; margin-top: 14px; min-width: 360px; }
.statement .balance td { border: 0; border-bottom: 1px dotted #c6ccd4; padding: 4px 8px; }
.statement .balance tr:last-child td { font-weight: 700; font-size: 15px; border-bottom: 2px solid #1c2430; }
.statement .sign { display: grid; grid-template-columns: 1fr 1fr; text-align: center; margin-top: 30px; font-weight: 700; min-height: 110px; }
.statement .sign span { display: block; font-weight: 400; font-style: italic; font-size: 12px; }
.statement .st-small { width: auto; min-width: 420px; }
.statement .st-narrow { display: none; }
.st-line { padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.st-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.st-row b { white-space: nowrap; font-variant-numeric: tabular-nums; }
.st-line.sum { font-weight: 700; border-bottom: 2px solid var(--text); }
@media screen and (max-width: 700px) {
  .statement { padding: 16px 14px; }
  .statement h2.title { font-size: 16px; }
  .statement .st-wide { display: none; }
  .statement .st-narrow { display: block; }
  .statement .st-small, .statement .balance { width: 100%; min-width: 0; }
  .statement .info td { display: block; padding: 0; }
  .statement .info td:first-child { margin-top: 6px; }
  .statement .sign { font-size: 12px; gap: 10px; }
}

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .page-head, .filters, #toast-root { display: none !important; }
  .content { padding: 0; max-width: none; }
  .statement { border: 0; padding: 0; }
  .card { box-shadow: none; border: 0; }
}

/* ---- Cài app lên màn hình chính ---- */
.install-banner { display: flex; align-items: center; gap: 10px; background: #fff7e6; border: 1px solid #f5c27a; border-radius: 12px; padding: 10px 8px 10px 12px; margin-bottom: 14px; }
.install-banner .ic { font-size: 26px; }
.install-banner .txt { flex: 1; min-width: 0; }
.install-banner .txt b { display: block; font-size: 15px; }
.install-banner .txt span { display: block; font-size: 12px; color: var(--muted); }
.install-banner .x { border: 0; background: none; font-size: 22px; color: var(--muted); padding: 4px 8px; cursor: pointer; }
.install-steps { padding-left: 22px; margin: 8px 0 12px; }
.install-steps li { margin-bottom: 10px; line-height: 1.5; }
.install-link { display: flex; gap: 8px; }
.install-link input { flex: 1; min-width: 0; }
@media print { .install-banner { display: none; } }
