/* MAI CAFE & TEA — màu hoa mai trên nền xám lá, chữ nâu cà phê */
:root {
  --ink: #2a1e16;
  --ink-2: #5c5048;
  --muted: #7d766d;
  --bg: #eceee9;
  --surface: #ffffff;
  --line: #d8dbd3;
  --mai: #f2b705;
  --mai-soft: #fff3c4;
  --mai-deep: #8a6500;
  --leaf: #2f6b4f;
  --leaf-soft: #e1efe6;
  --danger: #b3402a;
  --danger-soft: #f8e3dd;
  --radius: 10px;
  --radius-lg: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--mai); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------- Khung ứng dụng ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
/* min-width:0 để nội dung dài (hàng nhóm món…) không kéo giãn cả trang ra ngoài màn hình */
.main { flex: 1; min-width: 0; padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 16px); max-width: 1600px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; min-width: 0; }
.topbar > * { min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; background: var(--mai); display: grid; place-items: center; }
.brand-mark svg { width: 22px; height: 22px; }
.brand { min-width: 0; }
.brand-name { font-weight: 700; letter-spacing: 0.02em; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .search { flex: 0 1 240px; width: auto; min-width: 110px; }
@media (min-width: 900px) { section[style] { padding-bottom: 0 !important; } }

.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--ink); display: flex; z-index: 20; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #cfc5bb; text-decoration: none; font-size: 12px; font-weight: 500; }
.nav a svg { width: 22px; height: 22px; }
.nav a.on { color: var(--mai); }

@media (min-width: 900px) {
  .shell { flex-direction: row; }
  .nav { position: sticky; top: 0; height: 100vh; width: 92px; flex-direction: column; justify-content: flex-start; padding: 16px 0; gap: 6px; }
  .nav a { flex: 0 0 72px; }
  .main { padding-bottom: 24px; }
}

/* ---------- Thành phần chung ---------- */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: 16px; border: 1px solid var(--line); }
.list { background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--line); overflow: hidden; }
.list > .li { padding: 12px 14px; border-top: 1px solid var(--line); }
.list > .li:first-child { border-top: 0; }
.li.tap { cursor: pointer; }
.li.tap:active { background: #f6f6f2; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 10px 14px; font-weight: 600;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--mai); border-color: var(--mai); color: var(--ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--danger); border-color: #e7c2b8; background: var(--surface); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn { white-space: nowrap; }
.btn.block { width: 100%; }
a.btn { color: inherit; text-decoration: none; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn.icon { width: 44px; padding: 0; }

.field { display: block; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; font-weight: 500; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
  padding: 10px 12px; min-height: 44px; font-size: 16px; }
.input:focus { border-color: var(--mai-deep); outline: none; box-shadow: 0 0 0 3px var(--mai-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px;
  font-weight: 500; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
/* Bộ lọc nhóm món: lưới nhiều hàng, không vuốt ngang */
.cat-panel { background: var(--ink); border-radius: var(--radius-lg); padding: 8px; }
.cat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; color: var(--mai); font-weight: 700;
  font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; padding: 2px 4px 7px; }
.cat-head .small { color: #cfc5bb; text-transform: none; letter-spacing: 0; font-weight: 500; }
.cat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
@media (min-width: 700px) { .cat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }
.cat { position: relative; border: 0; border-radius: 9px; background: #43342a; color: #fff; padding: 6px 8px; min-height: 44px;
  display: flex; align-items: center; justify-content: center; text-align: center; }
.cat:active { transform: scale(0.97); }
.cat .cat-name { font-weight: 600; font-size: 13.5px; line-height: 1.2; overflow-wrap: anywhere; }
.cat.on { background: var(--mai); color: var(--ink); box-shadow: 0 0 0 2px var(--mai), inset 0 0 0 2px var(--ink); }
.cat .cat-count { position: absolute; top: -5px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--mai); color: var(--ink); font-size: 12px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--ink); }
.cat.on .cat-count { background: var(--ink); color: var(--mai); box-shadow: 0 0 0 2px var(--mai); }
@media (max-width: 340px) { .cat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: #eee; }
.badge.mai { background: var(--mai-soft); color: var(--mai-deep); }
.badge.leaf { background: var(--leaf-soft); color: var(--leaf); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.seg { display: flex; background: #e2e5de; border-radius: var(--radius); padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 9px 6px; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--surface); box-shadow: 0 1px 2px rgba(42, 30, 22, 0.15); }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; }

/* ---------- Bán hàng ---------- */
.pos { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.pos > * { min-width: 0; }
@media (min-width: 900px) { .pos { grid-template-columns: minmax(0, 1fr) clamp(320px, 30vw, 420px); align-items: start; } }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); gap: 10px; margin-top: 12px; }
@media (max-width: 360px) { .menu-grid { grid-template-columns: 1fr 1fr; } }
.tile { position: relative; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  padding: 12px; min-height: 84px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; }
.tile:active { transform: scale(0.98); }
.tile .name { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.tile .price { color: var(--ink-2); font-size: 14px; }
.tile .qty { position: absolute; top: -7px; right: -7px; min-width: 26px; height: 26px; border-radius: 13px; background: var(--ink);
  color: var(--mai); font-weight: 700; font-size: 13px; display: grid; place-items: center; padding: 0 6px; }
.tile.in-cart { border-color: var(--ink); }

/* Sơ đồ bàn */
.table-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(104px, 100%), 1fr)); gap: 10px; }
.ttile { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-lg); padding: 12px; min-height: 92px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 2px; text-align: left; }
.ttile:active { transform: scale(0.98); }
.ttile .tname { font-weight: 700; font-size: 16px; }
.ttile .ttotal { font-weight: 700; font-size: 17px; }
.ttile.busy { background: var(--mai); border-color: var(--mai); }
.ttile.busy .small { color: var(--ink); }
.ttile.current { border: 2px solid var(--ink); }

.qr-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.qr-box .qr { max-width: 100%; height: auto; }

.promo-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

.cart-bar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 15;
  background: var(--mai); color: var(--ink); border: 0; border-radius: var(--radius-lg); padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; font-weight: 700; box-shadow: 0 6px 18px rgba(42, 30, 22, 0.25); }
.cart-bar .total { font-size: 22px; }
@media (min-width: 900px) { .cart-bar { display: none; } }

.cart { background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--line); display: flex; flex-direction: column; }
.cart-panel { display: none; }
@media (min-width: 900px) {
  .cart-panel { display: block; position: sticky; top: 16px; }
  /* Đơn dài thì danh sách món cuộn bên trong, nút Gửi/Thanh toán luôn hiện trên màn hình */
  .cart-panel .lines { max-height: max(180px, calc(100vh - 440px)); overflow-y: auto; margin-right: -8px; padding-right: 8px; }
}
.cart-head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.cart-body { padding: 4px 16px 12px; }
.line { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.line .name { font-weight: 600; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); }
.stepper button { width: 36px; height: 36px; border: 0; background: transparent; font-size: 20px; font-weight: 600; }
.stepper span { min-width: 24px; text-align: center; font-weight: 700; }
.sum { display: flex; justify-content: space-between; padding: 3px 0; }
.sum.discount { color: var(--leaf); }
.grand { margin: 10px -16px -12px; padding: 14px 16px; background: var(--ink); color: #fff; border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  display: flex; justify-content: space-between; align-items: baseline; }
.grand .total { font-size: 28px; font-weight: 700; color: var(--mai); }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--leaf); }

/* ---------- Bảng điều khiển trượt (sheet) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(42, 30, 22, 0.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b)); animation: up 0.18s ease-out; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 80px); z-index: 60;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); font-weight: 500; max-width: 90vw; }
.toast.err { background: var(--danger); }

.paid { text-align: center; padding: 8px 0; }
.paid .tick { width: 64px; height: 64px; border-radius: 50%; background: var(--leaf); color: #fff; display: grid; place-items: center; margin: 0 auto 10px; }

/* ---------- Báo cáo ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat .v { font-size: 22px; font-weight: 700; }
.bar { height: 8px; border-radius: 4px; background: var(--mai); }
.low { color: var(--danger); font-weight: 600; }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--ink); }
.login .card { width: 100%; max-width: 380px; }
.login .mark { width: 72px; height: 72px; border-radius: 50%; background: var(--mai); display: grid; place-items: center; margin: 0 auto 12px; }
.login .mark svg { width: 46px; height: 46px; }

/* ---------- In hoá đơn qua trình duyệt (khổ 80mm) ---------- */
#print-area { display: none; }
@media print {
  @page { size: 80mm auto; margin: 2mm; }
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; left: 0; top: 0; width: 76mm; font: 12px/1.35 Arial, sans-serif; color: #000; }
  #print-area hr { border: 0; border-top: 1px dashed #000; margin: 4px 0; }
  #print-area .rh { text-align: center; font-weight: 700; font-size: 16px; }
  #print-area .rc { text-align: center; }
  #print-area .rb { font-weight: 700; }
  #print-area .rp { display: flex; justify-content: space-between; }
  #print-area .rt { font-weight: 700; font-size: 15px; }
  #print-area .rg { font-weight: 700; font-size: 16px; }
  #print-area .rq { text-align: center; margin: 4px 0; }
  #print-area .rq svg { width: 38mm; height: 38mm; }
}
