@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700;900&family=IBM+Plex+Mono:wght@500;700&display=swap');

:root {
  --ink: #1c1710;
  --ink-soft: #6b6255;
  --paper: #f9f6ef;
  --surface: #ffffff;
  --surface-sunken: #f0ead8;
  --rule: #e4d9c2;
  --gold: #b8791f;
  --gold-strong: #96600f;
  --gold-bg: #fdf3e3;
  --chili: #a63823;
  --chili-bg: #f9e8e3;
  --ok: #3e6b3f;
  --ok-bg: #e3ede3;
  --focus: #2f6fb0;
  --cart-bar-h: 72px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font-family: inherit; }
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- loading / splash ---------- */
.splash {
  height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; padding: 24px;
  text-align: center;
}
.splash-logo { font-size: 28px; font-weight: 900; letter-spacing: -0.5px; }
.splash-sub { font-size: 14px; color: var(--ink-soft); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--rule); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.7s linear infinite; margin-top: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- closed / error screen ---------- */
.notice-screen {
  height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px; text-align: center; gap: 12px;
}
.notice-icon { font-size: 48px; }
.notice-title { font-size: 20px; font-weight: 900; }
.notice-msg { font-size: 14px; color: var(--ink-soft); line-height: 1.6; max-width: 300px; }

/* ---------- header ---------- */
.order-header {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.order-header .shop-name { font-weight: 900; font-size: 17px; flex: 1; }
.order-header .order-type-toggle {
  display: flex; gap: 2px; background: var(--surface-sunken);
  border-radius: 8px; padding: 3px;
}
.ot-btn {
  appearance: none; border: none; background: transparent;
  padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 700;
  color: var(--ink-soft); cursor: pointer;
}
.ot-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.ot-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- category tabs ---------- */
.cat-bar {
  flex-shrink: 0;
  display: flex; gap: 6px;
  padding: 10px 14px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  scrollbar-width: none;
}
.cat-bar::-webkit-scrollbar { display: none; }
.cat-chip {
  appearance: none; border: 1.5px solid var(--rule); background: var(--surface);
  border-radius: 20px; padding: 6px 14px; font-size: 13px; font-weight: 700;
  color: var(--ink-soft); cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.cat-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- product list ---------- */
.product-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 10px 14px;
  padding-bottom: calc(var(--cart-bar-h) + 16px);
  display: flex; flex-direction: column; gap: 8px;
}
.product-item {
  appearance: none; border: 1px solid var(--rule); background: var(--surface);
  border-radius: 10px; padding: 14px 16px; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 12px;
  width: 100%;
}
.product-item:active { background: var(--surface-sunken); }
.product-item.sold-out { opacity: 0.5; cursor: not-allowed; }
.product-item-info { flex: 1; min-width: 0; }
.product-item-name { font-size: 15px; font-weight: 700; margin-bottom: 3px; }
.product-item-desc { font-size: 12.5px; color: var(--ink-soft); line-height: 1.4; }
.product-item-badges { display: flex; gap: 5px; margin-top: 4px; }
.badge-popular { font-size: 10.5px; color: var(--gold-strong); font-weight: 700; background: var(--gold-bg); padding: 2px 7px; border-radius: 10px; }
.badge-sold-out { font-size: 10.5px; color: var(--chili); font-weight: 700; background: var(--chili-bg); padding: 2px 7px; border-radius: 10px; }
.product-item-price { font-size: 15px; font-weight: 700; color: var(--gold-strong); flex-shrink: 0; }

/* ---------- cart bar (sticky bottom) ---------- */
.cart-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--cart-bar-h);
  background: var(--gold);
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
  box-shadow: 0 -2px 16px rgba(28,23,16,0.15);
  cursor: pointer; border: none;
  user-select: none;
}
.cart-bar[hidden] { display: none; }
.cart-bar-count {
  background: rgba(255,255,255,0.25); border-radius: 50%;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; color: #fff; flex-shrink: 0;
}
.cart-bar-label { flex: 1; font-size: 15px; font-weight: 700; color: #fff; }
.cart-bar-total { font-size: 17px; font-weight: 900; color: #fff; flex-shrink: 0; }

/* ---------- modifier modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(28,23,16,0.5);
  z-index: 30; display: flex; align-items: flex-end;
}
.modal-sheet {
  width: 100%; background: var(--surface);
  border-radius: 18px 18px 0 0;
  max-height: 88dvh; display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--rule); margin: 10px auto 0; flex-shrink: 0; }
.modal-sheet-head { padding: 12px 20px 10px; border-bottom: 1px solid var(--rule); }
.modal-sheet-head h2 { margin: 0; font-size: 17px; }
.modal-sheet-head .price { font-size: 13px; color: var(--gold-strong); font-weight: 700; margin-top: 2px; }
.modal-sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 20px; flex: 1; }
.modal-sheet-foot { padding: 14px 20px; border-top: 1px solid var(--rule); display: flex; align-items: center; gap: 14px; }

.mod-group { margin-bottom: 20px; }
.mod-group:last-child { margin-bottom: 0; }
.mod-group-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.mod-group-title .name { font-size: 14.5px; font-weight: 700; }
.mod-group-title .rule { font-size: 12px; color: var(--ink-soft); }
.mod-group-title .rule.unmet { color: var(--chili); font-weight: 700; }
.mod-options { display: flex; flex-wrap: wrap; gap: 8px; }
.mod-option {
  appearance: none; border: 1.5px solid var(--rule); background: var(--surface);
  border-radius: 8px; padding: 9px 14px; font-size: 14px; cursor: pointer; color: var(--ink);
}
.mod-option.selected { background: var(--gold); border-color: var(--gold); color: #fff; }
.mod-option .delta { font-size: 11px; opacity: 0.8; margin-left: 3px; }

.qty-row { display: flex; align-items: center; gap: 18px; }
.qty-btn {
  appearance: none; border: 1.5px solid var(--rule); background: var(--surface);
  width: 36px; height: 36px; border-radius: 8px; font-size: 20px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--ink);
}
.qty-val { font-size: 20px; font-weight: 900; min-width: 28px; text-align: center; }
.btn {
  appearance: none; border: none; border-radius: 10px;
  font-weight: 700; font-size: 15px; padding: 14px 20px; cursor: pointer;
}
.btn:active { filter: brightness(0.92); }
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1.5px solid var(--rule); }

/* ---------- checkout slide-up ---------- */
.checkout-overlay {
  position: fixed; inset: 0;
  background: rgba(28,23,16,0.5);
  z-index: 40; display: flex; align-items: flex-end;
}
.checkout-sheet {
  width: 100%; background: var(--surface);
  border-radius: 18px 18px 0 0;
  max-height: 92dvh; display: flex; flex-direction: column; overflow: hidden;
}
.checkout-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--rule); display: flex; align-items: center; }
.checkout-head h2 { margin: 0; font-size: 18px; flex: 1; }
.checkout-close { background: none; border: none; font-size: 22px; color: var(--ink-soft); cursor: pointer; padding: 0 4px; }
.checkout-body { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.checkout-section { padding: 16px 20px; border-bottom: 1px solid var(--rule); }
.checkout-section-title { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 12px; }

.checkout-line { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.checkout-line-name { flex: 1; font-size: 14.5px; font-weight: 700; }
.checkout-line-mods { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }
.checkout-line-qty { font-size: 13px; color: var(--ink-soft); flex-shrink: 0; }
.checkout-line-price { font-size: 14.5px; font-weight: 700; flex-shrink: 0; }
.checkout-line-remove { background: none; border: none; color: var(--chili); font-size: 18px; cursor: pointer; padding: 0 4px; flex-shrink: 0; line-height: 1; }

.type-pick { display: flex; gap: 10px; }
.type-card {
  flex: 1; padding: 14px 10px; border: 2px solid var(--rule); border-radius: 10px;
  background: var(--surface); cursor: pointer; text-align: center; appearance: none;
}
.type-card.active { border-color: var(--gold); background: var(--gold-bg); }
.type-card:disabled { opacity: 0.4; cursor: not-allowed; }
.type-card .icon { font-size: 22px; }
.type-card .label { font-size: 13px; font-weight: 700; margin-top: 4px; }
.type-card .sublabel { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

.pickup-slot-select { width: 100%; padding: 12px 14px; border: 2px solid var(--rule); border-radius: 10px; background: var(--surface); font-size: 14px; font-weight: 700; color: var(--ink); appearance: auto; }
.pickup-slot-select:focus { border-color: var(--gold); outline: none; }

.note-input {
  width: 100%; padding: 10px 12px; font-size: 14px; resize: none;
  border: 1.5px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink);
  min-height: 72px;
}
.note-input:focus { outline: none; border-color: var(--focus); }

.summary-row { display: flex; justify-content: space-between; font-size: 14px; padding: 5px 0; }
.summary-row.total { font-size: 20px; font-weight: 900; padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--rule); }

.checkout-foot { padding: 16px 20px; border-top: 1px solid var(--rule); }
.error-box { background: var(--chili-bg); color: var(--chili); border-radius: 8px; padding: 10px 13px; font-size: 13.5px; margin-bottom: 12px; }

/* ---------- success screen ---------- */
.success-screen {
  height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px; text-align: center; gap: 14px;
}
.success-icon { font-size: 56px; }
.success-title { font-size: 22px; font-weight: 900; }
.success-seq { font-size: 48px; font-weight: 900; color: var(--gold); line-height: 1; }
.success-msg { font-size: 14px; color: var(--ink-soft); line-height: 1.6; max-width: 300px; }
.success-detail { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 16px 20px; width: 100%; max-width: 360px; text-align: left; }
.success-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 5px 0; border-bottom: 1px solid var(--rule); }
.success-row:last-child { border-bottom: none; font-weight: 700; font-size: 15px; }

/* ---------- OTP screen ---------- */
.otp-screen {
  height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px; gap: 14px;
}
.otp-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.otp-title { font-size: 20px; font-weight: 900; text-align: center; }
.otp-sub { font-size: 13.5px; color: var(--ink-soft); text-align: center; line-height: 1.5; }
.otp-input {
  width: 100%; padding: 14px; font-size: 22px; text-align: center; letter-spacing: 6px;
  border: 2px solid var(--rule); border-radius: 10px; background: var(--paper); color: var(--ink);
}
.otp-input:focus { outline: none; border-color: var(--focus); }
.otp-phone-input { width: 100%; padding: 12px 14px; font-size: 16px; border: 1.5px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); }
.otp-phone-input:focus { outline: none; border-color: var(--focus); }
.otp-resend { background: none; border: none; color: var(--focus); font-size: 13px; cursor: pointer; text-decoration: underline; padding: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--cart-bar-h) + 12px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 8px;
  font-size: 13.5px; z-index: 200; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  white-space: nowrap; pointer-events: none;
}
.toast.err { background: var(--chili); }
.toast.up { bottom: 16px; }

/* ---------- product thumbnail ---------- */
.product-thumb { width: 80px; height: 80px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.product-thumb-placeholder { width: 80px; height: 80px; border-radius: 8px; background: var(--surface-sunken); flex-shrink: 0; }
.modal-product-img { width: 100%; max-height: 200px; object-fit: cover; flex-shrink: 0; }
.modal-product-desc { font-size: 14px; color: #666; line-height: 1.5; margin-top: 4px; }

/* ---------- batch 混炸模式 ---------- */
.batch-item { display: flex; align-items: center; gap: 12px; border: 1px solid var(--rule); background: var(--surface); border-radius: 10px; padding: 12px 14px; }
.batch-item.sold-out { opacity: 0.5; }
.batch-qty-ctrl { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.product-item.in-bag { border-color: var(--gold-strong); background: var(--gold-bg); position: relative; }
.in-bag-badge { position: absolute; top: 6px; right: 6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--gold-strong); color: #fff; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; }

/* 組裝中的這一包（尚未選調味送出） */
.staging-bag { border: 2px dashed var(--gold-strong); border-radius: 10px; background: var(--gold-bg); padding: 10px; margin-bottom: 4px; }
.staging-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 800; color: var(--gold-strong); margin-bottom: 8px; }
.staging-clear { background: none; border: none; font-size: 11px; font-weight: 700; color: var(--ink-soft); cursor: pointer; }
.staging-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 0; }
.staging-info { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.staging-name { font-size: 13px; font-weight: 700; }
.staging-edit { margin-top: 2px; padding: 2px 8px; font-size: 11px; font-weight: 700; color: var(--gold-strong); background: #fff; border: 1px solid var(--gold-strong); border-radius: 4px; cursor: pointer; }
.batch-qty-btn { width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--rule); background: none; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--ink); }
.batch-qty-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.batch-qty-btn:not(:disabled):active { background: var(--surface-sunken); }
.batch-qty-val { min-width: 24px; text-align: center; font-size: 16px; font-weight: 700; color: var(--ink); }
.batch-qty-val.has-qty { color: var(--gold-strong); }
.batch-confirm-bar { position: fixed; bottom: 0; left: 0; right: 0; height: var(--cart-bar-h); background: var(--gold); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; gap: 12px; border: none; cursor: pointer; }
.batch-confirm-count { background: rgba(255,255,255,0.25); border-radius: 20px; padding: 4px 12px; font-size: 13px; font-weight: 700; color: #fff; }
.batch-confirm-bar > span:last-child { font-size: 16px; font-weight: 800; color: #fff; }
.batch-summary-text { font-size: 13px; color: var(--ink-soft); line-height: 1.5; }
.checkout-line-batch { display: flex; align-items: flex-start; gap: 8px; flex: 1; cursor: pointer; }
.batch-expand-toggle { font-size: 12px; color: var(--ink-soft); padding: 2px; flex-shrink: 0; }
.batch-expand-list { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.batch-expand-row { font-size: 12.5px; color: var(--ink-soft); padding-left: 4px; }

/* ---------- Admin gear button ---------- */
.admin-gear-btn {
  appearance: none; border: none; background: none; padding: 4px 6px;
  font-size: 18px; cursor: pointer; color: var(--ink-soft); line-height: 1;
  border-radius: 6px; opacity: 0.35; flex-shrink: 0;
}
.admin-gear-btn.authed { opacity: 0.85; color: var(--gold-strong); }
.admin-gear-btn:active { background: var(--surface-sunken); opacity: 1; }

/* ---------- Admin login modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: var(--surface); border-radius: 14px; width: 100%; max-width: 360px; overflow: hidden; }
.modal-box-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-box-head h3 { font-size: 17px; font-weight: 700; }
.modal-box-body { padding: 16px 20px 20px; }
.modal-close-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--ink-soft); padding: 4px 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field input { padding: 10px 12px; border: 1.5px solid var(--rule); border-radius: 8px; font-size: 15px; background: var(--paper); color: var(--ink); }

/* ---------- Batch settings overlay ---------- */
.batch-overlay { position: fixed; inset: 0; background: var(--paper); z-index: 200; display: flex; flex-direction: column; }
.batch-header { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--rule); flex-shrink: 0; background: var(--surface); }
.batch-title { font-size: 17px; font-weight: 700; flex: 1; }
.batch-body { flex: 1; overflow-y: auto; padding: 8px 0 80px; }
.batch-footer { position: absolute; bottom: 0; left: 0; right: 0; display: flex; gap: 10px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--rule); }
.batch-footer .btn { flex: 1; padding: 13px; font-size: 15px; font-weight: 700; border-radius: 10px; border: none; cursor: pointer; }
.batch-footer .btn-ghost { background: var(--surface-sunken); color: var(--ink); }
.batch-footer .btn-primary { background: var(--gold); color: #fff; }
.batch-footer .btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.batch-loading { padding: 40px; text-align: center; color: var(--ink-soft); }
.batch-empty { padding: 32px; text-align: center; color: var(--ink-soft); font-size: 14px; }
.batch-empty-cat { padding: 8px 16px; font-size: 13px; color: var(--ink-soft); }
.batch-cat-section { margin-bottom: 4px; }
.batch-cat-title { padding: 14px 16px 6px; font-size: 13px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.batch-prod-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; background: var(--surface); border-bottom: 1px solid var(--rule); cursor: pointer;
}
.batch-prod-row.changed { background: #fffbea; }
.batch-prod-name { font-size: 15px; font-weight: 500; }
.batch-prod-price { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.batch-toggle-wrap { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.batch-toggle-wrap input[type=checkbox] { display: none; }
.batch-toggle-track { display: inline-block; width: 44px; height: 26px; border-radius: 13px; background: var(--rule); position: relative; flex-shrink: 0; transition: background .15s; }
.batch-prod-row input:checked ~ .batch-toggle-wrap .batch-toggle-track,
.batch-toggle-wrap input:checked + .batch-toggle-track { background: var(--ok); }
.batch-toggle-thumb { position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.batch-toggle-wrap input:checked + .batch-toggle-track .batch-toggle-thumb { transform: translateX(18px); }
.batch-toggle-label-text { font-size: 13px; font-weight: 600; color: var(--ink-soft); min-width: 26px; }
.batch-toggle-label-text.on { color: var(--ok); }

/* Batch confirm list */
.batch-confirm-list { display: flex; flex-direction: column; gap: 0; }
.batch-confirm-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
.batch-confirm-cat { font-size: 11px; color: var(--ink-soft); margin-bottom: 2px; }
.batch-confirm-name { font-size: 15px; font-weight: 500; }
.batch-confirm-badge { font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 20px; flex-shrink: 0; }
.batch-confirm-badge.on { background: #e8f8ef; color: #1a8a48; }
.batch-confirm-badge.off { background: #fff0f0; color: #c0392b; }
