:root {
  --bg: #f7f3ee;
  --card: #fffdfa;
  --ink: #2f2620;
  --muted: #8a7a6d;
  --line: #e6dcd1;
  --brand: #8b5e3c;
  --brand-2: #b9855c;
  --ok: #2f7d4f;
  --warn: #b45309;
  --danger: #b91c1c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}
.hidden { display: none !important; }
button { font: inherit; border: 0; background: none; color: inherit; cursor: pointer; }
input, select {
  font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 6px; }
h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: 2px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 20px; font-size: 14px; }
.screen { min-height: 100vh; }
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 26px 22px; box-shadow: 0 10px 30px rgba(80, 60, 40, 0.08);
}
.primary {
  width: 100%; margin-top: 14px; background: var(--brand); color: #fff;
  padding: 12px 16px; border-radius: 12px; font-weight: 600;
}
.primary:active { background: #744b2e; }
.primary.big { padding: 15px; font-size: 17px; }
.ghost { color: var(--brand); padding: 6px 8px; }
.ghost.small { font-size: 14px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: 1px; }
.sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tabs { display: flex; gap: 8px; padding: 6px 16px 10px; }
.tab {
  flex: 1; padding: 10px; border-radius: 10px; background: #efe7de; color: var(--muted);
}
.tab.active { background: var(--brand); color: #fff; font-weight: 600; }
main { padding: 0 12px 120px; max-width: 760px; margin: 0 auto; }
.searchbar { padding: 4px 4px 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 4px 10px; }
.chip {
  white-space: nowrap; padding: 7px 12px; border-radius: 999px; background: #efe7de;
  color: var(--muted); font-size: 14px;
}
.chip.active { background: var(--brand); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; display: flex; flex-direction: column; gap: 6px; min-height: 96px;
}
.card:active { border-color: var(--brand-2); }
.card .name { font-weight: 600; line-height: 1.3; }
.card .meta { font-size: 13px; color: var(--muted); }
.card .price { color: var(--brand); font-weight: 700; margin-top: auto; }
.card .price small { font-weight: 400; color: var(--muted); }
.cart-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card);
  border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 82vh; overflow-y: auto; box-shadow: 0 -8px 30px rgba(80, 60, 40, 0.12);
}
.cart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cart-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line);
}
.cart-row .nm { flex: 1; min-width: 0; }
.cart-row .nm div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button {
  width: 30px; height: 30px; border-radius: 8px; background: #efe7de; color: var(--brand);
  font-weight: 700;
}
.qty span { min-width: 28px; text-align: center; }
.cart-total { text-align: right; font-size: 18px; font-weight: 700; padding: 10px 0; }
.cart-total span { color: var(--brand); }
.field { margin-top: 6px; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { padding: 8px 10px; border-radius: 9px; background: #efe7de; color: var(--muted); font-size: 14px; }
.seg.active { background: var(--brand); color: #fff; }
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 15;
  background: var(--brand); color: #fff; padding: 12px 16px; border-radius: 999px;
  box-shadow: 0 8px 20px rgba(80, 60, 40, 0.25); font-weight: 600;
}
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px; }
.orders { display: flex; flex-direction: column; gap: 10px; }
.order {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px;
}
.order .top { display: flex; justify-content: space-between; gap: 8px; }
.order .no { font-weight: 700; }
.order .amt { color: var(--brand); font-weight: 700; }
.order .items { font-size: 14px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.order .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 8px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eee6dc; color: var(--muted); }
.badge.confirmed { background: #e6f4ea; color: var(--ok); }
.badge.partial { background: #fff4e5; color: var(--warn); }
.badge.voided { background: #fde8e8; color: var(--danger); }
.badge.returned { background: #fff4e5; color: var(--warn); }
.danger {
  color: var(--danger); font-size: 14px; padding: 6px 10px; border-radius: 8px;
  background: #fde8e8;
}
.order .foot { flex-wrap: wrap; }
.order .refund-note { font-size: 13px; margin-top: 4px; }
.return-card { max-width: 440px; }
.return-title { font-weight: 700; }
.return-items { max-height: 46vh; overflow-y: auto; margin-bottom: 10px; }
.return-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0; margin: 0;
  border-bottom: 1px dashed var(--line);
}
.return-row input[type="checkbox"] {
  width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--brand);
}
.return-row .info { flex: 1; min-width: 0; }
.return-row .info .muted { font-size: 12px; }
.return-row .return-qty { width: 72px; flex: 0 0 auto; padding: 6px 8px; text-align: right; }
.return-total { text-align: right; font-weight: 700; margin-bottom: 12px; }
.return-total span { color: var(--brand); }
.return-actions { flex-wrap: wrap; }
.return-actions .primary { width: auto; margin: 0; padding: 10px 16px; }
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(47, 38, 32, 0.38);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--card); border-radius: 16px; padding: 20px; width: 100%;
  max-width: 340px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
}
.modal-card p { margin: 0 0 16px; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.toast {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 50;
  background: rgba(47, 38, 32, 0.92); color: #fff; padding: 14px 18px; border-radius: 12px;
  max-width: 80vw; text-align: center; line-height: 1.5;
}

/* ===== T5 下单流程优化：吸底购物车 / 折叠 / 收据 / 小屏与安全区 ===== */
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.topbar { padding-top: calc(8px + env(safe-area-inset-top)); }
main { padding-bottom: calc(136px + env(safe-area-inset-bottom)); }

.net-hint {
  margin: 0 12px 8px; padding: 8px 10px; border-radius: 10px;
  background: #fff4e5; color: var(--warn); font-size: 13px;
}

.searchbar { position: relative; }
.searchbar input { padding-right: 46px; }
.search-clear {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border-radius: 50%; background: #efe7de;
  color: var(--muted); font-size: 18px; line-height: 1;
}

.card { text-align: left; overflow: hidden; }
.card.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(139, 94, 60, 0.14); }
.card .name { overflow-wrap: anywhere; }

.cart-tip { color: var(--muted); font-size: 13px; padding: 2px 4px 8px; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty-title { font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.empty .ghost { margin-top: 8px; }

/* 吸底购物车条 */
.cartbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--brand); color: #fff;
  box-shadow: 0 -8px 24px rgba(80, 60, 40, 0.2);
}
.cartbar-main { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.cartbar-count { font-size: 13px; opacity: 0.9; }
.cartbar-total { font-size: 20px; font-weight: 700; }
.cartbar-go {
  flex: 0 0 auto; background: #fff; color: var(--brand); font-weight: 700;
  padding: 10px 14px; border-radius: 999px;
}

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 19; background: rgba(47, 38, 32, 0.32);
}
.cart-panel {
  display: flex; flex-direction: column; max-height: 88vh; overflow: hidden;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.sheet-grab {
  width: 42px; height: 4px; border-radius: 999px; background: var(--line);
  margin: 0 auto 8px;
}
.cart-head { flex: 0 0 auto; }
.cart-head-actions { display: flex; gap: 4px; }
.cart-body { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1 1 auto; }
.cart-foot { position: sticky; bottom: 0; background: var(--card); padding-top: 8px; }
.cart-foot .primary { margin-top: 0; }

.cart-row { flex-wrap: nowrap; }
.cart-row .nm { flex: 1 1 auto; min-width: 0; }
.qty input.cart-qty {
  width: 64px; min-width: 56px; padding: 6px 4px; text-align: center;
  border-radius: 8px;
}
.qty input.cart-qty:focus { outline: 2px solid rgba(139, 94, 60, 0.25); }

.field-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }
.pay-grid, .channel-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.pay-grid .seg, .channel-grid .seg { min-height: 42px; padding: 8px 6px; font-size: 14px; }

.fold {
  border: 1px solid var(--line); border-radius: 12px; margin-top: 10px;
  padding: 0 12px; background: var(--card);
}
.fold summary {
  padding: 12px 0; font-weight: 600; cursor: pointer; list-style: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.fold summary::-webkit-details-marker { display: none; }
.fold-note { font-size: 12px; font-weight: 400; color: var(--muted); }
.fold-body { padding-bottom: 12px; }
.fold-body input { margin-bottom: 4px; }

/* 收据 */
.receipt-card { max-width: 400px; }
.receipt-head { text-align: center; margin-bottom: 14px; }
.receipt-ok { color: var(--ok); font-size: 18px; font-weight: 700; }
.receipt-no { margin-top: 6px; font-weight: 600; }
.receipt-time { font-size: 12px; margin-top: 2px; }
.receipt-lines { max-height: 40vh; overflow-y: auto; }
.receipt-line {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px;
}
.receipt-sum { margin-top: 10px; }
.receipt-sum-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-top: 8px; font-size: 18px;
}
.receipt-sum-row strong { color: var(--brand); }
.receipt-meta { margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.receipt-actions { margin-top: 16px; flex-wrap: wrap; }
.receipt-actions .primary { width: auto; margin: 0; padding: 10px 16px; }

/* 小屏：360 / 390 一列更紧凑，按钮不小于 40px */
@media (max-width: 390px) {
  main { padding-left: 10px; padding-right: 10px; }
  .grid { gap: 8px; }
  .card { padding: 10px; min-height: 92px; border-radius: 12px; }
  .card .name { font-size: 15px; }
  .card .price { font-size: 15px; }
  .brand { font-size: 18px; }
  .tabs { padding-left: 10px; padding-right: 10px; }
  .cartbar { padding-left: 12px; padding-right: 12px; }
  .cartbar-total { font-size: 18px; }
  .modal { padding: 12px; }
  .modal-card { padding: 16px; }
  .return-row { gap: 8px; }
  .return-row .return-qty { width: 64px; }
}
@media (max-width: 360px) {
  body { font-size: 15px; }
  .grid { gap: 7px; }
  .card { padding: 9px; min-height: 88px; }
  .card .name { font-size: 14px; }
  .seg { font-size: 13px; padding: 7px 5px; }
  .cart-row .nm div:first-child { font-size: 14px; }
  .qty button { width: 28px; height: 28px; }
  .qty input.cart-qty { width: 56px; }
  .receipt-line { font-size: 13px; }
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

body.is-busy .cart-body, body.is-busy .pay-grid, body.is-busy .channel-grid { pointer-events: none; opacity: 0.75; }


.danger-text { color: var(--danger); }
.cart-panel, .modal-card { overscroll-behavior: contain; }
.receipt-line span:first-child { min-width: 0; overflow-wrap: anywhere; }


.order-memo { font-size: 13px; margin-top: 4px; overflow-wrap: anywhere; }


/* T9: 确认层必须高于退货/收据弹层，避免弹窗内确认被遮挡 */
#modal { z-index: 80; }
#return-modal, #receipt-modal { z-index: 60; }
.badge.employee { background: #e8eefc; color: #2f5d9b; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font-size: 14px; }
.check-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); }
.check-row .muted { font-size: 12px; margin-left: auto; }


/* T15 checkout/auto discount */
#checkout-modal { z-index: 90; }
.discount-lines { margin: 6px 0 2px; }
.discount-row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; color: #2f5d9b; }
.checkout-card { max-height: 88vh; display: flex; flex-direction: column; }
.checkout-title { margin: 0 0 8px; font-size: 18px; }
.checkout-body { overflow: auto; max-height: 46vh; }
.checkout-line { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; }
.checkout-line small { color: #7a5c43; }
.checkout-meta { margin: 8px 0; padding-top: 8px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 13px; }
.checkout-total { margin: 8px 0; padding-top: 8px; border-top: 1px solid var(--line); line-height: 1.7; }
.checkout-total strong { display: flex; justify-content: space-between; font-size: 18px; color: var(--brand); }
.checkout-actions { flex-shrink: 0; }
@media (max-width: 390px) { .checkout-card { width: calc(100vw - 20px); } }


/* T20 variants/stock */
.category-modes { margin: 6px 0; }
.scheme-badge { margin-top: 4px; font-size: 11px; color: #2f5d9b; background: #e8eefc; border-radius: 8px; padding: 2px 6px; display: inline-block; }
.card:disabled { opacity: .55; }
.stock-overview { margin: 8px 0; }
.stock-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
#tab-stock .fold { margin-top: 10px; }
@media (max-width: 390px) { .stock-row { font-size: 13px; } }


/* T28 return layout */
.return-card { max-height: 88vh; overflow: auto; }
.return-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.return-check-line { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; }
.return-row .info { grid-column: 1 / -1; }
.return-row .return-qty { width: 100%; min-width: 0; }
.return-row .return-disposition { width: 100%; min-width: 0; }
@media (max-width: 390px) { .return-row { grid-template-columns: 1fr; } .return-row .info { grid-column: auto; } }


/* T31 stock row actions/modals */
.stock-head { display:flex; justify-content:space-between; align-items:center; gap:8px; }
.stock-actions { display:flex; gap:6px; }
.stock-modal { max-height:88vh; overflow:auto; }
@media (max-width:390px) { .stock-head { align-items:flex-start; flex-direction:column; } }

