:root {
  --primary: #2563eb;
  --primary-ink: #1d4ed8;
  --primary-soft: #eff6ff;
  --accent: #c2410c;
  --accent-soft: #fff7ed;
  --accent-line: #fdba74;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --ok-line: #bbf7d0;
  --warn-ink: #854d0e;
  --warn-soft: #fef9c3;
  --danger: #b91c1c;
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #1e293b;
  --ink-2: #334155;
  --muted: #475569;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --radius: 12px;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-ink); }
.boot { padding: 32px; text-align: center; color: var(--muted); }
:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Khung ---------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; z-index: 5; }
.topbar.blue { background: var(--primary-ink); color: #fff; border: 0; }
.topbar.blue .sub { color: #dbeafe; }
.topbar .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; }
.sub { font-size: 13px; color: var(--muted); }
.avatar-btn { width: 40px; height: 40px; border-radius: 20px; border: 0; background: #dbeafe; color: var(--primary-ink); font-weight: 700; cursor: pointer; flex-shrink: 0; }
.topbar.blue .avatar-btn { background: rgba(255,255,255,.18); color: #fff; }
.main { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 720px; margin: 0 auto; padding-bottom: 96px; }
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px 4px calc(8px + env(safe-area-inset-bottom)); z-index: 6; }
.bottomnav button { min-height: 52px; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 500; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; }
.bottomnav button::before { content: ''; width: 32px; height: 4px; border-radius: 2px; background: transparent; }
.bottomnav button[aria-current='page'] { color: var(--primary-ink); font-weight: 700; }
.bottomnav button[aria-current='page']::before { background: var(--primary); }
.badge { display: inline-flex; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; align-items: center; justify-content: center; margin-left: 4px; }

/* Quản lí: menu bên trái trên máy tính, thanh cuộn ngang trên điện thoại */
.mgr { display: flex; flex-wrap: wrap; min-height: 100dvh; }
.side { flex: 1 1 220px; max-width: 100%; background: #fff; border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.side .brand { padding: 0 4px 12px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side .brand b { color: var(--primary-ink); font-size: 18px; display: block; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav button { min-height: 44px; text-align: left; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 15px; }
.side nav button[aria-current='page'] { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.mgr-main { flex: 999 1 560px; min-width: 0; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 800px) {
  .side { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px; position: sticky; top: 0; z-index: 5; }
  .side .brand { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 8px; }
  .side nav { flex-direction: row; overflow-x: auto; gap: 6px; scrollbar-width: none; }
  .side nav button { white-space: nowrap; border: 1px solid var(--line-2); border-radius: 20px; min-height: 40px; }
  .side nav button[aria-current='page'] { border-color: var(--primary); }
  .mgr-main { padding: 16px; }
}

/* ---------- Thành phần ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card.tight { padding: 10px 12px; gap: 6px; }
.card.pin { background: var(--accent-soft); border: 2px solid #f97316; border-radius: 16px; }
.card.okay { background: var(--ok-soft); border-color: var(--ok-line); color: #166534; }
h2 { margin: 0; font-size: 18px; font-weight: 700; }
h3 { margin: 0; font-size: 15px; font-weight: 600; }
.title-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.page-title { margin: 0; font-size: 24px; font-weight: 700; }
.between { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi .v { font-size: 24px; font-weight: 700; }
.money { font-weight: 700; white-space: nowrap; }
.big { font-size: 26px; font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }
.danger-t { color: var(--danger); }
.accent-t { color: var(--accent); }
.ok-t { color: var(--ok); }

.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-2); background: #fff; color: var(--ink-2); font-weight: 600; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost-danger { color: var(--danger); border-color: #fca5a5; }
.btn.block { width: 100%; min-height: 52px; font-size: 16px; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line-2); background: #fff; color: var(--ink-2); font-size: 14px; white-space: nowrap; cursor: pointer; }
.chip[aria-pressed='true'] { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.seg { display: inline-flex; gap: 4px; }
.seg button { height: 32px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; color: var(--muted); font-size: 12px; cursor: pointer; }
.seg button[aria-pressed='true'] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.status { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-UNPAID { background: #ffedd5; color: #9a3412; }
.s-PARTIAL { background: var(--warn-soft); color: var(--warn-ink); }
.s-PAID { background: #dcfce7; color: #166534; }
.s-CANCELLED { background: #f1f5f9; color: var(--muted); text-decoration: line-through; }
.notice { border-radius: 12px; padding: 12px; font-size: 14px; }
.notice.ok { background: var(--ok-soft); border: 1px solid var(--ok-line); color: #166534; }
.notice.info { background: var(--primary-soft); border: 1px solid #bfdbfe; color: #1e3a8a; }
.notice.warn { background: var(--accent-soft); border: 1px solid #fed7aa; color: #9a3412; }
.notice.err { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); }

/* Điểm danh */
.att { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; align-items: center; gap: 8px; }
.att .who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.att .name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .note { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .ini { width: 32px; height: 32px; border-radius: 16px; background: #f1f5f9; color: var(--ink-2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.att .pay { width: 64px; height: 44px; flex-shrink: 0; border-radius: 10px; border: 1px dashed #64748b; background: #fff; color: var(--ink-2); font-size: 12px; font-weight: 600; line-height: 1.2; cursor: pointer; }
.att .pay.done { border: 0; background: var(--ok); color: #fff; }
.att .pres { width: 80px; height: 44px; flex-shrink: 0; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid #16a34a; background: var(--ok-soft); color: var(--ok); }
.att .pres.off { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.att.locked { opacity: .75; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 6px; background: #ffedd5; color: #9a3412; font-size: 11px; font-weight: 600; margin-left: 4px; vertical-align: 1px; }

/* Bảng */
.table-box { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th { font-weight: 600; font-size: 13px; color: var(--muted); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { font-size: 14px; padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

/* Biểu mẫu */
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.input, select.input, textarea.input { min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: #fff; font-size: 16px; font-weight: 400; width: 100%; }
textarea.input { min-height: 110px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

/* Hộp thoại */
.backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.dialog { background: #fff; width: 100%; max-width: 560px; max-height: 90dvh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 640px) { .backdrop { align-items: center; } .dialog { border-radius: 18px; } }
.lines .ln { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.lines .ln:last-child { border-bottom: 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 88px; background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: calc(100% - 32px); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-size: 14px; }

/* Đăng nhập */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px 20px; gap: 14px; }
.login h1 { margin: 0; color: var(--primary-ink); font-size: 24px; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .att .pay, .att .pres { transition: background-color .15s, border-color .15s, color .15s; }
}

/* Mã QR */
.qr { width: 240px; max-width: 80vw; aspect-ratio: 1; background: #fff; padding: 8px; border: 1px solid var(--line); border-radius: 12px; }
.qr svg { width: 100%; height: 100%; display: block; }
