/*
  VOICE   清楚、務實的業務表單，像一張整齊的申請單
  IDEA    填寫中的申請單：上方填資料，下方即時長出明細與總計
  PICTURE 表單本身就是主體；明細表與底部總計列是視覺重心
  COLOUR  白底、深墨色文字、鈷藍為唯一強調色，錯誤用紅、提醒用琥珀
  TYPE    系統中文字體（蘋方、微軟正黑體、思源黑體），四種字級
  LAYOUT  單欄，最寬 880px；600px 以下全部堆疊，明細改為卡片
*/
:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f5f7, #0f1115);
  --card: light-dark(#ffffff, #171a21);
  --ink: light-dark(#15171c, #e9ebf0);
  --muted: light-dark(#5b616e, #a3a9b6);
  --line: light-dark(#dfe2e8, #2a2f3a);
  --field: light-dark(#ffffff, #0f1218);
  --accent: light-dark(#1d4ed8, #7aa2ff);
  --accent-ink: light-dark(#ffffff, #0b1020);
  --accent-soft: light-dark(#e8eefc, #1c2540);
  --danger: light-dark(#c62828, #ff8a80);
  --warn-bg: light-dark(#fff6e0, #2d2614);
  --warn-line: light-dark(#e7c56b, #6b5a26);
  --radius: 10px;
}
:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; }
* { box-sizing: border-box; min-width: 0; }
html { scroll-padding-top: 16px; scroll-padding-bottom: 120px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", sans-serif;
  overflow-x: clip;
  padding-bottom: 120px;
}
.wrap { max-width: 880px; margin: 0 auto; padding-inline: max(4vw, 16px); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* 頁首 */
.head { background: var(--card); border-bottom: 1px solid var(--line); padding-block: clamp(24px, 4vw, 44px) 20px; margin-bottom: 20px; }
h1 { font-size: clamp(32px, 5vw, 44px); line-height: 1.05; margin: 0 0 10px; text-wrap: balance; }
.lead { margin: 0 0 6px; font-size: 17px; }
.disclaimer { margin: 0 0 14px; color: var(--muted); }
.notice { margin: 8px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); font-size: 14px; }
.notice-sample { background: var(--warn-bg); border: 1px solid var(--warn-line); }

/* 區塊 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(16px, 3vw, 28px); margin-bottom: 16px; }
h2 { font-size: 20px; line-height: 1.3; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 14px; flex: none; }

/* 欄位 */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; }
.span-2 { grid-column: 1 / -1; }
.field { margin-bottom: 8px; }
label { display: block; font-weight: 600; margin-bottom: 4px; white-space: nowrap; }
.req { color: var(--danger); margin-inline-start: 2px; }
input, select {
  width: 100%; min-height: 44px; padding: 8px 12px; font: inherit; font-size: 16px;
  color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 8px;
}
input:focus, select:focus, .btn:focus-visible, .link:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
input[aria-invalid=true], select[aria-invalid=true] { border-color: var(--danger); }
.affix { display: flex; align-items: stretch; }
.affix input { border-start-end-radius: 0; border-end-end-radius: 0; text-align: right; }
.unit { display: grid; place-items: center; padding: 0 10px; border: 1px solid var(--line); border-inline-start: 0; border-radius: 0 8px 8px 0; background: var(--bg); color: var(--muted); font-size: 14px; white-space: nowrap; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.err { margin: 4px 0 0; color: var(--danger); font-size: 14px; min-height: 0; }
.err:empty { display: none; }

/* 商品搜尋候選 */
.combo { position: relative; }
.candidates {
  position: absolute; z-index: 20; inset-inline: 0; top: calc(100% - 2px);
  list-style: none; margin: 0; padding: 4px; max-height: 360px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .14);
}
.candidates li { padding: 10px 12px; border-radius: 6px; cursor: pointer; }
.candidates li[aria-selected=true], .candidates li:hover { background: var(--accent-soft); }
.candidates .c-name { display: block; font-weight: 600; }
.candidates .c-meta { display: block; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.candidates .c-more { cursor: default; color: var(--muted); font-size: 13px; background: none !important; }
mark { background: light-dark(#ffe58a, #5a4a10); color: inherit; padding: 0; }

.picked { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; margin: 4px 0 12px; }
.picked-name { font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.picked-meta { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0 0 6px; font-size: 14px; }
.picked-meta div { display: flex; gap: 6px; }
.picked-meta dt { color: var(--muted); }
.picked-meta dd { margin: 0; font-variant-numeric: tabular-nums; }

.warning { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; padding: 12px 14px; margin: 8px 0; }
.warning p { margin: 0 0 8px; }

/* 按鈕 */
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.row-actions.end { justify-content: flex-end; }
.btn {
  min-height: 44px; padding: 8px 18px; font: inherit; font-weight: 600; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 48px; padding-inline: 24px; font-size: 17px; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: wait; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); font: inherit; font-size: 14px; cursor: pointer; text-decoration: underline; min-height: 32px; }

/* 申請明細 */
.empty { padding: 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }
.list { width: 100%; border-collapse: collapse; font-size: 15px; }
.list th { text-align: start; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.list td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .c-no { width: 3em; color: var(--muted); }
.list .c-act { width: 1%; white-space: nowrap; }
.list tr.editing td { background: var(--accent-soft); }
.p-name { font-weight: 600; }
.p-meta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; gap: 0 12px; }
.p-meta span { white-space: nowrap; }
.list tfoot td { border-bottom: 0; padding-top: 14px; }
.total-label { text-align: right; font-weight: 700; }
.total { font-size: 20px; font-weight: 700; }
.note-cell { overflow-wrap: anywhere; }
.act { display: flex; gap: 6px; }

/* 底部固定列 */
.dock { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgb(0 0 0 / .08); padding-bottom: env(safe-area-inset-bottom); }
.dock-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 10px; }
.dock-total { display: flex; flex-direction: column; line-height: 1.2; }
.dock-label { color: var(--muted); font-size: 13px; }
#dock-total { font-size: 22px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dock-status { margin: 0 auto; padding-bottom: 8px; font-size: 14px; color: var(--muted); }
.dock-status:empty { display: none; }
.dock-status.bad { color: var(--danger); }

/* 對話框 */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgb(0 0 0 / .45); padding: 16px; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 20px; max-width: 420px; width: 100%; }
.modal-box p { margin: 0 0 12px; }

/* 窄螢幕：欄位堆疊、明細改為卡片 */
@media (max-width: 600px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .list thead { display: none; }
  .list, .list tbody, .list tfoot { display: block; }
  .list tbody tr { display: grid; grid-template-columns: minmax(0, 1fr); padding: 12px 0; border-bottom: 1px solid var(--line); }
  .list td { display: flow-root; border: 0; padding: 3px 0 3px 6.5em; text-align: start; }
  .list td::before { content: attr(data-l); float: inline-start; width: 6em; margin-inline-start: -6.5em; color: var(--muted); font-size: 13px; padding-top: 2px; }
  .list td.num { text-align: start; }
  .list td.c-no { width: auto; }
  .list td:empty { display: none; }
  .list td.c-act { width: auto; padding-top: 8px; }
  .list tfoot tr { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; }
  .list tfoot td { padding: 0; }
  .list tfoot td::before { content: none; }
  .list tfoot td:not(.total-label):not(.total) { display: none; }
  .total-label { text-align: start; }
  .btn.big { padding-inline: 18px; }
  body.typing .dock { display: none; }
}
