:root {
  --bg: #f6f7f9; --card: #fff; --text: #1f2933; --muted: #616e7c; --line: #d9dee4;
  --brand: #1d4ed8; --danger: #b91c1c; --ok: #15803d; --warn-bg: #fff7e6; --warn-line: #f0b429;
  --err-bg: #fdecec; --ok-bg: #e9f7ef;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif; }
.topbar { display: flex; gap: 20px; align-items: center; padding: 10px 20px; background: #102a43; color: #fff; flex-wrap: wrap; }
.topbar a { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 700; font-size: 17px; }
.topbar nav { display: flex; gap: 16px; }
.topbar .env { margin-left: auto; background: #f0b429; color: #102a43; padding: 2px 10px; border-radius: 12px; font-size: 13px; font-weight: 700; }
.page { max-width: 1280px; margin: 0 auto; padding: 16px 20px 40px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h1 small { font-size: 15px; color: var(--muted); font-weight: 400; margin-left: 10px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin: 12px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; }
.filters label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); }
.hint, .count { color: var(--muted); font-size: 13px; }
input, select, button { font: inherit; }
input, select { padding: 5px 8px; border: 1px solid #b8c2cc; border-radius: 5px; background: #fff; min-width: 0; }
input[readonly] { background: #f0f2f5; }
button { padding: 6px 14px; border: 1px solid #9aa5b1; border-radius: 5px; background: #fff; cursor: pointer; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; padding: 8px 22px; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700; }
/* 表格：寬螢幕維持表格；文字欄可折行，單號／日期／金額／狀態不斷行。不使用左右捲軸。 */
table.grid { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); }
.grid th, .grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid th { background: #e4e7eb; font-size: 13px; white-space: nowrap; }
.grid .nw { white-space: nowrap; }
.grid .wrap { overflow-wrap: anywhere; }
.grid .num { text-align: right; }
.grid tr.voided td { color: #9aa5b1; text-decoration: line-through; }
.grid tr.voided td.card-title, .grid tr.voided td.status { text-decoration: none; }
.grid .empty { text-align: center; color: var(--muted); padding: 24px; }
.grid.lines { table-layout: fixed; }
.grid.lines td { padding: 4px; }
.grid.lines input { width: 100%; }
.grid.lines .c-seq { width: 36px; } .grid.lines .c-code { width: 12%; } .grid.lines .c-num { width: 9%; }
.grid.lines .c-unit { width: 7%; } .grid.lines .c-rem { width: 15%; } .grid.lines .c-act { width: 48px; }
.remove-line { padding: 4px 8px; }
.remove-line .lbl { display: none; }
input.num { text-align: right; }
.form-grid > *, .fields > * { min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 16px; }
.form-grid label, .totals label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 2px; }
.form-grid label.wide { grid-column: span 2; }
.form-grid label.check, .totals label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 15px; }
.inline { display: flex; gap: 6px; } .inline input { flex: 1; }
.totals { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
.totals input.num { width: 140px; font-weight: 700; }
.actions { display: flex; gap: 16px; align-items: center; margin-top: 8px; }
#add-line { margin-top: 8px; }
.error, .warning, .notice { border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.error { background: var(--err-bg); border: 1px solid var(--danger); color: var(--danger); }
.warning { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.notice { background: var(--ok-bg); border: 1px solid var(--ok); color: var(--ok); }
.badge { font-size: 14px; padding: 2px 10px; border-radius: 12px; vertical-align: middle; margin-left: 8px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.void { background: var(--err-bg); color: var(--danger); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 16px; margin: 0; }
.fields dt { font-size: 13px; color: var(--muted); }
.fields dd { margin: 0; min-height: 1.5em; overflow-wrap: anywhere; }
.danger-zone { border-color: #f5b5b5; display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.danger-zone h2 { width: 100%; color: var(--danger); }
.danger-zone label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); }
/* 窄寬（≤900px）：每筆資料一張卡，欄位標籤＋值，項目之間折行。 */
@media (max-width: 900px) {
  table.grid.cards, .grid.cards tbody, .grid.cards tfoot, .grid.cards tr, .grid.cards td { display: block; }
  table.grid.cards { border: 0; background: none; }
  .grid.cards thead, .grid.cards colgroup { display: none; }
  .grid.cards tr { display: flex; flex-wrap: wrap; gap: 6px 18px; background: var(--card); border: 1px solid var(--line);
    border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
  .grid.cards td { border: 0; padding: 0; min-width: 0; text-align: left; }
  .grid.cards td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); }
  .grid.cards td.card-title { flex-basis: 100%; font-weight: 700; font-size: 16px; }
  .grid.cards td.card-title::before { display: none; }
  .grid.cards td.wrap { flex-basis: 100%; }
  .grid.cards td.empty { flex-basis: 100%; text-align: center; }
  .grid.cards tr.voided td.card-title::after { content: "（已作廢）"; color: var(--danger); font-size: 13px; margin-left: 6px; }
  .grid.cards tr.sum-row { margin-bottom: 0; border-radius: 0; border-top: 0; padding: 6px 12px; justify-content: flex-end; }
  .grid.cards tr.sum-row:first-child { border-top: 1px solid var(--line); border-radius: 8px 8px 0 0; }
  .grid.cards tr.sum-row:last-child { border-radius: 0 0 8px 8px; margin-bottom: 10px; }
  .grid.cards tr.sum-row td.label-cell, .grid.cards tr.sum-row td.pad { display: none; }
  .grid.cards tr.sum-row td[data-label] { display: flex; gap: 12px; align-items: baseline; }
  .grid.cards tr.sum-row td[data-label]::before { display: inline; font-size: 13px; }
  .grid.lines.cards td { flex: 1 1 120px; padding: 0; }
  .grid.lines.cards td.seq { flex-basis: 100%; }
  .grid.lines.cards td.col-name, .grid.lines.cards td.col-rem, .grid.lines.cards td.act { flex-basis: 100%; }
  .grid.lines.cards td.seq::before { content: "第"; display: inline; font-size: 16px; color: inherit; }
  .grid.lines.cards td.seq::after { content: "筆明細"; }
  .remove-line .lbl { display: inline; }
  .remove-line { width: 100%; color: var(--danger); border-color: #f5b5b5; }
}
@media (max-width: 640px) {
  .form-grid label.wide { grid-column: span 1; }
  .topbar .env { margin-left: 0; }
}
/* ── 雲端版補充 ── */
.narrow { max-width: 480px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-stack label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 2px; }
.form-stack input, .form-stack select { width: 100%; }
.actions { flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }
button.link { background: none; border: 0; padding: 0; color: #fff; cursor: pointer; font: inherit; }
.topbar nav { flex-wrap: wrap; align-items: center; }
.wrap { overflow-wrap: anywhere; }
.nw { white-space: nowrap; }
.badge { margin-left: 0; white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: #8a5a00; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; }
.form-row > label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 2px; min-width: 0; }
fieldset.choices { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; min-width: 0; }
fieldset.choices legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 4px; }
label.check { flex-direction: row !important; align-items: center; gap: 6px; color: var(--text) !important; font-size: 15px !important; }
.key { font-family: ui-monospace, Consolas, monospace; font-size: 14px; overflow-wrap: anywhere; background: #fff; border: 1px dashed var(--warn-line); padding: 6px 8px; border-radius: 5px; margin-top: 6px; }
.form-grid + .form-grid, .grid + .form-grid { margin-top: 14px; }
.card h2 { margin-top: 0; }
.mock-banner { background: #fff3bf; border: 1px solid var(--warn-line); color: #6b4e00; font-weight: 700; border-radius: 8px; padding: 8px 14px; margin: 0 0 12px; }
.topbar .acct { font-size: 13px; background: rgba(255,255,255,.15); padding: 2px 10px; border-radius: 12px; }
.topbar .who { font-size: 13px; opacity: .85; }
.wb-pending { color: #8a5a00; font-weight: 700; }
.wb-done { color: var(--ok); font-weight: 700; }
.wb-conflict { color: var(--danger); font-weight: 700; }
/* T09 後台全部發票 */
.pager { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 12px 0; }
.audit-line { overflow-wrap: anywhere; }
.audit-field { color: var(--muted); }
