*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --gold: #b8860b;
  --gold-light: #f5e6a0;
  --blue: #1a73e8;
  --green: #22a34a;
  --red: #d83f3f;
  --ink: #1a1a1a;
  --ink-soft: #666;
  --paper: #fdfaf5;
  --surface: #f3ede0;
  --rule: #e0d9cc;
  --radius: 10px;
}

html, body { height: 100%; background: var(--surface); font-family: -apple-system, "PingFang TC", sans-serif; font-size: 15px; color: var(--ink); overflow: hidden; }
#app { height: 100vh; display: flex; flex-direction: column; }

/* ── login ── */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--surface); }
.login-box { background: var(--paper); border-radius: 16px; padding: 40px 36px; width: 340px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-title { font-size: 22px; font-weight: 800; color: var(--gold); text-align: center; }
.login-sub { font-size: 13px; color: var(--ink-soft); text-align: center; margin-top: -8px; }
.login-error { background: #fff0f0; color: var(--red); border-radius: 6px; padding: 8px 12px; font-size: 13px; }
.login-input { padding: 12px 14px; border: 1.5px solid var(--rule); border-radius: 8px; font-size: 16px; background: var(--surface); color: var(--ink); width: 100%; }
.login-input:focus { outline: none; border-color: var(--gold); }
.btn-login { margin-top: 4px; background: var(--gold); color: #fff; border: none; border-radius: 8px; padding: 14px; font-size: 16px; font-weight: 700; cursor: pointer; width: 100%; }
.btn-login:disabled { opacity: .6; cursor: not-allowed; }

/* ── success ── */
.success-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--surface); }
.success-box { background: var(--paper); border-radius: 20px; padding: 48px 40px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; box-shadow: 0 4px 24px rgba(0,0,0,.08); min-width: 260px; }
.success-icon { width: 72px; height: 72px; border-radius: 50%; background: var(--green); color: #fff; font-size: 36px; display: flex; align-items: center; justify-content: center; }
.success-seq { font-size: 40px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.success-code { background: var(--blue); color: #fff; font-size: 22px; font-weight: 800; padding: 6px 20px; border-radius: 99px; letter-spacing: .06em; }
.success-label { font-size: 16px; color: var(--ink-soft); }
.btn-next-order { margin-top: 8px; background: var(--gold); color: #fff; border: none; border-radius: 10px; padding: 16px 40px; font-size: 18px; font-weight: 700; cursor: pointer; }

/* ── POS layout ── */
.pos-wrap { display: flex; height: 100vh; overflow: hidden; }
.menu-panel { flex: 1 1 0; display: flex; flex-direction: column; overflow: hidden; }
.cart-panel { width: 340px; flex-shrink: 0; background: var(--paper); border-left: 1px solid var(--rule); display: flex; flex-direction: column; }

/* ── category tabs ── */
.menu-header { display: flex; align-items: center; background: var(--paper); border-bottom: 1px solid var(--rule); padding-right: 12px; flex-shrink: 0; }
.cat-tabs { display: flex; overflow-x: auto; flex: 1; scrollbar-width: none; }
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tab { flex-shrink: 0; padding: 14px 20px; border: none; background: none; font-size: 15px; font-weight: 600; color: var(--ink-soft); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.cat-tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.cat-tab:hover:not(.active) { background: var(--surface); }
.sold-out-toggle { flex-shrink: 0; padding: 8px 14px; border: 1.5px solid var(--rule); border-radius: 6px; background: none; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-soft); }
.sold-out-toggle.active { border-color: var(--red); color: var(--red); background: #fff0f0; }

/* ── product grid ── */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); grid-auto-rows: min-content; align-content: start; gap: 8px; padding: 10px; overflow-y: auto; flex: 1; }
.product-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; background: var(--paper); border: 2px solid var(--rule); border-radius: var(--radius); cursor: pointer; text-align: left; transition: border-color .1s, transform .08s; user-select: none; height: 72px; overflow: hidden; }
.product-btn:active { transform: scale(.96); }
.product-btn:hover:not(:disabled) { border-color: var(--gold); }
.product-btn.sold-out { background: var(--surface); opacity: .5; cursor: not-allowed; }
.product-btn.in-stock-edit { border-color: var(--green); background: #f0fff4; }
.p-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.p-price { font-size: 13px; color: var(--gold); font-weight: 700; }
.p-status { font-size: 12px; font-weight: 700; }
.product-btn.sold-out .p-status { color: var(--red); }
.product-btn.in-stock-edit .p-status { color: var(--green); }

/* ── cart ── */
.cart-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 12px; border-bottom: 1px solid var(--rule); flex-shrink: 0; }
.cart-title { font-size: 16px; font-weight: 700; }
.cart-clear { background: none; border: none; color: var(--ink-soft); font-size: 13px; cursor: pointer; padding: 4px 8px; }
.cart-lines { flex: 1; overflow-y: auto; padding: 8px 0; }
.cart-empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); font-size: 15px; }
.cart-line { padding: 10px 18px; border-bottom: 1px solid var(--rule); }
.cart-line-main { display: flex; align-items: center; gap: 8px; }
.cart-line-info { flex: 1; min-width: 0; }
.cart-line-name { font-size: 14px; font-weight: 600; display: block; }
.cart-line-mods { font-size: 12px; color: var(--ink-soft); display: block; }
.cart-line-note { font-size: 12px; color: var(--blue); display: block; }
.cart-line-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.cart-line-price { font-size: 14px; font-weight: 700; min-width: 48px; text-align: right; }
.cart-remove { background: none; border: none; color: var(--ink-soft); font-size: 14px; cursor: pointer; padding: 4px; }
.cart-qty-ctrl { display: flex; align-items: center; gap: 4px; }
.qty-btn { width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--rule); background: none; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.qty-btn:hover { border-color: var(--gold); color: var(--gold); }
.qty-val { min-width: 20px; text-align: center; font-size: 15px; font-weight: 700; }
.cart-note-row { padding: 8px 18px; border-top: 1px solid var(--rule); flex-shrink: 0; }
.cart-note-input { width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 6px; font-size: 13px; background: var(--surface); }
.cart-footer { padding: 14px 18px; border-top: 2px solid var(--rule); flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; }
/* 分包點餐 */
.bag-header { display: flex; align-items: center; gap: 8px; padding: 8px 18px 4px; font-size: 12px; font-weight: 800; color: var(--ink-soft); border-top: 1.5px dashed var(--rule); margin-top: 4px; letter-spacing: .04em; }
.bag-header:first-child { border-top: none; margin-top: 0; }
.bag-header.bag-active { color: var(--gold); }
.bag-current-label { font-size: 11px; font-weight: 600; background: var(--gold-light); color: var(--gold); border-radius: 4px; padding: 1px 6px; }
.bag-empty-hint { font-size: 12px; color: var(--ink-soft); padding: 6px 18px 8px; font-style: italic; }
.btn-next-bag { width: 100%; padding: 10px; border: 2px dashed var(--gold); background: none; color: var(--gold); border-radius: 8px; font-size: 14px; font-weight: 700; cursor: pointer; letter-spacing: .03em; }
.btn-next-bag:active { background: var(--gold-light); }
.cart-total-row { display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: 600; }
.cart-total-amount { font-size: 24px; font-weight: 900; color: var(--gold); }
.btn-checkout { width: 100%; padding: 18px; background: var(--gold); color: #fff; border: none; border-radius: 10px; font-size: 18px; font-weight: 800; cursor: pointer; }
.btn-checkout:disabled { background: var(--rule); color: var(--ink-soft); cursor: not-allowed; }
.btn-checkout:not(:disabled):active { transform: scale(.98); }

/* ── modifier modal ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
.mod-modal { background: var(--paper); border-radius: 20px 20px 0 0; width: 100%; max-width: 520px; max-height: 85vh; display: flex; flex-direction: column; }
.mod-modal-title { font-size: 18px; font-weight: 800; padding: 20px 24px 12px; border-bottom: 1px solid var(--rule); }
.mod-scroll { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; gap: 20px; }
.mod-group-name { font-size: 13px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.mod-options { display: flex; flex-wrap: wrap; gap: 8px; }
.mod-option-btn { padding: 10px 16px; border: 2px solid var(--rule); border-radius: 8px; background: none; font-size: 14px; font-weight: 600; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.mod-option-btn.active { border-color: var(--gold); background: var(--gold-light); color: var(--gold); }
.mod-price { font-size: 12px; color: var(--ink-soft); }
.mod-note-row { padding: 12px 24px; border-top: 1px solid var(--rule); }
.mod-note-input { width: 100%; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 6px; font-size: 14px; background: var(--surface); }
.mod-footer { padding: 16px 24px; border-top: 1px solid var(--rule); display: flex; align-items: center; gap: 14px; }
.mod-qty-row { display: flex; align-items: center; gap: 10px; }
.qty-val-lg { font-size: 22px; font-weight: 800; min-width: 32px; text-align: center; }
.btn-mod-confirm { flex: 1; padding: 16px; background: var(--gold); color: #fff; border: none; border-radius: 10px; font-size: 16px; font-weight: 700; cursor: pointer; }

/* ── checkout modal ── */
.checkout-modal { background: var(--paper); border-radius: 20px 20px 0 0; width: 100%; max-width: 400px; padding: 28px 28px 32px; display: flex; flex-direction: column; gap: 16px; }
.checkout-title { font-size: 18px; font-weight: 800; text-align: center; }
.checkout-total { font-size: 48px; font-weight: 900; color: var(--gold); text-align: center; line-height: 1; }
.checkout-sub { font-size: 14px; color: var(--ink-soft); text-align: center; }
.cash-row-co { display: flex; gap: 8px; justify-content: center; }
.cash-preset { padding: 8px 16px; border: 1.5px solid var(--rule); border-radius: 6px; background: none; font-size: 14px; font-weight: 600; cursor: pointer; }
.cash-preset:hover { border-color: var(--gold); }
.cash-input-co { width: 100%; padding: 14px; border: 2px solid var(--rule); border-radius: 8px; font-size: 24px; font-weight: 700; text-align: center; background: var(--surface); color: var(--ink); }
.cash-input-co:focus { outline: none; border-color: var(--gold); }
.cash-change-co { font-size: 20px; font-weight: 700; color: var(--green); text-align: center; }
.checkout-actions { display: flex; gap: 10px; }
.btn-cancel-co { flex: 1; padding: 16px; border: 2px solid var(--rule); border-radius: 10px; background: none; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn-pay { flex: 2; padding: 16px; background: var(--green); color: #fff; border: none; border-radius: 10px; font-size: 16px; font-weight: 800; cursor: pointer; }
.btn-pay:disabled { background: var(--rule); color: var(--ink-soft); cursor: not-allowed; }

/* ── toast ── */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 20px; border-radius: 99px; font-size: 14px; z-index: 999; pointer-events: none; }
.toast-err { background: var(--red); }

@media (max-width: 600px) {
  .cart-panel { width: 100%; position: fixed; bottom: 0; left: 0; height: 220px; border-top: 2px solid var(--rule); border-left: none; }
  .menu-panel { padding-bottom: 220px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}
