/* Mobile-first working surface for the purchasing and sales redesign. */
:root {
  --tap: 50px;
  --nav-height: 72px;
  --editor-footer: 126px;
}

[hidden] { display: none !important; }
body { font-size: 16px; }
body.modal-open { overflow: hidden; }
button { min-height: 44px; cursor: pointer; }
button:disabled { cursor: wait; opacity: .58; }
.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; }
.business-shell { padding-bottom: calc(var(--nav-height) + 50px + env(safe-area-inset-bottom)); }
.business-topbar { align-items: center; }
.brand-copy { min-width: 0; }
.brand-copy h1 { margin: 0; }
.brand-copy small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.topbar-actions button { min-width: 48px; }
.icon-button,.manage-button { min-height: 44px; font-size: 14px; }
.money-toggle { min-width: 44px !important; padding: 0 11px; }
.money-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.money-toggle .eye-closed { display: none; }
.money-toggle[aria-pressed="true"] .eye-open { display: none; }
.money-toggle[aria-pressed="true"] .eye-closed { display: block; }
.owner-switcher label > span { font-size: 14px; }
.owner-switcher select { min-height: 46px; font-size: 16px; }

.business-page { display: grid; gap: 16px; }
.section-heading { margin-bottom: 0; }
.section-heading > span { color: var(--muted); font-size: 14px; }
.page-hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.data-feedback { position: sticky; z-index: 20; top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,253,249,.96); box-shadow: 0 8px 25px rgba(19,47,47,.08); color: var(--muted); font-size: 14px; }
.data-feedback button { padding: 0 16px; border: 0; border-radius: 12px; background: var(--green); color: white; font-weight: 700; }

.quick-actions { margin-top: 2px; }
.quick-card { min-height: 92px; text-align: left; }
.quick-card strong { font-size: 18px; }
.quick-card small { font-size: 13px; line-height: 1.45; }
.dashboard-hero { margin-top: 0; }
.metric-card span { font-size: 14px; }
.metric-card strong { font-size: 20px; }
.negative { color: var(--red) !important; }

.search-field { display: block; }
.search-field input,.group-search { width: 100%; min-height: var(--tap); padding: 0 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--white); color: var(--ink); font-size: 16px; outline: none; }
.search-field input:focus,.group-search:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,63,61,.1); }
.view-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 5px; border-radius: 14px; background: #e9e6df; }
.view-switch button { border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; }
.view-switch button.active { background: var(--white); color: var(--green); box-shadow: 0 3px 12px rgba(19,47,47,.08); }
.region-overview { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 5px; margin: 0; }
.region-overview:has(> [hidden]) { grid-template-columns: repeat(3,minmax(0,1fr)); }
.region-overview > div { gap: 2px; min-width: 0; padding: 8px 6px; border-radius: 11px; }
.region-overview span { font-size: 10px; }
.region-overview strong { font-size: 15px; }
.summary-view { display: grid; gap: 7px; min-width: 0; }

.fee-details,.group-picker,.order-details { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,253,249,.82); }
.fee-details > summary,.group-picker > summary,.order-details > summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: var(--tap); padding: 0 15px; color: var(--ink); font-size: 14px; font-weight: 700; cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
.fee-details > summary::after,.group-picker > summary::after,.order-details > summary::after { content: "展开"; color: var(--green); font-size: 13px; }
.fee-details[open] > summary::after,.group-picker[open] > summary::after,.order-details[open] > summary::after { content: "收起"; }
.group-picker > .page-hint { padding: 0 15px 12px; }
.group-picker #group-cards { display: grid; gap: 10px; padding: 0 12px 12px; }
.group-picker .group-search { width: calc(100% - 24px); margin: 0 12px 12px; }
.fee-details > .field-grid { padding: 0 12px 14px; }
.fee-details summary span,.group-picker summary span { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 500; }

.inventory-list,.order-list,.region-list { display: grid; gap: 13px; }
.catalog-group,.stock-card,.ledger-card,.purchase-choice { border: 1px solid var(--line); border-radius: 18px; background: var(--white); box-shadow: 0 7px 22px rgba(24,49,47,.05); }
.catalog-group { overflow: hidden; }
.catalog-group-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px; border-bottom: 1px solid var(--line); background: rgba(220,232,226,.42); }
.catalog-group-heading h3,.stock-card h3,.card-heading h3 { margin: 0; font-size: 17px; }
.catalog-group-heading strong { color: var(--green); font-size: 15px; }
.catalog-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 15px; border-bottom: 1px solid rgba(22,57,56,.08); }
.catalog-item > div:first-child { display: grid; gap: 4px; min-width: 0; }
.catalog-item strong { font-size: 15px; overflow-wrap: anywhere; }
.catalog-item small { color: var(--muted); font-size: 13px; line-height: 1.45; }
.catalog-item-total { display: grid; flex: 0 0 auto; gap: 3px; text-align: right; }
.catalog-item-total b { font-size: 15px; }
.group-total { margin: 0; padding: 11px 15px; background: #f7f5f0; color: var(--muted); font-size: 13px; font-weight: 700; text-align: right; }
.summary-matrix-wrap { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--white); }
.summary-matrix-wrap > .page-hint { padding: 14px; }
.summary-matrix { width: 100%; table-layout: fixed; border-collapse: collapse; }
.summary-matrix th,.summary-matrix td { padding: 5px 3px; border-right: 1px solid rgba(22,57,56,.07); border-bottom: 1px solid rgba(22,57,56,.08); font-size: 10px; line-height: 1.2; text-align: center; vertical-align: middle; overflow-wrap: anywhere; }
.summary-matrix th:last-child,.summary-matrix td:last-child { border-right: 0; }
.summary-matrix tbody tr:last-child th,.summary-matrix tbody tr:last-child td { border-bottom: 0; }
.summary-matrix thead th { background: rgba(220,232,226,.55); color: var(--muted); font-weight: 800; }
.summary-matrix th:first-child { width: 26%; padding-left: 7px; color: var(--ink); text-align: left; }
.summary-matrix th:last-child { width: 15%; }
.summary-matrix tbody th { background: rgba(247,245,240,.68); font-size: 10px; font-weight: 700; }
.summary-matrix-value { display: grid; justify-items: center; gap: 1px; min-width: 0; }
.summary-matrix-value strong { color: var(--ink); font-size: 11px; white-space: nowrap; }
.summary-matrix-value small { color: var(--muted); font-size: 8px; white-space: nowrap; }
.summary-matrix-total strong { color: var(--green); }
.stock-card { display: grid; gap: 7px; padding: 16px; }
.stock-card p,.stock-card strong,.stock-card small { margin: 0; }
.stock-card p,.stock-card small { color: var(--muted); font-size: 14px; }
.stock-card .secondary-button { justify-self: end; margin-top: 6px; }

.ledger-card { display: grid; gap: 12px; padding: 16px; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.card-heading > strong { color: var(--green); font-size: 15px; white-space: nowrap; }
.owner-tag,.status-line,.order-note,.card-total { margin: 0; }
.owner-tag { width: fit-content; padding: 4px 9px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 700; }
.status-line { color: var(--muted); font-size: 14px; }
.purchase-cup-details,.sale-cup-details { display: grid; gap: 0; margin: 0; }
.card-cup-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.card-cup-line span { min-width: 0; font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.card-cup-line small { flex: 0 0 auto; color: var(--muted); font-size: 13px; text-align: right; }
.order-note { padding: 11px 12px; border-radius: 12px; background: #f6f3ed; color: #526361; font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.card-total { color: var(--ink); font-size: 17px; font-weight: 800; text-align: right; }
.card-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sale-card-metrics { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.sale-card-metrics > * { display: grid; align-content: center; min-height: 58px; padding: 10px 12px; border-radius: 12px; background: #f5f3ee; color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.sale-card-metrics .sale-total-profit { background: var(--green-soft); color: #21664e; }
.order-details { box-shadow: none; }
.order-details[open] { padding-bottom: 12px; }
.order-details > p { margin: 7px 14px; color: var(--muted); font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.order-details .danger { margin: 8px 14px 0; }
.purchase-choice { display: grid; gap: 7px; padding: 13px; box-shadow: none; }
.purchase-choice strong { font-size: 15px; }
.purchase-choice p,.purchase-choice small { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.purchase-choice button { justify-self: end; }

.page-add-bar { position: fixed; z-index: 28; right: max(16px,calc((100vw - 760px) / 2 + 16px)); bottom: calc(var(--nav-height) + 12px + env(safe-area-inset-bottom)); width: auto; padding: 0; pointer-events: none; }
.page-add-bar button { width: auto; min-width: 152px; min-height: 48px; padding: 0 18px; border-radius: 999px; box-shadow: 0 10px 26px rgba(23,63,61,.24); pointer-events: auto; }
#purchases-page,#sales-page { padding-bottom: 86px; }
.empty-card button { min-height: var(--tap); }

.ledger-dialog { z-index: 100; align-items: stretch; padding: 0; background: rgba(11,29,28,.48); }
.ledger-sheet { display: block; width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border-radius: 0; overflow: hidden; background: var(--paper); }
.ledger-sheet > .form-heading { position: sticky; z-index: 5; top: 0; display: grid; grid-template-columns: 72px 1fr 72px; min-height: 62px; margin: 0; padding: max(8px,env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid var(--line); background: rgba(245,241,233,.97); backdrop-filter: blur(16px); }
.ledger-sheet > .form-heading h2 { grid-column: 2; align-self: center; justify-self: center; margin: 0; font-size: 19px; }
.back-button { justify-self: start; min-width: 64px; padding: 0 10px; border: 0 !important; background: transparent !important; color: var(--green); font-size: 15px !important; font-weight: 700; }
.ledger-sheet > form { display: grid; gap: 16px; height: calc(100dvh - 62px); padding: 16px 14px calc(var(--editor-footer) + env(safe-area-inset-bottom)); overflow: auto; overscroll-behavior: contain; }
.ledger-sheet .field > span { color: #526462; font-size: 14px; }
.ledger-sheet .field em { font-size: 13px; }
.ledger-sheet .field input,.ledger-sheet .field select,.ledger-sheet .field textarea { min-height: var(--tap); border-radius: 12px; background: var(--white); font-size: 16px; }
.ledger-sheet .field textarea { min-height: 78px; }
.date-field { max-width: 230px; }
.field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }

.order-lines { display: grid; gap: 14px; }
.order-line { display: block; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--white); box-shadow: 0 5px 18px rgba(20,48,46,.05); }
.line-toolbar { display: flex; align-items: center; gap: 6px; margin-bottom: 13px; }
.line-toolbar strong { margin-right: auto; font-size: 16px; }
.line-toolbar button { min-height: 38px; padding: 0 10px; border: 0; border-radius: 10px; background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 700; }
.line-toolbar button:last-child { background: rgba(198,83,67,.09); color: var(--red); }
.line-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px 10px; }
.line-fields > .field:first-child { grid-column: 1 / -1; }
.line-fields > .field:nth-child(4) { grid-column: 1 / -1; }
.line-fields > .field-grid { grid-column: 1 / -1; grid-template-columns: minmax(134px,168px) minmax(0,1fr); align-items: end; }
.sale-line > .field { margin-bottom: 12px; }
.line-help,.line-subtotal { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.line-subtotal { color: var(--green); font-weight: 800; text-align: right; }
.price-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.price-hint { min-height: 36px; padding: 0 10px; border: 1px solid rgba(23,63,61,.15); border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 13px; }
.quantity-stepper { display: grid; grid-template-columns: 40px minmax(44px,1fr) 40px; width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); overflow: hidden; }
.quantity-stepper button { min-width: 40px; min-height: 46px; padding: 0; border: 0; background: var(--green-soft); color: var(--green); font-size: 21px; font-weight: 800; }
.quantity-stepper input { min-height: 46px !important; }
.quantity-stepper input { width: 100%; min-width: 0; padding: 0 4px !important; border: 0 !important; border-radius: 0 !important; text-align: center; box-shadow: none !important; appearance: textfield; }
.quantity-stepper input::-webkit-inner-spin-button { appearance: none; }
.add-line-button { width: 100%; min-height: 52px; border: 1px dashed rgba(23,63,61,.35); border-radius: 15px; background: rgba(220,232,226,.42); color: var(--green); font-size: 15px; font-weight: 800; }

.pricing-mode { margin: 0; }
.pricing-mode legend { margin-bottom: 9px; font-size: 14px; }
.mode-options span { min-height: var(--tap); font-size: 14px; }
.check-field { min-height: var(--tap); margin: 0; font-size: 14px; }
.check-field input { width: 21px; height: 21px; }
#itemized-price-fields .field:last-child { align-content: center; min-height: 76px; padding: 12px; border-radius: 13px; background: var(--green-soft); }
#itemized-revenue { color: var(--green); font-size: 18px; }

.editor-footer { position: fixed; z-index: 110; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; min-height: var(--editor-footer); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,253,249,.97); box-shadow: 0 -10px 32px rgba(20,48,46,.09); backdrop-filter: blur(16px); }
.editor-total { display: grid; gap: 2px; }
.editor-total span { color: var(--muted); font-size: 13px; }
.editor-total strong { font-size: 21px; font-variant-numeric: tabular-nums; }
.editor-costs { display: flex; align-items: center; justify-content: flex-end; gap: 10px; color: var(--muted); font-size: 12px; }
.editor-costs b { color: var(--ink); font-size: 13px; }
.editor-buttons { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0,.85fr) minmax(0,1.15fr); gap: 9px; }
.editor-buttons button { min-height: 48px; }
.secondary-button { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); color: var(--green); font-size: 14px; font-weight: 800; }
.primary-button { min-height: 48px; font-size: 15px; }
.danger { min-height: 42px; padding: 0 13px; border: 1px solid rgba(198,83,67,.2); border-radius: 11px; background: rgba(198,83,67,.08); color: var(--red); font-size: 13px; font-weight: 700; }

#admin-dialog { z-index: 120; }
.confirm-dialog { z-index: 200; align-items: center; padding: 22px; background: rgba(11,29,28,.52); }
.confirm-sheet { width: min(100%,390px); padding: 22px; border: 1px solid rgba(22,57,56,.12); border-radius: 22px; background: var(--white); box-shadow: 0 24px 70px rgba(11,29,28,.24); text-align: left; }
.confirm-sheet h2 { margin: 0; font-size: 20px; }
.confirm-sheet p { margin: 12px 0 20px; color: var(--muted); font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.confirm-actions button { min-height: 48px; }
.confirm-actions .confirm-danger { border: 0; background: var(--red); color: white; }
.login-form label > span,.login-error,.admin-error { font-size: 14px; }
.login-form input { min-height: 52px; font-size: 16px; }
.login-tabs button,.login-submit { min-height: 46px; font-size: 14px; }
.login-help { font-size: 13px; }
.admin-block-heading p,.new-code-box span,.new-code-box p,.admin-empty,.code-row small { font-size: 13px; }
.code-row strong,.code-actions button,.new-code-box button { font-size: 14px; }
.code-actions button,.new-code-box button { min-height: 42px; }
.admin-sheet .field > span { font-size: 14px; }
.admin-sheet .field input,.admin-sheet .field select { font-size: 16px; }
.bottom-nav button small { font-size: 13px; }

@media (min-width: 680px) {
  .business-shell { padding-right: 28px; padding-left: 28px; }
  .inventory-list,.order-list { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .inventory-list.matrix-mode { grid-template-columns: 1fr; }
  .ledger-dialog { align-items: center; padding: 24px; }
  .ledger-sheet { width: min(100%,760px); height: min(92dvh,900px); border-radius: 24px; }
  .ledger-sheet > form { height: calc(min(92dvh,900px) - 62px); }
  .editor-footer { position: sticky; right: auto; bottom: calc(-1 * var(--editor-footer) - env(safe-area-inset-bottom)); left: auto; margin: 0 -14px calc(-1 * var(--editor-footer) - env(safe-area-inset-bottom)); border-radius: 0 0 24px 24px; }
}

@media (max-width: 430px) {
  .region-overview { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .region-overview:has(> [hidden]) { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .field-grid { grid-template-columns: 1fr; }
  .line-fields { grid-template-columns: 1fr; }
  .line-fields > * { grid-column: 1 / -1 !important; }
  .sale-card-metrics { grid-template-columns: 1fr; }
  .card-cup-line { display: grid; gap: 3px; }
  .card-cup-line small { text-align: left; }
  .line-fields > .field-grid { grid-template-columns: 128px minmax(0,1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
