:root {
  --bg: #FFF8F0;
  --card: #FFFFFF;
  --ink: #2B1D14;
  --muted: #8A7666;
  --line: #EEDFCF;
  --accent: #D9480F;
  --accent-ink: #FFFFFF;
  --accent-soft: #FFE8D9;
  --ok: #2F9E44;
  --ok-soft: #E6F6EA;
  --warn: #E67700;
  --warn-soft: #FFF1D6;
  --late: #E03131;
  --late-soft: #FFE3E3;
  --note: #FFF3BF;
  --pay: #1C7ED6;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 30, 10, .06), 0 4px 14px rgba(60, 30, 10, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--late); min-height: 1.2em; margin: 6px 0 0; }
.warn { color: var(--warn); font-size: 15px; margin: 6px 0 0; }
.warn-text { color: var(--warn); }

/* ---------- Nút ---------- */
.btn {
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 48px;
  font-weight: 600;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--late); border-color: var(--late); color: #fff; }
.btn.pay { background: var(--pay); border-color: var(--pay); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 15px; padding: 8px 6px; }
.link-btn.danger { color: var(--muted); }
.icon-btn { border: 0; background: none; font-size: 22px; color: var(--muted); width: 40px; height: 40px; border-radius: 10px; }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-box {
  background: var(--card); border-radius: 24px; box-shadow: var(--shadow);
  padding: 32px; width: min(380px, 100%); text-align: center; display: grid; gap: 12px;
}
.login-logo { font-size: 56px; }
.login-box h1 { margin: 0; font-size: 26px; }
.login-box p { margin: 0; }
.login-box input {
  text-align: center; font-size: 28px; letter-spacing: .3em; padding: 12px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg);
}

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 20px; white-space: nowrap; }
.tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; }
.tab {
  border: 0; background: transparent; padding: 10px 16px; border-radius: 999px;
  font-weight: 600; color: var(--muted); white-space: nowrap; min-height: 44px;
}
.tab.active { background: var(--ink); color: #fff; }
.count { background: var(--late); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 14px; margin-left: 4px; }
.net { font-size: 13px; font-weight: 600; }
.net.ok::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.net.bad { color: #fff; background: var(--late); padding: 4px 10px; border-radius: 999px; }

main { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; }

/* ---------- Sơ đồ bàn ---------- */
.tables-layout { display: grid; grid-template-columns: 1fr minmax(360px, 42%); gap: 16px; align-items: start; }
.table-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tcard {
  text-align: left; border: 2px solid var(--line); background: var(--card);
  border-radius: var(--radius); padding: 14px; min-height: 132px;
  display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.tcard.empty { background: transparent; box-shadow: none; border-style: dashed; }
.tcard.empty .tstatus { color: var(--muted); }
.tcard.waiting { border-color: var(--accent); }
.tcard.served { border-color: var(--ok); background: var(--ok-soft); }
.tcard.sel { outline: 4px solid var(--ink); outline-offset: 2px; }
.tcard-top { display: flex; justify-content: space-between; align-items: center; }
.tname { font-size: 22px; font-weight: 800; }
.dot-note { background: var(--note); border-radius: 8px; padding: 0 6px; font-size: 15px; }
.tstatus { font-weight: 600; font-size: 15px; }
.tmoney { font-size: 18px; font-weight: 700; margin-top: auto; }
.tmoney small { color: var(--warn); }
.twait { font-weight: 700; font-size: 15px; border-radius: 8px; padding: 2px 8px; align-self: flex-start; white-space: nowrap; }
.twait.muted { padding-left: 0; font-weight: 600; }
.w-ok { background: var(--ok-soft); color: var(--ok); }
.w-warn { background: var(--warn-soft); color: var(--warn); }
.w-late { background: var(--late-soft); color: var(--late); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .w-late { animation: none; } }

/* ---------- Chi tiết bàn ---------- */
.table-detail {
  position: sticky; top: 76px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: calc(100vh - 100px); max-height: calc(100dvh - 100px);
  overflow: hidden;
}
.empty-detail { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-detail.small { padding: 24px 0; }
.detail-head { display: flex; align-items: baseline; gap: 10px; padding: 16px 16px 8px; flex-wrap: wrap; }
.detail-head h2 { margin: 0; font-size: 24px; }
.back-btn { display: none; }
.detail-scroll { overflow-y: auto; padding: 0 16px; flex: 1; -webkit-overflow-scrolling: touch; }
.detail-foot { border-top: 1px solid var(--line); padding: 12px 16px 16px; }
.sum { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; }
.sum b { font-size: 26px; }
.foot-btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.foot-btns .btn { flex: 1; }
.foot-btns .btn.primary { flex: 2 1 100%; }

.order { border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px; margin-bottom: 10px; }
.order-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 15px; font-weight: 600; color: var(--muted); }
.spacer { flex: 1; }
.ok-badge { color: var(--ok); font-weight: 700; }
.order-note { background: var(--note); border-radius: 10px; padding: 6px 10px; margin: 6px 0; font-weight: 600; }

.line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); }
.order-head + .line, .order-note + .line, .qhead + .line { border-top: 0; }
.line-main { flex: 1; min-width: 0; }
.line-name { font-size: 18px; font-weight: 600; }
.qty { color: var(--accent); }
.line-opts { color: var(--muted); font-size: 15px; }
.line-note { background: var(--note); display: inline-block; border-radius: 8px; padding: 1px 8px; font-size: 15px; margin-top: 2px; }
.line-price { font-weight: 600; white-space: nowrap; font-size: 15px; }
.line.done .line-name, .line.done .line-opts { color: var(--muted); }
.line.cancelled { opacity: .45; }
.line.cancelled .line-name { text-decoration: line-through; }
.tick {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); font-size: 22px; font-weight: 800; color: #fff;
}
.tick.on { background: var(--ok); border-color: var(--ok); }
.tick.off { display: grid; place-items: center; color: var(--muted); border-style: dashed; }

.lvl { display: inline-block; font-size: 14px; font-weight: 800; padding: 1px 8px; border-radius: 999px; background: #FFE8CC; color: #A33A00; vertical-align: 2px; }
.lvl-0 { background: #EDF2F7; color: #4A5568; }
.lvl-3, .lvl-4 { background: #FFD8A8; color: #A33A00; }
.lvl-5, .lvl-6, .lvl-7 { background: var(--late); color: #fff; }

/* ---------- Hàng chờ ---------- */
.queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; align-items: start; }
.qcard { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; border-top: 6px solid var(--ok); }
.qcard.w-warn { border-top-color: var(--warn); background: var(--card); color: inherit; }
.qcard.w-late { border-top-color: var(--late); background: var(--card); color: inherit; animation: none; }
.qcard.w-ok { background: var(--card); color: inherit; }
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.qtable { font-size: 24px; font-weight: 800; }
.qcard .btn { width: 100%; margin-top: 8px; }

/* ---------- Đã thu ---------- */
.today-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.today-sum { text-align: center; display: grid; }
.today-sum b { font-size: 32px; }
.today-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 16px; }
.today-row { display: grid; grid-template-columns: 56px 70px 1fr auto; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); align-items: baseline; }
.today-row:first-child { border-top: 0; }
.today-items { color: var(--muted); font-size: 15px; }

/* ---------- Sửa thực đơn ---------- */
.menu-admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hint { color: var(--muted); margin: 0; }
.cat-title { margin: 20px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.madmin-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.mrow {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: left;
  border: 0; border-top: 1px solid var(--line); background: none; padding: 12px 16px;
}
.mrow:first-child { border-top: 0; }
.mname { font-weight: 700; }
.mopts { grid-column: 1; color: var(--muted); font-size: 14px; }
.mprice { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 600; }
.hidden-item { opacity: .5; }

/* ---------- Khung phủ ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(43, 29, 20, .45); }
.overlay.center { display: grid; place-items: center; padding: 16px; z-index: 30; }
#confirmBox { z-index: 40; }
.sheet {
  background: var(--card); border-radius: 20px; padding: 20px; width: min(560px, 100%);
  max-height: calc(100dvh - 32px); overflow-y: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .2);
}
.sheet.small { width: min(440px, 100%); }
.sheet h2 { margin: 0 0 12px; font-size: 22px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.sheet-actions .btn { min-width: 120px; }
.full { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; }

.field { display: grid; gap: 4px; margin: 10px 0; flex: 1; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.field input, .field textarea {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); min-height: 48px; width: 100%;
}
.field-row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.check { display: flex; gap: 8px; align-items: center; min-height: 48px; margin: 10px 0; }
.check input { width: 22px; height: 22px; }

.chips { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 56px; min-height: 52px;
  padding: 8px 16px; border: 2px solid var(--line); border-radius: 12px; font-weight: 700; font-size: 18px; background: var(--card);
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips.levels .chip span { min-width: 60px; font-size: 22px; }

.qty-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-weight: 600; }
.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { width: 52px; height: 52px; border: 0; background: var(--bg); font-size: 26px; font-weight: 700; }
.stepper b { min-width: 44px; text-align: center; font-size: 20px; }
.stepper.small button { width: 44px; height: 44px; font-size: 22px; }
.stepper.small b { min-width: 32px; font-size: 18px; }

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.btn.choice { display: grid; min-height: 64px; font-size: 18px; }
.btn.choice small { font-weight: 500; font-size: 12px; color: var(--warn); }
.bill { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; }
.bill-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px dashed var(--line); font-size: 15px; }
.bill-row:first-child { border-top: 0; }
.bill-row.total { font-size: 20px; font-weight: 800; border-top: 1.5px solid var(--ink); }

/* ---------- Gọi món ---------- */
.composer { position: absolute; inset: 0; background: var(--bg); display: flex; flex-direction: column; }
.composer-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid var(--line);
}
.composer-head .btn { justify-self: start; }
.composer-head h2 { margin: 0; font-size: 20px; }
.composer-body { flex: 1; display: grid; grid-template-columns: 1fr 360px; min-height: 0; }
.picker { overflow-y: auto; padding: 12px 16px; -webkit-overflow-scrolling: touch; }
.cat-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.cat { border: 2px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 18px; font-weight: 700; min-height: 48px; }
.cat.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.item {
  position: relative; text-align: left; background: var(--card); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 14px; min-height: 110px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.item:active { border-color: var(--accent); }
.item-name { font-weight: 800; font-size: 19px; }
.item-price { color: var(--accent); font-weight: 700; margin-top: auto; }
.item-hint { font-size: 13px; color: var(--muted); }
.badge { position: absolute; top: -8px; right: -8px; background: var(--accent); color: #fff; border-radius: 999px; min-width: 30px; height: 30px; display: grid; place-items: center; font-weight: 800; border: 3px solid var(--bg); }
.cart {
  border-left: 1px solid var(--line); background: var(--card); padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; min-height: 0;
}
.cart h3 { margin: 4px 0 8px; }
.cart .field { flex: none; }
.cart .field textarea { resize: none; }
.cart-lines { flex: 1; overflow-y: auto; min-height: 60px; }
.cline { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px dashed var(--line); }
.cline:first-child { border-top: 0; }
.cline-main { flex: 1; min-width: 0; }
.cart-total { display: flex; justify-content: space-between; font-size: 18px; margin: 4px 0 10px; }
.cart-total b { font-size: 22px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; z-index: 50; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: calc(100% - 32px); text-align: center;
}
.toast.error { background: var(--late); }


/* ---------- Thứ tự ưu tiên ---------- */
.rank { background: var(--ink); color: #fff; font-weight: 800; border-radius: 10px; padding: 2px 10px; font-size: 18px; }
.rank.small { font-size: 14px; padding: 1px 7px; border-radius: 8px; }
.twait { font-variant-numeric: tabular-nums; }

/* ---------- Khách / nhóm trong bàn ---------- */
.guest { border: 2px solid var(--line); border-radius: 16px; padding: 10px; margin-bottom: 12px; background: #FFFCF8; }
.guest-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 18px; }
.guest-name { background: var(--accent-soft); color: #A33A00; border-radius: 8px; padding: 2px 10px; }
.guest-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.guest-btns .btn { flex: 1; }
.guest-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.gchip { border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 14px; min-height: 48px; font-weight: 700; }
.gchip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.gchip.add { border-style: dashed; color: var(--accent); }
.bill-guest { font-weight: 800; margin-top: 8px; color: #A33A00; }

/* ---------- Sửa món ---------- */
.cline-main { border: 0; background: none; text-align: left; padding: 4px 0; flex: 1; min-width: 0; }
.edit-hint { font-size: 13px; color: var(--accent); font-weight: 600; }
.choices.wide { grid-template-columns: 1fr 1fr; }
.btn.danger-outline { color: var(--late); border-color: var(--late-soft); }

/* ---------- Hàng chờ: theo món ---------- */
.seg { display: inline-flex; background: var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; gap: 4px; }
.seg-btn { border: 0; background: transparent; border-radius: 9px; padding: 8px 16px; min-height: 44px; font-weight: 700; color: var(--muted); }
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.queue.dish { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.qcount { color: var(--accent); }
.mix { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.mix-chip { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 15px; }
.part { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 6px; }
.part-who { font-size: 15px; }
.part .line { border-top: 0; padding: 4px 0; }
.part-onote { background: var(--note); border-radius: 8px; padding: 2px 8px; font-size: 14px; display: inline-block; }

/* ---------- iPad dọc / màn nhỏ ---------- */
@media (max-width: 900px) {
  .tables-layout { grid-template-columns: 1fr; }
  .table-detail { display: none; }
  body.detail-open .table-detail {
    display: flex; position: fixed; inset: 0; top: 0; z-index: 10; border-radius: 0; max-height: none;
    padding-top: env(safe-area-inset-top);
  }
  .back-btn { display: inline-flex; }
  .table-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .composer-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .cart { border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
}
@media (max-width: 560px) {
  .queue.dish { grid-template-columns: 1fr; }
  .brand span { display: none; }
  .tab { padding: 8px 12px; }
  .today-row { grid-template-columns: 48px 56px 1fr; }
  .today-row > b:last-child { grid-column: 3; }
}
