/* 叫貨通商家後台：各頁元件（訂單流程、訂單詳情、庫存、客戶、列印） */

/* ---------- 訂單中心：工具列與流程列 ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .search-row { flex: 1; min-width: 240px; align-items: center; }
.toolbar .search-row input { margin-top: 0; }
.toolbar .search-row label { max-width: 340px; }
.live-hint { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-3); }
.live-hint::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--line-green); animation: live-pulse 2s infinite; }
.live-hint.is-paused::before { background: var(--amber); animation: none; }
@keyframes live-pulse { 0% { box-shadow: 0 0 0 0 rgba(6, 199, 85, .5); } 70% { box-shadow: 0 0 0 7px rgba(6, 199, 85, 0); } 100% { box-shadow: 0 0 0 0 rgba(6, 199, 85, 0); } }

.pipeline { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.stat-card { position: relative; display: block; padding: 16px 20px 15px; color: var(--ink); text-decoration: none; border-left: 1px solid var(--line); transition: background .15s; }
.stat-card:first-child { border-left: 0; }
.stat-card:hover { background: var(--paper-deep); color: var(--ink); }
.stat-card .stat-step { font: 500 10.5px/1 var(--mono); letter-spacing: .12em; color: var(--ink-3); }
.stat-card .stat-label { display: block; margin-top: 7px; font-weight: 700; font-size: 14.5px; }
.stat-card strong { display: block; margin-top: 2px; font: 600 34px/1.15 var(--mono); letter-spacing: -.03em; }
.stat-card small { color: var(--ink-3); }
.stat-card:not(:first-child)::before {
  content: "→"; position: absolute; left: -11px; top: 50%; transform: translateY(-50%);
  width: 21px; height: 21px; display: grid; place-items: center; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line); color: var(--ink-3); font-size: 11px; z-index: 1;
}
.stat-card.review.has-items strong { color: var(--stamp); }
.stat-card.review.has-items { box-shadow: inset 0 3px 0 var(--stamp); }
.stat-card.customer.has-items strong { color: var(--amber); }
.stat-card.pending.has-items strong { color: var(--pine); }
.stat-card.pending.has-items { box-shadow: inset 0 3px 0 var(--pine); }
.stat-card.done strong { color: var(--ink-3); }

/* ---------- 訂單中心：各階段 ---------- */
.dashboard-section { scroll-margin-top: 76px; }
.section-heading { display: flex; gap: 13px; align-items: flex-start; }
.section-number { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff; font: 600 12px/1 var(--mono); }
.section-count { margin-left: 8px; font: 600 13px/1 var(--mono); color: var(--ink-3); }

.order { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px 18px; margin-bottom: 12px; background: #fff; }
.order.review { border-left: 4px solid var(--stamp); }
.order.is-ready { border-left-color: var(--pine); }
.order-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.order-meta strong { font-size: 16.5px; }
.order-meta span { color: var(--ink-3); font: 500 12.5px/1.4 var(--mono); }
.compare { display: grid; grid-template-columns: minmax(0, 1fr) 30px minmax(0, 1.15fr); align-items: stretch; margin-bottom: 14px; }
.compare > div { padding: 12px 14px; border-radius: var(--radius-sm); }
.compare small { display: block; margin-bottom: 6px; font: 500 11px/1 var(--mono); letter-spacing: .1em; color: var(--ink-3); }
.compare .source { position: relative; background: #e9f7ec; border: 1px solid #c9e8d0; }
.compare .source small { color: #1b8a45; }
.compare .source p { white-space: pre-wrap; word-break: break-word; }
.compare .arrow { display: grid; place-items: center; padding: 0; color: var(--ink-3); font-family: var(--mono); }
.compare .parsed { background: var(--paper); border: 1px solid var(--line-soft); }
.items { margin: 0; padding: 0; list-style: none; }
.items li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.items li:last-child { border-bottom: 0; }
.items li b { font: 600 14px/1.6 var(--mono); white-space: nowrap; }
.items li.needs-review { margin: 2px -8px; padding: 5px 8px; border: 0; border-radius: 5px; background: var(--stamp-tint); color: #8b2a1b; font-weight: 700; }
.items li.needs-review b { margin-left: auto; }
.items li.needs-review::after { content: "待確認"; padding: 1px 7px; border-radius: 20px; background: var(--stamp); color: #fff; font-size: 11px; font-weight: 700; align-self: center; }

.order-line { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 4px; border-bottom: 1px dashed var(--line); }
.order-line:last-of-type { border-bottom: 0; }
.order-line > span { display: grid; min-width: 0; flex: 1; }
.order-line strong { font-size: 15.5px; }
.order-line small { color: var(--ink-3); }
label.order-line { cursor: pointer; font-size: 15px; color: var(--ink); border-radius: var(--radius-sm); padding: 13px 10px; }
label.order-line:hover { background: var(--paper); }
label.order-line:has(input:checked) { background: var(--pine-tint); }
.order-line.printed strong { color: var(--ink-2); }
.batch-head { display: flex; align-items: center; gap: 10px; padding: 0 10px 10px; border-bottom: 2px solid var(--ink); font-size: 13.5px; color: var(--ink-2); }
.batch-head label { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.print-options { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--paper); }
.print-options label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--ink); }
.print-options .button { margin-left: auto; }
.print-options .selected-count { font: 600 13px/1.4 var(--sans); color: var(--ink-3); }
.print-options .selected-count.is-error { color: var(--stamp); }

/* ---------- 訂單詳情 ---------- */
.order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.order-main { min-width: 0; }
.order-rail { position: sticky; top: 76px; display: grid; gap: 14px; }
.order-rail .panel { margin: 0; padding: 18px 20px; }
.order-rail h2 { font-size: 15px; margin-bottom: 10px; }
.order-rail p { font-size: 13.5px; color: var(--ink-2); margin-bottom: 12px; }
.order-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.facts { display: grid; gap: 0; margin: 0; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; font-weight: 500; text-align: right; }
.shipped-stamp { display: inline-block; padding: 5px 14px; border: 2px solid var(--pine); border-radius: 6px; color: var(--pine); font: 900 15px/1.4 var(--serif); letter-spacing: .18em; transform: rotate(-3deg); margin-bottom: 10px; }
.original-message { position: relative; display: inline-block; max-width: 100%; padding: 11px 15px; margin: 0 0 4px 8px; border-radius: 16px 16px 16px 4px; background: #8de37e33; border: 1px solid #b9e3b1; white-space: pre-wrap; word-break: break-word; font-size: 15.5px; }
.message-label { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; font: 500 11.5px/1 var(--mono); letter-spacing: .08em; color: #1b8a45; }
.message-label::before { content: "LINE"; padding: 3px 6px; border-radius: 4px; background: var(--line-green); color: #fff; font-size: 10px; letter-spacing: .04em; }
.subhead { margin: 22px 0 8px; font: 700 15px/1.4 var(--sans); }
tr.needs-review td { background: var(--stamp-tint) !important; color: #8b2a1b; font-weight: 500; }
p.needs-review { margin-top: 14px; padding: 11px 14px; border-radius: var(--radius-sm); background: var(--stamp-tint); color: #8b2a1b; font-weight: 500; }
.order-note { margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--paper); font-size: 14px; }
.order-note b { color: var(--ink-3); font-weight: 500; margin-right: 6px; }
.new-product-prompt { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-color: #e3b2a6; background: #fff8f6; }
.new-product-prompt h2 { font-size: 16px; margin-bottom: 3px; }
.new-product-prompt p { font-size: 13.5px; color: var(--ink-2); }
.edit-item-row { display: grid; grid-template-columns: minmax(0, 1fr) 118px 52px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.edit-item-row select, .edit-item-row input { margin-top: 0 !important; }
.edit-item-row .unit-label { color: var(--ink-3); font-size: 13.5px; }
#addon-rows .edit-item-row { grid-template-columns: minmax(0, 1fr) 118px auto; }
.timeline { margin: 0; padding: 0; list-style: none; }
.history { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.history:last-child { padding-bottom: 0; border-left-color: transparent; }
.history::before { content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--card); border: 2px solid var(--pine); }
.history strong { font: 600 13px/1.4 var(--mono); }
.history span { margin-left: 8px; color: var(--ink-3); font-size: 13px; }
.history details { margin-top: 6px; }
.history summary { cursor: pointer; font-size: 13px; color: var(--pine); }
.history pre { margin: 8px 0 0; padding: 12px; border-radius: var(--radius-sm); background: var(--paper); font: 500 12px/1.6 var(--mono); overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.danger-zone { border-style: dashed; }
.danger-zone p { margin-bottom: 10px; }

/* ---------- 庫存 ---------- */
.stock-list { display: grid; gap: 0; }
.stock-row { border-bottom: 1px dashed var(--line); }
.stock-row:last-child { border-bottom: 0; }
.stock-row > summary { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 16px; padding: 13px 8px; cursor: pointer; list-style: none; border-radius: var(--radius-sm); }
.stock-row > summary::-webkit-details-marker { display: none; }
.stock-row > summary:hover { background: var(--paper); }
.stock-name strong { font-size: 15.5px; }
.stock-name small { color: var(--ink-3); margin-left: 6px; }
.stock-qty { text-align: right; white-space: nowrap; }
.stock-number { font: 600 22px/1.2 var(--mono); letter-spacing: -.02em; }
.stock-qty .unit { color: var(--ink-3); font-size: 13px; margin-left: 4px; }
.stock-row.is-low .stock-number { color: var(--stamp); }
.stock-row .toggle { font-size: 13px; font-weight: 700; color: var(--pine); white-space: nowrap; }
.stock-row[open] .toggle { color: var(--ink-3); }
.stock-row[open] > summary { background: var(--paper); }
.stock-row .fold-body { padding: 14px 8px 20px; }
.delta-plus { color: var(--pine); }
.delta-minus { color: var(--stamp); }

/* ---------- 客戶、商品 ---------- */
.customer-row > summary { grid-template-columns: 40px minmax(0, 1fr) auto auto; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--pine-tint); color: var(--pine); font: 700 17px/1 var(--serif); }
.binding-list { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); }
.binding-list h3 { font-size: 14px; margin-bottom: 8px; }
.binding-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.binding-row:last-child { border-bottom: 0; }
.binding-row > span { display: grid; font: 500 13px/1.5 var(--mono); min-width: 0; word-break: break-all; }
.binding-row small { color: var(--ink-3); font-family: var(--sans); }
.assign-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.assign-row select { margin-top: 0; min-width: 220px; width: auto; flex: 1; max-width: 360px; }
.assign-row label { flex-basis: 100%; }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.catalog-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px; background: #fff; }
.catalog-card h3 { font-size: 15px; margin-bottom: 8px; }
.catalog-card .button { margin-top: 12px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; color: var(--ink); }
.check-row input { margin-top: 3px; }
.check-row span { display: grid; }
.check-row small { color: var(--ink-3); }
.upload-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.upload-row input[type=file] { flex: 1; min-width: 220px; padding: 10px; border: 1px dashed #c9c9c7; border-radius: var(--radius-sm); background: var(--paper); }
.unit-price { display: flex; justify-content: space-between; gap: 14px; max-width: 190px; }
.unit-price b { font: 600 13.5px/1.6 var(--mono); }
.price-input { max-width: 150px; margin-top: 0 !important; text-align: right; }
.sticky-save { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 12px; align-items: center; margin: 0 -24px -22px; padding: 14px 24px; background: rgba(255, 255, 255, .95); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); backdrop-filter: blur(6px); }

/* ---------- 報表 ---------- */
.report-bar { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.report-bar label { min-width: 170px; }
.report-customer { margin-bottom: 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.report-customer-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 12px 16px; background: var(--paper); }
.report-customer-head span { color: var(--ink-2); font-size: 13.5px; }
.report-customer .table-wrap { margin: 0; padding: 0 4px; }

/* ---------- 列印 ---------- */
.print-desk { padding: 28px 16px; margin-bottom: 18px; border-radius: var(--radius); background: #dcdcda; background-image: radial-gradient(rgba(20, 20, 20, .08) 1px, transparent 1px); background-size: 14px 14px; overflow-x: auto; }
.print-controls { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.print-controls span { padding: 4px 12px; border-radius: 20px; background: var(--paper-deep); font-size: 13px; color: var(--ink-2); }
.print-page { width: var(--paper-width, 210mm); min-height: var(--paper-height, 297mm); max-width: none; margin: 0 auto 22px; padding: 12mm; background: #fff; color: #111; box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 14px 30px rgba(0, 0, 0, .16); font: 400 12pt/1.6 var(--sans); }
.print-page:last-child { margin-bottom: 0; }
.print-page header { text-align: center; border-bottom: 1px solid #333; padding-bottom: 8px; margin-bottom: 12px; }
.print-page header h1 { font: 700 18pt/1.4 var(--sans); margin: 0 0 10px; }
.print-page table { font-size: 12pt; }
.print-page table th { color: #111; font-size: 11pt; letter-spacing: 0; border-bottom: 1px solid #777; padding: 6px 4px; }
.print-page table td { border-bottom: 1px solid #777; padding: 6px 4px; }
.print-page tbody tr:hover td { background: none; }
.print-page footer { text-align: right; font-weight: 700; margin: 14px 0; }
.signature { text-align: right; margin-top: 24px; }
.test-print-page { position: relative; padding: var(--margin-top, 0) var(--margin-right, 0) var(--margin-bottom, 0) var(--margin-left, 0); }
.test-mark { font: 500 10pt/1 var(--mono); }
.test-mark.bottom { position: absolute; right: var(--margin-right, 0); bottom: var(--margin-bottom, 0); }
.test-cross { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font: 500 11pt/1 var(--mono); }
.test-ruler { margin-top: 10mm; padding: 2mm 0; border-top: 1px solid #000; border-bottom: 1px solid #000; text-align: center; font-size: 10pt; }
.confirm-list { display: grid; gap: 0; }
.confirm-list .inline { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px dashed var(--line); }
.confirm-list .inline:last-child { border-bottom: 0; }
.confirm-list span { font-weight: 500; }

@media (max-width: 960px) {
  .order-layout { grid-template-columns: minmax(0, 1fr); }
  .order-rail { position: static; }
  .dashboard-section { scroll-margin-top: 64px; }
}
@media (max-width: 720px) {
  .pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card:nth-child(3) { border-left: 0; }
  .stat-card:nth-child(n+3) { border-top: 1px solid var(--line); }
  .stat-card::before { display: none !important; }
  .stat-card strong { font-size: 28px; }
  .compare { grid-template-columns: 1fr; }
  .compare .arrow { padding: 4px 0; transform: rotate(90deg); }
  .order-line { flex-wrap: wrap; }
  .print-options .button { margin-left: 0; width: 100%; }
  .edit-item-row, #addon-rows .edit-item-row { grid-template-columns: minmax(0, 1fr) 96px auto; }
  .edit-item-row .unit-label { display: none; }
  .stock-row > summary { grid-template-columns: minmax(0, 1fr) auto; }
  .stock-row .toggle { display: none; }
  .customer-row > summary { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .sticky-save { margin: 0 -16px -18px; padding: 12px 16px; }
  .table-wrap table { min-width: 560px; }
  .print-page table { min-width: 0; }
}

@media print {
  @page { margin: 0; }
  body { background: #fff; }
  .sidebar, .workspace-header, .workspace-footer, .messages, .no-print, .skip-link { display: none !important; }
  .app-layout { display: block; }
  .shell { max-width: none; padding: 0; margin: 0; }
  .print-desk { padding: 0; margin: 0; background: none; overflow: visible; border-radius: 0; }
  /* 紙張尺寸與邊距沿用原本的列印規則，避免影響實機對位 */
  .print-page { width: auto; min-height: 0; height: var(--paper-height, 297mm); margin: 0; padding: var(--margin-top, 12mm) var(--margin-right, 12mm) var(--margin-bottom, 12mm) var(--margin-left, 12mm); border: 0; box-shadow: none; page-break-after: always; break-after: page; }
  .print-page:last-of-type { page-break-after: auto; break-after: auto; }
  .print-page table { page-break-inside: avoid; }
}

/* ---------- 配色：成功狀態維持綠色 ---------- */
.delta-plus { color: var(--ok); }
.shipped-stamp { border-color: var(--ok); color: var(--ok); }
.history::before { border-color: var(--accent); }
.stat-card.pending.has-items { box-shadow: inset 0 3px 0 var(--ink); }
label.order-line:has(input:checked) { background: #fff1ea; }
