:root {
  --bg: #f6f1eb;
  --surface: #ffffff;
  --surface-2: #faf6f1;
  --ink: #2b1d14;
  --muted: #8a7a6d;
  --line: #e8ddd2;
  --brand: #6f4e37;
  --brand-dark: #3b2a1f;
  --accent: #c8873a;
  --ok: #2f7d4f;
  --ok-bg: #e5f3ea;
  --warn: #b86e00;
  --warn-bg: #fdf0d9;
  --danger: #c0392b;
  --danger-bg: #fbe4e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(59, 42, 31, .06), 0 4px 14px rgba(59, 42, 31, .06);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, select { -webkit-user-select: text; user-select: text; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, h3, h4 { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
.muted { color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
[hidden] { display: none !important; }

/* ===== Nút ===== */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 11px 16px; min-height: 46px; font-weight: 600; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: #efc4bf; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn.block { width: 100%; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px;
  font-size: 18px; color: var(--muted); flex: none;
}
.icon-btn:active { background: var(--line); }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 16px; min-height: 42px; font-weight: 600; white-space: nowrap;
}
.chip.on { background: var(--brand-dark); color: #fff; border-color: var(--brand-dark); }

/* ===== Khung chính ===== */
.shell {
  display: grid; grid-template-columns: calc(96px + var(--safe-l)) 1fr;
  height: 100vh; height: 100dvh;
}
.sidebar {
  background: var(--brand-dark); color: #f3e6da; display: flex; flex-direction: column;
  padding: calc(12px + var(--safe-t)) 8px calc(12px + var(--safe-b)) calc(8px + var(--safe-l));
  gap: 4px; overflow-y: auto;
}
.brand { text-align: center; font-size: 30px; padding: 4px 0 10px; }
.nav-btn {
  position: relative; border: 0; background: transparent; color: inherit; border-radius: 12px;
  padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12.5px; font-weight: 600; opacity: .8;
}
.nav-btn .ic { font-size: 24px; line-height: 1.1; }
.nav-btn.on { background: rgba(255, 255, 255, .14); opacity: 1; }
.nav-btn .dot {
  position: absolute; top: 4px; right: 10px; background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; padding: 0 4px;
}
.side-foot { margin-top: auto; text-align: center; font-size: 12px; }
.side-foot .avatar { margin: 0 auto 4px; width: 40px; height: 40px; font-size: 15px; }
.side-foot button { border: 0; background: rgba(255, 255, 255, .1); color: inherit; border-radius: 10px; padding: 8px 6px; width: 100%; margin-top: 6px; font-size: 12.5px; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; padding-right: var(--safe-r); }
.page-head {
  display: flex; align-items: center; gap: 12px; padding: calc(14px + var(--safe-t)) 20px 12px;
  background: var(--bg); flex-wrap: wrap;
}
.page-head h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 20px calc(24px + var(--safe-b)); }
.sec { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 10px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; margin: 0; }
.avatar {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 20px;
}

/* ===== Đăng nhập ===== */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #3b2a1f, #6f4e37); }
.login-card { background: var(--surface); border-radius: 22px; padding: 28px; width: min(520px, 100%); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.login-logo { font-size: 46px; }
.login-card h1 { margin-bottom: 4px; }
.user-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-top: 16px; }
.user-tile { border: 1px solid var(--line); background: var(--surface-2); border-radius: 16px; padding: 16px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.user-tile small { color: var(--muted); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 16px 0 20px; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand); }
.pin-dots span.on { background: var(--brand); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 320px; margin: 0 auto; }
.pinpad button { height: 68px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface-2); font-size: 26px; font-weight: 600; }
.pinpad button.ghost { font-size: 16px; background: transparent; border-color: transparent; color: var(--muted); }
.pinpad button:active { background: var(--line); }

/* ===== Bán hàng ===== */
.today-bar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.today-bar .card { padding: 12px 16px; flex: 1; min-width: 160px; }
.today-bar b { display: block; font-size: 22px; }
.table-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.table {
  border: 2px dashed var(--line); background: var(--surface-2); border-radius: var(--radius);
  min-height: 104px; padding: 12px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; text-align: left;
}
.table b { font-size: 18px; }
.table.busy { border: 2px solid var(--accent); background: #fff6ea; }
.table.busy span { font-weight: 600; color: var(--brand); }
.table small { color: var(--muted); }

.pos { display: grid; grid-template-columns: 1fr minmax(330px, 38%); height: 100%; min-height: 0; }
.pos-menu { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.cats { display: flex; gap: 8px; padding: 0 20px 12px; overflow-x: auto; flex: none; }
.cats::-webkit-scrollbar { display: none; }
.menu-grid {
  flex: 1; overflow-y: auto; padding: 0 20px calc(20px + var(--safe-b));
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; align-content: start;
}
.menu-item {
  position: relative; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  min-height: 96px; padding: 14px 12px; text-align: left; display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  box-shadow: var(--shadow);
}
.menu-item:active { transform: scale(.97); background: var(--surface-2); }
.menu-item b { font-size: 16.5px; line-height: 1.25; }
.menu-item span { color: var(--brand); font-weight: 700; }
.menu-item small { color: var(--warn); font-weight: 600; font-size: 12px; }
.menu-item.warn { border-color: #f0d199; }
.menu-item .badge {
  position: absolute; top: -6px; right: -6px; background: var(--accent); color: #fff; border-radius: 999px;
  min-width: 26px; height: 26px; display: grid; place-items: center; font-weight: 700; font-size: 14px; padding: 0 6px;
}
.pos-cart { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.cart-head { display: flex; align-items: center; justify-content: space-between; padding: calc(16px + var(--safe-t)) 16px 12px; border-bottom: 1px solid var(--line); gap: 8px; }
.cart-head b { font-size: 18px; }
.cart-lines { flex: 1; overflow-y: auto; }
.line { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.line-main { display: flex; flex-direction: column; min-width: 0; cursor: pointer; }
.line-main small { font-size: 13px; color: var(--warn); }
.line-main small.muted { color: var(--muted); }
.line-main .muted { font-size: 13px; }
.line-total { min-width: 74px; text-align: right; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 20px; font-weight: 700; }
.qty span { min-width: 22px; text-align: center; font-weight: 700; }
.cart-foot { padding: 14px 16px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--surface-2); }
.total-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.total-row b { font-size: 26px; color: var(--brand); }
.cart-btns { display: grid; grid-template-columns: auto 1fr; gap: 10px; }

/* ===== Modal ===== */
.modal-back {
  position: fixed; inset: 0; background: rgba(30, 20, 12, .45); z-index: 50; display: grid; place-items: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: 20px; width: min(560px, 100%); max-height: 100%;
  display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0, 0, 0, .3); overflow: hidden;
}
.modal.wide { width: min(760px, 100%); }
.modal > header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 10px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal > footer { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal > footer .spacer { flex: 1; }
.confirm-msg ul { padding-left: 20px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .recipe-row select, .recipe-row input, .ing-use input {
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px; background: var(--surface); width: 100%; font-size: 16px;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }
.input-group select { width: 80px; flex: none; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tags .chip { min-height: 38px; padding: 6px 14px; }

.recipe { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.recipe-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; align-items: center; }
.ing-use { display: grid; grid-template-columns: 1fr 120px 50px; gap: 8px; align-items: center; margin-bottom: 8px; }
.ing-use small { grid-column: 1 / -1; margin-top: -6px; color: var(--muted); font-size: 13px; }
.ing-use small.low { color: var(--danger); }
.hint { font-size: 13.5px; color: var(--muted); margin: 0 0 12px; }

/* Thanh toán */
.pay-row { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; }
.pay-row.total { border-top: 1px dashed var(--line); margin-bottom: 10px; }
.pay-row.total b { font-size: 30px; color: var(--brand); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.seg button { border: 2px solid var(--line); background: var(--surface); border-radius: 12px; min-height: 52px; font-weight: 700; }
.seg button.on { border-color: var(--brand); background: #f3ebe3; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 8px; }
.quick button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-weight: 600; min-height: 42px; }
.bank-box { background: var(--surface-2); border-radius: 12px; padding: 12px; white-space: pre-wrap; }

/* Hóa đơn */
.receipt { font-family: ui-monospace, Menlo, monospace; font-size: 13.5px; background: #fff; border: 1px dashed var(--line); border-radius: 8px; padding: 14px; max-width: 340px; margin: 0 auto; color: #000; }
.receipt .c { text-align: center; }
.receipt h3 { font-size: 16px; text-align: center; }
.receipt hr { border: 0; border-top: 1px dashed #999; margin: 8px 0; }
.receipt .r { display: flex; justify-content: space-between; gap: 8px; }
.receipt .note { font-size: 12px; padding-left: 10px; }
.receipt .big { font-size: 16px; font-weight: 700; }

/* ===== Pha cốt ===== */
.alert { border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; font-weight: 600; }
.alert.danger { background: var(--danger-bg); color: var(--danger); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.cot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.cot-card { display: flex; flex-direction: column; gap: 12px; }
.cot-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.cot-head p { margin: 4px 0 0; font-size: 13.5px; }
.cot-avail { text-align: right; flex: none; }
.cot-avail b { display: block; font-size: 28px; color: var(--ok); line-height: 1.1; }
.cot-avail span { font-size: 12.5px; color: var(--muted); }
.cot-avail.low b { color: var(--warn); }
.cot-avail.zero b { color: var(--danger); }
.batches { display: flex; flex-direction: column; gap: 8px; }
.batch { display: grid; grid-template-columns: 1fr auto auto; grid-template-areas: "info left btn" "bar bar bar"; gap: 6px 10px; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; border: 1px solid transparent; }
.batch-info { grid-area: info; display: flex; flex-direction: column; }
.batch-info small, .batch-left small { color: var(--muted); font-size: 12.5px; }
.batch-left { grid-area: left; text-align: right; display: flex; flex-direction: column; }
.batch .btn { grid-area: btn; }
.bar { grid-area: bar; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.batch.soon { border-color: #f0d199; background: var(--warn-bg); }
.batch.soon .batch-left small { color: var(--warn); font-weight: 700; }
.batch.soon .bar i { background: var(--warn); }
.batch.expired { border-color: #efc4bf; background: var(--danger-bg); }
.batch.expired .batch-left small { color: var(--danger); font-weight: 700; }
.batch.expired .bar i { background: var(--danger); }

/* ===== Bảng ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 15px; }
table.list th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
table.list td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list .acts { text-align: right; white-space: nowrap; }
table.list .acts .btn { margin-left: 6px; }
.pill { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill.mute { background: var(--line); color: var(--muted); }
.plus { color: var(--ok); font-weight: 700; }
.minus { color: var(--danger); font-weight: 700; }
.small-text { font-size: 13px; color: var(--muted); }

/* Menu */
.cat-block { margin-bottom: 20px; }
.cat-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 10px; }
.cat-title h3 { font-size: 18px; flex: 1; }

/* ===== Báo cáo ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi span { color: var(--muted); font-size: 14px; font-weight: 600; }
.kpi b { display: block; font-size: 26px; margin-top: 4px; color: var(--brand-dark); font-variant-numeric: tabular-nums; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.report-grid .card h3, .card > h3 { font-size: 16px; margin-bottom: 12px; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 180px; padding-top: 20px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.chart .col i { display: block; width: 100%; max-width: 36px; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 2px; }
.chart .col small { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.chart .col .v { font-size: 10.5px; color: var(--brand); font-weight: 700; margin-bottom: 2px; white-space: nowrap; }
.split-bar { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--line); margin: 6px 0 12px; }
.split-bar i:nth-child(1) { background: var(--brand); }
.split-bar i:nth-child(2) { background: var(--accent); }
.legend-row { display: flex; justify-content: space-between; padding: 4px 0; }
.legend-row .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.date-range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.date-range input { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 42px; background: var(--surface); }

/* ===== Cài đặt ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.settings-grid .card h3 { margin-bottom: 14px; font-size: 17px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row:last-of-type { border-bottom: 0; }
.user-row .avatar { width: 42px; height: 42px; font-size: 15px; }
.user-row div { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.guide ol { padding-left: 20px; margin: 0; }
.guide li { margin-bottom: 6px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--brand-dark); color: #fff; padding: 12px 20px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-weight: 600; animation: fade .2s; max-width: 90vw; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

#print { display: none; }

/* ===== Màn hình hẹp (iPad dọc / điện thoại) ===== */
@media (max-width: 900px) {
  .report-grid, .settings-grid { grid-template-columns: 1fr; }
  .cot-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .pos { grid-template-columns: 1fr 320px; }
  .menu-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
@media (max-width: 680px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { order: 2; flex-direction: row; padding: 4px 4px calc(4px + var(--safe-b)); overflow-x: auto; }
  .brand, .side-foot .avatar, .side-foot span { display: none; }
  .side-foot { margin: 0 0 0 auto; display: flex; align-items: center; }
  .side-foot button { margin: 0; }
  .nav-btn { min-width: 64px; }
  .pos { grid-template-columns: 1fr; grid-template-rows: 1fr 45%; }
  .pos-cart { border-left: 0; border-top: 1px solid var(--line); }
  .grid2 { grid-template-columns: 1fr; }
  .page-head, .page-body, .cats, .menu-grid { padding-left: 16px; padding-right: 16px; }
}

/* ===== In hóa đơn ===== */
@media print {
  @page { margin: 4mm; }
  body { background: #fff; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; }
  #print .receipt { border: 0; max-width: 72mm; padding: 0; margin: 0; font-size: 12px; }
}
