:root {
  --blue: #808080; --blue-d: #5c5c5c; --blue-l: #efefef; --line: #d9d9d9; --bg: #f4f4f4;   /* --blue＝LOGO 的灰（變數名沿用） */
  --text: #1f2933; --muted: #6b7785; --red: #c62828; --orange: #b45309; --green: #1b7a3d;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 18px; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--blue); }
h1 small { font-size: 13px; font-weight: normal; color: var(--muted); margin-left: 10px; }

/* 上方列 */
.top { position: sticky; top: 0; z-index: 30; height: 46px; display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--blue); color: #fff; }
.top-title { display: flex; align-items: center; font-weight: 700; font-size: 16px; letter-spacing: .3px; white-space: nowrap; }
.top-title img { display: block; height: 36px; width: auto; }
.top-title span { font-weight: 400; font-size: 12px; opacity: .85; margin-left: 10px; letter-spacing: 1px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; min-width: 0; }
#whoami { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { background: none; border: 0; color: #fff; cursor: pointer; text-decoration: underline; padding: 0; white-space: nowrap; }
.menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 20px; cursor: pointer; }

.layout { display: flex; min-height: calc(100% - 46px); }
.side { width: 168px; flex: none; background: #fff; border-right: 1px solid var(--line); padding: 8px 0; }
.side-group { padding: 12px 16px 4px; font-size: 12px; color: var(--muted); }
.side a { display: block; padding: var(--side-pad, 9px) 16px; color: var(--text); text-decoration: none; border-left: 3px solid transparent; }
/* 管理員編輯選單（改名、拖曳排序、間距） */
.ui-bar { margin-top: 18px; padding: 10px 12px; border-top: 1px dashed var(--line); font-size: 12px; }
.ui-bar .link { color: var(--muted); font-size: 12px; background: none; border: 0; cursor: pointer; padding: 0; text-decoration: underline; }
.ui-bar .hint { margin: 0 0 8px; line-height: 1.5; }
.ui-bar .ui-gap { display: block; margin-bottom: 8px; color: var(--muted); }
.ui-bar .ui-gap input { width: 100%; }
.ui-bar .btn { margin: 0 4px 6px 0; }
.side.editing a, .side.editing .side-group { cursor: grab; outline: 1px dashed #c9c9c9; outline-offset: -3px; user-select: none; }
.side.editing a.on { background: none; font-weight: normal; border-left-color: transparent; color: var(--text); }
.side.editing .drop-before { box-shadow: inset 0 3px 0 var(--blue-d); }
.side.editing .drop-after { box-shadow: inset 0 -3px 0 var(--blue-d); }
.side.editing .dragging { opacity: .4; }
.side .lbl-input { width: 100%; font: inherit; padding: 2px 4px; border: 1px solid var(--blue-d); border-radius: 3px; }
.ui-bar .ui-gap select { width: 100%; margin-top: 2px; }
body.ui-editing .main th[data-ui-key], body.ui-editing .main button[data-ui-key],
body.ui-editing .top button[data-ui-key] { outline: 1px dashed #9a9a9a; outline-offset: 1px; cursor: text; }
.ui-float { position: absolute; z-index: 300; font: inherit; padding: 3px 6px; border: 2px solid var(--blue-d); border-radius: 3px; background: #fff; color: var(--text); box-shadow: 0 4px 14px rgba(0,0,0,.2); min-width: 110px; }
/* 表格欄寬、欄位順序（編輯介面時）：右邊的藍線拉寬度、拖曳欄名換位置 */
.grid th.col-edit { position: relative; cursor: grab; }
.grid th.col-edit.dragging { opacity: .4; }
.grid th.drop-before { box-shadow: inset 3px 0 0 var(--blue-d); }
.grid th.drop-after { box-shadow: inset -3px 0 0 var(--blue-d); }
.col-rs { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 2; }
.col-rs::after { content: ""; position: absolute; top: 4px; bottom: 4px; left: 3px; width: 2px; background: #3b7ddd; border-radius: 1px; }
.col-rs:hover::after { background: var(--blue-d); left: 2px; width: 3px; }
/* 右上角快速切換身分（只有管理員） */
.quick-as { font-size: 12px; padding: 2px 4px; border-radius: 3px; border: 1px solid rgba(255,255,255,.6); background: rgba(255,255,255,.12); color: #fff; max-width: 220px; }
.quick-as option { color: #222; background: #fff; }
.tag.has-tip { cursor: help; }
.btn.added { background: #e7f5ec; border-color: #bfe3cc; color: var(--green); }
/* 右上角「檢視中：客戶 ✕」 */
#viewAsTag { display: inline-flex; align-items: center; gap: 2px; padding-right: 2px; }
#viewAsTag[hidden] { display: none; }
#viewAsTag .va-name { cursor: pointer; text-decoration: underline dotted; }
#viewAsTag .va-x { border: 0; background: none; color: inherit; cursor: pointer; font-size: 12px; line-height: 1; padding: 2px 5px; margin-left: 2px; border-radius: 8px; }
#viewAsTag .va-x:hover { background: rgba(0,0,0,.12); }
.float-tip { position: fixed; z-index: 400; max-width: 360px; padding: 7px 10px; border-radius: 4px; background: #1f2933; color: #fff; font-size: 12px; line-height: 1.6; box-shadow: 0 6px 18px rgba(0,0,0,.25); pointer-events: none; white-space: normal; }
.banner.editable { cursor: pointer; outline: 1px dashed #c9a94a; }
.banner.editable::after { content: "　✎ 點這裡修改公告"; font-size: 12px; opacity: .7; }
.side a:hover { background: var(--blue-l); }
.side a.on { background: var(--blue-l); border-left-color: var(--blue); color: var(--blue-d); font-weight: 700; }
.main { flex: 1; min-width: 0; padding: 14px 18px 40px; }

.banner { background: #fff8e1; border: 1px solid #f1d98a; color: #6b4e00; padding: 9px 14px; border-radius: 4px; margin-bottom: 14px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
/* 等待畫面（匯入回單等要跑一陣子的動作）：來回跑的進度條 */
.busy { padding: 8px 0 4px; }
.busy-msg { font-weight: 700; margin: 14px 0 6px; }
.busy-bar { position: relative; height: 8px; border-radius: 4px; background: #e6eaf0; overflow: hidden; }
.busy-bar span { position: absolute; top: 0; bottom: 0; width: 35%; border-radius: 4px; background: var(--blue-d); animation: busy-slide 1.3s ease-in-out infinite; }
@keyframes busy-slide { 0% { left: -35%; } 100% { left: 100%; } }
@media (prefers-reduced-motion: reduce) { .busy-bar span { animation-duration: 3s; } }
.view { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 16px; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px; margin-bottom: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid .wide { grid-column: span 2; }
input, select { border: 1px solid #b9c3d0; border-radius: 3px; padding: 6px 8px; background: #fff; min-width: 0; }
input:focus, select:focus { outline: 2px solid #bdbdbd; outline-offset: -1px; border-color: var(--blue-d); }
input.bad { border-color: var(--red); background: #fff5f5; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar .sep { flex: 1; }
.hint { color: var(--muted); font-size: 12px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; margin-bottom: 14px; max-width: 760px; }
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.panel p { margin: 0 0 10px; }
.panel .stack { margin-bottom: 8px; max-width: 520px; }
.panel .kv { margin-bottom: 8px; }
.panel.wide-panel { max-width: 1100px; }
.scope-box { display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; max-height: 220px; overflow-y: auto; }
.scope-box label.chk { flex-direction: row !important; align-items: center; gap: 6px; font-size: 13px !important; color: var(--text) !important; }
.form-grid label { flex-wrap: wrap; }
.req { color: var(--red); font-size: 11px; }
.form-grid label:has(.req) { flex-direction: row; align-items: baseline; gap: 4px 6px; }
.form-grid label:has(.req) input { flex: 1 0 100%; }
input.invalid { border-color: var(--red) !important; box-shadow: 0 0 0 2px rgba(198,40,40,.15); }
.panel h2 small { font-weight: normal; margin-left: 8px; }
.addr-pop { min-width: 380px; }
.addr-pop .ac-item { display: block; }
.addr-pop .ac-item b { margin-right: 8px; }
.addr-pop .ac-item .hint { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.addr-pop .ac-foot { padding: 6px 10px; font-size: 12px; color: var(--muted); background: #fafafa; }
.btn { border: 1px solid #aab6c6; background: #fff; border-radius: 3px; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f2f2f2; }
.btn.primary { background: var(--blue-d); border-color: var(--blue-d); color: #fff; }
.btn.primary:hover { background: #444; border-color: #444; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn.block { width: 100%; padding: 10px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: default; }
.actions { display: flex; gap: 8px; margin-top: 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); }
table.grid { width: 100%; border-collapse: collapse; min-width: 980px; }
#grid { table-layout: fixed; min-width: 1080px; }   /* 固定欄寬：輸入框不被擠扁，品名欄吃剩餘寬度 */
#grid td { overflow-wrap: anywhere; }
.grid th { background: var(--blue-l); border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; font-weight: 700; white-space: nowrap; font-size: 13px; }
.grid td { border-bottom: 1px solid #e8ecf1; padding: 4px 8px; vertical-align: middle; }
.grid tbody tr:hover { background: #fafafa; }
.grid.list td { padding: 7px 8px; }
.grid input { width: 100%; }
.c-no { width: 30px; color: var(--muted); text-align: center; }
.c-code { width: 140px; } .c-spec { width: 110px; color: var(--muted); font-size: 12px; word-break: break-all; }
.c-qty { width: 80px; } .c-num { width: 92px; text-align: right !important; } .c-memo { width: 130px; } .c-stock { width: 104px; } .c-x { width: 34px; text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num small { color: var(--muted); margin-left: 3px; }
.in-qty { text-align: right; }
.in-ship { width: 80px; text-align: right; }       /* 代客下單：同仁改運費 */
#editNote .btn { margin-left: 8px; }
.grid tfoot td { background: #f7f7f7; font-weight: 700; padding: 8px; border-top: 2px solid var(--line); }
.tf-label { text-align: right; } .tf-total { text-align: right; } .tf-total b { font-size: 17px; color: var(--blue-d); }
.eta { font-size: 12px; color: var(--orange); margin-top: 2px; }
.x { border: 0; background: none; color: #98a2b0; cursor: pointer; font-size: 14px; padding: 2px 6px; }
.x:hover { color: var(--red); }
a.rowlink { color: #3d3d3d; font-weight: 700; cursor: pointer; text-decoration: underline; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; border: 1px solid transparent; }
.tag.ok { background: #e7f5ec; color: var(--green); border-color: #bfe3cc; }
.tag.low { background: #fff4e0; color: var(--orange); border-color: #f3d6a0; }
.tag.out { background: #fdeaea; color: var(--red); border-color: #f3bcbc; }
.tag.warn { background: #ffe9a8; color: #5c4300; }
.tag.gray { background: #eef1f5; color: #55606e; border-color: #d9dfe7; }
.tag.blue { background: #e8f0fb; color: #1d4f91; border-color: #c5d9f5; }

.note { margin-top: 10px; padding: 8px 12px; border-radius: 4px; font-size: 13px; }
.note.warn { background: #fff8e1; border: 1px solid #f1d98a; color: #6b4e00; }
.note.info { background: #fff4e0; border: 1px solid #f3d6a0; color: #7a3d00; }

/* 自動完成 */
.ac { position: absolute; z-index: 60; background: #fff; border: 1px solid #9fb0c6; box-shadow: 0 6px 18px rgba(0,0,0,.16); max-height: 320px; overflow-y: auto; min-width: 420px; max-width: 94vw; }
.ac-item { padding: 6px 10px; cursor: pointer; display: flex; gap: 10px; align-items: baseline; border-bottom: 1px solid #f0f2f5; }
.ac-item.on, .ac-item:hover { background: var(--blue-l); }
.ac-code { font-family: Consolas, monospace; color: var(--blue-d); flex: none; }
.ac-name { flex: 1; min-width: 0; }
.ac-none { padding: 10px; color: var(--muted); }

/* 對話框 */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(20,30,45,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px 12px; overflow-y: auto; }
.modal-box { background: #fff; border-radius: 6px; width: 100%; max-width: 860px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal-box.narrow { max-width: 460px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 15px; }
.modal-body { padding: 14px 16px; max-height: 66vh; overflow-y: auto; }
.modal-foot { padding: 10px 16px 14px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 110px 1fr 110px 1fr; gap: 6px 10px; margin-bottom: 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.pw-box { font-family: Consolas, monospace; font-size: 20px; letter-spacing: 1px; background: #f3f6fa; border: 1px dashed #9fb0c6; padding: 12px; text-align: center; border-radius: 4px; user-select: all; }
.pick-list { border: 1px solid var(--line); max-height: 220px; overflow-y: auto; }
.pick-list div { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid #f0f2f5; }
.pick-list div:hover, .pick-list div.on { background: var(--blue-l); }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 99; background: #1f2933; color: #fff; padding: 10px 18px; border-radius: 4px; box-shadow: 0 6px 18px rgba(0,0,0,.25); max-width: 90vw; }
.toast.err { background: var(--red); }

/* 登入頁 */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100%; background: linear-gradient(160deg, #9a9a9a 0%, #808080 50%, #5c5c5c 100%); padding: 16px; }
.login-card { background: #fff; border-radius: 8px; padding: 30px 28px 22px; width: 100%; max-width: 380px; box-shadow: 0 16px 48px rgba(0,0,0,.3); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo { display: block; margin: 0 auto; width: 266px; max-width: 80%; height: auto; }
.login-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input:not([type=checkbox]) { padding: 9px 10px; font-size: 15px; }
.login-card .chk { flex-direction: row; align-items: center; gap: 6px; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; }
.login-forgot { text-align: right; margin: 8px 0 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; }
.link-btn:hover { color: var(--text); }
.login-ok { color: var(--green); font-size: 13px; margin: 6px 0 0; line-height: 1.6; }
.login-ok:empty { display: none; }
.login-foot { text-align: center; font-size: 12px; color: var(--muted); margin: 16px 0 0; }

@media (max-width: 860px) {
  .menu-toggle { display: block; }
  .side { position: fixed; top: 46px; bottom: 0; left: 0; z-index: 25; transform: translateX(-100%); transition: transform .18s; box-shadow: 4px 0 16px rgba(0,0,0,.15); }
  .side.open { transform: none; }
  .main { padding: 10px 10px 40px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .top-title span, #whoami { display: none; }
  .kv { grid-template-columns: 96px 1fr; }
}
@media print {
  /* 只印對話框（訂貨單明細）。畫面版的 html/body 高度 100%、.layout 最小高度一頁，不關掉會先印出一整頁空白 */
  html, body { height: auto !important; min-height: 0 !important; background: #fff !important; }
  .top, .toast, .ac, .modal-foot, #modalClose, #loading { display: none !important; }
  body:has(#modal:not([hidden])) .layout { display: none !important; }
  .modal { position: static !important; display: block !important; inset: auto !important; background: none !important; padding: 0 !important; overflow: visible !important; }
  .modal-box { box-shadow: none !important; max-width: none !important; width: 100% !important; border-radius: 0; }
  .modal-head { padding: 0 0 8px; font-size: 18px; }
  .modal-body { max-height: none !important; overflow: visible !important; padding: 10px 0 0; }
  .table-wrap { overflow: visible !important; border: 0; }
  table.grid { min-width: 0 !important; }
  .grid th, .grid tfoot td, .tag { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  tr { break-inside: avoid; }
}

.grid tfoot tr.ship-row td { background: #fffdf3; font-weight: 400; border-top: 1px solid var(--line); }
.ac-name .eta { display: inline; }

.tag.quote { background: #eef3fb; color: #2f4f7f; border-color: #c9d8ee; }

.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: #1b7a3d; color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }
.note.ok { background: #e7f5ec; border: 1px solid #bfe3cc; color: #145c2e; margin: 0 0 12px; }
.note.ok a { color: #145c2e; font-weight: 700; cursor: pointer; text-decoration: underline; }
#alertInfo { background: #f7f7f7; border: 1px solid var(--line); color: #444; margin: 0 0 12px; }

.grid tr.subtotal td { background: #f7f7f7; font-weight: 700; border-bottom: 2px solid var(--line); }
.neg { color: var(--red); }
.month-cards { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.month-card { border: 1px solid var(--line); border-radius: 4px; padding: 8px 14px; background: #fafafa; min-width: 170px; }
.month-card b { display: block; font-size: 17px; margin-top: 2px; }
.month-card span { color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 4px; margin: 0 0 10px; border-bottom: 1px solid var(--line); }
.tab { border: 1px solid var(--line); border-bottom: 0; background: #f4f4f4; padding: 6px 16px; cursor: pointer; border-radius: 4px 4px 0 0; color: #555; }
.tab.on { background: #fff; color: var(--text); font-weight: 700; position: relative; top: 1px; }

/* 管理：功能開關 */
.c-cap { width: 110px; text-align: center !important; }
#cpTbl td { padding-top: 10px; padding-bottom: 10px; }
#cpTbl label.chk { display: inline-flex; justify-content: center; padding: 2px 14px; cursor: pointer; }
#cpTbl input[type=checkbox] { width: 18px; height: 18px; }
.scope-box .sc-tools { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 2px; }

/* 結帳區間、超量下單開關、搜尋清單裡的到貨通知按鈕 */
.month-card .period { display: block; margin-top: 2px; }
.toolbar label.over-box { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; margin-left: auto; padding: 4px 10px; border: 1px dashed #c9a227; border-radius: 4px; background: #fffbea; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap; }
.ac .ac-item .btn.sm { margin-left: auto; flex: none; align-self: center; }

/* 自訂單價：開關（跟超量下單同一種外觀）與訂貨單上的單價輸入 */
.toolbar label.manual-box { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; padding: 4px 10px; border: 1px dashed #c9a227; border-radius: 4px; background: #fffbea; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap; }
.toolbar label.over-box[hidden] + label.manual-box { margin-left: auto; }
#grid .in-price { width: 84px; text-align: right; }
#grid .in-tax { width: 62px; margin-left: 4px; padding: 3px 2px; font-size: 12px; }
#grid .in-price.bad { border-color: #c0392b; background: #fdf0ee; }
#grid.manual-on .c-price { width: 176px; }
#grid.manual-on td .hint { white-space: nowrap; }

/* 匯入採購單（2026-11-17） */
.po-ch { display: inline-flex; gap: 4px; }
.po-card { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 12px 0; background: #fff; }
.po-card.off { opacity: .55; background: #fafafa; }
.po-card.done { background: #e7f5ec; border-color: #bfe3cc; color: #145c2e; }
.po-card.done a, .po-card a[data-order] { cursor: pointer; text-decoration: underline; font-weight: 700; }
.po-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 8px; }
.po-head label { font-size: 13px; }
.po-head .sep { flex: 1; }
.po-recv { margin-bottom: 8px; }
.po-tbl { table-layout: fixed; min-width: 1080px; }      /* 跟「輸入訂貨單」同一套欄寬 */
.po-tbl td { overflow-wrap: anywhere; }
.po-tbl .c-price { width: 120px; }
.po-tbl tr.po-bad td { background: #fff5f5; }
.po-tbl .in-qty, .po-tbl .in-price { text-align: right; }
.po-badtxt { color: var(--red); }

/* 訂貨單明細依單號分組（2026-11-17） */
#linesTbl td:first-child { white-space: nowrap; }
#linesTbl tr.grp-first td { border-top: 1px solid var(--line); }

/* 測試版（PORTAL_TEST=1）：上方整條變紅、標「測試版」，避免跟正式版搞混 */
.test-mode .top { background: #b71c1c; }
.test-tag { margin-left: 12px; padding: 2px 10px; border-radius: 10px; background: #fff; color: #b71c1c; font-weight: 700; font-size: 13px; white-space: nowrap; }
.test-login { margin: 0 0 14px; padding: 8px 12px; border-radius: 4px; background: #fdeaea; border: 1px solid #f3bcbc; color: #b71c1c; font-size: 13px; font-weight: 700; }

/* ═══════════ 手機版（2026-11-25）═══════════
   ≤ 640px：表格改成「一列一張卡片」（欄名放在每一格左邊，app.js 的 cardLabels 幫每一格貼上欄名）；
   輸入訂貨單的品項表改成一個品項一張卡；搜尋下拉、店址清單撐滿螢幕寬；下方「儲存」固定在畫面底部。 */
@media (max-width: 860px) {
  .side { width: 220px; }
  body.side-open .main { filter: brightness(.92); }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; }            /* iPhone 輸入框字小於 16px 會自動放大畫面 */
  /* iPhone Safari 的日期欄有自己的外觀（比別的輸入框高、文字置中）→ 統一成同樣高度、靠左（Nina 2026-11-25 回報） */
  input:not([type=checkbox]):not([type=radio]):not([type=file]), select { height: 40px; }
  input[type=date] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; line-height: 26px; text-align: left; background: #fff; }
  input[type=date]::-webkit-date-and-time-value { text-align: left; margin: 0; }
  input[type=date]::-webkit-datetime-edit { padding: 0; }
  .top { gap: 8px; padding: 0 10px; }
  .top-title img { height: 30px; }
  .test-tag { font-size: 11px; padding: 1px 6px; margin-left: 6px; }
  .top-right { gap: 10px; font-size: 13px; }
  #viewAsTag { max-width: 130px; overflow: hidden; }
  #viewAsTag .va-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .quick-as { max-width: 120px; }
  .main { padding: 8px 8px 90px; }
  .view { padding: 12px 10px; }
  .banner { padding: 8px 10px; font-size: 13px; }
  h1 { font-size: 17px; }
  h1 small { display: block; margin: 4px 0 0; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
  .form-grid input, .form-grid select { width: 100%; }
  .form-grid .wide { grid-column: 1 / -1; }
  .toolbar { gap: 6px; }
  .toolbar > label { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; width: 100%; }
  .toolbar > label input[type=date] { flex: 1; min-width: 0; }
  .toolbar .grow, .toolbar > input, .toolbar > select { flex: 1 1 100%; min-width: 0; }
  .toolbar .sep { display: none; }
  .toolbar .hint { flex-basis: 100%; }
  .btn { padding: 8px 14px; }
  .btn.sm { padding: 5px 10px; font-size: 13px; }
  .panel { padding: 12px; }

  /* 一般表格 → 卡片 */
  .table-wrap { border: 0; overflow: visible; }
  table.grid.cardify { min-width: 0 !important; width: 100% !important; table-layout: auto !important; }
  .cardify thead { display: none; }
  .cardify, .cardify tbody, .cardify tfoot { display: block; }
  .cardify tbody tr, .cardify tfoot tr { display: block; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; background: #fff; }
  .cardify tbody tr:hover { background: #fff; }
  .cardify td { display: block; position: relative; border: 0 !important; padding: 3px 0 3px 88px !important; text-align: left !important; white-space: normal; width: auto !important; min-height: 24px; }
  .cardify td::before { content: attr(data-label); position: absolute; left: 0; top: 4px; width: 80px; color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.5; }
  .cardify td.nolabel { padding-left: 0 !important; }
  .cardify td.nolabel::before { display: none; }
  .cardify td:empty { display: none; }
  .cardify td.c-x { position: absolute; right: 8px; top: 8px; padding: 0 !important; min-height: 0; }
  .cardify tbody tr { position: relative; }
  .cardify td .num, .cardify .num { text-align: left !important; }
  .cardify td.empty { padding: 20px 0 !important; text-align: center !important; }
  .cardify tr.subtotal, .cardify tfoot tr { background: #f7f7f7; }
  .cardify tr.subtotal td::before, .cardify tfoot td::before { display: none; }
  .cardify tr.subtotal td, .cardify tfoot td { padding-left: 0 !important; display: inline-block; margin-right: 10px; }
  .cardify tfoot td.num:not(.nolabel)::before, .cardify tr.subtotal td.num:not(.nolabel)::before { display: inline; position: static; content: attr(data-label) " "; font-size: 12px; color: var(--muted); font-weight: 400; }
  #aoTbl tr.ao-erp { background: #fafafa; }
  #linesTbl tr.grp-first { margin-top: 14px; }

  /* 輸入訂貨單：一個品項一張卡（2026-11-25 Nina：再扁一點）
     第 1 行：品項編碼｜品名｜✕　第 2 行：數量｜單價｜可訂數量　第 3 行：摘要（只留輸入框）。每列的稅前／營業稅手機不顯示，看下面合計 */
  #grid { min-width: 0 !important; display: block; }
  #grid thead { display: none; }
  #grid tbody, #grid tfoot { display: block; }
  #grid tbody tr { display: grid; grid-template-columns: 118px minmax(0, 1fr) auto 24px; gap: 6px 8px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; margin-bottom: 6px; background: #fff; }
  #grid tbody td { display: block; border: 0; padding: 0; min-width: 0; }
  #grid tbody td:nth-child(1), #grid tbody td:nth-child(4), #grid tbody td:nth-child(7), #grid tbody td:nth-child(8) { display: none; }   /* 序號、規格、稅前、營業稅 */
  #grid tbody td:nth-child(2) { grid-column: 1; grid-row: 1; }                                 /* 品項編碼 */
  #grid tbody td:nth-child(3) { grid-column: 2 / 4; grid-row: 1; font-weight: 700; font-size: 14px; line-height: 1.35; }   /* 品名 */
  #grid tbody td:nth-child(11) { grid-column: 4; grid-row: 1; text-align: right; }            /* ✕ */
  #grid tbody td:nth-child(5) { grid-column: 1; grid-row: 2; display: flex; align-items: center; gap: 6px; }   /* 數量 */
  #grid tbody td:nth-child(6) { grid-column: 2; grid-row: 2; text-align: left; }               /* 單價 */
  #grid tbody td:nth-child(10) { grid-column: 3 / 5; grid-row: 2; text-align: right; }         /* 可訂數量 */
  #grid tbody td:nth-child(9) { grid-column: 1 / -1; grid-row: 3; }                            /* 摘要 */
  #grid tbody td:nth-child(5)::before { content: "數量"; font-size: 12px; color: var(--muted); flex: none; }
  #grid tbody td:nth-child(10)::before { content: "可訂 "; font-size: 12px; color: var(--muted); }
  #grid tbody .in-code, #grid tbody .in-qty, #grid tbody .in-memo, #grid tbody .in-price, #grid tbody .in-tax { height: 34px; padding: 4px 8px; }
  #grid tbody .in-qty { width: 100%; min-width: 0; }
  #grid tbody .in-memo::placeholder { color: #b0b8c2; }
  #grid tbody td .eta { font-weight: 400; font-size: 12px; }
  #grid tbody tr.empty-row td:nth-child(n+3):not(:nth-child(11)) { display: none; }
  #grid tbody tr.empty-row td:nth-child(2) { grid-column: 1 / 4; }                     /* 空白列的搜尋框撐滿 */   /* 還沒選品項的空白列只留搜尋框 */
  #grid tbody tr.empty-row ~ tr.empty-row { display: none; }                          /* 空白列只留一列 */
  /* 運費列：運費｜說明｜金額｜✕　合計列：合計｜件數｜含稅總計 */
  #grid tfoot tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
  #grid tfoot tr[hidden] { display: none; }
  #grid tfoot td { display: block; border: 0; padding: 0; background: none; }
  #grid tfoot td:empty { display: none; }
  #grid tfoot tr.ship-row td:nth-child(1), #grid tfoot tr.ship-row td:nth-child(4),
  #grid tfoot tr.ship-row td:nth-child(6), #grid tfoot tr.ship-row td:nth-child(7) { display: none; }
  #grid tfoot tr.ship-row #sPrice { margin-left: auto; }
  #grid tfoot tr.ship-row #sDesc { flex: 1 1 100%; order: 5; font-size: 12px; color: var(--muted); }
  #grid tfoot tr:last-child td:nth-child(3), #grid tfoot tr:last-child td:nth-child(4), #grid tfoot tr:last-child td:nth-child(5) { display: none; }
  #grid tfoot tr:last-child #tQty::after { content: " 件"; font-weight: 400; }
  #grid tfoot tr:last-child .tf-label { text-align: left; }
  #grid tfoot tr:last-child .tf-total { margin-left: auto; }
  #grid .in-price { width: 100% !important; }
  #grid .in-tax { margin: 4px 0 0; width: 100% !important; }
  .toolbar label.over-box, .toolbar label.manual-box { margin-left: 0 !important; white-space: normal; }
  /* 儲存鈕固定在畫面底部，打完不用捲回來找 */
  #view-order .actions { position: sticky; bottom: 0; z-index: 20; background: #fff; margin: 12px -10px -12px; padding: 10px; border-top: 1px solid var(--line); box-shadow: 0 -4px 12px rgba(0,0,0,.06); }
  #view-order .actions .btn.primary { flex: 1; }

  /* 打品項編碼時：頁面下方墊高度（那一格才捲得到頂端）、底部儲存列先收起來（不要擋住搜尋清單） */
  body.typing-item .main { padding-bottom: 85vh; }
  body.typing-item #view-order .actions { display: none; }
  .ac { z-index: 70; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  /* 搜尋下拉、店址清單：撐滿螢幕寬 */
  .ac, .addr-pop { min-width: 0 !important; left: 8px !important; right: 8px; width: auto !important; max-width: none; }
  /* 搜尋清單每一列：編碼｜品名｜右邊一欄（庫存標籤在上、到貨通知我按鈕在下），全部垂直置中，不再上下飄（Nina 2026-11-25） */
  .ac-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 8px; row-gap: 4px; align-items: center; padding: 8px 10px; }
  .ac-item .ac-code { grid-column: 1; grid-row: 1 / span 2; font-size: 13px; }
  .ac-item .ac-name { grid-column: 2; grid-row: 1 / span 2; line-height: 1.4; }
  .ac-item .ac-name .eta { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-indent: -1em; margin-top: 2px; }   /* 到貨說明自己一行、不拆字 */
  .ac-item > .tag { grid-column: 3; grid-row: 1 / span 2; justify-self: end; }
  .ac-item > .tag:has(~ .btn), .ac-item > .tag:has(+ .tag) { grid-row: 1; align-self: end; }
  .ac-item > .tag + .tag { grid-row: 2; align-self: start; }
  .ac .ac-item > .btn.sm { grid-column: 3; grid-row: 2; justify-self: end; align-self: start; margin: 0; }

  /* 對話框 */
  .modal { padding: 8px 6px; }
  .modal-box { max-width: none !important; }
  .modal-body { max-height: calc(100vh - 150px); padding: 12px; }
  .modal-foot { padding: 10px 12px 12px; }
  .modal-foot .btn { flex: 1 1 auto; }
  .kv { grid-template-columns: 84px 1fr !important; }
  .month-card { flex: 1 1 100%; }
  .float-tip { max-width: calc(100vw - 16px); }
}
