:root {
  --theme: #ff7a45;
  --theme-ink: #ffffff;
  --bg: #fff8f0;
  --bg-image: none;
  --card: #ffffff;
  --ink: #2b2118;
  --muted: #8a7a6d;
  --line: #efe3d6;
  --soft: #faf5ef;
  --ok: #2e9e5b;
  --warn: #c98a0b;
  --danger: #d94444;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(60, 35, 10, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
/* 用固定的偽元素當背景，iOS 也不會跑版 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg) var(--bg-image) center / cover no-repeat;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 頂部 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--theme);
  color: var(--theme-ink);
}
.brand { min-width: 0; }
.brand h1 { margin: 0; font-size: 1.25rem; line-height: 1.3; }
.brand p { margin: 2px 0 0; font-size: 0.875rem; opacity: 0.9; }
.account { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,0.35); object-fit: cover;
  display: grid; place-items: center; font-weight: 700;
}
.account-btn {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.18); color: inherit;
  border: 0; border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer;
}
.account-btn span { max-width: 6em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; }

.tabs {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 4px; padding: 8px 16px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tabs button {
  flex: 1 0 auto; border: 0; background: transparent; padding: 8px 10px;
  border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
/* 寬螢幕：分頁按鈕置中，不要拉滿整個畫面 */
@media (min-width: 800px) {
  .tabs { justify-content: center; }
  .tabs button { flex: 0 1 200px; }
}
/* 窄手機：後台 4 個分頁擠得下 */
@media (max-width: 420px) {
  .tabs { gap: 2px; padding: 8px 10px; }
  #adminTabs button { padding: 8px 6px; font-size: 0.875rem; }
}
.tabs button.active { background: var(--theme); color: var(--theme-ink); }
.count-dot {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.75rem; line-height: 20px;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(110px + var(--safe-bottom)); }
.wrap.wide { max-width: 1200px; }

/* ---------- 共用元件 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.notice {
  background: #fff; border-left: 4px solid var(--theme); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px; box-shadow: var(--shadow); white-space: pre-line;
}
.notice.warn { border-left-color: var(--warn); background: #fff8e6; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border: 0; border-radius: 12px;
  background: var(--theme); color: var(--theme-ink); font-weight: 700;
  cursor: pointer; text-decoration: none; transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(0.98); }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.light { background: var(--soft); color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 0.875rem; border-radius: 10px; }
.topbar .btn.ghost { color: var(--theme-ink); border-color: rgba(255,255,255,0.5); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9375rem; }
.field small { display: block; color: var(--muted); margin-top: 4px; font-size: 0.8125rem; }
.input, .field input:not([type=checkbox]):not([type=color]):not([type=file]), .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 16px; /* 16px 以上 iOS 才不會自動放大 */
}
.field textarea { min-height: 80px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--theme);
}
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.check input { width: 22px; height: 22px; accent-color: var(--theme); flex: none; }
.check.wrap { white-space: normal; padding: 4px 0; }
.check.wrap small { display: block; font-weight: 400; font-size: 0.8125rem; }
.history { margin-top: 14px; }
.history ul { list-style: none; padding: 0; margin: 6px 0 0; }
.history li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid #eee; }
.spam-tip { display: block; margin-top: 4px; color: var(--muted); font-size: 0.8125rem; }

.badge-status {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 700; white-space: nowrap;
}
.s-pending { background: #eef2ff; color: #4054b2; }
.s-preparing { background: #fff4dc; color: #a26a00; }
.s-ready { background: #e3f6ea; color: #1d7a44; }
.s-done { background: #eeeeee; color: #666; }
.s-cancelled { background: #fde8e8; color: #b23030; }

/* ---------- 菜單 ---------- */
.ready-board {
  background: #e3f6ea; color: #1d7a44; border-radius: 12px; padding: 10px 14px;
  margin-bottom: 14px; font-weight: 600;
}
.ready-board b { display: inline-block; margin: 2px 6px 2px 0; background: #fff; padding: 0 8px; border-radius: 8px; }

.menu-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.item {
  display: flex; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.item-img { position: relative; width: 120px; flex-shrink: 0; background: var(--soft); }
.item-img img { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 1; }
.img-ph { display: grid; place-items: center; height: 100%; min-height: 120px; font-size: 2.5rem; }
.tag-soldout {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,0.45); color: #fff; font-weight: 800; font-size: 1.1rem;
}
.item-body { flex: 1; min-width: 0; padding: 12px; display: flex; flex-direction: column; }
.item-body h3 { margin: 0; font-size: 1.0625rem; }
.item-body .desc {
  margin: 4px 0 0; color: var(--muted); font-size: 0.875rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.item-meta { display: flex; align-items: baseline; gap: 8px; margin-top: auto; padding-top: 8px; }
.price { font-size: 1.125rem; font-weight: 800; color: var(--theme); }
.stock { font-size: 0.8125rem; color: var(--muted); }
.stock.low { color: var(--danger); font-weight: 700; }
.item.soldout .item-body { opacity: 0.6; }

.stepper { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 8px; }
.step {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--theme); color: var(--theme-ink); font-size: 1.375rem; font-weight: 700;
  display: grid; place-items: center; cursor: pointer; line-height: 1;
}
.step.minus { background: var(--soft); color: var(--ink); }
.step:disabled { opacity: 0.3; cursor: not-allowed; }
.qty { min-width: 32px; text-align: center; font-weight: 800; font-size: 1.125rem; }

@media (min-width: 640px) {
  .menu-grid { grid-template-columns: 1fr 1fr; }
  .item { flex-direction: column; }
  .item-img { width: 100%; }
  .item-img img { aspect-ratio: 4 / 3; }
  .img-ph { aspect-ratio: 4 / 3; min-height: 0; }
}

/* ---------- 分類 / 選項 / 預估時間 ---------- */
.wait-info {
  background: #fff; border-radius: 12px; padding: 10px 14px; margin-bottom: 14px;
  box-shadow: var(--shadow); font-size: 0.9375rem;
}
.wait-info b { color: var(--theme); }
.cat-nav { margin-bottom: 4px; }
.cat-title {
  font-size: 1.125rem; margin: 18px 0 10px; padding: 4px 12px;
  display: inline-block; background: rgba(255,255,255,0.9); border-radius: 10px;
  scroll-margin-top: 70px; /* 不要被固定的分頁列擋住 */
}
.cat-title:first-child { margin-top: 4px; }
.menu-grid + .cat-title { margin-top: 22px; }
.in-cart { font-size: 0.8125rem; font-weight: 700; color: var(--theme); margin-right: 6px; }

.opt-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 14px; margin: 0 0 12px; }
.opt-group { margin: 18px 0 6px; }
.opt-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.choice {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 14px; margin-bottom: 8px;
  border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; background: #fff;
}
.choice input { width: 20px; height: 20px; margin: 0; accent-color: var(--theme); flex-shrink: 0; }
.choice .delta { margin-left: auto; color: var(--muted); font-size: 0.875rem; }
.choice:has(input:checked) { border-color: var(--theme); background: var(--soft); font-weight: 600; }
.qty-row { display: flex; align-items: center; justify-content: space-between; margin: 16px 0; }
.qty-row .stepper { margin: 0; }

.opt-text { display: block; color: var(--muted); font-size: 0.8125rem; }
.summary li.cart-line { align-items: center; }
.cart-line .grow { flex: 1; min-width: 0; }
.cart-line .stepper { margin: 0; flex-shrink: 0; }
.cart-line .step { width: 34px; height: 34px; font-size: 1.125rem; }
.eta-hint { margin: 8px 0 0; font-weight: 700; }
.eta-big { margin-top: 6px; font-weight: 700; color: var(--ink); }

/* ---------- 底部購物車 ---------- */
.cart-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: #fff; box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}
.cart-bar .inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.cart-sum { flex: 1; min-width: 0; }
.cart-sum b { font-size: 1.25rem; color: var(--theme); }
.cart-bar .btn { min-width: 140px; min-height: 50px; font-size: 1.0625rem; }

/* ---------- 底部抽屜 / 對話框 ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  animation: up .2s ease;
}
.sheet h2 { margin: 0 0 6px; font-size: 1.25rem; padding-right: 40px; }
.sheet-close {
  position: absolute; top: 12px; right: 12px; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: var(--soft); font-size: 1.375rem; cursor: pointer;
}
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
body.no-scroll { overflow: hidden; }

.summary { list-style: none; padding: 0; margin: 12px 0; border-top: 1px dashed var(--line); }
.summary li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.summary .total { font-weight: 800; font-size: 1.125rem; border-bottom: 0; }
.summary .total span:last-child { color: var(--theme); }

.gbtn { display: flex; justify-content: center; min-height: 48px; margin: 16px 0; }
.divider { text-align: center; color: var(--muted); font-size: 0.8125rem; margin: 16px 0; }

.big-number {
  text-align: center; margin: 12px 0; padding: 18px; border-radius: 16px;
  background: var(--soft); border: 2px dashed var(--theme);
}
.big-number small { display: block; color: var(--muted); font-weight: 600; }
.big-number strong { display: block; font-size: 3.5rem; line-height: 1.1; letter-spacing: 2px; color: var(--theme); }

/* ---------- 我的訂單 ---------- */
.profile { display: flex; align-items: center; gap: 12px; }
.profile .avatar { width: 48px; height: 48px; background: var(--soft); color: var(--ink); }
.profile .info { flex: 1; min-width: 0; }
.profile .info b { display: block; }
.profile .info span { display: block; font-size: 0.875rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.order-card .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.order-num { font-size: 2rem; font-weight: 900; color: var(--theme); line-height: 1; }
.order-card.is-done .order-num, .order-card.is-cancelled .order-num { color: var(--muted); }
.order-lines { margin: 10px 0 0; padding: 0; list-style: none; font-size: 0.9375rem; }
.order-lines li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.order-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.progress { display: flex; margin: 14px 0 4px; }
.progress div { flex: 1; text-align: center; font-size: 0.75rem; color: var(--muted); position: relative; padding-top: 18px; }
.progress div::before {
  content: ""; position: absolute; top: 4px; left: 50%; width: 12px; height: 12px; margin-left: -6px;
  border-radius: 50%; background: var(--line); z-index: 1;
}
.progress div::after {
  content: ""; position: absolute; top: 9px; left: -50%; width: 100%; height: 3px; background: var(--line);
}
.progress div:first-child::after { display: none; }
.progress div.on { color: var(--ink); font-weight: 700; }
.progress div.on::before, .progress div.on::after { background: var(--theme); }

.site-footer { text-align: center; color: var(--muted); font-size: 0.8125rem; padding: 24px 0 0; white-space: pre-line; }
.legal-links { text-align: center; font-size: 0.8125rem; padding: 10px 0 0; color: var(--muted); }
.legal-links a, .doc a, .login-legal a { color: var(--theme); }

/* ---------- 攤位位置 ---------- */
.location-card {
  background: #fff; border-radius: 12px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.location-card summary { padding: 12px 14px; font-weight: 700; cursor: pointer; list-style-position: inside; }
.location-card #locationBody { padding: 0 14px 14px; }
.location-text { margin: 0 0 10px; white-space: pre-line; }
.location-img { display: block; text-decoration: none; }
.location-img img { width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.location-img span { display: block; text-align: center; margin-top: 4px; }
.location-box { background: var(--soft); border-radius: 12px; padding: 12px; margin: 0 0 14px; }
.location-box > b { display: block; margin-bottom: 6px; }
.order-card > .btn { margin-top: 10px; }

/* ---------- 隱私權政策 / 服務條款 ---------- */
.doc-wrap { padding-bottom: 40px; }
.doc { padding: 20px 20px 28px; line-height: 1.75; }
.doc h2 { font-size: 1.0625rem; margin: 24px 0 8px; }
.doc p { margin: 0 0 10px; }
.doc ul { margin: 0 0 10px; padding-left: 1.3em; }
.doc li { margin-bottom: 6px; }

/* ---------- 提示 ---------- */
.toast {
  /* 放在上方，才不會擋住底部的按鈕 */
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top, 0px)); z-index: 100;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: rgba(30, 20, 10, 0.92); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-weight: 600; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }

/* ---------- 後台 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: #fff; border-radius: 12px; padding: 10px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.375rem; }
.stat span { font-size: 0.75rem; color: var(--muted); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(6, 1fr); } }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.chip {
  flex-shrink: 0; border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 14px; font-weight: 600; cursor: pointer; min-height: 38px;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.admin-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .admin-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1080px) { .admin-grid { grid-template-columns: repeat(3, 1fr); } }
.admin-grid .card { margin: 0; }
.order-card .cust { margin-top: 8px; font-size: 0.9375rem; }
.order-card .cust a { color: var(--theme); font-weight: 700; text-decoration: none; }
.order-card .note { margin-top: 8px; background: #fff8e6; padding: 6px 10px; border-radius: 8px; font-size: 0.875rem; }
.order-card .notice-log { margin-top: 6px; font-size: 0.8125rem; color: var(--muted); }
.order-card .notice-log .fail { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.actions .btn { flex: 1 1 auto; }
.order-card.is-pending { border-top: 4px solid #4054b2; }
.order-card.is-preparing { border-top: 4px solid #e8a317; }
.order-card.is-ready { border-top: 4px solid var(--ok); }

.item-row { display: flex; gap: 12px; align-items: center; }
.item-row .thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: var(--soft); flex-shrink: 0; display: grid; place-items: center; font-size: 1.5rem; }
.item-row .info { flex: 1; min-width: 0; }
.item-row .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .info span { font-size: 0.875rem; color: var(--muted); }
.item-row.off { opacity: 0.55; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--soft);
  color: var(--muted); font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.opt-strong { color: var(--theme); font-weight: 700; font-size: 0.875rem; }
.opt-editor {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px;
  display: grid; gap: 8px; background: var(--soft);
}
.admin-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.admin-row .email { font-weight: 600; word-break: break-all; }

.img-preview {
  width: 100%; aspect-ratio: 4 / 3; border-radius: 12px; background: var(--soft) center / cover no-repeat;
  display: grid; place-items: center; color: var(--muted); border: 1.5px dashed var(--line); margin-bottom: 8px;
}
.img-preview.contain { background-size: contain; background-color: #fff; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] { width: 56px; height: 44px; border: 1.5px solid var(--line); border-radius: 10px; padding: 2px; background: #fff; }
.section-title { margin: 22px 0 10px; font-size: 1.0625rem; }
.save-bar {
  position: sticky; bottom: 0; z-index: 10; padding: 12px 0 calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
