/* QR 點餐 — 共用樣式（手機優先） */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --text: #22201c;
  --muted: #6f6a61;
  --line: #e6e0d6;
  --brand: #c2410c;
  --brand-ink: #ffffff;
  --brand-soft: #fdeee4;
  --ok: #15803d;
  --ok-soft: #e3f5e8;
  --warn: #b45309;
  --warn-soft: #fdf3dc;
  --danger: #b91c1c;
  --danger-soft: #fde8e8;
  --info: #1d4ed8;
  --info-soft: #e5edfd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(34, 32, 28, .06), 0 4px 14px rgba(34, 32, 28, .06);
  --font: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #211e1b;
    --surface-2: #2a2622;
    --text: #f1ece4;
    --muted: #a69f94;
    --line: #3a3530;
    --brand: #f97316;
    --brand-ink: #1a0d04;
    --brand-soft: #3a2314;
    --ok: #4ade80;
    --ok-soft: #173322;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --danger: #f87171;
    --danger-soft: #3d1a1a;
    --info: #93b4fb;
    --info-soft: #1b2540;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--brand); }
img { max-width: 100%; }
[hidden] { display: none !important; }

.wrap { max-width: 960px; margin: 0 auto; padding: 16px; }
.wrap.narrow { max-width: 480px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 640px) {
  .grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 卡片 */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card h2 { margin-bottom: 12px; }

/* 表單 */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url],
input[type=tel], input[type=search], input[type=date], input[type=month], select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 72px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.field-error { color: var(--danger); font-size: .875rem; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }

/* 按鈕 */
button, .btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 36px; padding: 4px 10px; font-size: .875rem; }
.btn-block { width: 100%; }
.icon-btn { min-width: 44px; padding: 0; }

/* 開關 */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 44px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; transition: background .15s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* 徽記 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; font-weight: 600; line-height: 1;
  padding: 4px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

/* 清單 */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }

/* 頁籤 */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border-radius: 999px; min-height: 38px; padding: 6px 14px; border-color: var(--line); flex: none;
}
.tabs button[aria-selected=true] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* 後台頂列與導覽 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .inner { max-width: 960px; margin: 0 auto; padding: 8px 16px; display: flex; gap: 8px; align-items: center; }
.topbar .brand { font-weight: 700; color: var(--brand); white-space: nowrap; }
.topbar select { min-height: 38px; padding: 4px 8px; width: auto; max-width: 50vw; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(6, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; font-size: .75rem; color: var(--muted); text-decoration: none;
}
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current=page] { color: var(--brand); font-weight: 700; }
body.has-nav { padding-bottom: 72px; }
@media (min-width: 900px) {
  .nav { position: sticky; top: 55px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line);
    grid-template-columns: repeat(6, auto); justify-content: center; gap: 8px; }
  .nav a { flex-direction: row; min-height: 44px; padding: 0 14px; font-size: .9375rem; }
  .nav a svg { width: 18px; height: 18px; }
  body.has-nav { padding-bottom: 0; }
}

/* 對話框 */
dialog {
  border: 0; padding: 0; border-radius: 16px; width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
@media (min-width: 600px) { dialog.wide { width: min(760px, calc(100vw - 24px)); } }
dialog::backdrop { background: rgba(20, 18, 15, .5); }
dialog .dlg-head { padding: 16px 16px 8px; display: flex; align-items: center; gap: 8px; }
dialog .dlg-head h2 { margin: 0; flex: 1; }
dialog .dlg-body { padding: 0 16px 16px; overflow-y: auto; max-height: calc(100dvh - 160px); }
dialog .dlg-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 599px) {
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; max-height: 92dvh; }
  dialog.sheet .dlg-body { max-height: calc(92dvh - 140px); }
}

/* 提示 */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 88px; z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: .9375rem; }
.toast.error { background: var(--danger); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--info-soft); color: var(--info); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }

/* 金額表 */
.sum { width: 100%; border-collapse: collapse; }
.sum td { padding: 4px 0; }
.sum td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.sum tr.total td { font-weight: 700; font-size: 1.125rem; border-top: 1px solid var(--line); padding-top: 8px; }

/* 資料表 */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9375rem; }
table.data th, table.data td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8125rem; }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
dialog h2:focus { outline: none; }
