/* 商管通收銀 App：手機／平板優先 */
:root {
  --bg: #f5f4f1;
  --card: #fff;
  --text: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --accent: #e0531c;
  --accent-soft: #fdeee7;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --tabbar: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --card: #23211f;
    --text: #ece9e4;
    --muted: #a39e96;
    --line: #36332f;
    --accent: #f06a35;
    --accent-soft: #3a2419;
    --ok: #4cc27a;
    --ok-soft: #173222;
    --warn: #e5a443;
    --warn-soft: #3a2c12;
    --bad: #ef6b6b;
    --bad-soft: #3d1c1c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
  overscroll-behavior-y: none;
}
a { color: var(--accent); text-decoration: none; }
h3 { font-size: 20px; margin: 0 0 12px; }
h4 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.accent { color: var(--accent); }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pad { padding: 0 12px; margin: 10px 0; }
.err-text { color: var(--bad); }
.warn-text { color: var(--warn); }

/* ---------- 啟動畫面 ---------- */
.boot { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.boot-name { font-size: 40px; font-weight: 800; color: var(--accent); letter-spacing: 4px; }
.boot-sub { color: var(--muted); font-size: 14px; }
#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 12px 16px; background: var(--bad-soft); color: var(--bad); z-index: 1000; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* ---------- 版面 ---------- */
.app { min-height: 100dvh; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
.bar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 50px; padding: 0 14px; background: var(--card); border-bottom: 1px solid var(--line);
}
.bar strong { font-size: 17px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; position: relative; }
.tab .ico { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active .ico { filter: none; opacity: 1; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 2px; }
.tab .badge { position: absolute; top: 4px; left: 55%; }
.notice { padding: 8px 14px; font-size: 14px; background: var(--accent-soft); color: var(--accent); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.center-page { min-height: 70dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }

/* ---------- 按鈕、輸入 ---------- */
.btn, button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.small { padding: 5px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn.big { padding: 14px; font-size: 18px; border-radius: 14px; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 0; text-align: left; }
.stack > * + * { margin-top: 10px; }

input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input:disabled { opacity: .6; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.row-field { display: grid; grid-template-columns: 6.5em 1fr; align-items: center; gap: 8px; }
.row-field > span { margin: 0; font-size: 15px; color: var(--text); }
.row-fields { display: grid; grid-template-columns: 1fr 90px 80px auto; gap: 6px; }
input.cash { font-size: 24px; font-weight: 700; }
.search { border-radius: 99px; padding: 10px 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip { padding: 10px 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); font-size: 15px; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip.big { flex: 1; min-width: 30%; padding: 14px 8px; border-radius: 12px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
a.pill.accent { font-weight: 600; font-size: 13px; padding: 4px 12px; }

/* ---------- 清單 ---------- */
.group-box { background: var(--card); border-radius: 14px; margin: 12px; padding: 12px; }
.group-box.links a, .group-box.links .link-btn { display: block; padding: 12px 4px; color: var(--text); border-bottom: 1px solid var(--line); width: 100%; }
.group-box.links a:last-child, .group-box.links .link-btn:last-child { border-bottom: 0; }
.row-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%;
  padding: 10px 2px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; color: var(--text);
}
.row-item:last-child { border-bottom: 0; }
.row-item.add { color: var(--accent); justify-content: flex-start; }
.row-item.void { opacity: .5; text-decoration: line-through; }
.row-item .right { text-align: right; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-btns.end { margin-top: 6px; }
.no { font-weight: 800; font-size: 18px; margin-right: 6px; }
.plate { font-weight: 700; letter-spacing: 1px; }
.plate.big { font-size: 28px; display: block; color: var(--text); }
.kv { display: flex; justify-content: space-between; margin: 6px 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }
.card-box { background: var(--card); margin: 12px; padding: 16px; border-radius: 14px; }
.card-box > * + * { margin-top: 8px; }
.tel { margin-left: 8px; }
.note { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 6px 10px; }

/* ---------- 收銀 ---------- */
.pos { display: flex; flex-direction: column; height: calc(100dvh - var(--tabbar) - env(safe-area-inset-bottom)); }
.app:has(> .notice) .pos { height: calc(100dvh - var(--tabbar) - env(safe-area-inset-bottom) - 38px); }
.pos-body { flex: 1; display: flex; min-height: 0; }
.cats { flex: none; width: 92px; overflow-y: auto; background: var(--card); border-right: 1px solid var(--line); }
.cats button { display: block; width: 100%; padding: 18px 8px; border: 0; background: none; font-size: 15px; text-align: center; border-left: 3px solid transparent; }
.cats button.on { background: var(--bg); border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.grid { flex: 1; overflow-y: auto; padding: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; align-content: start; }
.small-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); padding: 0; margin-bottom: 12px; max-height: 40dvh; }
.product {
  min-height: 84px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 10px; text-align: left;
}
.product:active { background: var(--accent-soft); border-color: var(--accent); }
.product .name { font-size: 17px; font-weight: 600; }
.product .price { color: var(--accent); font-size: 15px; }
.product.soldout { opacity: .45; }
.product.soldout .price { color: var(--bad); }
.grid .empty { grid-column: 1 / -1; }
.checkout-bar { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--card); border-top: 1px solid var(--line); }
.cart-btn { display: flex; align-items: center; gap: 8px; border: 0; background: none; flex: 1; text-align: left; }
.cart-ico { font-size: 26px; position: relative; }
.cart-ico .badge { position: absolute; top: -4px; right: -10px; }
.hint { color: var(--muted); font-size: 13px; }
.total { font-size: 22px; font-weight: 800; color: var(--accent); }
.checkout-bar .btn { padding: 12px 26px; font-size: 17px; border-radius: 99px; }

/* ---------- 下方面板 ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 50; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 92dvh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; animation: up .18s ease-out;
}
.sheet.center { top: 50%; bottom: auto; left: 50%; right: auto; transform: translate(-50%, -50%); border-radius: 18px; width: min(88vw, 380px); animation: none; }
@keyframes up { from { transform: translateY(30%); opacity: .5; } }
.sheet-close { position: absolute; top: 10px; right: 10px; border: 0; background: none; font-size: 20px; color: var(--muted); padding: 6px 10px; }
.group { margin-bottom: 14px; }
.group-title { font-weight: 600; margin-bottom: 8px; }
.group-title span { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }
.qty { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; font-weight: 600; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 18px; }
.stepper button:disabled { opacity: .4; }
.stepper .v { min-width: 32px; text-align: center; font-weight: 700; }
.line { display: grid; grid-template-columns: 1fr auto 72px; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.line small { display: block; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions .btn { flex: 1; }
.due { text-align: center; font-size: 18px; margin-bottom: 8px; }
.due strong { display: block; font-size: 40px; color: var(--accent); }
.methods { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.change { text-align: right; font-size: 18px; margin: 8px 4px 12px; }
.change strong { font-size: 28px; color: var(--ok); }
.change.bad strong { color: var(--bad); }
.done { padding: 8px 4px; text-align: center; }
.done > * + * { margin-top: 8px; }
.done-ok { font-size: 44px; color: var(--ok); }
.done-no { font-size: 72px; font-weight: 800; line-height: 1.1; color: var(--accent); }
.qr-img { width: 240px; height: 240px; background: #fff; padding: 8px; border-radius: 10px; }

/* ---------- 訂單 ---------- */
.day { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 12px 0; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 12px; }
.summary div { background: var(--card); border-radius: 12px; padding: 10px; text-align: center; }
.summary span { display: block; font-size: 12px; color: var(--muted); }
.summary strong { font-size: 20px; }
.diff { margin: 12px; padding: 14px; border-radius: 12px; text-align: center; font-size: 22px; font-weight: 700; }
.diff.ok { background: var(--ok-soft); color: var(--ok); }
.diff.over { background: var(--warn-soft); color: var(--warn); }
.diff.short { background: var(--bad-soft); color: var(--bad); }

/* ---------- 出餐 ---------- */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; padding: 12px; }
.cols h3 { font-size: 17px; margin: 4px; }
.count { display: inline-block; min-width: 24px; text-align: center; background: var(--line); border-radius: 99px; font-size: 13px; padding: 1px 8px; margin-left: 6px; }
.ticket { background: var(--card); border-radius: 12px; padding: 12px; margin-top: 10px; border-left: 6px solid var(--accent); }
.ticket.ready { border-left-color: var(--ok); }
.ticket .head { display: flex; justify-content: space-between; align-items: baseline; }
.ticket .no { font-size: 34px; }
.age { color: var(--muted); font-size: 13px; }
.age.late { color: var(--bad); font-weight: 700; }
.ticket ul { list-style: none; padding: 0; margin: 8px 0 10px; font-size: 17px; }
.ticket li small { display: block; color: var(--warn); font-size: 14px; }

/* ---------- 工單 ---------- */
.wo-item { display: grid; grid-template-columns: 1fr 84px auto 70px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.wo-item .price { padding: 6px 8px; }
@media (max-width: 420px) {
  .wo-item { grid-template-columns: 1fr auto; }
  .wo-name { grid-column: 1 / -1; }
}

/* ---------- 登入 ---------- */
.login { max-width: 420px; margin: 0 auto; padding: 8vh 16px 40px; }
.login h1 { text-align: center; font-size: 40px; margin: 0; color: var(--accent); letter-spacing: 4px; }
.login .sub { text-align: center; color: var(--muted); margin: 8px 0 24px; }
.seg { display: flex; gap: 6px; margin-bottom: 16px; }
.seg button { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.staff { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.who { font-size: 17px; padding: 14px 22px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.who.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.login .hint { text-align: center; margin: 12px 0; font-size: 14px; }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 12px 0 20px; }
.pin-dots .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots .dot.on { background: var(--accent); border-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 300px; margin: 0 auto; }
.keypad button { height: 58px; font-size: 24px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }
.keypad button:active { background: var(--accent-soft); }

/* ---------- 叫號畫面 ---------- */
.display { position: fixed; inset: 0; background: #1c1917; color: #fafaf9; display: flex; flex-direction: column; }
.display header { display: flex; justify-content: space-between; align-items: center; padding: 2vh 3vw; font-size: clamp(18px, 3vh, 32px); }
.display .store { font-weight: 700; }
.display .lost { color: #fca5a5; font-size: .7em; }
.display main { flex: 1; display: grid; grid-template-columns: 3fr 2fr; gap: 2vw; padding: 0 3vw 3vh; min-height: 0; }
.display section { border-radius: 2vh; padding: 2vh 2vw; overflow: hidden; }
.display h2 { margin: 0 0 2vh; font-size: clamp(22px, 5vh, 56px); }
.d-ready { background: #14532d; }
.d-ready h2 { color: #bbf7d0; }
.d-preparing { background: #292524; }
.d-preparing h2 { color: #a8a29e; }
.nums { display: flex; flex-wrap: wrap; gap: 1.5vh 2vw; align-content: flex-start; }
/* 每個號碼一塊底色，遠看才不會把「離2」「15」讀成「離215」 */
.nums .num { font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; padding: .08em .3em; border-radius: .15em; text-align: left; }
.d-ready .num { font-size: clamp(48px, 14vh, 180px); color: #fff; background: rgb(255 255 255 / .12); }
.d-preparing .num { font-size: clamp(28px, 7vh, 90px); color: #d6d3d1; background: rgb(255 255 255 / .06); }
.num.flash { color: #fde047; animation: blink .8s ease-in-out 6; }
@keyframes blink { 50% { opacity: .25; } }
.err-big { font-size: 22px; color: #fca5a5; }
.start {
  position: fixed; inset: 0; background: rgb(0 0 0 / .7); color: #fff; border: 0; font-size: clamp(24px, 5vh, 48px); font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
.start small { font-size: .5em; font-weight: 400; opacity: .8; }
@media (orientation: portrait) {
  .display main { grid-template-columns: 1fr; grid-template-rows: 3fr 2fr; }
}

/* ---------- 提示 ---------- */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; width: max-content; max-width: 90vw; pointer-events: none; }
.toast { background: rgb(28 25 23 / .92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; text-align: center; }
.toast.err { background: var(--bad); }
