:root {
  --paper: #f6f4ec;
  --card: #ffffff;
  --ink: #22271e;
  --muted: #6e7267;
  --line: #e7e3d6;
  --green: #1f7a4d;
  --green-dark: #17603c;
  --chosen: #eaf4ec;
  --ticket: #232a20;
  --danger: #b23b3b;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Noto Sans TC", "Microsoft JhengHei", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  /* 底部餐券列固定,預留空間避免遮住最後一列 */
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* ---------- 頂欄 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  padding: calc(16px + env(safe-area-inset-top)) 20px 12px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--green);
}

.session-meta { margin-top: 6px; }

.meta-vendor {
  display: block;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.meta-sub {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 內容 ---------- */
.main { padding: 16px 16px 0; }

.status {
  margin: 48px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  /* 錯誤訊息會帶換行,讓它照實顯示 */
  white-space: pre-line;
  line-height: 1.7;
}

.dish-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dish {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color 0.15s, background 0.15s;
}

.dish.chosen {
  border-color: var(--green);
  background: var(--chosen);
}

.dish-name { font-size: 16px; font-weight: 600; }

.dish-price {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- 數量調整 ---------- */
.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.step {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  font-size: 20px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.step.plus { background: var(--green); color: #fff; border-color: var(--green); }
.step:disabled { opacity: 0.35; cursor: default; }
.step:active { transform: scale(0.94); }

.qty {
  min-width: 28px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stepper[data-locked] { opacity: 0.5; pointer-events: none; }

/* ---------- 餐券式底欄(signature) ---------- */
.ticket {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ticket);
  color: var(--paper);
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  /* 上緣做出撕票虛線 */
  border-top: 2px dashed rgba(246, 244, 236, 0.35);
}

/* 餐券兩側缺口,強化票券感 */
.ticket::before,
.ticket::after {
  content: "";
  position: absolute;
  top: -9px;
  width: 16px;
  height: 16px;
  background: var(--paper);
  border-radius: 50%;
}
.ticket::before { left: -8px; }
.ticket::after { right: -8px; }

.ticket-info {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.ticket-count { font-size: 13px; opacity: 0.75; }

.ticket-total {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.btn-submit {
  margin-left: auto;
  flex: none;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 26px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-submit:active { transform: scale(0.98); }
.btn-submit:disabled { background: #566152; cursor: default; }

.ticket.locked .ticket-total { color: #c9b78a; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 7;
  background: var(--ink);
  color: var(--paper);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  max-width: 88vw;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .step:active, .btn-submit:active { transform: none; }
}

/* ============================================================
   管理後台
   ============================================================ */
.adm-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.adm-tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.adm-tab {
  flex: 1;
  padding: 9px 0;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.adm-tab.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.adm-panel { padding: 18px 16px 0; }

.adm-h1 { font-size: 20px; font-weight: 800; margin-bottom: 12px; }
.adm-h2 { font-size: 15px; font-weight: 700; margin: 20px 0 8px; color: var(--ink); }

/* 歷史列表 */
.hist-list { list-style: none; margin: 0; padding: 0; }
.hist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.hist-row:active { background: var(--chosen); }
.hist-main { display: flex; flex-direction: column; gap: 2px; }
.hist-vendor { font-weight: 700; }
.hist-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist-status {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; white-space: nowrap;
}
.hist-status.on { color: var(--green); border-color: var(--green); }

/* 逐人明細 */
#hist-back { margin-bottom: 12px; }
.person-list { list-style: none; margin: 0; padding: 0; }
.person {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
}
.person-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.person-name { font-weight: 700; }
.person-sub { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.person-lines { list-style: none; margin: 6px 0 0; padding: 0; }
.person-lines li {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 14px; color: var(--ink); padding: 2px 0;
  font-variant-numeric: tabular-nums;
}

.adm-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

/* 統計卡 */
.stat-cards { display: flex; gap: 10px; margin: 14px 0; }
.stat-card {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-num {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.stat-lab { font-size: 12px; color: var(--muted); }

.adm-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

/* 統計表 */
.stat-table { width: 100%; border-collapse: collapse; }
.stat-table th, .stat-table td {
  text-align: left;
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.stat-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-table td:nth-child(2), .stat-table td:nth-child(3),
.stat-table th:nth-child(2), .stat-table th:nth-child(3) { text-align: right; width: 72px; }
.stat-table tr.zero td { color: #b6b3a8; }

/* 表單 */
.form-col { display: flex; flex-direction: column; gap: 14px; max-width: 460px; }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.fld select, .fld input, .row-add input, .edit-row input {
  font-size: 15px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
}
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; }
.hint.warn { color: var(--danger); font-weight: 600; }

/* 按鈕 */
.btn-primary {
  background: var(--green); color: #fff; border: none;
  border-radius: 10px; padding: 12px 20px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-primary:disabled { background: #9aa79f; cursor: default; }
.btn-sec {
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-danger {
  background: var(--card); color: var(--danger); border: 1px solid var(--danger);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-toggle {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; cursor: pointer; flex: none;
}

/* 新增列 / 可編輯清單 */
.row-add { display: flex; gap: 8px; margin: 12px 0 16px; flex-wrap: wrap; }
.row-add input { flex: 1; min-width: 90px; }

.edit-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.edit-row {
  display: flex; gap: 8px; align-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px;
}
.edit-row .v-name, .edit-row .m-name { flex: 2; min-width: 80px; }
.edit-row .v-phone, .edit-row .m-price { flex: 1; min-width: 64px; }
.edit-row.stopped { opacity: 0.55; }
