: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: 16px; }

.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; }
.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 ---------- */
.sales-layout { display: flex; gap: 16px; height: calc(100vh - 90px); }
.sales-left { flex: 3; overflow-y: auto; }
.sales-right { flex: 1.4; background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; min-width: 320px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 12px 18px; font-size: 14px; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.menu-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px 10px; min-height: 92px; text-align: center; position: relative; }
.menu-item:hover { border-color: var(--brand); transform: translateY(-1px); }
.menu-item-name { font-weight: 600; margin-bottom: 6px; }
.menu-item-price { color: var(--accent); font-weight: 700; }
.menu-item-out { opacity: 0.5; }
.menu-item-tag { position: absolute; top: 6px; right: 6px; background: var(--danger); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; }

.cart-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.cart-header h3 { margin: 0; }
.cart-list { flex: 1; overflow-y: auto; margin-bottom: 12px; }
.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: 8px 0; border-bottom: 1px solid var(--line); }
.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; }
.cart-line-total { font-weight: 600; min-width: 80px; text-align: right; }
.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; }
.cart-total-row { display: flex; justify-content: space-between; font-size: 20px; font-weight: 700; padding: 12px 0; border-top: 2px solid var(--line); }

/* ---------- Thanh toán ---------- */
.checkout-card { background: var(--card); border-radius: var(--radius); padding: 28px; width: 420px; box-shadow: 0 4px 24px rgba(0,0,0,0.08); }
.checkout-lines { max-height: 200px; overflow-y: auto; margin-bottom: 8px; }
.checkout-line { display: flex; justify-content: space-between; padding: 4px 0; }
.checkout-total-row { display: flex; justify-content: space-between; font-size: 22px; font-weight: 700; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.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; margin-top: 16px; }

/* ---------- 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); }

/* ---------- Hoá đơn in ---------- */
#receipt-area { display: none; }
@media print {
  #app { display: none !important; }
  #receipt-area {
    display: block;
    width: 80mm;
    font-family: "Courier New", monospace;
    font-size: 12px;
    color: #000;
  }
  #receipt-area .r-center { text-align: center; }
  #receipt-area .r-bold { font-weight: bold; }
  #receipt-area .r-big { font-size: 14px; }
  #receipt-area .r-row { display: flex; justify-content: space-between; }
  #receipt-area .r-line { white-space: pre; }
  @page { size: 80mm auto; margin: 0; }
}

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