/* ── 門市叫貨／工廠收單（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-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); }

@media print {
  .pk-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .pk-table { font-size: 11px; }
  .pk-table th, .pk-table td { padding: 1px 4px; }
  .pk-table tr.pk-on td { background: none; }
  .pk-table { break-inside: avoid; }
}

/* 叫貨／庫存：一格顯示，點進去填箱／個 */
.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 橫式） */
@media (min-width: 1100px) {
  .om-main:has(.cats) { max-width: none; padding: 10px 12px; }
  .oh { grid-template-columns: auto repeat(4, minmax(130px, 170px)) 1fr; padding: 6px 12px; gap: 6px 12px; margin-bottom: 6px; }
  .oh .om-input { padding: 4px 8px; }
  .oh-notes { grid-column: auto; }
  .oh-store { font-size: 20px; }
  .of-tools { margin-bottom: 8px; }
  .cards-only { display: none; }
  .cats { grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); gap: 8px 6px; padding-bottom: 70px; }
  .cat { border-radius: 4px; }
  .cat-head { padding: 3px 6px; cursor: default; }
  .cat-head .name { font-size: 13px; letter-spacing: 0.06em; }
  .cat-head .arrow, .cat-head .sum { display: none; }
  .cat.collapsed .cat-body { display: block; }
  .ot { min-width: 0; font-size: 12px; table-layout: fixed; }
  .ot th { padding: 2px 3px; font-size: 10px; }
  .ot th:first-child { width: 40%; }
  .ot td { padding: 0 2px; line-height: 16px; height: 19px; }
  .ot .nm { font-size: 13px; font-weight: 500; min-width: 0; padding-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ot td.qc { width: auto; padding: 1px 2px 0; }
  .ot th { line-height: 14px; }
  .qcell { display: block; min-height: 17px; height: 17px; line-height: 16px; padding: 0 6px; font-size: 13px; border-radius: 3px; white-space: nowrap; overflow: hidden; }
  .om-tabs { margin-bottom: 8px; }
  .om-tab { padding: 6px 14px; }
  .of-foot { padding: 6px 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; }
