/* ── 門市叫貨／工廠收單（store.html、factory.html）── */
:root {
  --bg: #f3ece0;
  --surface: #faf6ef;
  --surface-2: #fffdf8;
  --border: #e8ddc8;
  --text: #1a0f08;
  --text-2: #5c4a3a;
  --muted: #a8916f;
  --accent: #8b1a1a;
  --accent-hover: #b5312a;
  --gold: #c9a84c;
  --gold-light: #f5ecd4;
  --ok: #2d7a4f;
  --info: #2563eb;
  --warn: #b45309;
  --shadow: 0 1px 3px rgba(26,15,8,0.07), 0 1px 2px rgba(26,15,8,0.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: 'Noto Sans TC', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* Top bar */
.om-topbar { background: var(--accent); color: #f5e6c0; height: 52px; padding: 0 16px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; }
.om-topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: linear-gradient(90deg, #8b1a1a, #c9a84c, #8b1a1a); }
.om-brand { font-family: 'Noto Serif TC', serif; letter-spacing: 0.16em; font-size: 15px; white-space: nowrap; }
.om-spacer { flex: 1; }
.om-user { font-size: 13px; opacity: 0.85; }
.om-topbar button { background: transparent; border: 1px solid rgba(245,230,192,0.4); color: #f5e6c0; border-radius: 5px; padding: 4px 10px; cursor: pointer; font-size: 12px; }
.om-topbar button:hover { background: rgba(201,168,76,0.2); }

/* Login */
.om-login { min-height: 100vh; display: none; align-items: center; justify-content: center; padding: 16px; }
.om-login-card { background: var(--surface); width: 100%; max-width: 360px; border-radius: 8px; box-shadow: 0 4px 16px rgba(26,15,8,0.12); padding: 32px 28px; border-top: 3px solid var(--accent); }
.om-login-card h1 { font-family: 'Noto Serif TC', serif; font-weight: 500; font-size: 20px; letter-spacing: 0.2em; text-align: center; color: var(--accent); }
.om-login-card .sub { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 0 22px; letter-spacing: 0.1em; }
.om-field { display: block; margin-bottom: 14px; }
.om-field span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.om-input { width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px; padding: 9px 10px; font-size: 15px; }
.om-input:focus, .qty:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: var(--gold); }
.om-error { padding: 8px 10px; background: #fdf5f5; border: 1px solid #fecaca; border-radius: 4px; color: var(--accent); font-size: 13px; margin-bottom: 12px; text-align: center; }
.om-denied { min-height: 80vh; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px; text-align: center; color: var(--text-2); }

/* Buttons */
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 7px 14px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--gold); background: var(--bg); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #faf6ef; font-family: 'Noto Serif TC', serif; letter-spacing: 0.08em; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: #b91c1c; border-color: #e7b4b4; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }

/* Layout */
.om-main { max-width: 1500px; margin: 0 auto; padding: 16px; }
.om-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.om-tab { border: none; background: none; padding: 9px 16px; cursor: pointer; font-size: 14px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.om-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.om-card { background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); }
.om-muted { color: var(--muted); font-size: 12px; }

/* Order header form */
.oh { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 14px; padding: 14px 16px; margin-bottom: 12px; }
.oh label span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 3px; }
.oh .om-input { padding: 7px 9px; font-size: 14px; }
.oh-store { font-family: 'Noto Serif TC', serif; font-size: 22px; color: var(--accent); letter-spacing: 0.1em; align-self: end; }
.edit-banner { background: #fff7e6; border: 1px solid #f5d38a; color: #8a5a00; border-radius: 6px; padding: 9px 12px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }

.of-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.of-tools .om-input { max-width: 240px; padding: 7px 10px; font-size: 14px; }
.of-tools label { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; }

/* Category cards */
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 14px; align-items: start; padding-bottom: 90px; }
.cat { background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.cat-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: var(--accent); color: #f5e6c0; cursor: pointer; user-select: none; }
.cat-head .name { font-family: 'Noto Serif TC', serif; letter-spacing: 0.12em; font-size: 15px; flex: 1; }
.cat-head .sum { font-size: 12px; opacity: 0.9; }
.cat-head .arrow { transition: transform .15s; font-size: 11px; }
.cat.collapsed .cat-head .arrow { transform: rotate(-90deg); }
.cat.collapsed .cat-body { display: none; }
.cat-body { overflow-x: auto; }
.ot { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 340px; }
.ot th { font-size: 11px; font-weight: 600; color: var(--text-2); padding: 6px 6px; border-bottom: 1px solid var(--border); background: var(--gold-light); white-space: nowrap; }
.ot th.grp { text-align: center; }
.ot td { padding: 3px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ot tr.filled td { background: #fffbea; }
.ot tr:last-child td { border-bottom: none; }
.ot .nm { font-weight: 500; min-width: 90px; white-space: normal; }
.ot .upb { display: block; font-size: 10px; color: var(--muted); font-weight: 400; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.ot .sep { border-left: 1px solid var(--border); }
.qwrap { display: inline-flex; align-items: center; gap: 2px; }
.qty { width: 46px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 4px; padding: 5px 4px; text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }
.qty:disabled { background: transparent; border-style: dashed; color: transparent; }
.qty::-webkit-outer-spin-button, .qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty { -moz-appearance: textfield; }
.qb { display: inline-flex; align-items: center; gap: 2px; }
.qb.none { visibility: hidden; }
.qu { font-size: 11px; color: var(--muted); margin-right: 3px; }
.sub-amt { color: var(--text-2); font-size: 12px; }

/* Sticky footer */
.of-foot { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 2px solid var(--gold); padding: 10px 16px; display: flex; align-items: center; gap: 18px; z-index: 15; box-shadow: 0 -4px 12px rgba(26,15,8,0.06); flex-wrap: wrap; }
.of-foot .tot { display: flex; flex-direction: column; }
.of-foot .tot span { font-size: 11px; color: var(--text-2); }
.of-foot .tot b { font-size: 18px; font-variant-numeric: tabular-nums; }
.of-foot .draft { font-size: 11px; color: var(--muted); }

/* Status tags */
.st { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.st-submitted { background: #fdf0dc; color: var(--warn); }
.st-transferred { background: #e3f1e8; color: var(--ok); }
.st-cancelled { background: #eee; color: #888; }
.st-none { background: transparent; color: var(--muted); font-weight: 400; }

/* Lists */
.lt { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.lt th { background: var(--accent); color: #f5e6c0; font-weight: 500; font-size: 12px; padding: 9px 10px; text-align: left; white-space: nowrap; }
.lt td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.lt tr:last-child td { border-bottom: none; }
.lt tr.dim td { color: var(--muted); }
.lt input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
.lt-wrap { overflow-x: auto; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Order detail */
.od-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 14px; margin-bottom: 12px; font-size: 14px; }
.od-meta span { display: block; font-size: 11px; color: var(--text-2); }
.od-notes { background: var(--gold-light); padding: 8px 10px; border-radius: 6px; margin-bottom: 10px; font-size: 13px; white-space: pre-wrap; }
.od-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.od-table th { font-size: 11px; color: var(--text-2); padding: 6px; border-bottom: 1px solid var(--border); text-align: left; }
.od-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); }
.od-table .od-cat td { background: var(--gold-light); font-weight: 700; font-size: 12px; color: var(--accent); }
.od-table tfoot td { font-weight: 700; border-top: 2px solid var(--gold); }
.od-strong { font-weight: 700; }
.od-zero { color: var(--muted); }
.od-upb { font-size: 10px; color: var(--muted); margin-left: 6px; }

/* Modal */
.om-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; align-items: center; justify-content: center; padding: 12px; }
.om-overlay.open { display: flex; }
.om { background: var(--surface); border-radius: 8px; width: 100%; max-width: 820px; max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; border-top: 3px solid var(--accent); }
.om-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); font-family: 'Noto Serif TC', serif; font-size: 15px; letter-spacing: 0.06em; }
.om-x { width: 30px; height: 30px; border: 1px solid var(--border); background: var(--bg); border-radius: 5px; cursor: pointer; }
.om-body { padding: 16px 18px; overflow-y: auto; }
.om-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }

/* Toast */
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1a0f08; color: #faf6ef; padding: 10px 18px; border-radius: 6px; font-size: 14px; opacity: 0; transition: all .2s; z-index: 200; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #8b1a1a; }

/* Factory */
.datebar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.datebar .om-input { width: auto; padding: 6px 9px; font-size: 14px; }
.datebar .big { font-family: 'Noto Serif TC', serif; font-size: 20px; color: var(--accent); margin-left: 6px; }
.fsum th.store, .fsum td.store { text-align: right; min-width: 52px; }
.fsum td { font-size: 15px; }
.fsum td.store { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fsum td.tot { font-weight: 700; text-align: right; font-size: 18px; }
.fsum tr.cat td { background: var(--gold-light); color: var(--accent); font-weight: 700; font-size: 12px; }
.fsum td { white-space: nowrap; }

@media (max-width: 640px) {
  .om-main { padding: 10px; }
  .cats { grid-template-columns: 1fr; }
  .om-brand { font-size: 13px; letter-spacing: 0.08em; }
  .oh { grid-template-columns: 1fr 1fr; padding: 12px; }
  .oh-store { grid-column: 1 / -1; font-size: 20px; }
  .of-foot { gap: 12px; padding: 8px 10px; }
  .of-foot .tot b { font-size: 16px; }
  .of-foot .btn-primary { flex: 1; }
  .ot { min-width: 0; }
  .ot .m-hide { display: none; }
  .ot td { padding: 3px 4px; }
  .qty { width: 40px; }
  .qu { margin-right: 1px; }
}

.od-table th.num, .ot th.num, .lt th.num { text-align: right; }

@media print {
  body:has(.om-overlay.open) #om-app { display: none; }
  .om-overlay.open { position: static; background: none; padding: 0; }
  .om-overlay.open .om { max-height: none; border: none; }
  .om-head .om-x, .om-foot { display: none !important; }
  .om-topbar, .om-tabs, .datebar .btn, .no-print, .of-foot, .toast { display: none !important; }
  body { background: #fff; }
  .lt, .om-card { box-shadow: none; }
  .lt th { background: #eee !important; color: #000 !important; }
}

/* 工廠用叫貨單（揀貨單）：各分類並排，品名和數量同字級 */
.pk-head { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-bottom: 12px; font-size: 14px; }
.pk-head span { font-size: 11px; color: var(--text-2); margin-right: 5px; }
.pk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: start; }
.pk-col { min-width: 0; }
.pk-col > .pk-table + .pk-table { margin-top: 6px; }
.pk-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.pk-table th, .pk-table td { border: 1px solid #c9b896; padding: 3px 6px; }
.pk-table th { background: var(--gold-light); color: var(--accent); font-weight: 700; text-align: left; white-space: nowrap; }
.pk-table td { white-space: nowrap; }
.pk-table .pk-q { text-align: right; width: 1%; }
.pk-table th.pk-q { font-size: 12px; color: var(--text-2); font-weight: 600; }
.pk-table tr.pk-on td { font-weight: 700; background: #fffbea; }
.om.om-wide { max-width: 1200px; }
.pk-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.pk-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

/* 列印揀貨單：A4 橫式一張。所有分類排成一橫排（--pk-cols = 分類數），
   factory.js 列印前用 .pk-print 量高度，超出一頁就整體等比例縮小（zoom） */
body.pk-print #m-view .om { width: 1077px; max-width: none; }   /* 297mm − 邊界 12mm ≈ 285mm */
body.pk-print #m-view.om-overlay { padding: 0; }
body.pk-print #m-view .om { background: #fff; border: none; border-radius: 0; box-shadow: none; }
body.pk-print #m-view .om-body, .pk-sheet-print { padding: 0; overflow: visible; }
body.pk-print .pk-head, .pk-sheet-print .pk-head { font-size: 11px; gap: 2px 16px; margin-bottom: 4px; }
body.pk-print .pk-head span { font-size: 9px; }
body.pk-print .od-notes { font-size: 10px; padding: 2px 6px; margin-bottom: 4px; }
body.pk-print .pk-grid { grid-template-columns: repeat(var(--pk-cols, 6), minmax(0, 1fr)); gap: 3px; }
body.pk-print .pk-table { font-size: var(--pk-fs, 9px); table-layout: fixed; }
body.pk-print .pk-table th, body.pk-print .pk-table td { padding: 0 2px; line-height: var(--pk-lh, 1.25); overflow: hidden; white-space: nowrap; }
body.pk-print .pk-table th:first-child { width: 50%; }
body.pk-print .pk-table td:first-child { white-space: normal; word-break: normal; overflow-wrap: anywhere; }
body.pk-print .pk-table .pk-q { width: auto; }
body.pk-print .pk-table th.pk-q { font-size: calc(var(--pk-fs, 9px) - 1px); }

@media print {
  .pk-table tr.pk-on td { background: none; }
  .pk-table tr.pk-on td:first-child { text-decoration: underline; }
  .pk-table th { background: #eee !important; color: #000 !important; }
  .pk-table { break-inside: avoid; }
  body.pk-print #m-view .om { width: auto; }
}

/* 叫貨／庫存：一格顯示，點進去填箱／個 */
.ot td.qc { padding: 3px 5px; width: 34%; }
.qcell { width: 100%; min-height: 34px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 5px; cursor: pointer; text-align: right; padding: 5px 9px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.qcell:hover { border-color: var(--gold); }
.qcell .q-short { display: none; }
.qcell:focus-visible, .qcell.editing { outline: 2px solid var(--gold); outline-offset: -1px; border-color: var(--gold); }
.qpop { position: fixed; z-index: 50; display: none; background: var(--surface); border: 1px solid var(--gold); border-radius: 8px; box-shadow: 0 6px 24px rgba(26,15,8,0.18); padding: 10px 12px; min-width: 200px; }
.qpop.open { display: block; }
.qpop-title { font-size: 13px; font-weight: 700; margin-bottom: 8px; white-space: nowrap; }
.qpop-title span { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 6px; }
.qpop-row { display: flex; gap: 10px; }
.qpop-row label { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--text-2); }
.qpop-in { width: 64px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 5px; padding: 7px 8px; font-size: 16px; text-align: right; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.qpop-in::-webkit-outer-spin-button, .qpop-in::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qpop-in:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
.qpop-btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }

.oh-notes { grid-column: 1 / -1; }

/* 電腦：像紙本盤點表一樣，所有分類並排塞進一個畫面（約一張 A4 橫式） */
.th-cat { display: none; }

/* 電腦：跟揀貨單（列印）一樣的版面——所有分類排成一橫排、表格格線，所有品項在同一個畫面 */
@media all {   /* A4 紙本版面：所有螢幕都用，螢幕小就縮放＋捲動 */
  .om-main:has(.cats) { max-width: none; padding: 8px 10px; }
  .oh { grid-template-columns: auto repeat(4, minmax(130px, 170px)) 1fr; padding: 4px 12px; gap: 4px 12px; margin-bottom: 4px; }
  .oh label span { margin-bottom: 1px; }
  .oh .om-input { padding: 3px 8px; }
  .oh-notes { grid-column: auto; }
  .oh-store { font-size: 20px; }
  .of-tools { margin-bottom: 4px; }
  .of-tools .om-input { padding: 4px 10px; }
  .cards-only { display: none; }
  .cats { grid-template-columns: repeat(var(--cols, 9), minmax(0, 1fr)); gap: 3px; padding-bottom: 64px; }
  .cat { border-radius: 0; box-shadow: none; background: #fff; }
  .cat-head { display: none; }
  .cat.collapsed .cat-body { display: block; }
  .cat-body { overflow: visible; }
  .th-cat { display: inline; }
  .th-item { display: none; }
  .ot { min-width: 0; font-size: 12px; table-layout: fixed; border-collapse: collapse; }
  .ot th, .ot td { border: 1px solid #c9b896; }
  .ot th { padding: 2px 3px; font-size: 10px; line-height: 14px; background: var(--gold-light); color: var(--text-2); }
  .ot th.th-name { width: 46%; text-align: left; font-size: 12px; font-weight: 700; color: var(--accent); }
  .ot td { padding: 0; line-height: 14px; height: 19px; }
  .ot .nm { font-size: 12px; font-weight: 500; min-width: 0; padding: 1px 3px; white-space: normal; word-break: normal; overflow-wrap: anywhere; line-height: 1.15; }
  .ot td.qc { width: auto; padding: 0; }
  .ot .sep { border-left: 1px solid #c9b896; }
  .ot tr.filled td { background: #fff7d6; }
  .ot tr.filled .nm { font-weight: 700; text-decoration: underline; }
  .qcell { display: block; width: 100%; min-height: 18px; height: 100%; line-height: 17px; padding: 0 3px; font-size: 12px; border: none; border-radius: 0; background: transparent; white-space: nowrap; overflow: hidden; letter-spacing: -0.02em; }
  .qcell:hover { background: rgba(201,168,76,0.18); }
  .qcell.editing { outline: 2px solid var(--accent); outline-offset: -2px; }
  .om-tabs { margin-bottom: 4px; }
  .om-tab { padding: 5px 14px; }
  .of-foot { padding: 5px 16px; }
  .of-foot .tot b { font-size: 16px; }
}

/* 工廠實際出貨 */
.od-ship, .pk-ship { color: #b45309; font-weight: 700; }
.pk-edit { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; font-size: 12px; color: var(--text-2); }
.pk-edit input { width: 42px; padding: 2px 4px; border: 1px solid var(--gold); border-radius: 4px; background: #fff; text-align: right; font-size: 13px; -moz-appearance: textfield; }
.pk-edit input::-webkit-outer-spin-button, .pk-edit input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.st-picking { background: #e0e9fb; color: #2563eb; }
.st-shipped { background: #ede5fb; color: #6d28d9; }
.st-received { background: #e3f1e8; color: var(--ok); }
.st-diff { background: #fde2e2; color: #b91c1c; }
.st-receiving { background: #e0e9fb; color: #2563eb; }
/* 點貨：點好了打勾（分批到貨可以暫存，下次接著點） */
.rv-table .rv-ok { width: 40px; text-align: center; padding: 0; }
.rv-ok label { display: flex; align-items: center; justify-content: center; min-height: 36px; cursor: pointer; }
.rv-chk { width: 22px; height: 22px; accent-color: var(--ok); cursor: pointer; }
.rv-table tr.rv-done td { background: #f1f8f3; }
.rv-table tr.rv-done td:not(.rv-ok) { color: var(--muted); }
.rv-table.rv-hide-done tr.rv-done { display: none; }
.rv-filter { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.st-transferred { background: #fff1d6; color: #8a5a00; }
.od-recv, .pk-recv { color: #b91c1c; font-weight: 700; }
.rv-edit { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; font-size: 13px; color: var(--text-2); }
.rv-edit input { width: 52px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); text-align: right; font-size: 15px; -moz-appearance: textfield; }
.rv-edit input::-webkit-outer-spin-button, .rv-edit input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rv-edit.diff input { border-color: #b91c1c; background: #fdf5f5; color: #b91c1c; font-weight: 700; }

/* 中文／音譯切換 */
.nm-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); vertical-align: middle; }
.nm-toggle button { border: none; background: none; padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--text-2); }
.nm-toggle button + button { border-left: 1px solid var(--border); }
.nm-toggle button.on { background: var(--accent); color: #faf6ef; font-weight: 700; }
.desk-only { display: none; }
.desk-only { display: inline-flex; }

/* 電腦版盤點畫面＝一張 A4 橫式的紙（跟列印的盤點單同排版），整張縮放放進畫面（store.js fitSheet） */
@media all {   /* A4 紙本版面：所有螢幕都用，螢幕小就縮放＋捲動 */
  .paper-wrap { display: block; overflow: auto; padding: 4px 4px 8px; background: var(--bg); }   /* 高度由 store.js fitSheet 設成「工具列到底部總額列」之間 */
  .paper { margin: 0 auto; width: 1077px; min-height: 740px; background: #fff; box-shadow: 0 2px 14px rgba(26,15,8,0.14); padding: 10px 12px; }
  .paper .oh { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; background: none; box-shadow: none; border-radius: 0; padding: 0 0 6px; margin: 0; }
  .paper .oh label { display: flex; align-items: center; gap: 4px; }
  .paper .oh label span { display: inline; font-size: 11px; color: var(--text-2); margin: 0; white-space: nowrap; }
  .paper .oh .om-input { width: auto; border: none; border-bottom: 1px solid #c9b896; border-radius: 0; background: transparent; padding: 1px 4px; font-size: 13px; }
  .paper .oh input[type=date].om-input { width: 132px; }
  .paper .oh input:not([type]).om-input { width: 90px; }
  .paper .oh .oh-notes { flex: 1; }
  .paper .oh .oh-notes .om-input { width: 100%; }
  .paper .oh-store { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: 0.06em; align-self: center; }
  .paper .oh select.om-input { padding: 1px 4px; font-size: 13px; }
  .paper .cats { padding-bottom: 0; gap: 3px; }
  .paper .ot th { background: #efefef; color: #333; font-size: 9px; padding: 1px 2px; line-height: 12px; }
  .paper .ot th.th-name { color: #1a0f08; font-size: 10px; width: 50%; }
  .paper .ot td { height: 21px; line-height: 12px; }
  .paper .ot tr:last-child td { border-bottom: 1px solid #c9b896; }   /* 最後一列也要底線（手機卡片版才不畫） */
  .paper .ot .nm { font-size: 10.5px; padding: 1px 3px; }
  .paper .qcell { font-size: 10.5px; min-height: 20px; line-height: 19px; padding: 0 2px; text-align: right; }
}

/* 音譯模式：品名比中文長 → 品名欄加寬、字小一點、行距收緊，兩行也放得進同一格 */
@media all {   /* A4 紙本版面：所有螢幕都用，螢幕小就縮放＋捲動 */
  body.nm-en .paper .ot th.th-name { width: 60%; }
  body.nm-en .paper .ot .nm { font-size: 9.5px; line-height: 11px; letter-spacing: -0.01em; padding: 1px 2px; }
}
body.nm-en.pk-print .pk-table th:first-child { width: 60%; }
body.nm-en.pk-print .pk-table td:first-child { letter-spacing: -0.01em; }

/* 盤點紙本的縮放控制 */
.zoom-ctl { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); }
.zoom-ctl button { border: none; background: none; padding: 4px 10px; font-size: 14px; cursor: pointer; color: var(--text-2); }
.zoom-ctl button:hover { background: var(--gold-light); }
.zoom-ctl button.fit { font-size: 12px; border-left: 1px solid var(--border); }
.zoom-ctl button.fit.on { background: var(--accent); color: #faf6ef; }
.zoom-ctl .pct { min-width: 46px; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; border-left: 1px solid var(--border); border-right: 1px solid var(--border); padding: 4px 0; }

/* 盤點紙本的捲動條：一直顯示（Mac 預設會自動隱藏） */
.paper-wrap::-webkit-scrollbar { width: 14px; height: 14px; }
.paper-wrap::-webkit-scrollbar-track { background: #e9dfcd; border-radius: 7px; }
.paper-wrap::-webkit-scrollbar-thumb { background: #b9a27a; border-radius: 7px; border: 3px solid #e9dfcd; }
.paper-wrap::-webkit-scrollbar-thumb:hover { background: #8b1a1a; }
.paper-wrap::-webkit-scrollbar-corner { background: transparent; }
.paper-wrap { scrollbar-color: #b9a27a #e9dfcd; }

/* 視窗裡的 A4 叫貨單（唯讀）：一張紙縮放到視窗寬度 */
.om.om-sheet { max-width: min(96vw, 1400px); }
.om-overlay:has(.sheet-zoom) { align-items: flex-start; padding-top: 4vh; }   /* 調大小時標題列不跟著跳 */
.sheet-view { overflow: auto; }
/* 放大後表格比視窗寬：讓表格區塊填滿視窗、自己上下左右捲，左右捲軸才會一直在視窗底部（不用先捲到表格最下面） */
@media screen {
  body:not(.pk-print) .om.om-sheet .om-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  body:not(.pk-print) .om.om-sheet .sheet-view { flex: 1; min-height: 0; }
}
.sheet-view::-webkit-scrollbar { width: 14px; height: 14px; }
.sheet-view::-webkit-scrollbar-track { background: #e9dfcd; border-radius: 7px; }
.sheet-view::-webkit-scrollbar-thumb { background: #b9a27a; border-radius: 7px; border: 3px solid #e9dfcd; }
.sheet-view::-webkit-scrollbar-thumb:hover { background: #8b1a1a; }
.sheet-view::-webkit-scrollbar-corner { background: transparent; }
.sheet-zoom { display: flex; align-items: center; gap: 6px; margin: 0 12px 0 auto; font-family: inherit; letter-spacing: 0; font-size: 13px; }
.sheet-zoom .btn { padding: 3px 9px; font-size: 13px; font-family: system-ui, sans-serif; }
.sheet-zoom input[type=range] { width: 160px; max-width: 30vw; accent-color: var(--accent); }
.sheet-zoom-pct { min-width: 42px; font-variant-numeric: tabular-nums; color: var(--text-2); }
.sheet-zoom .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.sheet-page { width: 1077px; background: #fff; padding: 8px 10px; }
.sheet-page .pk-head { font-size: 12px; gap: 2px 16px; margin-bottom: 4px; }
.sheet-page .pk-head span { font-size: 10px; }
.sheet-page .pk-grid { grid-template-columns: repeat(var(--pk-cols, 9), minmax(0, 1fr)); gap: 3px; }
.sheet-page .pk-table { font-size: 10.5px; table-layout: fixed; }
.sheet-page .pk-table th, .sheet-page .pk-table td { padding: 1px 2px; line-height: 1.35; white-space: nowrap; overflow: hidden; }
.sheet-page .pk-table th { background: #efefef; color: #333; font-size: 9px; }
.sheet-page .pk-table th:first-child { width: 46%; font-size: 10px; color: #1a0f08; }
.sheet-page .pk-table .pk-q { width: auto; text-align: right; }
.sheet-page .pk-table td:first-child { white-space: normal; word-break: normal; overflow-wrap: anywhere; }
.sheet-page .pk-table tr.pk-on td { background: #fff7d6; font-weight: 700; }
body.nm-en .sheet-page .pk-table th:first-child { width: 56%; }
body.nm-en .sheet-page .pk-table td:first-child { font-size: 9.5px; }
.sheet-page .pk-edit { gap: 1px; font-size: 9px; }
.sheet-page .pk-edit input { width: 26px; padding: 0 2px; font-size: 10px; }
.sheet-page .pk-ship { color: #b45309; }
.sheet-page .pk-recv { color: #b91c1c; }
/* 工廠回報實際出貨（同一張 A4）：實出欄加寬，箱＋個放不下就換行 */
.sheet-editing .pk-table th:first-child, body.nm-en .sheet-editing .pk-table th:first-child { width: 40%; }
.sheet-editing .pk-table th:nth-child(2) { width: 22%; }
.sheet-editing .pk-table td.pk-q { overflow: visible; }
.sheet-editing .pk-edit { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 1px 2px; }
.sheet-editing .pk-edit input { width: 24px; padding: 0 2px; font-size: 10.5px; border-radius: 2px; }

/* 音譯模式的數量（例如 1 Xiang 20 Ge）比較長：數量欄可以換行 */
body.nm-en .paper .qcell { white-space: normal; line-height: 10px; padding: 1px 2px; font-size: 9.5px; }
body.nm-en .sheet-page .pk-table td.pk-q, body.nm-en.pk-print .pk-table td.pk-q { white-space: normal; line-height: 1.15; }
/* 音譯：品名欄窄一點、數量欄寬一點，「10 He」放得進一行 */
body.nm-en .paper .ot th.th-name { width: 50%; }
body.nm-en .sheet-page .pk-table th:first-child, body.nm-en.pk-print .pk-table th:first-child { width: 50%; }
body.nm-en .sheet-page .pk-table td.pk-q { font-size: 9.5px; padding: 1px 1px; }
/* 門市點貨後多一欄「實收」：品名欄讓出寬度，數量放不下就換行（不要被切掉） */
.sheet-page .pk-table.pk-has-recv th:first-child, body.nm-en .sheet-page .pk-table.pk-has-recv th:first-child,
body.pk-print .pk-table.pk-has-recv th:first-child { width: 38%; }
.sheet-page .pk-table.pk-has-recv td.pk-q, body.pk-print .pk-table.pk-has-recv td.pk-q { white-space: normal; overflow-wrap: anywhere; }
.sheet-page .pk-table.pk-has-recv td.pk-q { line-height: 1.15; }
.sheet-a4 .pk-table.pk-has-recv th:first-child { width: 40%; }
#m-confirm-box { z-index: 150; }

/* 數量文字（例如 2箱1個）：「2箱」「1個」不拆開，格子放不下就分兩行，不會被切掉 */
.qcell .qt { display: inline-block; white-space: nowrap; }
.paper .qcell { white-space: normal; line-height: 10px; letter-spacing: -0.03em; }
.paper .cats:not(.mode-count) .ot th.th-name { width: 44%; }

/* 盤點模式：只有「庫存」一欄，直接在格子裡填箱／個 */
.mode-toggle button { white-space: nowrap; }
.ot td.qc-in { padding: 0 2px; text-align: right; }
.qin-wrap { display: inline-flex; align-items: center; justify-content: flex-end; gap: 0; white-space: nowrap; }
.paper .cats.mode-count .ot th.th-name, body.nm-en .paper .cats.mode-count .ot th.th-name { width: 38%; }
.paper .cats.mode-count .ot-small th.th-name, body.nm-en .paper .cats.mode-count .ot-small th.th-name { width: 62%; }   /* 只有「個」的分類：一格就夠，品名欄寬一點 */
.qin { width: 22px; height: 17px; padding: 0 2px; border: 1px solid #d8c9a8; border-radius: 2px; background: #fffdf8; text-align: right; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.qin::-webkit-outer-spin-button, .qin::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qin:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); background: #fff; }
.qin-u { font-size: 9px; color: var(--text-2); margin: 0 1px 0 0; }
body.nm-en .qin-u { font-size: 8px; letter-spacing: -0.03em; }
body.nm-en .paper .qcell { font-size: 8px; letter-spacing: -0.04em; line-height: 9px; padding: 0 1px; }
/* 數量字不要太粗 */
.paper .qcell, .qin { font-weight: 400; }

/* ── 工廠配貨／門市新增／自由輸入（不是產品）── */
.x-tag { display: inline-block; margin-left: 3px; padding: 0 3px; border-radius: 3px; background: #fef3c7; color: #b45309; font-size: .8em; font-weight: 700; line-height: 1.3; vertical-align: 1px; }
.pk-edit .pk-unit { width: 26px; text-align: left; }
.pk-cname { width: 100%; min-width: 0; padding: 0 3px; border: 1px solid var(--gold); border-radius: 2px; background: #fff; font-size: 10.5px; font-family: inherit; box-sizing: border-box; }
.sheet-editing .pk-edit .pk-unit { width: 22px; }
.rv-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 8px; font-size: 13px; color: var(--text-2); }
.rv-add select { width: auto; max-width: 220px; padding: 5px 8px; font-size: 14px; }
.rv-edit .rv-unit { width: 44px; text-align: left; background: var(--surface-2); }
.rv-cname { width: 100%; min-width: 120px; padding: 4px 6px; font-size: 14px; }
@media print { .rv-add { display: none; } }
.pk-add { padding: 0 5px; border: 1px dashed var(--border); border-radius: 3px; background: transparent; color: var(--text-3, #999); font-size: 10px; line-height: 1.2; cursor: pointer; }
.pk-add:hover { border-color: var(--gold); color: #b45309; background: #fffbeb; }

/* ── 截圖（screenshotSheet）：欄寬照內容，不裁切 ── */
.sheet-page.sheet-shot { width: max-content; padding: 12px 14px; }
.sheet-shot .pk-head { font-size: 14px; }
.sheet-shot .pk-head span { font-size: 12px; }
.sheet-shot .pk-grid { grid-template-columns: repeat(var(--pk-cols, 9), max-content); gap: 4px; }
.sheet-shot .pk-table { table-layout: auto; width: auto; font-size: 13px; }
.sheet-shot .pk-table th, .sheet-shot .pk-table td { overflow: visible; white-space: nowrap; line-height: 1.4; }
.sheet-shot .pk-table th { font-size: 11px; }
.sheet-shot .pk-table th:first-child { width: auto; font-size: 12px; }
.sheet-shot .pk-table .pk-q { padding: 1px 5px; }

/* ── 揀貨單直接送 A4 印表機（a4-print.js）：畫面外排版，字級／欄數由程式挑最大的 ── */
.sheet-a4 { background: #fff; color: #000; padding: 0; font-family: 'Noto Sans TC', sans-serif; }
.sheet-a4 .pk-head { font-size: clamp(12px, var(--pk-fs, 12px), 22px); gap: 0 0.9em; margin-bottom: 0.25em; line-height: 1.3; }
.sheet-a4 .pk-head span { font-size: 0.75em; color: #444; margin-right: 0.3em; }
.sheet-a4 .od-notes { font-size: clamp(11px, var(--pk-fs, 12px), 20px); padding: 2px 6px; margin-bottom: 0.25em; }
/* 一個分類一欄（跟畫面上的叫貨單一樣），只有「其他（非產品）」會疊在最短那欄下面（pkGridHTML） */
.sheet-a4 .pk-grid { grid-template-columns: repeat(var(--pk-cols, 9), minmax(0, 1fr)); gap: 4px; }
.sheet-a4 .pk-table { font-size: var(--pk-fs, 12px); table-layout: fixed; width: 100%; }
.sheet-a4 .pk-col > .pk-table + .pk-table { margin-top: 4px; }
.sheet-a4 .pk-table th, .sheet-a4 .pk-table td { border-color: #888; padding: 0 0.2em; line-height: var(--pk-lh, 1.25); overflow: hidden; white-space: nowrap; }
.sheet-a4 .pk-table th { background: #e6e6e6; color: #000; }
.sheet-a4 .pk-table th:first-child { width: 52%; }
.sheet-a4 .pk-table th.pk-q { font-size: 0.8em; color: #000; }
.sheet-a4 .pk-table td:first-child { white-space: normal; word-break: normal; overflow-wrap: anywhere; }
.sheet-a4 .pk-table .pk-q { width: auto; text-align: right; }
.sheet-a4 .pk-table tr.pk-on td { background: none; font-weight: 700; }
.sheet-a4 .pk-table tr.pk-on td:first-child { text-decoration: underline; }
.sheet-a4 .pk-ship, .sheet-a4 .pk-recv { color: #000; }
.a4p-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.a4p-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 14px; }
.a4p-item input { accent-color: var(--accent); }

/* 品名「1箱幾個」提示泡泡（order-common.js perHint） */
[data-uh] { cursor: help; }
.uh-tip { position: fixed; z-index: 9999; display: none; pointer-events: none; padding: 4px 9px; border-radius: 6px;
  background: #3b2f1e; color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
@media print { .uh-tip { display: none !important; } }
