:root {
  --bg: #f6f2ec; --surface: #fff; --surface-2: #faf7f3; --line: #e4dbd0; --line-strong: #cbbcaa;
  --text: #2a1d14; --muted: #6d5d50; --brand: #7a4a2a; --brand-ink: #fff; --brand-soft: #f1e5d9;
  --pay: #18774a; --pay-hover: #12633d; --danger: #b42318; --danger-soft: #fdecea; --warn: #9a5b00; --warn-soft: #fff4dc;
  --ok-soft: #e6f4ec; --info: #1f5fa8; --info-soft: #e8f0fb;
  --radius: 12px; --radius-sm: 8px; --shadow: 0 1px 2px rgba(42,29,20,.06), 0 4px 16px rgba(42,29,20,.06);
  --tap: 48px; --nav-w: 220px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--bg); font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--brand); }
.muted { color: var(--muted); } .small { font-size: .875rem; } .num { font-variant-numeric: tabular-nums; }
.right { text-align: right; } .nowrap { white-space: nowrap; } .grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; } .wrap { flex-wrap: wrap; } .between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid #d08a3c; outline-offset: 2px; }

/* ---------- Nút ---------- */
.btn { min-height: var(--tap); padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; touch-action: manipulation; user-select: none; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.pay { background: var(--pay); border-color: var(--pay); color: #fff; }
.btn.pay:hover { background: var(--pay-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: .9rem; }
.btn.lg { min-height: 60px; font-size: 1.1rem; }
.btn.block { width: 100%; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ""; position: absolute; width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.5); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; }
.btn:not(.primary):not(.pay):not(.danger).busy::after { border-color: var(--line); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: var(--tap); height: var(--tap); border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1.25rem; flex: none; }

/* ---------- Form ---------- */
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .92rem; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
.input, select.input, textarea.input { min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; width: 100%; font-weight: 400; }
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { border-color: var(--brand); outline: 2px solid #e6c9a8; }
.input.big { font-size: 1.6rem; font-weight: 700; text-align: right; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; font-weight: 500; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

/* Nút chọn dạng phân đoạn */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { min-height: 44px; min-width: 52px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: #fff;
  cursor: pointer; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.seg button[disabled] { opacity: .45; text-decoration: line-through; }

/* ---------- Khung ứng dụng ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; height: 100vh; height: 100dvh; }
.nav { background: #2a1d14; color: #f3e9df; display: flex; flex-direction: column; overflow-y: auto; }
.nav .brand { padding: 16px; font-weight: 800; font-size: 1.05rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.nav .brand small { display: block; font-weight: 500; color: #c9b6a4; font-size: .8rem; margin-top: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 50px; color: #f3e9df; text-decoration: none; font-weight: 600; position: relative; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a[aria-current="page"] { background: #7a4a2a; }
.nav a .ico { width: 24px; text-align: center; font-size: 1.15rem; }
.nav a .badge { margin-left: auto; }
.nav .spacer { flex: 1; }
.nav .who { padding: 12px 16px; font-size: .85rem; color: #c9b6a4; border-top: 1px solid rgba(255,255,255,.08); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: none; }
.page { flex: 1; overflow-y: auto; padding: 20px; min-height: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.banner { padding: 10px 16px; font-weight: 600; font-size: .92rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.offline { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid #f0d49a; }
.banner.info { background: var(--info-soft); color: var(--info); }

@media (max-width: 899px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .nav { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #2a1d14; color: #fff; min-height: 56px; }
  .topbar .icon-btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.2); }
  .topbar .title { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page { padding: 14px; }
}

/* ---------- Thẻ, bảng ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card h2 { margin-bottom: 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .label { color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi .value { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: .8rem; color: var(--muted); }
.kpi.accent { border-color: var(--pay); background: var(--ok-soft); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th, .tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; background: var(--surface-2); position: sticky; top: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--surface-2); }
.tbl tr.low td { background: var(--danger-soft); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap;
  background: var(--brand-soft); color: var(--brand); }
.badge.new { background: var(--info-soft); color: var(--info); }
.badge.preparing { background: var(--warn-soft); color: var(--warn); }
.badge.ready { background: var(--ok-soft); color: var(--pay); }
.badge.paid { background: var(--pay); color: #fff; }
.badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.badge.draft { background: #eee; color: #555; }
.badge.red { background: var(--danger); color: #fff; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { min-height: 46px; padding: 0 16px; border: 0; background: none; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 2.4rem; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.loading::before { content: ""; display: block; margin: 0 auto 12px; width: 32px; height: 32px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.error-box { background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c1bb; border-radius: var(--radius-sm); padding: 12px 14px; font-weight: 600; }
.note-box { background: var(--warn-soft); color: #6b4300; border: 1px solid #f0d49a; border-radius: var(--radius-sm); padding: 10px 14px; font-size: .92rem; }
.info-box { background: var(--info-soft); color: #173f6e; border-radius: var(--radius-sm); padding: 10px 14px; font-size: .92rem; }
details.explain summary { cursor: pointer; font-weight: 700; color: var(--brand); min-height: 40px; display: flex; align-items: center; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: #cbbcaa; border-radius: 999px; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--pay); }
.switch input:checked + span::after { transform: translateX(22px); }

/* ---------- Bán hàng ---------- */
.pos { display: grid; grid-template-columns: 1fr 380px; height: 100%; min-height: 0; }
.pos-menu { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pos-tools { padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.pos-tools .search { position: relative; flex: 1; }
.pos-tools .search input { padding-left: 40px; }
.pos-tools .search::before { content: "🔍"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: .95rem; opacity: .6; }
.cats { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cats button { flex: none; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-strong); background: #fff; font-weight: 700; cursor: pointer; }
.cats button[aria-pressed="true"] { background: var(--text); color: #fff; border-color: var(--text); }
.products { flex: 1; overflow-y: auto; padding: 4px 14px 90px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start; }
.product { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; overflow: hidden; min-height: 120px; touch-action: manipulation; box-shadow: var(--shadow); }
.product:active { transform: scale(.98); }
.product .img { height: 82px; background: var(--brand-soft) center/cover no-repeat; display: flex; align-items: center; justify-content: center; font-size: 2rem; }
.product .info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.product .name { font-weight: 700; font-size: .98rem; line-height: 1.25; }
.product .price { color: var(--brand); font-weight: 800; font-variant-numeric: tabular-nums; margin-top: auto; }
.product.out { opacity: .5; cursor: not-allowed; }
.product.out::after { content: "Tạm hết"; position: absolute; top: 8px; right: 8px; background: var(--danger); color: #fff; font-size: .75rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.product .opt { position: absolute; top: 6px; left: 6px; background: rgba(255,255,255,.92); border-radius: 999px; font-size: .72rem; padding: 2px 8px; font-weight: 700; color: var(--muted); }

.cart { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.cart-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.cart-items { flex: 1; overflow-y: auto; padding: 4px 0; min-height: 80px; }
.cart-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 14px; border-bottom: 1px dashed var(--line); }
.cart-item .nm { font-weight: 700; cursor: pointer; }
.cart-item .opts { font-size: .83rem; color: var(--muted); grid-column: 1 / -1; }
.cart-item .opts .itemnote { color: var(--warn); font-weight: 600; }
.cart-item .qty { display: flex; align-items: center; gap: 4px; }
.cart-item .qty button:not(.btn) { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-strong); background: #fff; font-size: 1.2rem; font-weight: 700; cursor: pointer; }
.cart-item .qty span { min-width: 26px; text-align: center; font-weight: 800; }
.cart-item .lt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.cart-item.voided { opacity: .5; } .cart-item.voided .nm { text-decoration: line-through; }
.cart-item .sent { font-size: .72rem; background: var(--ok-soft); color: var(--pay); border-radius: 999px; padding: 1px 8px; font-weight: 700; margin-left: 6px; }
.cart-foot { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 1.5rem; font-weight: 800; }
.totals .disc { color: var(--pay); }
.cart-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cart-actions .pay { grid-column: span 2; }
.cart-mini { display: none; }

@media (max-width: 1100px) { .pos { grid-template-columns: 1fr 340px; } }
@media (max-width: 760px) {
  .pos { grid-template-columns: 1fr; }
  .cart { position: fixed; inset: 0; z-index: 40; transform: translateY(100%); transition: transform .2s; border-left: 0; }
  .pos.cart-open .cart { transform: none; }
  .cart-mini { display: flex; position: fixed; left: 10px; right: 10px; bottom: 10px; z-index: 30; min-height: 60px; border-radius: 14px;
    background: var(--pay); color: #fff; border: 0; font-weight: 800; font-size: 1.05rem; align-items: center; justify-content: space-between; padding: 0 18px; box-shadow: 0 6px 20px rgba(0,0,0,.25); cursor: pointer; }
  .cart-mini.empty-cart { background: #6d5d50; }
  .products { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
@media (min-width: 761px) { .cart .close-cart { display: none; } }

/* ---------- Hộp thoại ---------- */
.overlay { position: fixed; inset: 0; background: rgba(30,20,12,.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .btn { flex: 1 1 140px; }
@media (max-width: 560px) {
  .overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 94dvh; }
}
.toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 440px); pointer-events: none; }
.toast { background: #2a1d14; color: #fff; padding: 12px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: fade .15s; pointer-events: auto; }
.toast.error { background: var(--danger); } .toast.ok { background: var(--pay); } .toast.warn { background: #8a5200; }

/* Thanh toán */
.pay-total { text-align: center; padding: 6px 0; }
.pay-total .lbl { color: var(--muted); font-weight: 600; }
.pay-total .amt { font-size: 2.4rem; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--text); }
.methods { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.methods button { min-height: 64px; border-radius: 12px; border: 2px solid var(--line-strong); background: #fff; font-weight: 800; font-size: 1.02rem; cursor: pointer; }
.methods button[aria-pressed="true"] { border-color: var(--pay); background: var(--ok-soft); color: var(--pay); }
.quick-cash { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick-cash button { min-height: 52px; border-radius: 10px; border: 1px solid var(--line-strong); background: #fff; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; }
.change { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-radius: 12px; background: var(--ok-soft); font-weight: 800; font-size: 1.3rem; }
.change.short { background: var(--danger-soft); color: var(--danger); }

/* Bàn */
.tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.tables button { min-height: 84px; border-radius: 12px; border: 2px solid var(--line-strong); background: #fff; cursor: pointer; font-weight: 800; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px; }
.tables button.busy-t { border-color: var(--brand); background: var(--brand-soft); }
.tables button[aria-pressed="true"] { border-color: var(--pay); background: var(--ok-soft); }
.tables small { font-weight: 600; color: var(--muted); font-size: .78rem; }

/* Pha chế */
.prep-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.prep-col h2 { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.ticket { background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--info); border-radius: 10px; padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow); }
.ticket.preparing { border-left-color: #d08a3c; } .ticket.ready { border-left-color: var(--pay); }
.ticket.late { box-shadow: 0 0 0 2px var(--danger); }
.ticket ul { margin: 8px 0; padding-left: 0; list-style: none; }
.ticket li { padding: 4px 0; border-bottom: 1px dotted var(--line); }
.ticket li b { font-size: 1.05rem; }
@media (max-width: 900px) { .prep-board { grid-template-columns: 1fr; } }

/* Biểu đồ */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; overflow-x: auto; }
.bars .bar { flex: 1 0 28px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bars .bar i { display: block; width: 100%; max-width: 44px; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 2px; }
.bars .bar span { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.bars .bar b { font-size: .7rem; font-variant-numeric: tabular-nums; }
.hbar { height: 10px; background: var(--brand-soft); border-radius: 999px; overflow: hidden; min-width: 80px; }
.hbar i { display: block; height: 100%; background: var(--brand); }

/* Đăng nhập */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 20% 10%, #f1e5d9, transparent 60%), var(--bg); }
.login .card { width: 100%; max-width: 400px; padding: 28px 24px; }
.login .logo { font-size: 2.6rem; text-align: center; }

/* ---------- Hóa đơn & in ---------- */
.receipt { font-family: "Courier New", ui-monospace, monospace; font-size: 13px; color: #000; background: #fff; width: 80mm; max-width: 100%; margin: 0 auto; padding: 4mm; line-height: 1.35; border: 1px dashed #bbb; }
.receipt.w58 { width: 58mm; font-size: 11.5px; }
.receipt .c { text-align: center; } .receipt .r { text-align: right; }
.receipt .store { font-size: 1.25em; font-weight: 800; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { padding: 1px 0; vertical-align: top; }
.receipt .big { font-size: 1.3em; font-weight: 800; }
.receipt .opt { font-size: .88em; padding-left: 8px; }
#print-area { display: none; }
@media print {
  @page { margin: 0; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  #print-area .receipt { border: 0; margin: 0; }
}
@media (max-width: 560px) { .hide-sm { display: none; } }
