/* 高對比配色：灰底襯白卡片，文字與邊框都拉深，遠看也分得出層次 */
:root {
  --bg: #e9ebe7;
  --surface: #ffffff;
  --surface-alt: #f4f5f2;
  --hover: #e6e8e3;
  --border: #c9ccc5;
  --border-strong: #a9ada4;
  --text: #0e1012;
  --muted: #55595f;

  --brand: #b02e1f;
  --brand-dark: #8a1f13;
  --brand-soft: #fae3df;
  --on-brand: #ffffff;

  --accent: #16644a;
  --accent-soft: #d8ede4;
  --gold: #96690a;
  --gold-soft: #fbeecd;

  --danger: #a01c14;
  --danger-soft: #fbe4e2;
  --danger-border: #dfaba5;

  --neutral-soft: #dfe1dc;
  --toast-bg: #0e1012;
  --toast-text: #ffffff;
  --mine-bg: #e4f2eb;

  --radius: 14px;
  --shadow: 0 1px 3px rgba(14, 16, 18, .10), 0 6px 20px rgba(14, 16, 18, .08);
}

/* 手機在暗色模式下不刺眼 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12;
    --surface: #1a1e24;
    --surface-alt: #232830;
    --hover: #2e343d;
    --border: #3c434d;
    --border-strong: #5a626e;
    --text: #f3f5f7;
    --muted: #b0b7c0;

    --brand: #ef7359;
    --brand-dark: #ff9077;
    --brand-soft: #46261f;
    --on-brand: #1a0d09;

    --accent: #5fd3a0;
    --accent-soft: #14392c;
    --gold: #f0bd5e;
    --gold-soft: #3b2d11;

    --danger: #ff9c92;
    --danger-soft: #40211e;
    --danger-border: #63332e;

    --neutral-soft: #2e343d;
    --toast-bg: #333b45;
    --toast-text: #ffffff;
    --mine-bg: #143229;

    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 6px 20px rgba(0, 0, 0, .4);
  }

  input[type="datetime-local"] { color-scheme: dark; }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); }

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 96px;
}

.wrap.wide { max-width: 1120px; }

/* 點餐頁 / 管理頁的雙欄版面：桌機左右分欄，手機自然堆疊 */
.page-grid {
  display: grid;
  gap: 0 20px;
  align-items: start;
}

@media (min-width: 960px) {
  .page-grid { grid-template-columns: minmax(0, 1fr) 400px; }
}

/* ------------------------------- Header ------------------------------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header .wrap {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 1.15rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo span { font-size: 1.4rem; }

.site-header nav {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* -------------------------------- Cards -------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

h1 { font-size: 1.5rem; margin: 24px 0 6px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 8px; }

.subtitle { color: var(--muted); margin: 0 0 20px; font-size: .95rem; }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 28px 0 12px;
}

.section-title h2 { margin: 0; }
.section-title .hint { color: var(--muted); font-size: .85rem; }

/* -------------------------------- Forms -------------------------------- */

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }

input[type="text"],
input[type="datetime-local"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-alt);
  font: inherit;
  color: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}

textarea { resize: vertical; min-height: 64px; }

.field { margin-bottom: 14px; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

/* --------------------------- 店家卡片 / 快捷選項 --------------------------- */

.rest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.rest-card {
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--surface-alt);
  border: 2px solid var(--border-strong);
  border-radius: 12px;
  padding: 14px;
  transition: border-color .15s, background .15s, transform .1s;
}

.rest-card:hover { border-color: var(--border-strong); background: var(--surface); }
.rest-card:active { transform: scale(.99); }

.rest-card.selected {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.rest-card.selected .rest-name::after {
  content: ' ✓';
  color: var(--brand);
}

.rest-name { font-weight: 700; font-size: 1rem; }
.rest-branch { color: var(--muted); font-size: .83rem; }
.rest-sig { color: var(--brand-dark); font-size: .8rem; margin-top: 6px; }
.rest-meta { color: var(--muted); font-size: .8rem; margin-top: 2px; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  font: inherit;
  font-size: .9rem;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.chip:hover { background: var(--hover); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

details.more { margin: 20px 0; }

details.more summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 600;
  padding: 6px 0;
  list-style: none;
}

details.more summary::before { content: '▸ '; }
details.more[open] summary::before { content: '▾ '; }
details.more summary::-webkit-details-marker { display: none; }
details.more > .field:first-of-type { margin-top: 12px; }

/* ------------------------------- Buttons ------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--brand);
  color: var(--on-brand);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
}

.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.ghost:hover { background: var(--surface-alt); }

.btn.small { padding: 6px 12px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger-border); }
.btn.danger:hover { background: var(--danger-soft); }

/* -------------------------------- Menu -------------------------------- */

.menu-cat { margin-bottom: 22px; }

.menu-cat > h3 {
  font-size: .85rem;
  letter-spacing: .12em;
  color: var(--muted);
  text-transform: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--surface);
}

.item.picked { border-color: var(--brand); background: var(--brand-soft); }

.item-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; }

.item-tag {
  display: inline-block;
  font-size: .68rem;
  background: var(--brand);
  color: var(--on-brand);
  border-radius: 999px;
  padding: 0 8px;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: 2px;
  margin-left: 6px;
}

.item-price {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: .9rem;
  font-weight: 600;
}

.qty {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.qty button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}

.qty button:hover { background: var(--hover); }
.qty output { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; }

.item-opts {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  font-size: .9rem;
  margin: 0;
  cursor: pointer;
}

.check input { width: 17px; height: 17px; accent-color: var(--brand); margin: 0; }

.item-note { flex: 1 1 180px; }
.item-note input { padding: 6px 10px; font-size: .85rem; }

/* -------------------------------- Orders -------------------------------- */

.order {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--surface);
}

.order-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.order-name { font-weight: 700; }
.order-total { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

.order ul { margin: 0; padding-left: 18px; font-size: .9rem; }
.order li { margin-bottom: 2px; }

.opt-chip {
  display: inline-block;
  font-size: .76rem;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-radius: 6px;
  padding: 0 6px;
  margin-left: 4px;
}

.note-chip { color: var(--muted); font-size: .83rem; margin-left: 4px; }

/* ------------------------------- Summary ------------------------------- */

table.summary {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}

table.summary th,
table.summary td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}

table.summary th { color: var(--muted); font-size: .8rem; font-weight: 600; white-space: nowrap; }
table.summary tfoot td { font-weight: 700; }
table.summary td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.summary tr:last-child td { border-bottom: none; }

/* ------------------------------- Group list ------------------------------- */

.group-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}

.group-item:last-child { border-bottom: none; }
.group-item:hover .group-title { color: var(--brand); }
.group-title { font-weight: 600; }
.group-meta { color: var(--muted); font-size: .85rem; }
.group-arrow { margin-left: auto; color: var(--muted); }

.badge {
  font-size: .75rem;
  border-radius: 999px;
  padding: 2px 9px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.open { background: var(--accent-soft); color: var(--accent); }
.badge.closed { background: var(--neutral-soft); color: var(--muted); }

/* -------------------------------- Misc -------------------------------- */

.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 12px;
  font-size: .92rem;
}

.bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(20, 22, 24, .07);
  z-index: 30;
}

.bar .wrap {
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar .total { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar .total small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.bar .btn { margin-left: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(10px);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.share {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: .85rem;
}

.share code {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.share-label {
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
}

/* ---------------------------- 熱門排行 / 參考區 ---------------------------- */

.hot-badge {
  display: inline-block;
  font-size: .75rem;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-radius: 999px;
  padding: 0 8px;
  margin-left: 6px;
  white-space: nowrap;
  font-weight: 600;
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rank-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}

.rank-list li:last-child { border-bottom: none; }
.rank-medal { width: 28px; text-align: center; flex: none; }
.rank-name { font-weight: 600; }
.rank-qty { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.order.mine { border-color: var(--accent); background: var(--mine-bg); }

/* --------------------------------- 對帳 --------------------------------- */

.pay-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.pay-stat {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: center;
}

.pay-stat-label { color: var(--muted); font-size: .78rem; }
.pay-stat-value {
  font-weight: 700;
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pay-stat-value.ok { color: var(--accent); }
.pay-stat-value.warn { color: var(--brand); }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 999px;
  transition: width .3s ease;
}

.progress-fill.done { background: var(--accent); }

.pay-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
}

.pay-row:last-child { border-bottom: none; }
.pay-who { flex: 1; min-width: 0; }
.pay-name { font-weight: 600; }
.pay-time { color: var(--muted); font-size: .78rem; }

.pay-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pay-row.paid { background: var(--mine-bg); }
.pay-row.paid .pay-name { color: var(--muted); text-decoration: line-through; }
.pay-row.paid .pay-amount { color: var(--muted); }

.pay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* --------------------------- 選項群組（單選/複選） --------------------------- */

.opt-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  width: 100%;
}

.opt-group.single {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.opt-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  width: 100%;
}

.opt-hint {
  font-size: .8rem;
  color: var(--brand);
  font-weight: 600;
  margin-top: 2px;
}

.opt-hint-short { display: none; }
.menu-cat.compact .opt-hint-long { display: none; }
.menu-cat.compact .opt-hint-short { display: inline; }
.menu-cat.compact .opt-hint { margin-top: 0; }

.check input[type="radio"] { width: 17px; height: 17px; accent-color: var(--brand); margin: 0; }

/* ---------------------------- 菜單編號 / 老闆清單 ---------------------------- */

/* 袋號：老闆寫在餐盒蓋上的號碼 */
.seq-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--brand);
  color: var(--on-brand);
  font-size: .85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.boss-list {
  margin: 12px 0 14px;
  padding: 14px;
  max-height: 420px;
  overflow: auto;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: .85rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* ------------------------- 密集菜單版面（品項多的店） ------------------------- */

.menu-nav {
  position: sticky;
  top: 56px;
  z-index: 10;
  background: var(--surface);
  padding: 10px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.menu-nav .chips {
  overflow-x: auto;
  flex-wrap: nowrap;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.menu-nav .chip { flex: none; font-size: .85rem; padding: 5px 12px; }

.menu-search {
  margin-top: 8px;
  padding: 8px 12px !important;
  font-size: .9rem;
}

.menu-cat.compact { margin-bottom: 18px; }

.menu-cat.compact .item-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

@media (min-width: 700px) {
  .menu-cat.compact .item-grid { grid-template-columns: 1fr 1fr; }
  /* 展開客製選項的品項佔滿整行，選項才不會擠成一團 */
  .menu-cat.compact .item.picked:has(.item-opts:not([hidden])) { grid-column: 1 / -1; }
}

.menu-cat.compact .item { padding: 7px 10px; margin-bottom: 0; }
.menu-cat.compact .item-head { gap: 8px; }

.menu-cat.compact .item-info {
  display: flex;
  align-items: baseline;
  gap: 4px 8px;
  flex-wrap: wrap;
  line-height: 1.3;
}

.menu-cat.compact .item-info > div { display: contents; }
.menu-cat.compact .hot-badge { font-size: .7rem; padding: 0 6px; }
.menu-cat.compact .item-tag { font-size: .65rem; padding: 0 6px; }

.menu-cat.compact .item-name { font-size: .95rem; }
.menu-cat.compact .item-price { font-size: .88rem; }
.menu-cat.compact .qty button { width: 28px; height: 28px; }

.item-unit { color: var(--muted); font-weight: 400; font-size: .8rem; }
