/* 操作介面樣式（繁體中文 UI）。單據本身的樣式在 document-*.css。
   外觀語言跟隨 mockups/mockup.css v3（2026-09-14 確認版）：
   共用 tokens／殼層（shell）／卡片／表格／徽章全部對齊設計稿；
   介面 class 名稱沿用原型既有命名（.type-link、.status、table.list、.tab 等），只換視覺。 */

:root {
  --brand: #304c38;
  --brand-hover: #203b29;
  --bg: #f3f5f5;
  --paper: #fff;
  --ink: #192b28;
  --muted: #546763;
  --line: #dce4e1;
  --soft: #edf3ef;
  --orange: #994321;
  --orange-bg: #fff0e7;
  --green: #216343;
  --green-bg: #e9f5ed;
  --red: #a43631;
  --red-bg: #fff0ed;
  --amber: #805408;
  --amber-bg: #fff5df;
  --radius: 16px;
  --shadow: 0 8px 26px #17332908;
  font-family: Lexend, "PingFang HK", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
button, input, select { min-height: 44px; }
input[type="checkbox"] { min-height: auto; width: 18px; height: 18px; accent-color: var(--brand); }
a { color: var(--brand); text-underline-offset: 4px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.6rem, 2.6vw, 2rem); line-height: 1.25; letter-spacing: -.035em; }
h2 { font-size: 1.125rem; line-height: 1.4; margin: 0 0 10px; }
small, .meta { font-size: .875rem; color: var(--muted); }
strong { font-weight: 600; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #2776b8;
  outline-offset: 3px;
}
.skip { position: fixed; top: -100px; left: 16px; z-index: 100; background: white; padding: 12px; }
.skip:focus { top: 12px; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.mono, .money { font-variant-numeric: tabular-nums; }
.money { white-space: nowrap; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.hint { font-size: .875rem; color: var(--muted); }

/* ---------- 按鈕（.btn-primary／.btn-danger／.btn-sm 為原型既有命名；.primary/.danger/.sm 為 mockup 命名） ---------- */
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 15px;
  text-decoration: none;
  font-weight: 500;
  font-size: .875rem;
}
.btn:hover { background: var(--soft); }
.btn-primary, .btn.primary { color: white; background: var(--brand); border-color: var(--brand); }
.btn-primary:hover, .btn.primary:hover { background: var(--brand-hover); }
.btn-danger, .btn.danger { color: var(--red); border-color: #e6b6b1; }
.btn-sm, .btn.sm { min-height: 36px; padding: 5px 10px; font-size: .875rem; }

/* ---------- 徽章／狀態（.status draft|issued|revising 為既有命名，視覺＝mockup .badge.status-*） ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: .875rem;
  white-space: nowrap;
  font-weight: 500;
  background: var(--soft);
  color: var(--muted);
}
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: .875rem;
  white-space: nowrap;
  font-weight: 500;
  background: var(--soft);
  color: var(--muted);
}
.status.draft      { background: var(--amber-bg); color: var(--amber); }
.status.issued     { background: var(--green-bg); color: var(--green); }
.status.revising   { background: var(--orange-bg); color: var(--orange); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
  min-width: 0;
}
.card.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

/* ---------- 殼層：側欄 + 頂欄 + 主區（mockup .shell） ---------- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100dvh; }
.shell-main { min-width: 0; }
.sidebar {
  padding: 28px 18px;
  background: #233d2d;
  color: #fff;
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.wordmark { font-family: Comfortaa, sans-serif; font-size: 1.15rem; font-weight: 700; letter-spacing: -.035em; }
.wordmark small { display: block; font-family: inherit; color: #c3d3c5; font-size: .75rem; letter-spacing: .13em; margin-top: 5px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid #91aa964d; border-radius: 12px; font-size: 1.2rem; color: #dbebdb; }
.nav-section { color: #b7c9bc; font-size: .75rem; padding: 0 12px; margin: 6px 0 8px; letter-spacing: .08em; }
.nav { display: grid; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 9px; min-height: 46px; text-decoration: none; color: #d8e5db; font-size: .875rem; }
.nav a:hover { background: #ffffff0b; }
.nav a[aria-current="page"], .nav a.active { background: #edf3e8; color: #233d2d; font-weight: 600; }
.side-bottom { margin-top: auto; border-top: 1px solid #ffffff20; padding-top: 18px; color: #c3d3c5; font-size: .875rem; }
.nav-icon { width: 19px; height: 19px; flex: none; }
.sidebar .nav a { gap: 11px; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 32px; background: #fff; border-bottom: 1px solid var(--line); gap: 16px; }
.company-group { display: flex; gap: 12px; align-items: center; }
.company-logo { width: 56px; height: 56px; object-fit: contain; background: white; border-radius: 10px; }
.company-select { border: 0; background: transparent; font-weight: 600; max-width: none; padding: 0 24px 0 0; }

.bottom-nav { display: none; }

/* ---------- 登陸頁／登入頁／未設定頁：無側欄外殼的全頁狀態 ---------- */
.fullpage { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.landing-card, .login-card { width: min(560px, 100%); display: grid; gap: 16px; }
.login-banner { width: 100%; max-width: 360px; height: auto; margin: 0 auto; }
.company-tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.company-tile { display: grid; gap: 6px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; text-decoration: none; color: inherit; }
.company-tile:hover { background: var(--soft); }
.tile-fallback { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 10px; background: var(--soft); font-weight: 700; }
.tile-badge { font-size: .75rem; color: var(--muted); }

.main { max-width: 1450px; margin: auto; padding: 32px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 26px; }
.page-head p { color: var(--muted); font-size: .875rem; margin-top: 8px; }

/* ---------- 提示條 ---------- */
.notice { padding: 13px 16px; background: #eaf2fa; color: #244d70; border-radius: 10px; font-size: .875rem; margin-bottom: 14px; }
.notice.warning { background: var(--amber-bg); color: var(--amber); }
.notice.error { background: var(--red-bg); color: var(--red); }
.text-btn { display: inline-block; background: none; border: 0; padding: 6px 0; color: var(--brand); text-align: left; font-weight: 500; text-decoration: underline; text-underline-offset: 4px; }

/* ---------- 列表：分頁／工具列／表格 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 0 20px; overflow: auto; }
.tabs button, .tab { border: 0; background: transparent; padding: 10px 14px; white-space: nowrap; color: var(--muted); font-size: .875rem; border-bottom: 3px solid transparent; font-family: inherit; }
.tabs button[aria-pressed="true"], .tab.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }

.toolbar { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar label { font-size: .875rem; display: grid; gap: 5px; }
.toolbar select, .toolbar input { border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; background: white; }
.search-field { flex: 1; min-width: 190px; }

.table-wrap { overflow-x: auto; }
table.list, .doc-table { width: 100%; border-collapse: collapse; text-align: left; font-size: .875rem; }
table.list th, .doc-table th { font-weight: 500; color: var(--muted); background: #f6f8f7; text-align: left; padding: 12px; }
table.list td, .doc-table td { padding: 18px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr:last-child td, .doc-table tbody tr:last-child td { border-bottom: 0; }
table.list .num, table.list td.num, .doc-table .right { text-align: right; font-variant-numeric: tabular-nums; }
.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--soft); }
.doc-number { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
input.doc-number { color: var(--ink); text-overflow: ellipsis; }

.empty { text-align: center; padding: 48px 24px; max-width: 640px; margin: 20px auto; color: var(--muted); }
.empty p { margin: 12px 0 24px; color: var(--muted); }

.mobile-docs { display: none; }

/* ---------- 表單 ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-2 h2:first-child { margin-top: 0; }

.field { display: grid; gap: 6px; min-width: 0; font-size: .875rem; }
.field > span, .field legend { color: var(--muted); }
.field input, .field select, .field textarea,
input[type="text"], input[type="email"], input[type="tel"], input[type="date"], input[type="number"], textarea {
  width: 100%;
  border: 1px solid #bfcfc7;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  min-width: 0;
}
.field textarea, textarea { resize: vertical; min-height: 54px; }
.field input:read-only { background: #f5f7f6; color: var(--muted); }
input:disabled, textarea:disabled, select:disabled { background: #f5f7f6; color: var(--muted); }
label.field.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .875rem; }
label.field.checkbox input { width: auto; }

/* 客戶資料卡「搜尋聯絡人套用」：輸入框下方浮動結果清單 */
.contact-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 30;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.contact-search-item { padding: 10px 12px; cursor: pointer; font-size: .875rem; }
.contact-search-item:hover { background: var(--soft); }
.contact-search-empty { padding: 10px 12px; font-size: .875rem; color: var(--muted); }

/* ---------- 編輯器：項目表（.items-table 為 mockup 命名；舊 table.items 已由 items-table 取代） ---------- */
.items-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.items-table th { font-weight: 500; color: var(--muted); background: #f6f8f7; text-align: left; padding: 10px; border-bottom: 1px solid var(--line); }
.items-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.items-table input, .items-table textarea { width: 100%; min-height: 0; border: 1px solid #bfcfc7; border-radius: 8px; padding: 8px 10px; background: #fff; font: inherit; }
.items-table textarea { resize: vertical; }
.num-col { text-align: center; color: var(--muted); width: 28px; }
.price-col { width: 120px; }
.qty-col { width: 90px; }
.total-col { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; width: 110px; }
.act-col { width: 44px; text-align: center; }
.items-table input[type="number"] { text-align: right; }

/* ---------- 編輯器：總計與折扣 ---------- */
.totals-block { min-width: 300px; display: grid; gap: 6px; }
.totals-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; font-size: .875rem; font-variant-numeric: tabular-nums; }
.totals-row.grand { font-size: 1.05rem; border-top: 2px solid var(--line); padding-top: 8px; }
.totals-row .hint { margin-left: 6px; }
.discount-row .hint { font-weight: 400; font-size: .8125rem; }
.discount-inputs { display: flex; gap: 6px; align-items: center; }
.discount-inputs input { width: 90px; min-height: 0; border: 1px solid #bfcfc7; border-radius: 8px; padding: 6px 8px; background: #fff; font: inherit; text-align: right; }
.discount-inputs select { width: auto; min-height: 0; border: 1px solid #bfcfc7; border-radius: 8px; padding: 6px 8px; background: #fff; font: inherit; }

/* ---------- 編輯器：僱員快速新增 ---------- */
.quick-form { border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 12px; background: var(--soft); margin: 4px 0 12px; }

/* ---------- 回收站手機卡 ---------- */
/* display 由 .mobile-docs 規則控制（桌面隱藏、≤760px 顯示 grid）；.bin-list／.history-list 不可另設 display，否則桌面會同時顯示表格與卡片 */
.bin-list { gap: 10px; }

/* ---------- 預覽 overlay（置中對話框外觀，沿用 .overlay/.overlay-body/.paper 類名供列印樣式辨認） ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: #11291ccc;
  backdrop-filter: blur(3px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 10px;
}
.overlay-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px #0003;
  width: min(900px, calc(100vw - 20px));
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.overlay-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.overlay-actions { display: flex; gap: 10px; }
.overlay-body { flex: 1; overflow: auto; padding: 26px; }
.paper {
  margin: 0 auto;
  box-shadow: 0 8px 26px #0002;
  width: 210mm;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  z-index: 110;
  background: #183225;
  color: white;
  padding: 14px 20px;
  border-radius: 12px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 30px #0002;
  font-size: .875rem;
}

/* ================= 1150px 斷點 ================= */
@media (max-width: 1150px) {
  .shell { grid-template-columns: 200px minmax(0, 1fr); }
  .main { padding: 24px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  /* 頂欄在 761–1150px 之間空間有限：公司選擇器可收窄（文字截斷），避免頁面橫向溢出 */
  .company-group { flex: 1; min-width: 0; }
  .company-select { min-width: 0; max-width: 100%; text-overflow: ellipsis; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ================= 760px 斷點（手機版；與 mockups/mobile.html 的 data-layout="mobile" 規則逐條對應） ================= */
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 22px 16px 104px; }
  .topbar { padding: 10px 16px; min-height: 64px; position: sticky; top: 0; z-index: 25; box-shadow: 0 2px 12px #1733290b; }
  .company-group { flex: 1; min-width: 0; gap: 10px; width: 100%; }
  .company-logo { width: 42px; height: 42px; flex: none; }
  .company-select { flex: 1; max-width: 100%; font-size: 14px; font-weight: 700; color: #243b2c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .page-head { align-items: start; gap: 10px; margin-bottom: 18px; }
  .page-head h1 { font-size: 24px; line-height: 1.2; letter-spacing: -.045em; color: #1d3526; }
  .page-head > .row { flex-wrap: wrap; justify-content: flex-end; }
  .card { padding: 18px; border-radius: 13px; border-color: #e0e9e2; box-shadow: 0 6px 18px #1733290a; }
  .card h2 { font-size: 16px; line-height: 1.35; margin-bottom: 12px; color: #233b2b; }
  .notice { border: 1px solid #dce9df; background: #f0f7f2; border-radius: 12px; padding: 11px 13px; color: #426249; line-height: 1.45; font-size: 12px; }
  .company-tiles { grid-template-columns: 1fr; }

  /* 列表標頭：標題＋新增按鈕同行，「重設測試資料」折到下一行右側 */
  .list-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .list-head .row { display: contents; }
  .list-head #btnNew, .list-head #btnNewContact { grid-column: 2; grid-row: 1; padding: 8px 12px; min-height: 40px; font-size: 13px; white-space: nowrap; }
  .list-head #btnSeed { grid-column: 1 / -1; grid-row: 2; justify-self: end; min-height: 30px; padding: 3px 0; border: 0; background: transparent; color: var(--muted); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }

  /* 分頁改膠囊 */
  .tabs { gap: 8px; margin: 0 0 16px; padding: 0 0 3px; border: 0; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button, .tab { flex: none; min-height: 38px; padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: white; font-size: 13px; font-weight: 500; color: var(--muted); }
  .tabs button[aria-pressed="true"], .tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

  /* 工具列：搜尋 + 排序同一行 */
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 118px); align-items: end; gap: 10px; margin-bottom: 16px; }
  .toolbar label { min-width: 0; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
  .toolbar .search-field { min-width: 0; flex-basis: auto; }
  .toolbar .sort-field { min-width: 0; }
  .toolbar input, .toolbar select { width: 100%; min-height: 44px; border-color: #d7e3da; border-radius: 11px; font-size: 14px; color: var(--ink); }
  .table-wrap { overscroll-behavior-x: contain; }

  /* 桌面表格 ↔ 手機卡片切換（兩者同時在 DOM，純 CSS 切換） */
  .desktop-docs { display: none; }
  .mobile-docs { display: grid; gap: 10px; background: transparent; }
  #listCard { border: 0; background: transparent; box-shadow: none; }
  .mobile-doc { padding: 17px; border: 1px solid #e0e9e2; border-radius: 15px; background: white; box-shadow: 0 5px 16px #17332909; }
  .mobile-doc .doc-link { font-weight: 600; overflow-wrap: anywhere; text-decoration: none; color: #213a29; font-size: 15px; }
  .mobile-doc .row { gap: 8px; }
  .mobile-doc > .meta { margin-top: 6px; line-height: 1.4; }
  .mobile-doc .money { font-size: 18px; font-weight: 600; color: #213a29; }
  .mobile-doc .badge, .mobile-doc .status { font-size: 11px; }

  /* 編輯器欄位改單欄（grid-2 已在 1150px 收單欄，此處調間距） */
  .grid-2 { gap: 22px; }
  .grid-2 > div { min-width: 0; }
  .grid-2 .field + .field { margin-top: 12px; }
  .field { gap: 6px; font-size: 13px; font-weight: 600; color: #41584a; }
  .field input, .field select, .field textarea { min-height: 44px; border-color: #cfddd3; border-radius: 10px; font-size: 14px; color: #21372a; }
  .page-head:has(.doc-title) { flex-direction: column; }
  .page-head:has(.doc-title) > .row { justify-content: flex-start; }
  .doc-title { font-size: 1.5rem; overflow-wrap: anywhere; }

  /* 項目表卡片化 */
  .items-table, .items-table tbody, .items-table tr, .items-table td { display: block; width: 100%; }
  .items-table thead { display: none; }
  .items-table tr { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line); }
  .items-table tbody tr:first-child { padding-top: 2px; }
  .items-table tbody tr:last-child { border-bottom: 0; }
  .items-table td { padding: 0; border: 0; min-width: 0; }
  .items-table td::before { content: attr(data-label); display: block; margin-bottom: 5px; color: #607567; font-size: 11px; font-weight: 600; }
  .items-table .num-col { grid-column: 1 / -1; color: var(--brand); font-weight: 700; font-size: 12px; }
  .items-table .num-col::before { content: "項目 "; display: inline; margin: 0; }
  .items-table td:nth-child(2) { grid-column: 1 / -1; }
  .items-table .price-col { grid-column: 1; }
  .items-table .qty-col { grid-column: 2; }
  .items-table .total-col { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; text-align: left; width: 100%; font-size: 13px; font-weight: 700; color: #24442d; }
  .items-table .total-col::before { margin: 0; }
  .items-table .act-col { position: absolute; top: 8px; right: 0; width: auto; }
  .items-table textarea { min-height: 70px; resize: vertical; }
  .items-table input, .items-table textarea { width: 100%; font-size: 14px; }

  .totals-block { min-width: 0; max-width: 100%; width: 100%; }
  .totals-row { min-width: 0; }
  .totals-row > span:first-child { min-width: 0; }
  .discount-row { flex-wrap: wrap; }
  .discount-inputs { margin-left: auto; }
  .discount-inputs input { width: 72px; }
  .discount-inputs select { max-width: 94px; }

  /* 動作列雙欄按鈕 */
  .card.actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .card.actions .btn { width: 100%; min-width: 0; min-height: 42px; padding: 8px; text-align: center; white-space: normal; line-height: 1.25; }
  .card.actions .spacer { display: none; }

  /* 相關單據卡手機版 */
  #relatedCard .doc-table, #relatedCard tbody, #relatedCard table.list { display: block; width: 100%; }
  #relatedCard thead { display: none; }
  #relatedCard tr { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; padding: 13px 0; border-bottom: 1px solid var(--line); }
  #relatedCard tr:last-child { border-bottom: 0; }
  #relatedCard td { display: block; width: auto; padding: 0; border: 0; font-size: 12px; }
  #relatedCard td:first-child { grid-column: 1; color: var(--muted); }
  #relatedCard td.doc-number { grid-column: 1; grid-row: 2; font-size: 14px; }
  #relatedCard td:nth-child(3) { grid-column: 2; grid-row: 1 / 3; text-align: right; }
  #relatedCard td:nth-child(4) { grid-column: 1; grid-row: 3; color: var(--muted); }
  #relatedCard td:last-child { grid-column: 2; grid-row: 3; text-align: right; font-weight: 600; }

  /* 修訂歷史手機版 */
  .history-list { display: grid; gap: 0; }
  .history-entry { display: grid; gap: 6px; padding: 14px 0; border-bottom: 1px solid var(--line); }
  .history-entry:last-child { border-bottom: 0; padding-bottom: 0; }
  .history-entry-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; font-size: 13px; }
  .history-entry-head strong { min-width: 0; overflow-wrap: anywhere; }
  .history-entry-head .money { font-size: 14px; font-weight: 700; color: #24442d; }
  .history-note { margin: 2px 0; overflow-wrap: anywhere; }
  .history-entry .btn { justify-self: start; min-width: 106px; margin-top: 3px; }

  /* 回收站手機卡 */
  .bin-list { padding: 0; gap: 10px; }
  .bin-card { box-shadow: 0 5px 16px #17332909; }
  .bin-card > .money { display: block; margin: 8px 0 3px; }
  .bin-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
  .bin-actions .btn { min-width: 0; padding: 5px 3px; font-size: 11px; }

  /* 底部導覽列 */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 74px;
    padding: 6px max(6px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    border-top: 1px solid #dce6df;
    background: #fffffff7;
    backdrop-filter: blur(12px);
    box-shadow: 0 -5px 18px #17332912;
    gap: 1px;
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; flex: 1; min-width: 0; min-height: 58px; padding: 6px 1px; border-radius: 12px; color: var(--muted); font-size: 11px; line-height: 1.1; white-space: nowrap; text-decoration: none; }
  .bottom-nav a[aria-current="page"] { background: #e9f3eb; color: #234a30; font-weight: 700; }
  .bottom-nav .nav-icon { width: 20px; height: 20px; }
  .bottom-nav a:focus-visible { outline-offset: -3px; }

  .toast { bottom: 85px; }
  .empty { padding: 32px 8px; }
  .overlay { padding: 10px 6px; }
  .overlay-card { max-height: calc(100dvh - 20px); }
  .overlay-bar { flex-wrap: wrap; }
}

@media (max-width: 359px) {
  .topbar { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

/* ---------- 列印：只輸出預覽中的單據（與 css/print.css 配合；側欄／底欄在此隱藏） ---------- */
@media print {
  .sidebar, .bottom-nav, .skip { display: none !important; }
  .shell, .shell-main { display: block !important; }
  .overlay { padding: 0 !important; backdrop-filter: none !important; }
  .overlay-card {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    max-height: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    overflow: visible !important;
  }
  .overlay-actions { display: none !important; }
}
