/* ============================================================
   炭火设计系统 —— 夜市摊位的深色界面
   炭黑底 / 炭火橙主操作 / 暖白文字；红色只用于估清与取消
   ============================================================ */

:root {
  --bg: #171310;
  --surface: #211b15;
  --surface-2: #2c241b;
  --line: #3b3025;
  --text: #f6eee3;
  --dim: #b3a695;
  --faint: #7a6f60;
  --ember: #ff7a1a;
  --ember-press: #e76a0c;
  --on-ember: #201000;
  --red: #f05b45;
  --green: #7cc98b;
  --radius: 14px;
  --radius-s: 10px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px;
  --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --font: system-ui, -apple-system, "PingFang SC", "HarmonyOS Sans SC",
          "MiSans", "Noto Sans CJK SC", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* 防止组件的 display 声明覆盖 hidden 属性 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}

input {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
input::placeholder { color: var(--faint); }
input:focus { border-color: var(--ember); }

.num { font-variant-numeric: tabular-nums; }

/* ---------- 通用布局 ---------- */

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--space-4);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.page-header { padding: var(--space-2) 0 var(--space-4); }
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: 0.02em; }
.page-header .sub { color: var(--dim); font-size: 14px; margin-top: 2px; }

.badge-open {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--green); font-size: 14px; font-weight: 500;
}
.badge-open::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
}

/* ---------- 卡片与菜单行 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.menu-list { display: flex; flex-direction: column; gap: var(--space-3); }

.menu-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  transition: opacity 200ms ease;
}
.menu-item.sold-out { opacity: 0.45; }

.menu-item .info { min-width: 0; }
.menu-item .name { font-size: 18px; font-weight: 600; }
.menu-item .meta { display: flex; align-items: baseline; gap: 10px; margin-top: 2px; }
.menu-item .price { color: var(--ember); font-weight: 700; font-size: 17px; }
.menu-item .stock { color: var(--dim); font-size: 13px; }
.menu-item .stock.low { color: var(--red); }

.tag-soldout {
  display: inline-block;
  color: var(--red); border: 1px solid var(--red);
  font-size: 12px; padding: 1px 8px; border-radius: 999px;
}

/* ---------- 数量加减 ---------- */

.stepper { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.stepper button {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 22px; font-weight: 600;
  transition: transform 120ms ease, background 150ms ease;
  -webkit-user-select: none; user-select: none;
}
.stepper button:active { transform: scale(0.92); background: var(--line); }
.stepper button:disabled { opacity: 0.3; cursor: default; }
.stepper .qty {
  min-width: 40px; text-align: center;
  font-size: 18px; font-weight: 700;
}
.stepper button.plus { background: var(--ember); color: var(--on-ember); border-color: var(--ember); }
.stepper button.plus:active { background: var(--ember-press); }
.stepper button.plus:disabled { background: var(--surface-2); color: var(--faint); border-color: var(--line); }

/* ---------- 底部结算栏 ---------- */

.cart-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface); /* color-mix 的回退（iOS ≤16.1） */
  background: color-mix(in srgb, var(--surface) 92%, black);
  border-top: 1px solid var(--line);
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.cart-bar .inner {
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.cart-total .count { color: var(--dim); font-size: 14px; }
.cart-total .money { font-size: 22px; font-weight: 800; color: var(--text); }
.cart-total .money em { font-style: normal; font-size: 15px; margin-right: 1px; }

.btn-primary {
  background: var(--ember); color: var(--on-ember);
  font-size: 17px; font-weight: 700;
  min-height: 52px; padding: 0 32px;
  border-radius: var(--radius);
  transition: transform 120ms ease, background 150ms ease;
}
.btn-primary:active { transform: scale(0.97); background: var(--ember-press); }
.btn-primary:disabled { background: var(--surface-2); color: var(--faint); }

/* ---------- 取餐票（签名元素） ---------- */

.ticket {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: var(--space-5);
  animation: ticket-in 400ms cubic-bezier(0.2, 0.9, 0.3, 1.05);
}
@keyframes ticket-in {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ticket { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

.ticket-top { padding: var(--space-5) var(--space-4); text-align: center; }
.ticket-top .label { color: var(--dim); font-size: 14px; letter-spacing: 0.2em; }
.ticket-top .no {
  font-size: 88px; font-weight: 900; line-height: 1.1;
  color: var(--ember);
  font-variant-numeric: tabular-nums;
}
.ticket-top .queue { color: var(--dim); font-size: 15px; }
.ticket-top .queue strong { color: var(--text); font-size: 17px; }

/* 撕边：打孔 + 虚线 */
.ticket-tear {
  position: relative; height: 0;
  border-top: 2px dashed var(--line);
}
.ticket-tear::before, .ticket-tear::after {
  content: ""; position: absolute; top: -11px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
}
.ticket-tear::before { left: -11px; }
.ticket-tear::after { right: -11px; }

.ticket-body { padding: var(--space-4); }
.ticket-line {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 0; font-size: 16px;
}
.ticket-line .n { color: var(--dim); font-size: 14px; margin-left: 8px; }
.ticket-line.total {
  border-top: 1px solid var(--line);
  margin-top: var(--space-2); padding-top: var(--space-3);
  font-weight: 700; font-size: 18px;
}
.ticket-line.total .money { color: var(--ember); }

.status-banner {
  text-align: center; padding: var(--space-3);
  border-radius: var(--radius);
  margin-top: var(--space-4);
  font-weight: 600; font-size: 17px;
}
.status-banner.making { background: var(--surface-2); color: var(--text); }
.status-banner.done {
  background: var(--surface-2); /* color-mix 回退 */
  background: color-mix(in srgb, var(--green) 18%, var(--bg));
  color: var(--green);
}
.status-banner.cancelled {
  background: var(--surface-2); /* color-mix 回退 */
  background: color-mix(in srgb, var(--red) 14%, var(--bg));
  color: var(--red);
}

/* ---------- 管理端 ---------- */

.admin-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  background: var(--surface); /* color-mix 的回退（iOS ≤16.1） */
  background: color-mix(in srgb, var(--surface) 94%, black);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.admin-tabs button {
  flex: 1; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--dim); font-size: 12px;
}
.admin-tabs button svg { width: 24px; height: 24px; }
.admin-tabs button.active { color: var(--ember); }
.admin-tabs button .tab-badge {
  position: absolute; transform: translate(16px, -4px);
  background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px;
  display: grid; place-items: center; padding: 0 5px;
}
.admin-tabs button { position: relative; }

.order-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.order-card .head {
  display: flex; align-items: center; gap: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line);
}
.order-card .head .no {
  font-size: 34px; font-weight: 900; color: var(--ember);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.order-card .head .who { font-size: 15px; }
.order-card .head .who .t { color: var(--faint); font-size: 12.5px; }
.order-card .head .money {
  margin-left: auto; font-size: 20px; font-weight: 800;
}
.order-card .lines { padding: var(--space-3) 0; }
.order-card .line {
  display: flex; justify-content: space-between;
  font-size: 19px; font-weight: 600;
  padding: 4px 0;
}
.order-card .line .q { color: var(--ember); font-weight: 800; }
.order-card .actions { display: flex; gap: var(--space-3); }
.order-card .actions button {
  min-height: 52px;
  border-radius: var(--radius-s);
  font-size: 17px; font-weight: 700;
  transition: transform 120ms ease;
}
.order-card .actions button:active { transform: scale(0.97); }
/* 出餐是高频主操作占满剩余宽度；取消低频且危险，收窄防误触 */
.btn-done { flex: 1; background: var(--ember); color: var(--on-ember); }
.btn-cancel { flex: 0 0 auto; padding: 0 22px; background: var(--surface-2); color: var(--red); border: 1px solid var(--line); }

.order-card.finished { opacity: 0.55; }
.order-card.finished .head { border-bottom: none; padding-bottom: 0; }
.order-card .state-tag { font-size: 14px; font-weight: 600; margin-left: 8px; }
.order-card .state-tag.done { color: var(--green); }
.order-card .state-tag.cancelled { color: var(--red); }

.inv-row {
  display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
}
.inv-row .row-top { display: flex; align-items: center; gap: var(--space-2); }
.inv-row .name { font-size: 17px; font-weight: 600; flex: 1; min-width: 0; }
.inv-row .row-fields { display: flex; gap: var(--space-3); }
.inv-row .row-fields > div { flex: 1; }
.inv-row label { color: var(--dim); font-size: 13px; display: block; margin-bottom: 2px; }
.inv-row input { text-align: center; padding: 8px 6px; }
.btn-soldout {
  min-height: 44px; padding: 0 14px;
  border-radius: var(--radius-s);
  border: 1px solid var(--red); color: var(--red);
  font-size: 14px; font-weight: 600;
}
.btn-soldout.on { background: var(--red); color: #fff; }
.btn-del {
  min-height: 44px; width: 44px;
  display: grid; place-items: center;
  color: var(--faint); border-radius: var(--radius-s);
}
.btn-del:active { color: var(--red); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.stat-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--space-4);
}
.stat-card .v { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-card .v.ember { color: var(--ember); }
.stat-card .k { color: var(--dim); font-size: 13px; margin-top: 2px; }

.empty {
  text-align: center; color: var(--dim);
  padding: var(--space-6) var(--space-4);
  font-size: 15px;
}

.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 999px;
  font-size: 15px; max-width: 88vw;
  z-index: 100;
  animation: toast-in 200ms ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.section-title {
  font-size: 15px; font-weight: 600; color: var(--dim);
  margin: var(--space-5) 0 var(--space-3);
}

.login-box { max-width: 360px; margin: 18vh auto 0; padding: var(--space-4); }
.login-box h1 { font-size: 22px; margin-bottom: var(--space-4); text-align: center; }
.login-box .btn-primary { width: 100%; margin-top: var(--space-3); }
.login-box .err { color: var(--red); font-size: 14px; margin-top: var(--space-2); min-height: 20px; }
