:root {
  --bg: #f6f1ea;
  --panel: #ffffff;
  --ink: #2b211b;
  --muted: #8a7b70;
  --line: #e5dbd0;
  --brand: #3b2a20;
  --accent: #b86b2b;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #c0392b;
  --soft: #f1e7dc;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
input { user-select: text; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--warn); min-height: 1.2em; margin: 8px 0 0; }
.hint { display: block; color: var(--muted); min-height: 1.2em; margin-top: 4px; }

/* 按鈕 */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: 10px 16px; min-height: 44px; cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:disabled { opacity: .45; }
.btn.big { min-height: 56px; font-size: 1.15rem; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 6px 10px; font-size: .9rem; }
.btn.danger { color: var(--warn); border-color: #f0c8c2; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 1 auto; min-height: 48px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
}
.seg button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.seg button.linepay { color: #06c755; font-weight: 700; }
.seg button.linepay.on { background: #06c755; border-color: #06c755; color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 14px;
  border-radius: 22px; border: 1px solid var(--line); background: var(--panel); cursor: pointer;
}
.chip input { width: 20px; height: 20px; }

/* 登入 */
#login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-box { background: var(--panel); padding: 32px; border-radius: 16px; width: min(360px, 100%); text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.login-box h1 { margin: 0; color: var(--brand); }
.login-box input { width: 100%; font-size: 1.5rem; text-align: center; padding: 12px; margin: 20px 0 12px; border: 1px solid var(--line); border-radius: 10px; }
.login-box .btn { width: 100%; }

/* 主畫面 */
#app { display: flex; flex-direction: column; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--brand); color: #fff; flex-wrap: wrap; }
.topbar .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; min-height: 40px; padding: 6px 12px; }
.topbar .spacer { flex: 1; }
.badge { font-size: .8rem; padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.2); }
.badge.test { background: #f1c40f; color: #3b2a20; font-weight: 700; }
.badge.warn { background: var(--warn); color: #fff; }

.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0; }
.menu-panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.cats { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.cats button { flex: 0 0 auto; padding: 10px 16px; min-height: 44px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.cats button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.items { flex: 1; overflow-y: auto; padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start; }
.item {
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px; text-align: left;
  min-height: 84px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer;
}
.item span { font-weight: 600; line-height: 1.3; }
.item small { color: var(--accent); }
.item:active { background: var(--soft); }
.item.sold { opacity: .45; cursor: not-allowed; }
.item.sold small { color: var(--warn); font-weight: 700; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

.cart-panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.cart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.cart-head h2 { margin: 0; font-size: 1.1rem; }
.cart-head .seg button { min-height: 40px; padding: 4px 14px; }
.cart { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.cart li { display: grid; grid-template-columns: 1fr auto 64px; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.cart li.empty { display: block; color: var(--muted); text-align: center; padding: 40px 12px; border: 0; }
.cart-name small { display: block; color: var(--muted); }
.cart-sum { text-align: right; font-variant-numeric: tabular-nums; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 1.2rem; cursor: pointer; }
.qty span { min-width: 24px; text-align: center; font-variant-numeric: tabular-nums; }
.cart-foot { padding: 12px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cart-foot .total { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; font-size: 1.1rem; }
.cart-foot .total strong { font-size: 2rem; color: var(--brand); font-variant-numeric: tabular-nums; }
.cart-foot #checkout { grid-column: 1 / -1; }

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .cart-panel { border-left: 0; border-top: 1px solid var(--line); max-height: 48dvh; }
  .items { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* 對話框 */
dialog { border: 0; border-radius: 16px; padding: 0; max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); color: var(--ink); }
dialog::backdrop { background: rgba(30,20,10,.45); }
.dlg { padding: 20px; width: min(420px, calc(100vw - 32px)); }
.dlg.wide { width: min(680px, calc(100vw - 32px)); }
.dlg h2 { margin: 0 0 12px; }
.dlg-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.dlg-head h2 { margin: 0; }
.dlg-head input { padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.field { margin: 12px 0; }
.field > label { display: block; font-size: .9rem; color: var(--muted); margin: 8px 0 6px; }
.field input:not([type=checkbox]) { width: 100%; padding: 12px; font-size: 1.2rem; border: 1px solid var(--line); border-radius: 10px; }
.cash-row { display: grid; gap: 8px; }
.change { margin-top: 8px; font-size: 1.1rem; }
.change strong { font-size: 1.6rem; color: var(--ok); }
.change strong.neg { color: var(--warn); }
.big-num { font-size: 2rem; color: var(--ok); }
#done-msg { font-size: 1.1rem; line-height: 1.6; }

.table-wrap { overflow: auto; max-height: 60dvh; }
table.list { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.list th, table.list td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list small { display: block; color: var(--muted); font-size: .8rem; }
table.list .acts { display: flex; gap: 4px; justify-content: flex-end; }
table.list .empty { text-align: center; color: var(--muted); padding: 30px; }
tr.st-void td, tr.st-cancelled td { color: var(--muted); text-decoration: line-through; }
tr.st-void .acts, tr.st-cancelled .acts { text-decoration: none; }
tr.st-pending td { color: var(--warn); }

.report { max-height: 60dvh; overflow: auto; background: var(--soft); border-radius: 12px; padding: 12px; }
.receipt-preview { background: #fff; width: 58mm; margin: 0 auto; padding: 4mm 5mm; box-shadow: 0 2px 10px rgba(0,0,0,.08); color: #000; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--brand); color: #fff; padding: 12px 20px; border-radius: 10px; z-index: 1000; max-width: calc(100vw - 32px); }

/* 線上點單 */
.topbar .count { display: inline-block; min-width: 22px; margin-left: 6px; padding: 1px 6px; border-radius: 11px; background: #e74c3c; color: #fff; font-size: .8rem; font-weight: 700; }
.self-banner { margin: 8px 12px 0; padding: 10px 12px; border-radius: 10px; background: #fff3e0; color: var(--accent); }
.online-list { max-height: 62dvh; overflow: auto; display: grid; gap: 8px; }
.online-list .empty { text-align: center; padding: 30px; }
.online-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; }
.online-card.st-new { border-color: var(--accent); background: #fffaf3; }
.online-card.st-done, .online-card.st-cancelled { opacity: .55; }
.oc-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.oc-no { font-size: 1.4rem; color: var(--brand); }
.oc-st { font-size: .85rem; padding: 2px 8px; border-radius: 6px; background: var(--soft); }
.oc-head strong { margin-left: auto; font-size: 1.1rem; }
.oc-items { margin-top: 6px; }
.oc-note { margin-top: 4px; color: var(--accent); }
.oc-acts { display: flex; gap: 8px; margin-top: 10px; }
.oc-acts .btn.primary { flex: 1; }

/* ---- 小票(畫面預覽與列印共用)---- */
#print-area { display: none; }
.r-invoice, .r-detail { font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif; color: #000; width: 48mm; font-size: 9pt; line-height: 1.35; }
.r-test { text-align: center; font-weight: 700; border: 1px dashed #000; margin-bottom: 2mm; font-size: 8pt; }
.r-seller { text-align: center; font-size: 11pt; font-weight: 700; }
.r-title { text-align: center; font-size: 15pt; font-weight: 700; margin-top: 1mm; }
.r-reprint { font-size: 9pt; border: 1px solid #000; padding: 0 1mm; margin-left: 1mm; vertical-align: middle; }
.r-period, .r-number { text-align: center; font-size: 17pt; font-weight: 700; line-height: 1.15; letter-spacing: .5px; }
.r-row { display: flex; justify-content: space-between; gap: 2mm; }
.r-invoice .barcode { display: block; margin: 2mm auto 1.5mm; }
.r-qrs { display: flex; justify-content: space-between; }
.r-qrs .qr { width: 22mm; height: 22mm; }
.r-foot { text-align: center; font-size: 8pt; margin-top: 2mm; }
.r-sub { text-align: center; font-weight: 700; margin: 2mm 0 1mm; }
.r-pickup { text-align: center; font-size: 16pt; font-weight: 700; }
.r-pickup small { font-size: 9pt; margin-left: 2mm; }
.r-items { width: 100%; border-collapse: collapse; margin: 1mm 0; }
.r-items th { border-bottom: 1px dashed #000; font-weight: 400; text-align: left; }
.r-items td { vertical-align: top; }
.r-items .n { text-align: right; white-space: nowrap; }
.r-total { font-size: 12pt; font-weight: 700; border-top: 1px dashed #000; padding-top: 1mm; margin-top: 1mm; }
.r-note { margin-top: 1mm; }
.r-warn { font-weight: 700; }

@media print {
  @page { size: 58mm auto; margin: 0; }
  html, body { background: #fff; height: auto; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; padding: 2mm 5mm; }
  .r-invoice { break-after: page; }
  .r-invoice + .r-detail { break-before: page; }
}
