:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #2a2118;
  --muted: #8a7f6f;
  --brand: #6b4226;
  --brand-dark: #4a2d1a;
  --accent: #c47f3a;
  --line: #e4dccb;
  --danger: #b5432e;
  --radius: 14px;
}

/* Màn cảm ứng: bỏ delay 300ms khi chạm, chặn double-tap zoom, chặn bôi đen văn bản
   khi bấm nhanh liên tục (thao tác bán hàng cần bấm rất nhanh). */
* { box-sizing: border-box; touch-action: manipulation; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px; /* kích thước chạm tối thiểu khuyến nghị cho tay người lớn */
}
input, select, textarea {
  font-family: inherit;
  -webkit-user-select: text;
  user-select: text;
}

.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }

/* ---------- Layout chung ---------- */
#app { display: flex; flex-direction: column; height: 100vh; }
#topbar { background: var(--brand); color: #fff; flex: none; }
.topbar-inner { display: flex; align-items: center; gap: 16px; padding: 10px 16px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; margin-right: 8px; }
.tabs { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.tab { background: transparent; border: none; color: #f0e6da; padding: 12px 16px; border-radius: 8px; font-size: 15px; }
.tab.active, .tab:hover { background: rgba(255,255,255,0.18); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.me { font-weight: 600; }
.shift-badge { background: #3f8a52; padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.shift-badge-off { background: rgba(255,255,255,0.15); }

#view-root { flex: 1; overflow: auto; padding: 12px; min-height: 0; }

.btn { border-radius: 10px; border: 1px solid transparent; padding: 10px 16px; font-size: 15px; font-weight: 600; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: #c9bfae; cursor: not-allowed; }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--brand); }
#topbar .btn-outline { background: transparent; color: #fff; border-color: rgba(255,255,255,0.5); }
.btn-block { width: 100%; }
.btn-lg { padding: 16px; font-size: 18px; }
.btn-sm { padding: 10px 16px; font-size: 14px; }

/* ---------- Đăng nhập / màn giữa ---------- */
.center-screen { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { background: var(--card); border-radius: var(--radius); padding: 28px; width: 340px; text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,0.08); }
.login-card-wide { width: 560px; }
.field-label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.link-back { display: block; background: none; border: none; color: var(--brand); font-size: 15px; font-weight: 600; padding: 8px 0; margin-bottom: 4px; text-align: left; min-height: 44px; }
.big-input, .text-input, .date-input {
  width: 100%; padding: 12px; font-size: 18px; border: 1px solid var(--line); border-radius: 10px; background: #fffdf9;
}
.text-input { font-size: 15px; padding: 10px; margin-bottom: 4px; }

.staff-grid { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 16px; }
.staff-card { display: flex; flex-direction: column; align-items: center; gap: 8px; background: #fffdf9; border: 1px solid var(--line); border-radius: 12px; padding: 14px; width: 110px; }
.staff-card:hover { border-color: var(--brand); }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 20px; }

.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 16px 0; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--brand); display: inline-block; }
.pin-dot.filled { background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { padding: 20px; min-height: 60px; font-size: 24px; border-radius: 10px; border: 1px solid var(--line); background: #fffdf9; }
.key:hover { border-color: var(--brand); }
.key-muted { color: var(--muted); font-size: 15px; }

/* ---------- Bán hàng (tối ưu màn hình ngang, không cần cuộn cả trang —
   chỉ cuộn bên trong lưới món/giỏ hàng khi thật sự không đủ chỗ) ---------- */
.sales-layout { display: flex; gap: 12px; height: 100%; min-height: 0; }
.sales-left { flex: 3; min-height: 0; display: flex; flex-direction: column; }
.sales-right { flex: 1.3; background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; min-width: 300px; min-height: 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; flex: none; }
.chips-scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 10px 16px; font-size: 14px; flex: none; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.menu-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; align-content: start; }
.menu-item { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 8px; min-height: 72px; text-align: center; position: relative; }
.menu-item:hover { border-color: var(--brand); transform: translateY(-1px); }
.menu-item-sku { font-size: 10px; color: var(--muted); position: absolute; top: 4px; left: 6px; }
.menu-item-name { font-weight: 600; margin-bottom: 4px; margin-top: 8px; font-size: 14px; line-height: 1.2; }
.menu-item-price { color: var(--accent); font-weight: 700; font-size: 13px; }
.menu-item-out { opacity: 0.5; }
.menu-item-tag { position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff; font-size: 10px; padding: 2px 5px; border-radius: 6px; }

.cart-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; flex: none; }
.cart-header h3 { margin: 0; font-size: 16px; }
.cart-list { flex: 1; min-height: 0; overflow-y: auto; margin-bottom: 8px; }
.cart-empty { text-align: center; margin-top: 40px; }
.cart-line { display: grid; grid-template-columns: 1fr auto auto auto; align-items: center; gap: 4px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.cart-line-name { font-size: 14px; }
.cart-line-qty { display: flex; align-items: center; gap: 4px; }
.qty-btn { width: 44px; height: 44px; min-height: 44px; border-radius: 50%; border: 1px solid var(--line); background: #fff; font-size: 20px; font-weight: 700; line-height: 1; padding: 0; flex: none; }
.cart-line-total { font-weight: 600; min-width: 72px; text-align: right; font-size: 14px; }
.cart-line-remove { width: 44px; height: 44px; min-height: 44px; border-radius: 50%; border: none; background: none; color: var(--muted); font-size: 18px; padding: 0; flex: none; }
.cart-total-row { display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; padding: 10px 0; border-top: 2px solid var(--line); flex: none; }

/* ---------- Thanh toán (2 cột ngang, không cuộn cả trang — giống bố cục Bán hàng) ---------- */
.checkout-layout { display: flex; gap: 12px; height: 100%; min-height: 0; }
.checkout-summary { flex: 1; min-width: 280px; background: var(--card); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; min-height: 0; }
.checkout-summary h2 { margin-top: 0; flex: none; }
.checkout-lines-wrap { flex: 1; overflow-y: auto; min-height: 0; }
.checkout-sub-rows { flex: none; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.checkout-line { display: flex; justify-content: space-between; padding: 5px 0; }
.checkout-total-row { display: flex; justify-content: space-between; font-size: 22px; font-weight: 700; padding: 12px 0 0; flex: none; }

.checkout-panel { flex: 1.15; min-width: 300px; background: var(--card); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; min-height: 0; }
.checkout-panel-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.method-toggle { display: flex; gap: 8px; margin-bottom: 8px; }
.method-btn { flex: 1; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; }
.method-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.quick-amounts { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.change-row { display: flex; justify-content: space-between; font-size: 20px; font-weight: 700; color: #3f8a52; margin: 10px 0; }
.change-negative { color: var(--danger); }
.checkout-actions { display: flex; gap: 10px; padding-top: 12px; flex: none; }

/* ---------- Báo cáo / trang chung ---------- */
.page { max-width: 900px; margin: 0 auto; }
.stat-cards { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.stat-card { background: var(--card); border-radius: 12px; padding: 16px 20px; min-width: 160px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
.stat-card-highlight { background: var(--brand); color: #fff; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-card-highlight .stat-label { color: #f0e6da; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }

.report-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; margin: 10px 0 24px; }
.report-table th, .report-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.report-table th { background: #efe7d8; font-size: 13px; color: var(--muted); }
.order-row { cursor: pointer; }
.order-row:hover { background: #f5efe2; }
.order-row td { padding-top: 14px; padding-bottom: 14px; }

.promo-preview { background: var(--card); border-radius: 12px; padding: 16px; margin: 12px 0; max-width: 420px; }
.promo-preview-media { max-width: 100%; max-height: 300px; border-radius: 10px; display: block; background: #000; }

/* ---------- Dashboard ---------- */
.dash-hero { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; border-radius: var(--radius); padding: 24px; margin: 16px 0; }
.dash-hero-label { font-size: 14px; opacity: 0.85; }
.dash-hero-value { font-size: 40px; font-weight: 800; margin: 6px 0; }
.dash-hero-change { display: inline-block; background: rgba(255,255,255,0.18); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.dash-hero-change.change-negative { background: rgba(0,0,0,0.2); }

.chart-bars { display: flex; align-items: flex-end; gap: 10px; background: var(--card); border-radius: 12px; padding: 20px 16px 12px; margin: 10px 0 24px; height: 220px; }
.chart-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.chart-bar-value { font-size: 11px; color: var(--muted); margin-bottom: 4px; white-space: nowrap; }
.chart-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.chart-bar { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 2px; }
.chart-bar-label { font-size: 12px; color: var(--muted); margin-top: 6px; }

.dash-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.rank-list { background: var(--card); border-radius: 12px; padding: 8px 16px; margin-bottom: 20px; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border-bottom: none; }
.rank-badge { width: 22px; height: 22px; border-radius: 50%; background: var(--line); color: var(--ink); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.rank-badge.rank-1 { background: #f0c419; color: #5a4200; }
.rank-badge.rank-2 { background: #c7cdd6; color: #3a3f47; }
.rank-badge.rank-3 { background: #cd8a52; color: #4a2d15; }
.rank-name { flex: 1; font-size: 14px; }
.rank-value { font-weight: 700; font-size: 14px; }

@media (max-width: 700px) {
  .dash-two-col { grid-template-columns: 1fr; }
  .chart-bar-value { display: none; }
}

/* Hoá đơn in: CSS nằm trong print.js (RECEIPT_STYLE), nhúng thẳng vào tài liệu của
   iframe ẩn dùng để in — không còn dùng #receipt-area/@media print trên trang chính
   để tránh màn hình chính bị chớp khi in (xem print.js). */

@media (max-width: 900px) {
  .sales-layout { flex-direction: column; height: auto; }
  .sales-right { min-width: 0; }
}

/* ---------- Chỉnh số liệu Dashboard/Báo cáo (chỉ Chủ quán) ---------- */
.metric-btn {
  background: none; border: none; padding: 0; margin: 0; font: inherit; color: inherit;
  cursor: pointer; border-bottom: 1px dashed var(--brand); display: inline-flex; align-items: center; gap: 4px;
}
.metric-btn:hover { color: var(--brand); }
.metric-edited-badge { font-size: 12px; }
.metric-edit-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex;
  align-items: center; justify-content: center; z-index: 1000; padding: 16px;
}
.metric-edit-box { background: var(--card); border-radius: var(--radius); padding: 24px; width: 360px; max-width: 100%; }
.metric-edit-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.metric-edit-actions .btn { flex: 1; min-width: 100px; }
.export-check-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.export-check-row input { width: 18px; height: 18px; flex: none; }

/* ---- QR chuyển khoản ở màn thanh toán ---- */
.qr-pay { text-align: center; margin-top: 8px; }
.qr-pay-img {
  width: 100%; max-width: 300px; aspect-ratio: 1 / 1; object-fit: contain;
  background: #fff; border-radius: 12px; padding: 8px; border: 1px solid var(--line, #e3e3e3);
}
.qr-pay-amount { margin-top: 8px; font-size: 15px; }
.qr-pay-amount b { font-size: 20px; }
