:root {
  --brand: #b23a2a;
  --brand-dark: #8e2a1e;
  --brand-soft: #fbe9e4;
  --bg: #fff8f0;
  --card: #ffffff;
  --text: #3b2a20;
  --muted: #8a7a6e;
  --line: #eadfd3;
  --ok: #2e7d32;
  --ok-soft: #e6f4e7;
  --warn: #b26a00;
  --warn-soft: #fff1d6;
  --bad: #c62828;
  --bad-soft: #fde7e7;
  --done: #757575;
  --done-soft: #efefef;
  --radius: 14px;
  --bar-h: 76px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--brand); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { height: calc(var(--bar-h) + 24px); }

/* 頂部 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: #fff;
  padding: 10px 16px 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .05em; }
.brand small { font-weight: 400; opacity: .85; font-size: 13px; margin-left: 4px; }
.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: rgba(255, 255, 255, .75);
  padding: 10px 6px; font-size: 16px; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs button.active { color: #fff; font-weight: 700; border-bottom-color: #fff; }
.tabs.scroll { overflow-x: auto; scrollbar-width: none; }
.tabs.scroll::-webkit-scrollbar { display: none; }
.tabs.scroll button { flex: 0 0 auto; padding: 10px 12px; }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }
.loading { text-align: center; padding: 48px 0; color: var(--muted); }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: 0 1px 3px rgba(80, 40, 20, .08);
}
.card h2 { font-size: 18px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 small { font-weight: 400; font-size: 14px; }
.card h3 { font-size: 16px; margin: 0 0 8px; }
.num {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  min-width: 1.6em; height: 1.6em; border-radius: 50%; line-height: 1; padding: 0;
  background: var(--brand); color: #fff; font-size: 14px;
}

/* 按鈕 */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-size: 16px; font-weight: 700;
  min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: #fff; color: var(--text); border: 1.5px solid var(--line); }
.btn.link { background: transparent; color: var(--brand); font-weight: 400; }
.btn.sm { min-height: 40px; padding: 8px 14px; font-size: 15px; font-weight: 400; }
.btn.big { min-height: 60px; font-size: 22px; }
.btn:disabled { opacity: .4; }
.btns { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.btns.row { flex-direction: row; }
.btns.row .btn { flex: 1; }

/* 日期列 */
.date-strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity; }
.date-chip {
  flex: 0 0 76px; scroll-snap-align: start; border: 1.5px solid var(--line); background: #fff;
  border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 0;
}
.date-chip b { font-size: 18px; }
.date-chip span { font-size: 14px; }
.date-chip small { font-size: 12px; color: var(--ok); max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date-chip:disabled { background: #f3eee9; color: #b5a99f; border-color: transparent; }
.date-chip:disabled small { color: #b5a99f; }
.date-chip.selected { border-color: var(--brand); background: var(--brand); color: #fff; }
.date-chip.selected small { color: #fff; }

/* 時段 */
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.slot {
  border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center;
}
.slot b { font-size: 18px; }
.slot small { font-size: 13px; color: var(--muted); }
.slot:disabled { background: #f3eee9; color: #b5a99f; border-color: transparent; }
.slot.selected { background: var(--brand); border-color: var(--brand); color: #fff; }
.slot.selected small { color: #fff; }

/* 品項 */
.hint { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 0 0 12px; }
.product { border-top: 1px solid var(--line); padding: 12px 0; }
.product:first-of-type { border-top: 0; padding-top: 0; }
.p-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.p-head b { font-size: 17px; }
.price { font-weight: 700; color: var(--brand); }
.tag { display: inline-block; font-size: 13px; background: var(--brand-soft); color: var(--brand); border-radius: 6px; padding: 0 6px; margin-left: 4px; }
.product.soon { opacity: .6; }
.product.soon p { margin: 0; font-size: 14px; }
.q-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0 4px 8px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--brand); background: #fff;
  color: var(--brand); font-size: 22px; line-height: 1; display: grid; place-items: center; padding: 0;
}
.stepper button:disabled { border-color: var(--line); color: var(--line); }
.stepper output { min-width: 32px; text-align: center; font-size: 18px; font-weight: 700; }

/* 底部列 */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: #fff; border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 12px; align-items: center; justify-content: center;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, .06);
}
.bottombar > * { max-width: 600px; }
.bottombar .sum { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.bottombar .sum b { font-size: 22px; color: var(--brand); }
.bottombar .btn { flex: 1; }

/* 確認頁 */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { margin: 0; }
.lines { list-style: none; padding: 0; margin: 0; border-top: 1px dashed var(--line); }
.lines li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.lines.small li { font-size: 15px; padding: 4px 0; }
.total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 10px; }
.total b { font-size: 22px; color: var(--brand); }
.pay { margin: 8px 0 0; color: var(--ok); font-weight: 700; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field em { color: var(--bad); font-style: normal; }
.field input, .field textarea, .field select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; font-size: 16px;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--brand); }
.rules ul { margin: 0; padding-left: 20px; font-size: 14px; color: var(--muted); }
.rules li { margin-bottom: 6px; }
.rules b { color: var(--text); }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 12px 0 0; }

/* 完成頁 */
.done { text-align: center; }
.done h2 { justify-content: center; }
.done .kv, .done .lines { text-align: left; }
.ok-mark {
  width: 56px; height: 56px; border-radius: 50%; background: var(--ok);
  display: flex; align-items: center; justify-content: center; margin: 8px auto;
}
.ok-mark svg { width: 30px; height: 30px; }
.order-no {
  font-size: clamp(30px, 10vw, 44px); white-space: nowrap; font-weight: 800; letter-spacing: .04em; color: var(--brand);
  background: var(--brand-soft); border-radius: 12px; padding: 8px; margin: 8px 0 16px;
}

/* 訂單 */
.o-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.o-no { font-size: 20px; font-weight: 800; }
.o-no.big { font-size: 26px; }
.o-time { margin: 0 0 8px; }
.badge { font-size: 13px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.done { background: var(--done-soft); color: var(--done); }
.badge.new { background: #e3f0ff; color: #1565c0; }
.order.highlight { outline: 3px solid var(--brand); }
.empty { text-align: center; padding: 32px 16px; }

/* 對話框 */
.modal {
  position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto;
}
.sheet h3 { font-size: 20px; margin: 0 0 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + 20px); transform: translateX(-50%); z-index: 40;
  background: rgba(40, 25, 15, .92); color: #fff; padding: 12px 18px; border-radius: 12px;
  max-width: calc(100% - 32px); text-align: center; font-size: 15px;
}

/* ===== 後台 ===== */
.admin-body main { max-width: 760px; }
.date-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.date-nav .label { font-size: 20px; font-weight: 700; flex: 1; text-align: center; min-width: 110px; }
.date-nav input[type=date] { border: 1.5px solid var(--line); border-radius: 10px; padding: 8px; background: #fff; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { background: #fff; border-radius: 12px; text-align: center; padding: 8px 4px; box-shadow: 0 1px 3px rgba(80, 40, 20, .08); }
.stats b { display: block; font-size: 26px; line-height: 1.2; }
.stats div:first-child b { color: var(--brand); }
.stats div:nth-child(2) b { color: var(--ok); }
.stats small { color: var(--muted); }
.slot-head { font-size: 18px; margin: 20px 0 8px; display: flex; justify-content: space-between; align-items: baseline; }
.slot-head small { font-size: 14px; color: var(--muted); font-weight: 400; }
.a-order p { margin: 0 0 6px; }
.a-order.dim { opacity: .55; }
.a-order .lines li b { font-size: 18px; }
.a-actions { display: flex; gap: 8px; margin-top: 12px; align-items: stretch; }
.a-actions .big { flex: 1; }
.note { background: var(--warn-soft); border-radius: 8px; padding: 6px 10px; font-size: 15px; }
.note.admin { background: #eef3fb; }
.tbl { width: 100%; border-collapse: collapse; background: #fff; font-size: 16px; }
.tbl th, .tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { font-size: 13px; color: var(--muted); font-weight: 400; }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.sum td { font-weight: 800; border-top: 2px solid var(--text); }
.tbl-wrap { overflow-x: auto; border-radius: 12px; }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head b { font-size: 20px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: 13px; color: var(--muted); padding: 4px 0; }
.cal button {
  aspect-ratio: 1 / 1; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 16px; min-height: 44px;
}
.cal button small { font-size: 11px; line-height: 1.1; }
.cal button.open { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.cal button.partial { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); font-weight: 700; }
.cal button.off { background: #f3eee9; color: #b5a99f; }
.cal button.selected { outline: 3px solid var(--brand); outline-offset: 1px; }
.cal button:disabled { opacity: .35; }
.ocal button { aspect-ratio: auto; min-height: 44px; position: relative; font-weight: 400; }
.ocal button.is-open { border-color: var(--ok); }
.ocal button.is-today { font-weight: 800; color: var(--brand); }
.ocal button.selected { background: var(--brand); border-color: var(--brand); color: #fff; }
.ocal .dot {
  position: absolute; top: -6px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px;
  box-shadow: 0 0 0 2px #fff;
}
.ocal .dot.gray { min-width: 0; width: 8px; height: 8px; top: 4px; right: 4px; padding: 0; background: #bbb; box-shadow: none; }
.ocal button.selected .dot { background: #fff; color: var(--brand); }
.day-title { font-size: 20px; margin: 4px 0 12px; display: flex; align-items: baseline; gap: 4px; }
.day-title small { font-size: 16px; font-weight: 400; color: var(--muted); }
.legend { display: flex; gap: 12px; font-size: 13px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1.5px solid var(--ok); background: var(--ok-soft); color: var(--ok); border-radius: 999px; padding: 6px 12px; font-size: 15px; }
.chip.off { border-color: var(--line); background: #f3eee9; color: #b5a99f; text-decoration: line-through; }
.chip.filter { border-color: var(--line); background: #fff; color: var(--text); }
.chip.filter.active { border-color: var(--brand); background: var(--brand); color: #fff; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.switch input, .checks input { width: 22px; height: 22px; accent-color: var(--brand); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; }
.checks label { display: flex; align-items: center; gap: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.warn { color: var(--bad); font-weight: 700; margin: 0 0 8px; }
.set-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row label { font-size: 15px; }
.set-row small { display: block; color: var(--muted); font-size: 13px; }
.set-row input, .set-row select { border: 1.5px solid var(--line); border-radius: 8px; padding: 8px; background: #fff; width: 96px; }
.set-row .pair { display: flex; gap: 6px; }
.set-row .pair select { width: 96px; }
.set-row .pair input { width: 120px; }
.slot-row { display: grid; grid-template-columns: 1fr 1fr 72px auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.slot-row input { border: 1.5px solid var(--line); border-radius: 8px; padding: 8px 4px; background: #fff; width: 100%; min-width: 0; }
.login { max-width: 360px; margin: 48px auto; }
.section-title { font-size: 15px; color: var(--muted); margin: 20px 0 8px; }

@media (max-width: 380px) {
  .grid2 { grid-template-columns: 1fr; }
  .set-row { grid-template-columns: 1fr; }
}
