/* =========================================================================
   倉租管理系統：介面樣式（DESIGN_QUALITY_R1）
   設計原則：暖白背景、深墨藍文字與導覽、節制的深青綠主動作色；狀態一律有文字，顏色只是輔助。
   對比（依下列色碼以 WCAG 公式計算）：內文 13.9:1、次要文字 9.0:1、提示 5.5～6.1:1、
   主按鈕白字 6.4:1、表單框線對白底 3.4:1、焦點框對背景 5.2:1 以上。
   不使用任何遠端字型、圖庫或 UI 套件；動態只用於狀態回饋，並遵循 prefers-reduced-motion。
   ========================================================================= */
:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-muted: #faf8f4;
  --surface-sunken: #f1efea;
  --line: #e4dfd6;
  --line-strong: #d3ccc0;
  --control-border: #858b94;
  --ink: #15253b;
  --ink-soft: #3b4a5e;
  --muted: #566377;
  --nav: #122033;
  --nav-2: #1a2c45;
  --nav-ink: #e8eef6;
  --nav-muted: #a9b8cb;
  --nav-active: #223a58;
  --primary: #0b6b61;
  --primary-strong: #08564e;
  --primary-soft: #e2f1ee;
  --primary-ink: #064c45;
  --focus: #1f63c6;
  --focus-on-dark: #8fd3c8;
  --danger: #b3261e;
  --danger-soft: #fcedeb;
  --danger-line: #f1b8b2;
  --success: #1c6b3a;
  --success-soft: #e6f4ea;
  --success-line: #b5dcc1;
  --warning-ink: #7a4b00;
  --warning-soft: #fff3d6;
  --warning-line: #efcb78;
  --info-ink: #1f4e7a;
  --info-soft: #eaf2fb;
  --info-line: #c3d7ee;
  --neutral-soft: #eceae4;
  --cny: #9e3a22;
  --twd: #1f4e7a;
  --radius-sm: 8px;
  --radius: 12px;
  --shadow-1: 0 1px 2px rgba(21, 37, 59, 0.06);
  --shadow-2: 0 8px 28px rgba(21, 37, 59, 0.16);
  --font: "Segoe UI", "Microsoft JhengHei UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", "Noto Sans CJK TC",
    "Heiti TC", system-ui, sans-serif;
  font-size: 16px;
}

/* 简体中文介面：改用簡體字型（Windows 的微軟雅黑、Apple 的蘋方 SC 等），字形與用字一致；
   切換語言時 <html lang> 就地改變，字型跟著切換，不必重新載入。 */
:root:lang(zh-Hans) {
  --font: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Noto Sans CJK SC",
    "Heiti SC", system-ui, sans-serif;
}

/* ---------- 基礎 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  line-height: 1.3;
  color: var(--ink);
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}

h2 {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 1.5rem 0 0.75rem;
}

h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 1.25rem 0 0.5rem;
}

p {
  margin: 0.5rem 0;
}

a {
  color: var(--primary);
  text-underline-offset: 3px;
}

a:not([class]):hover {
  color: var(--primary-strong);
}

b,
strong {
  font-weight: 700;
}

img {
  max-width: 100%;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[tabindex="-1"]:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  font-weight: 600;
}

.skip-link:focus {
  top: 12px;
}

table,
.num,
.currency-total,
.stat dd,
.bill-amount dd,
.meta-item dd {
  font-variant-numeric: tabular-nums;
}

/* ---------- 版面：員工工作台（桌面側欄／窄螢幕上方列＋選單） ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  line-height: 1.2;
}

.brand:hover {
  color: inherit;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  font-size: 1.0625rem;
}

.brand-sub {
  font-size: 0.8125rem;
  font-weight: 500;
  opacity: 0.85;
}

.shell-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar {
  background: var(--nav);
  color: var(--nav-ink);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar :focus-visible,
.nav-menu-panel :focus-visible {
  outline-color: var(--focus-on-dark);
}

.side-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-label,
.nav-section {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--nav-muted);
  letter-spacing: 0.02em;
}

.nav-section {
  margin: 14px 0 6px;
  padding: 0 12px;
}

.client-switch {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--nav-2);
  border-radius: 10px;
}

.client-option {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px; /* 主要觸控操作至少 44px（手機選單內的客戶切換） */
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--nav-ink);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.client-option:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.client-option.is-current {
  background: #fff;
  color: var(--ink);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--nav-ink);
  text-decoration: none;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.nav-link.is-active {
  background: var(--nav-active);
  color: #fff;
  font-weight: 700;
  border-left-color: var(--focus-on-dark);
}

.side-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.account-who {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}

.account-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-role {
  font-size: 0.8125rem;
  opacity: 0.85;
}

.inline-form {
  display: inline;
  margin: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.topbar-page {
  font-weight: 700;
  font-size: 1.0625rem;
}

.client-chip,
.client-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--info-ink);
  border: 1px solid var(--info-line);
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
  vertical-align: middle;
}

.nav-menu > summary {
  list-style: none;
}

.nav-menu > summary::-webkit-details-marker {
  display: none;
}

.nav-menu-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.nav-menu[open] > .nav-menu-button {
  background: var(--nav);
  color: #fff;
  border-color: var(--nav);
}

.nav-menu-icon,
.nav-menu-icon::before,
.nav-menu-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.nav-menu-icon {
  position: relative;
}

.nav-menu-icon::before,
.nav-menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.nav-menu-icon::before {
  top: -6px;
}

.nav-menu-icon::after {
  top: 6px;
}

.nav-menu[open] .nav-menu-icon {
  background: transparent;
}

.nav-menu[open] .nav-menu-icon::before {
  top: 0;
  transform: rotate(45deg);
}

.nav-menu[open] .nav-menu-icon::after {
  top: 0;
  transform: rotate(-45deg);
}

.nav-menu-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--nav);
  color: var(--nav-ink);
  box-shadow: var(--shadow-2);
}

.nav-menu-panel .account {
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost:hover {
  background: rgba(127, 127, 127, 0.18);
  border-color: currentColor;
  color: inherit;
}

@media (min-width: 1100px) {
  .layout-staff .shell {
    display: grid;
    grid-template-columns: 256px minmax(0, 1fr);
    min-height: 100vh;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .topbar {
    display: none;
  }
}

@media (max-width: 1099px) {
  .sidebar {
    display: none;
  }

  /* 員工窄螢幕的頂部列左邊是「選單」、右邊是語言鍵：「跳到主要內容」聚焦時改成正常文件流、自己佔一行，
     不浮在它們上面；沒有聚焦時照舊移出畫面。焦點樣式、跳到主內容與觸控導覽不變，文字放大時跟著撐高。
     is-held：聚焦時開始的觸控／滑鼠按壓，在這次點擊送出前維持原位（nav.js），避免失焦後版面上移讓點擊落空。 */
  .layout-staff .skip-link:focus,
  .layout-staff .skip-link.is-held {
    position: static;
    display: block;
    width: fit-content;
    max-width: calc(100% - 24px);
    margin: 8px 12px;
  }
}

/* ---------- 版面：客戶專區 ---------- */
.portal-top {
  background: var(--nav);
  color: var(--nav-ink);
}

.portal-top :focus-visible {
  outline-color: var(--focus-on-dark);
}

.portal-top-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px 32px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.identity {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.identity-label {
  font-size: 0.8125rem;
  color: var(--nav-muted);
  font-weight: 600;
}

.client-fixed {
  display: inline-flex;
  align-items: center;
  padding: 3px 14px;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.portal-top .account {
  margin-left: auto;
}

.portal-tabs {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  gap: 4px;
}

.portal-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 18px;
  color: var(--nav-ink);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}

.portal-tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.portal-tab.is-active {
  color: #fff;
  font-weight: 700;
  border-bottom-color: var(--focus-on-dark);
}

/* ---------- 版面：登入／錯誤等一般頁 ---------- */
.plain-top {
  padding: 16px 24px;
  background: var(--nav);
  color: var(--nav-ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
}

.plain-top :focus-visible {
  outline-color: var(--focus-on-dark);
}

/* ---------- 介面語言切換（繁體中文／简体中文） ----------
   員工桌面版在側欄品牌下方、窄螢幕在頂部列右側；客戶專區與登入／錯誤頁在頂部。兩個選項各用自己
   的文字顯示語言名稱，目前語言以 aria-pressed 與實心底色標示（不只靠顏色：另有粗體）。窄手機只顯示
   「繁」「简」單字，按鈕本身仍以完整名稱提供輔助工具。深色區（側欄、客戶專區頂部、登入頁頂部）與
   淺色頂部列各自設定選中底色，對比都在 7:1 以上。 */
.lang-switch {
  --lang-on-bg: #fff;
  --lang-on-ink: var(--nav);
  display: inline-flex;
  flex: none;
  align-items: stretch;
  gap: 2px;
  padding: 2px;
  border: 1px solid currentColor;
  border-radius: 999px;
}

.topbar .lang-switch {
  --lang-on-bg: var(--nav);
  --lang-on-ink: #fff;
  margin-left: auto;
  color: var(--ink);
}

.sidebar .lang-switch {
  align-self: flex-start;
}

button.lang-option {
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

button.lang-option:hover {
  background: rgba(127, 127, 127, 0.2);
  border-color: transparent;
  color: inherit;
}

button.lang-option[aria-pressed="true"],
button.lang-option[aria-pressed="true"]:hover {
  background: var(--lang-on-bg);
  border-color: var(--lang-on-bg);
  color: var(--lang-on-ink);
  font-weight: 700;
}

/* 語言名稱用各自的字型顯示（例如在简体介面裡，「繁體中文」仍以繁體字型呈現）。 */
.lang-option:lang(zh-Hant) {
  font-family: "Segoe UI", "Microsoft JhengHei UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

.lang-option:lang(zh-Hans) {
  font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

.lang-short {
  display: none;
}

/* ---------- 內容區 ---------- */
.content {
  flex: 1 0 auto;
  width: 100%;
  padding: 24px 32px 48px;
}

.content:focus {
  outline: none;
}

.portal-content {
  max-width: 1480px;
  margin: 0 auto;
}

.plain-content {
  padding-top: 32px;
}

.app-footer {
  padding: 16px 24px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8125rem;
}

.page-head {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin-bottom: 20px;
}

.page-head-text {
  min-width: 0;
  flex: 1 1 420px;
}

.page-head h1 {
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.lede {
  margin: 6px 0 0;
  max-width: 72ch;
  text-wrap: pretty; /* 支援的瀏覽器避免最後一行只剩一兩個字；不支援時照常換行 */
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.page-head .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 20px 24px;
  margin-bottom: 16px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.card-head h2,
.card-title {
  margin: 0 0 12px;
}

.card-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.title-note {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}

.section-subtitle {
  margin-top: 20px;
}

.hint {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 6px 0;
}

.muted-text {
  color: var(--muted);
}

.count-note {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.9375rem;
}

.inline-note,
.field-note {
  margin: 4px 0 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.wrap,
p.wrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 狀態標籤與單一時間不拆字；期間只在「～」兩側換行（每個日期本身完整），窄螢幕放大文字時不撐破版面。 */
.badge,
time {
  white-space: nowrap;
}

.meta-note {
  display: block;
  margin-top: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-soft);
}

/* ---------- 表單 ---------- */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  min-width: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0 20px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.form-grid-tight {
  max-width: 640px;
}

label {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--ink);
}

.req {
  color: var(--danger);
  margin-left: 2px;
}

.field-hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.875rem;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
}

input::placeholder,
textarea::placeholder {
  color: #6b7385;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #efede8;
  color: #6b7385;
}

textarea {
  min-height: 5rem;
  resize: vertical;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 0;
  padding: 0;
  accent-color: var(--primary);
}

input[type="file"] {
  padding: 8px;
  background: var(--surface-muted);
}

input.invalid,
textarea.invalid,
select.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.field-error {
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 600;
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

fieldset {
  min-width: 0;
  max-width: 100%;
  border: 0;
  margin: 0;
  padding: 0;
}

.fieldset-box {
  padding: 12px 16px;
  margin: 0 0 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 600;
}

details.more,
details.rules {
  margin: 4px 0 16px;
}

details.more > summary,
details.rules > summary,
details.lines > summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  /* 品質覆驗（2026-10-06）：右側留白 6px，鍵盤焦點框（外移 2px）不貼住最後一個字；左側已有 ▸ 符號本身的留白，左右看起來一致。 */
  padding-right: 6px;
  /* 窄螢幕換行時各行長度平均，不讓最後一兩個字單獨落到下一行（不支援的瀏覽器照一般換行）。 */
  text-wrap: balance;
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  list-style: none;
}

details.more > summary::-webkit-details-marker,
details.rules > summary::-webkit-details-marker,
details.lines > summary::-webkit-details-marker {
  display: none;
}

details.more > summary::before,
details.rules > summary::before,
details.lines > summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  margin-right: 6px;
  transition: transform 0.15s ease;
}

details[open].more > summary::before,
details[open].rules > summary::before,
details[open].lines > summary::before {
  transform: rotate(90deg);
}

details.rules {
  max-width: 72ch;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

details.rules ul {
  margin: 0 0 12px;
  padding-left: 1.25rem;
  color: var(--ink-soft);
}

details.rules li {
  margin: 4px 0;
}

details.lines {
  margin-top: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.toolbar .grow {
  flex: 1 1 280px;
}

.toolbar select {
  width: auto;
  min-width: 10rem;
}

.toolbar-actions {
  flex-direction: row !important;
  gap: 8px !important;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.form-actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* ---------- 按鈕 ---------- */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:hover,
.btn:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
  color: #fff;
}

button.secondary,
.btn.secondary {
  background: var(--surface);
  color: var(--primary-ink);
  border-color: var(--primary);
}

button.secondary:hover,
.btn.secondary:hover {
  background: var(--primary-soft);
  color: var(--primary-ink);
}

button.danger,
.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

button.danger:hover,
.btn.danger:hover {
  background: #8f1e18;
  border-color: #8f1e18;
}

button.secondary.danger-text {
  color: var(--danger);
  border-color: var(--danger-line);
}

button.secondary.danger-text:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

button.small,
.btn.small {
  min-height: 36px;
  padding: 4px 12px;
  font-size: 0.875rem;
}

button.big,
.btn.big {
  min-height: 48px;
  padding: 10px 24px;
  font-size: 1.0625rem;
  font-weight: 700;
}

button.block,
.btn.block {
  width: 100%;
}

button:disabled,
button:disabled:hover {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--primary);
  border-color: var(--primary);
}

button.secondary:disabled,
button.secondary:disabled:hover {
  background: var(--surface);
}

button.danger:disabled,
button.danger:disabled:hover {
  background: var(--danger);
  border-color: var(--danger);
}

.link-btn {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  font-weight: 600;
}

.btn-light {
  background: #fff;
  color: var(--ink);
  border-color: #fff;
}

.btn-light:hover {
  background: #e8eef6;
  border-color: #e8eef6;
  color: var(--ink);
}

.chip-btn {
  min-height: 32px;
  padding: 2px 12px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
}

.chip-btn:hover {
  background: var(--primary);
  color: #fff;
}

.chip-btn.is-empty {
  background: var(--surface);
  border-style: dashed;
}

/* ---------- 表格：只在區塊內橫向捲動（右側陰影提示還有欄位） ---------- */
/* position: relative：表格內絕對定位的報讀文字（.sr-only）以捲動框為準、隨框裁切，表格比框寬時不撐寬整頁（LIST_COLUMNS_01 1024 寬實測）。 */
.table-scroll {
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(to left, var(--surface) 30%, rgba(255, 255, 255, 0)) right center / 40px 100% no-repeat local,
    radial-gradient(farthest-side at 100% 50%, rgba(21, 37, 59, 0.2), rgba(21, 37, 59, 0)) right center / 14px 100% no-repeat
      scroll,
    var(--surface);
}

.scroll-hint {
  display: none;
  margin: 0 0 6px;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.scroll-hint::before {
  content: "↔ ";
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
  font-size: 0.9375rem;
}

table.compact {
  min-width: 480px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  background: #f3f1ec;
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 700;
}

tbody tr:hover td {
  background: #fbfaf7;
}

td.wrap {
  white-space: pre-wrap;
  min-width: 12rem;
}

td.num,
th.num {
  text-align: right;
}

td:first-child,
th:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
}

th:first-child {
  background: #f3f1ec;
}

tbody tr:hover td:first-child {
  background: #fbfaf7;
}

.table-note {
  color: var(--muted);
  text-align: center;
  padding: 20px 12px;
}

td.table-note {
  position: static;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

/* ---------- 狀態標籤與訊息 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--neutral-soft);
  color: var(--ink-soft);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.55;
  vertical-align: middle;
  text-decoration: none;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.badge.ok {
  background: var(--success-soft);
  border-color: var(--success-line);
  color: var(--success);
}

.badge.warn {
  background: var(--warning-soft);
  border-color: var(--warning-line);
  color: var(--warning-ink);
}

.badge.info {
  background: var(--info-soft);
  border-color: var(--info-line);
  color: var(--info-ink);
}

.badge.danger {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: var(--danger);
}

a.badge:hover {
  text-decoration: underline;
}

.error-box,
.ok-box,
.info-box,
.notice {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 0 0 14px;
  border: 1px solid;
  border-left-width: 4px;
  overflow-wrap: anywhere;
  font-size: 0.9375rem;
}

.error-box,
.notice-danger {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  border-left-color: var(--danger);
  color: var(--danger);
  font-weight: 600;
}

.ok-box {
  background: var(--success-soft);
  border-color: var(--success-line);
  border-left-color: var(--success);
  color: var(--success);
  font-weight: 600;
}

.info-box,
.notice-info {
  background: var(--info-soft);
  border-color: var(--info-line);
  border-left-color: var(--info-ink);
  color: var(--ink);
}

.notice-warn {
  background: var(--warning-soft);
  border-color: var(--warning-line);
  border-left-color: var(--warning-ink);
  color: var(--warning-ink);
}

.notice a,
.ok-box a:not(.btn),
.error-box a:not(.btn) {
  font-weight: 700;
}

.ok-box .btn,
.error-box .btn {
  margin-left: 8px;
}

.progress-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--info-soft);
  color: var(--info-ink);
  font-weight: 600;
}

.progress-note::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.empty-state {
  padding: 28px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  text-align: center;
  color: var(--ink-soft);
}

.empty-title {
  margin: 0 0 6px;
  font-weight: 700;
  color: var(--ink);
}

.empty-note {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  color: var(--ink-soft);
}

/* ---------- 匯入預覽的筆數格 ---------- */
.totals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.totals-grid .box {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  text-align: center;
}

.totals-grid .box .num {
  font-size: 1.375rem;
  font-weight: 800;
}

/* ---------- 首頁客戶卡片 ---------- */
.client-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}

.client-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
  margin: 0;
}

.stat {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.stat dt {
  font-size: 0.8125rem;
  color: var(--muted);
  font-weight: 600;
}

.stat dd {
  margin: 2px 0 0;
  color: var(--ink-soft);
}

.stat dd b {
  font-size: 1.375rem;
  color: var(--ink);
}

.stat.is-attention {
  background: var(--warning-soft);
  border-color: var(--warning-line);
}

.stat.is-attention dd b {
  color: var(--warning-ink);
}

.client-card .notice {
  margin: 0;
}

.client-card-status .hint {
  margin: 2px 0;
}

.quick {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: auto;
}

.admin-links {
  margin-top: 20px;
}

/* ---------- 結帳步驟、分幣卡片、頁內確認 ---------- */
.step-card {
  padding-top: 18px;
}

.step-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 1.125rem;
}

.step-title-spaced {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.step-no {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.9375rem;
  flex: none;
}

.scope-line {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
  font-weight: 600;
}

.currency-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin: 12px 0 8px;
}

.currency-card {
  position: relative;
  min-width: 0;
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.currency-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--line-strong);
}

.currency-card.cny::before {
  background: var(--cny);
}

.currency-card.twd::before {
  background: var(--twd);
}

.currency-title {
  margin: 0;
  font-weight: 700;
}

.currency-card.cny .currency-title {
  color: var(--cny);
}

.currency-card.twd .currency-title {
  color: var(--twd);
}

.currency-total {
  margin: 4px 0 10px;
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.currency-lines {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  margin: 0;
  font-size: 0.9375rem;
}

.currency-lines dt {
  color: var(--muted);
}

.currency-lines dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.currency-rule {
  margin: 4px 0 12px;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.meta-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 8px 0;
}

.meta-inline > div {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.meta-inline dt {
  color: var(--muted);
  font-size: 0.875rem;
}

.meta-inline dd {
  margin: 0;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px 24px;
  margin: 0 0 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.meta-item {
  min-width: 0;
}

.meta-item dt {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.meta-item dd {
  margin: 4px 0 0;
  font-weight: 600;
}

.confirm-panel {
  margin-top: 12px;
  padding: 16px 18px;
  border: 1px solid var(--warning-line);
  border-left: 4px solid var(--warning-ink);
  border-radius: var(--radius-sm);
  background: #fffbf0;
}

.confirm-text {
  margin: 0 0 12px;
  font-size: 1.0625rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ack-box {
  margin-bottom: 10px;
  padding: 8px 14px;
  border: 1px dashed var(--warning-line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.danger-zone {
  border-color: var(--danger-line);
}

.zone-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.zone-label {
  margin: 0;
  font-weight: 700;
}

.zone-row .hint {
  margin: 2px 0 0;
}

/* ---------- 帳單清單（客戶） ---------- */
.bill-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}

.bill-card {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bill-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.bill-card-title {
  margin: 0;
  font-size: 1.125rem;
}

.bill-card-title a {
  color: var(--ink);
  text-decoration: none;
}

.bill-card-title a:hover {
  text-decoration: underline;
}

.bill-period,
.bill-states {
  margin: 0;
  color: var(--ink-soft);
}

.bill-amounts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0;
}

.bill-amount {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-top: 3px solid var(--line-strong);
}

.bill-amount.cny {
  border-top-color: var(--cny);
}

.bill-amount.twd {
  border-top-color: var(--twd);
}

.bill-amount dt {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.bill-amount dd {
  margin: 2px 0 0;
  font-size: 1.125rem;
  font-weight: 800;
}

/* ---------- 編輯區（貨品／事項）：桌面時照片與欄位並排 ---------- */
.editor {
  border-color: var(--line-strong);
}

.editor-narrow {
  max-width: 960px;
}

.editor-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 16px;
}

.editor-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.editor-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}

.editor-main {
  min-width: 0;
  max-width: 880px;
}

@media (min-width: 1280px) {
  .editor-body {
    grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr);
    align-items: start;
  }
}

.photo-jump {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  border: 1px solid var(--primary);
  font-weight: 700;
  font-size: 0.9375rem;
  text-decoration: none;
}

.photo-jump:hover {
  background: var(--primary);
  color: #fff;
}

.history-box {
  margin-top: 20px;
}

.history-title {
  margin: 0 0 8px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-list li {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.history-meta {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.history-reason {
  margin: 4px 0 0;
}

/* ---------- 照片：保持原圖比例（contain，不裁切），固定框比例避免載入時版面跳動 ---------- */
.photo-panel {
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 1.125rem;
}

.panel-note {
  font-size: 0.875rem;
  color: var(--ink-soft);
  margin: 6px 0 12px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin: 8px 0 12px;
}

.photo-grid .wide {
  grid-column: 1 / -1;
}

.photo-tile {
  margin: 0;
  min-width: 0;
}

.photo-thumb,
.thumb-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-sunken);
  overflow: hidden;
  cursor: zoom-in;
}

.photo-thumb:hover,
.thumb-button:hover {
  background: var(--surface-sunken);
  border-color: var(--primary);
}

.photo-thumb img,
.thumb-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.photo-thumb.is-broken img,
.thumb-button.is-broken img {
  visibility: hidden;
}

/* 縮圖失敗文字由詞條提供（app.js 在框上設定 data-broken-label，切換語言時就地改字）。 */
.photo-thumb.is-broken::after,
.thumb-button.is-broken::after {
  content: attr(data-broken-label);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 600;
}

.photo-count-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(18, 32, 51, 0.85);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.no-photo {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 6px;
  color: var(--ink-soft);
  font-size: 0.875rem;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.photo-tile figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.photo-tile.pending {
  padding: 6px;
  border: 2px dashed var(--primary);
  border-radius: 10px;
  background: var(--primary-soft);
}

.photo-tile.pending img,
.photo-tile.pending .no-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 6px;
  background: var(--surface);
}

/* 待上傳預覽：瀏覽器解不出的檔案（偽裝副檔名、損壞的圖片）顯示設計過的佔位，不顯示破圖圖示。
   是否接受仍由上傳時伺服器的整批檢查決定。 */
.pending-thumb {
  position: relative;
  display: block;
}

.pending-thumb img {
  display: block;
}

.pending-thumb.is-broken img {
  visibility: hidden;
}

.pending-thumb.is-broken::after {
  content: attr(data-broken-label);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 6px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
}

/* 刪除照片確認：照片格上醒目標示要刪的那一張，確認區附同一張縮圖與「第 N 張」。 */
.photo-tile.is-delete-target .photo-thumb {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger);
}

.delete-confirm-body {
  display: flex;
  align-items: center;
  gap: 12px;
}

.delete-preview:empty {
  display: none;
}

.delete-preview img {
  display: block;
  width: 88px;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 2px solid var(--danger);
  border-radius: 8px;
  background: var(--surface-sunken);
}

.upload-box {
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px dashed var(--line-strong);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- 對話框：照片大圖、貨品詳情抽屜、申請表單 ---------- */
dialog {
  color: var(--ink);
}

/* 固定在畫面上：原生對話框本來就是如此；不支援原生對話框的舊瀏覽器（以 open 屬性顯示）也照樣
   蓋在頁面上方。用上下左右四個屬性而不用 inset，舊瀏覽器也看得懂。 */
dialog.lightbox,
dialog.drawer,
dialog.sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
}

dialog.lightbox {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(10, 16, 26, 0.95);
  color: #fff;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

dialog.lightbox:not([open]) {
  display: none;
}

dialog.lightbox::backdrop {
  background: rgba(10, 16, 26, 0.6);
}

.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.lightbox-caption {
  margin: 0;
  font-weight: 700;
}

.lightbox-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0 64px;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 64px;
  padding: 0;
  border-radius: 10px;
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.6);
}

.lightbox-nav:disabled,
.lightbox-nav:disabled:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.2);
}

.lightbox-nav.is-prev {
  left: 8px;
}

.lightbox-nav.is-next {
  right: 8px;
}

.lightbox-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 16px 14px;
}

.lightbox-status {
  margin: 0;
  font-weight: 600;
}

.lightbox-help {
  margin: 0;
  font-size: 0.8125rem;
  color: #c9d3df;
}

.lightbox :focus-visible {
  outline-color: var(--focus-on-dark);
}

dialog.drawer {
  width: min(560px, 100vw);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-2);
}

dialog.drawer:not([open]) {
  display: none;
}

dialog.drawer::backdrop,
dialog.sheet::backdrop {
  background: rgba(18, 32, 51, 0.45);
}

.drawer-head,
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2,
.sheet-head h2 {
  margin: 0;
  font-size: 1.125rem;
  min-width: 0; /* 長標題自行換行，不擠壓右側的關閉按鈕 */
}

/* 標題列右側的按鈕（例如「關閉」）維持完整寬度、文字不拆成兩行。 */
.drawer-head > button,
.sheet-head > button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.drawer-body,
.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 20px 24px;
}

dialog.sheet {
  width: min(640px, calc(100vw - 32px));
  height: fit-content;
  max-width: 100vw;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-2);
}

dialog.sheet:not([open]) {
  display: none;
}

.sheet-foot {
  margin: 0;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}

.detail-fields {
  display: grid;
  grid-template-columns: minmax(6rem, max-content) minmax(0, 1fr);
  gap: 8px 16px;
  margin: 0 0 8px;
}

.detail-fields dt {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9375rem;
}

.detail-fields dd {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.detail-fields dd.is-empty {
  color: var(--muted);
}

/* ---------- 客戶庫存：卡片清單、選取與申請 ---------- */
.toolbar + .error-box,
.result-summary {
  margin-top: 4px;
}

.result-summary {
  margin: 0 0 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.portal-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.portal-list[aria-busy="true"] {
  opacity: 0.6;
}

.portal-list > .empty-state {
  grid-column: 1 / -1;
}

.portal-item {
  display: grid;
  grid-template-columns: auto 132px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  min-width: 0;
}

.portal-item.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
  background: #f6fbfa;
}

.pick {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -4px -4px 0;
  cursor: pointer;
}

.pick input {
  width: 22px;
  height: 22px;
}

.portal-item-body {
  min-width: 0;
  overflow-wrap: anywhere;
}

.portal-item-title {
  margin: 0 0 2px;
  font-size: 1.0625rem;
}

.portal-item-title.is-unnamed {
  color: var(--muted);
  font-weight: 600;
}

.item-ids,
.item-dates {
  margin: 2px 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.item-ids .sep {
  margin: 0 4px;
  color: var(--muted); /* 與旁邊的編號文字同色；即使只是分隔點，也維持一般文字的對比 */
}

.item-status {
  margin: 6px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.portal-item-body > button {
  margin-top: 6px;
}

.request-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin: 16px -4px 0;
  padding: 14px 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 -6px 20px rgba(21, 37, 59, 0.1);
}

.request-bar-text {
  flex: 1 1 320px;
  min-width: 0;
}

.selected-count {
  margin: 0;
  font-weight: 700;
  font-size: 1.0625rem;
}

.request-bar-note {
  margin: 2px 0 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.request-bar > button {
  margin-left: auto;
  min-width: 10rem;
}

.selected-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 6.5rem;
  overflow-y: auto;
}

.selected-list:empty {
  display: none;
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 4px 2px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-size: 0.875rem;
  font-weight: 600;
}

.selected-chip span {
  min-width: 0; /* 彈性項目預設不縮小；要能縮才會出現省略號，長品名不撐破畫面 */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-remove {
  min-height: 32px;
  width: 32px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--primary-ink);
  font-size: 1.125rem;
  line-height: 1;
}

.chip-remove:hover {
  background: var(--primary);
  color: #fff;
}

/* ---------- 寄出申請：卡片、進度（只顯示真實狀態與時間） ---------- */
.request-list {
  display: grid;
  gap: 12px;
}

.request-card {
  margin: 0;
  overflow-wrap: anywhere;
}

.request-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.request-title {
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 1.125rem;
}

.request-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.progress {
  list-style: none;
  margin: 14px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.progress-step {
  padding: 8px 12px;
  border-top: 4px solid var(--line);
  background: var(--surface-muted);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.progress-label {
  font-weight: 700;
  font-size: 0.9375rem;
}

.progress-time {
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.progress-step.is-done {
  border-top-color: var(--primary);
}

.progress-step.is-current {
  border-top-color: var(--info-ink);
  background: var(--info-soft);
}

.progress-step.is-todo .progress-label {
  color: var(--muted);
  font-weight: 600;
}

.progress-step.is-cancelled {
  border-top-color: var(--ink-soft);
  background: var(--neutral-soft);
}

/* 申請內的貨品：一筆一列、寬度一致（不再依單號長短變成寬窄不一的晶片）。 */
.request-items {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}

.request-items li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  font-size: 0.9375rem;
}

.request-item-name {
  font-weight: 600;
}

.audit-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 20px;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

/* ---------- 登入／錯誤頁 ---------- */
.auth-card {
  max-width: 440px;
  margin: 24px auto;
  padding: 28px 28px 24px;
}

.auth-card h1 {
  margin-bottom: 4px;
}

.auth-card form {
  margin-top: 18px;
}

.error-code {
  margin: 0 0 4px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--muted);
}

.error-detail {
  font-size: 1.0625rem;
}

/* ---------- 窄螢幕（平板與手機） ---------- */
@media (max-width: 899px) {
  .scroll-hint {
    display: block;
  }

  .content {
    padding: 20px 20px 40px;
  }

  .portal-top-inner,
  .portal-tabs {
    padding-left: 20px;
    padding-right: 20px;
  }

  .portal-list {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 599px) {
  h1 {
    font-size: 1.3125rem;
  }

  /* 窄手機：頂部列與客戶專區頂部的語言切換只顯示「繁」「简」，不擠掉頁面名稱與帳號。 */
  .topbar .lang-long,
  .portal-top .lang-long {
    display: none;
  }

  .topbar .lang-short,
  .portal-top .lang-short {
    display: inline;
  }

  .topbar button.lang-option,
  .portal-top button.lang-option {
    min-width: 40px;
    padding: 4px 10px;
  }

  .content {
    padding: 16px 16px 32px;
  }

  .card {
    padding: 16px;
  }

  .portal-top-inner {
    padding: 10px 16px;
    gap: 8px 12px;
  }

  .portal-top .brand-text {
    font-size: 1rem;
  }

  .portal-tabs {
    padding: 0;
    gap: 0;
  }

  .portal-tab {
    flex: 1 1 0;
    padding: 8px 4px;
    min-width: 0;
  }

  .page-head .actions {
    margin-left: 0;
    width: 100%;
  }

  .page-head .actions > * {
    flex: 1 1 auto;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .toolbar > div,
  .toolbar > button {
    flex: 1 1 100%;
  }

  .toolbar select {
    width: 100%;
  }

  .toolbar-actions > button {
    flex: 1 1 0;
  }

  .client-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .confirm-panel .button-row > *,
  .sheet-foot > * {
    flex: 1 1 100%;
  }

  .portal-item {
    grid-template-columns: auto 96px minmax(0, 1fr);
    gap: 10px;
  }

  .request-bar {
    margin: 12px -8px 0;
    padding: 12px 14px;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .request-bar > button {
    width: 100%;
    margin-left: 0;
  }

  /* 尚未勾選任何貨品：精簡成一行提示＋按鈕，不再佔掉約四分之一的手機畫面；
     勾選後（移除 is-empty）才展開已選清單與「勾選不是寄出」說明（申請表單內也有同一說明）。 */
  .request-bar.is-empty {
    flex-wrap: nowrap;
    padding: 8px 12px;
  }

  .request-bar.is-empty .request-bar-text {
    flex: 1 1 0;
  }

  .request-bar.is-empty .request-bar-note {
    display: none;
  }

  .request-bar.is-empty .selected-count {
    font-size: 0.9375rem;
    font-weight: 600;
  }

  .request-bar.is-empty > button {
    width: auto;
    min-width: 0;
    flex: 0 0 auto;
  }

  .bill-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .bill-amounts {
    grid-template-columns: minmax(0, 1fr);
  }

  /* 帳單摘要（編號、期間、狀態、收款、貨品、事項）手機上兩欄並排，人民幣／台幣應收不會被擠到首屏下方。
     半欄放不下的時間（全站 time 預設不換行，例如「建立時間 2026/10/01 18:33（UTC+8）」）在欄內換行，
     不把整頁撐寬。 */
  .meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 16px;
  }

  .meta-grid time {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  }

  .detail-fields {
    grid-template-columns: minmax(5rem, max-content) minmax(0, 1fr);
  }

  dialog.sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    max-height: 92dvh;
  }

  dialog.drawer {
    width: 100vw;
    border-left: 0;
  }

  .lightbox-stage {
    padding: 0 8px 64px;
  }

  .lightbox-nav {
    top: auto;
    bottom: 4px;
    transform: none;
    height: 52px;
  }

  .lightbox-nav.is-prev {
    left: calc(50% - 60px);
  }

  .lightbox-nav.is-next {
    right: calc(50% - 60px);
  }

  .lightbox-help {
    display: none;
  }

  .auth-card {
    margin: 8px auto;
    padding: 22px 18px;
  }
}

/* 觸控裝置：所有按鈕與可點擊標籤至少 44px 高。 */
@media (pointer: coarse) {
  button.lang-option {
    min-height: 40px;
  }

  button.small,
  .btn.small,
  .btn-ghost,
  .chip-btn,
  .link-btn,
  .photo-jump {
    min-height: 44px;
  }

  .chip-remove {
    min-height: 44px;
    width: 44px;
  }
}

/* 動態只做狀態回饋；使用者要求減少動態時全部關閉。 */
@media (prefers-reduced-motion: no-preference) {
  dialog.drawer[open] {
    animation: drawer-in 0.2s ease-out;
  }

  dialog.sheet[open] {
    animation: sheet-in 0.18s ease-out;
  }

  .progress-note::before {
    animation: pulse 1.2s ease-in-out infinite;
  }
}

@keyframes drawer-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* 列印（帳單等）：只留內容。 */
@media print {
  .sidebar,
  .topbar,
  .portal-top,
  .lang-switch,
  .app-footer,
  .page-head .actions,
  .request-bar,
  .skip-link,
  .danger-zone {
    display: none !important;
  }

  /* 員工外殼：側欄在列印時隱藏，寬版媒體（≥1100px）原本的 256px＋主欄格線會讓主內容落進 256px 欄；
     列印改成全寬單欄，並取消依螢幕高度的最小高度。一般桌面（螢幕）與客戶專區不受影響。 */
  .layout-staff .shell {
    display: block;
    min-height: 0;
  }

  .layout-staff .shell-main {
    min-height: 0;
  }

  body,
  .card {
    background: #fff;
    box-shadow: none;
  }

  .table-scroll {
    overflow: visible;
  }
}

/* ---------- 寄出擴充（資料庫第 5 版）：物流單號、分區、收件資料、寄件文件、大榮與貨到付款 ---------- */
.lnum-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.lnum {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.lnum-no {
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 0.95em;
  letter-spacing: 0.02em;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  overflow-wrap: anywhere;
}

.lnum-tag {
  color: var(--muted);
  font-size: 0.85em;
}

.copy-btn {
  min-height: 32px;
  padding: 2px 10px;
  font-size: 0.85em;
  background: var(--surface);
  color: var(--primary-ink);
  border: 1px solid var(--line-strong);
}

.lnum-toggle {
  margin-top: 4px;
}

/* 一筆號碼（號碼＋用途／承運商＋複製）在桌機寬度盡量排成一行，不被擠成多行。 */
.numbers-cell {
  min-width: 19rem;
}

.item-numbers {
  margin: 6px 0;
}

.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.status-tab {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  min-height: 40px;
}

.status-tab[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.tab-count {
  display: inline-block;
  min-width: 1.6em;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(21, 37, 59, 0.08);
  font-variant-numeric: tabular-nums;
}

.status-tab[aria-pressed="true"] .tab-count {
  background: rgba(255, 255, 255, 0.22);
}

.numbers-editor {
  margin: 16px 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.number-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}

.number-row .num-no {
  flex: 2 1 12rem;
}

.number-row .num-carrier {
  flex: 1 1 8rem;
}

.ship-content {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 12px 0;
}

.ship-content legend {
  font-weight: 700;
  padding: 0 6px;
}

.recipient-block {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--info-line);
  background: var(--info-soft);
  border-radius: var(--radius-sm);
}

.recipient-block > .section-subtitle {
  margin-top: 0;
}

.recipient-block.is-missing {
  background: var(--surface-muted);
  border-color: var(--line);
}

.recipient-list {
  display: grid;
  gap: 6px;
  margin: 0;
}

.recipient-row {
  display: grid;
  grid-template-columns: minmax(6rem, 9rem) 1fr;
  gap: 8px;
  align-items: center;
}

.recipient-row dt {
  color: var(--muted);
  font-weight: 600;
}

.recipient-row dd {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.recipient-tools {
  margin-top: 8px;
}

.cod-block,
.batch-numbers,
.doc-block,
.kerry-block {
  margin: 12px 0;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.doc-row {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.doc-row.is-retired {
  opacity: 0.7;
  background: var(--surface-muted);
}

.doc-name {
  font-weight: 600;
}

.doc-meta {
  color: var(--muted);
  font-size: 0.9em;
}

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.readiness {
  margin: 8px 0;
}

.lock-note {
  color: var(--warning-ink);
  font-weight: 600;
}

.ship-method {
  margin: 8px 0;
}

.warn-box {
  background: var(--warning-soft);
  border: 1px solid var(--warning-line);
  color: var(--warning-ink);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 12px 0;
}

/* UPLOAD_REPLAY_01：上傳結果尚未確認（可能已存也可能沒有）。警示色區塊；按鈕沿用一般按鈕（觸控 44px）；檔名可換行。 */
.upload-pending {
  background: var(--warning-soft);
  border: 1px solid var(--warning-line);
  color: var(--warning-ink);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 12px 0;
}

.upload-pending p {
  margin: 0 0 8px;
}

.upload-pending-title {
  font-weight: 700;
}

.upload-pending-files {
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.upload-pending .button-row {
  margin-top: 4px;
}

.create-panel {
  margin-bottom: 16px;
}

.create-panel > summary {
  cursor: pointer;
  font-weight: 700;
  padding: 4px 0;
}

.check-list {
  display: grid;
  gap: 6px;
  max-height: 18rem;
  overflow: auto;
}

.static-value {
  margin: 6px 0 0;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .recipient-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .numbers-cell {
    min-width: 12rem;
  }
}

@media print {
  /* 「列印這筆申請」：只印目前這張申請卡（收件資料、方式、貨品、單號），按鈕與其他卡片都不印；
     不自動選擇或啟動實體印表機，由使用者在列印對話框確認。 */
  body.print-one .request-card:not(.print-target),
  body.print-one .page-head,
  body.print-one .toolbar,
  body.print-one .create-panel,
  body.print-one .ok-box,
  body.print-one .error-box,
  .copy-btn,
  .doc-actions,
  .request-card .button-row,
  .status-tabs {
    display: none !important;
  }
}

/* ---------- 待整理照片區 ---------- */
.pending-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.pending-card {
  margin: 0;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.pending-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.pending-card figcaption {
  display: grid;
  gap: 4px;
  font-size: 0.9em;
}

/* =========================================================================
   品質階段 Q1（2026-10-04，Claude 自審）：依真瀏覽器逐頁稽核（quality-phase/audit/a0-baseline）修正
   - 320 CSS px 重排（WCAG 1.4.10）：有傳統捲軸時可用寬度不到 320，body 最小寬度會造成整頁橫向捲動；
     改為不設最小寬度，並讓卡片內較長的狀態標籤可以換行。
   - 對比（WCAG 1.4.3）：選中分頁上的數量底色原為半透明白，白字只有 3.98:1；改用深青綠底（約 8.6:1）。
   - 焦點可見（WCAG 2.4.7）：日期欄位以鍵盤進入時焦點落在內部的年／月／日，外框不套用 :focus-visible；明確加上焦點框。
   - 觸控（本案內部目標：主要控制在觸控裝置至少 44px，不是 WCAG 全面認證）：複製、分頁、語言、品牌、展開與帳單連結。
   - 有固定底部列的頁面，鍵盤捲動時保留底部空間，焦點元件不被底部列遮住（WCAG 2.4.11）。
   ========================================================================= */
body {
  min-width: 0;
}

.status-tab[aria-pressed="true"] .tab-count {
  background: var(--primary-strong);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

input[type="date"]:focus,
input[type="month"]:focus,
input[type="time"]:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

html:has(.request-bar) {
  scroll-padding-bottom: 132px;
}

.admin-links a,
.bill-link,
.notice a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 6px;
}

@media (pointer: coarse) {
  .notice a {
    min-height: 44px;
  }
}

.bill-link {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 599px) {
  .portal-item .badge,
  .request-card .badge,
  .card .badge {
    white-space: normal;
  }
}

@media (pointer: coarse) {
  button.lang-option {
    min-height: 44px;
    min-width: 44px;
  }

  .copy-btn,
  .status-tab,
  .lnum-toggle,
  .brand,
  .admin-links a,
  .bill-link,
  .bill-card-title a,
  details > summary {
    min-height: 44px;
  }

  .copy-btn {
    min-width: 44px;
  }

  .bill-card-title a {
    display: inline-flex;
    align-items: center;
  }

  /* 窄螢幕規則（.topbar button.lang-option 等）的寬度較小且優先序較高，這裡以相同優先序補足觸控寬度。 */
  .topbar button.lang-option,
  .portal-top button.lang-option,
  .plain-top button.lang-option,
  .bill-link,
  .brand {
    min-width: 44px;
  }

  .bill-link,
  .brand {
    justify-content: center;
  }

  a.badge {
    min-height: 44px;
  }
}

/* ---------- 品質階段 Q1：員工貨品清單（6 欄表格／窄版卡片）、精簡搜尋列、狀態分區 ---------- */
/* 狀態選單保留為狀態值，畫面上只留分區按鈕；.toolbar > div 的 display 會蓋過 hidden 屬性，這裡明確隱藏。 */
.status-select[hidden] {
  display: none !important;
}

/* 清單區寬度（不是整個視窗）決定表格或卡片：側欄展開的小筆電、平板、手機與放大 200% 都依實際可用寬度切換。 */
.items-list {
  container-type: inline-size;
  container-name: itemslist;
}

/* LIST_COLUMNS_01（使用者 2026/10/07「盡量都在標題上」）：每個資料一欄——貨品／單號／倉儲位／狀態／入庫日／寄出日／已計費至／
   物流單號／照片／操作。固定版面、欄寬由表頭決定，內容在欄內換行，不再因某一欄內容較長而把右側的照片與「編輯」擠出畫面。
   寄出日、已計費至這一頁都沒有值時整欄不顯示（no-out／no-billed）。短內容的欄固定寬度（日期 76px、狀態標籤 74px、「上傳照片」82px
   加左右各 12px 都放得下；物流單號 12rem，號碼與「複製」同一行），貨品與單號平分其餘寬度。最小寬度依實際顯示的欄數；清單區比最小寬度
   窄時在框內左右捲動（頁面本身不橫向捲動），清單區 920px 以下改為卡片。客戶專區的「清單」顯示方式用同一套表格樣式（沒有已計費至）。 */
.items-table {
  table-layout: fixed;
  min-width: 64rem;
}

.items-table.no-out,
.items-table.no-billed {
  min-width: 57.5rem;
}

.items-table.no-out.no-billed {
  min-width: 51.5rem;
}

/* 貨品、單號不設寬度：平分其餘寬度。 */
.items-table th.col-place {
  width: 4.5rem;
}

.items-table th.col-notes { width: 6.25rem; }
.item-note summary { cursor: pointer; color: var(--primary, #086c63); }
.item-note p { margin: .5rem 0 0; overflow-wrap: anywhere; }
.document-number-choices { min-width: 0; margin: .5rem 0; padding: .75rem; border: 1px solid var(--border, #d9d4c9); border-radius: .5rem; }
.document-number-choices .check-row { margin: .35rem 0; overflow-wrap: anywhere; }
.doc-management > summary { cursor: pointer; padding: .6rem 0; color: var(--primary, #086c63); }
.recipient-note { margin: .6rem 0; }
.request-operation-status { margin-top: .75rem; }
.request-operation-toast { position: fixed; z-index: 80; bottom: 1rem; left: 50%; transform: translateX(-50%); width: max-content; max-width: min(38rem, calc(100vw - 2rem)); box-shadow: 0 4px 18px #0002; pointer-events: none; }
.legacy-import > summary { cursor: pointer; }
@media print { .request-operation-toast, .request-operation-status, .doc-management { display: none !important; } }

.items-table th.col-status,
.items-table th.col-in,
.items-table th.col-out,
.items-table th.col-billed {
  width: 6.25rem;
}

.items-table th.col-numbers {
  width: 12rem;
}

.items-table th.col-photo {
  width: 6.5rem;
}

.items-table th.col-actions {
  width: 5rem;
}

.items-table.no-out .col-out,
.items-table.no-billed .col-billed {
  display: none;
}

/* 號碼後面直接接「複製」，用途標籤排在後面：欄寬不足時只有標籤換到下一行，號碼與複製永遠同一行（報讀順序不變）。 */
.items-table .lnum .copy-btn {
  order: 1;
}

.items-table .lnum .lnum-tag {
  order: 2;
}

.items-table td {
  vertical-align: top;
}

.items-table .badge {
  white-space: normal;
}

/* flow-root：品名自成一塊排在勾選框（float）右側，換行時對齊品名第一個字，不繞到勾選框下方。 */
.items-table .item-name {
  display: flow-root;
  font-weight: 700;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* 單號可能很長（例如「620AA44096--羊260629BPBVB3S3--74370943028」）：在欄內換行，不撐寬表格。 */
.items-table .cell-order,
.items-table .cell-place {
  white-space: normal;
  overflow-wrap: anywhere;
}

.items-table .cell-in,
.items-table .cell-out,
.items-table .cell-billed {
  font-variant-numeric: tabular-nums;
}

.items-table .cell-empty {
  color: var(--muted);
}

.items-table .cell-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}

/* 主要狀態（在庫／已寄出）不換行；後面的寄出申請標籤較長，仍可在欄內換行。 */
.items-table .cell-badges > .badge:first-child {
  white-space: nowrap;
}

.items-table .cell-photo,
.items-table .cell-actions {
  white-space: nowrap;
}

.items-table .numbers-cell {
  min-width: 0;
  white-space: normal;
}

.items-table .cell-actions {
  text-align: right;
}

.items-table tr.item-row.is-selected > td {
  background: var(--primary-soft);
}

@container itemslist (max-width: 920px) {
  .items-scroll {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: none;
  }

  .items-table,
  .items-table.no-out,
  .items-table.no-billed,
  .items-table.no-out.no-billed {
    min-width: 0;
  }

  .items-table thead {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .items-table,
  .items-table tbody {
    display: block;
    border: 0;
  }

  /* 卡片：品名、狀態、物流單號占整行；單號／倉儲位、入庫日／寄出日／已計費至兩兩並排；照片與操作在最下面。空白的欄不列。 */
  .items-table tr.item-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px 16px;
    margin: 0 0 12px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-1);
  }

  .items-table tr.item-row > td {
    display: block;
    width: auto;
    padding: 0;
    border: 0;
    white-space: normal;
    background: none;
  }

  .items-table tr.item-row > td.is-empty {
    display: none;
  }

  .items-table tr.item-row.is-selected {
    border-color: var(--primary);
    background: var(--primary-soft);
  }

  .items-table tr.item-row.is-selected > td {
    background: none;
  }

  .items-table .cell-item {
    grid-column: 1 / -1;
    order: 0;
  }

  .items-table .item-name {
    font-size: 1.0625rem;
  }

  .items-table .cell-status {
    grid-column: 1 / -1;
    order: 1;
  }

  .items-table .cell-order {
    order: 2;
  }

  .items-table .cell-place {
    order: 3;
  }

  .items-table .cell-in {
    order: 4;
  }

  .items-table .cell-out {
    order: 5;
  }

  .items-table .cell-billed {
    order: 6;
  }

  .items-table .numbers-cell {
    grid-column: 1 / -1;
    order: 7;
    min-width: 0;
  }

  .items-table .cell-photo {
    grid-column: 1;
    order: 8;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .items-table .cell-actions {
    order: 9;
    justify-self: end;
    align-self: center;
  }

  .items-table .cell-order::before,
  .items-table .cell-place::before,
  .items-table .cell-in::before,
  .items-table .cell-out::before,
  .items-table .cell-billed::before,
  .items-table .numbers-cell::before,
  .items-table .cell-photo::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
  }

  .items-table .cell-photo::before {
    margin: 0;
  }

  .items-table .numbers-cell .lnum-list {
    margin: 0;
  }

  /* 載入中、查無資料、讀取失敗的提示列：卡片模式下占滿寬度（s2 實測原本只占部分寬度）。 */
  .items-table tr:not(.item-row),
  .items-table td.table-note {
    display: block;
  }

  .items-table td.table-note {
    padding: 20px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: center;
  }
}

@media (max-width: 599px) {
  .toolbar.toolbar-compact {
    flex-wrap: wrap;
  }

  .toolbar.toolbar-compact > .grow {
    flex: 1 1 12rem;
  }

  .toolbar.toolbar-compact > button,
  .toolbar.toolbar-compact > .toolbar-actions {
    flex: 0 0 auto;
  }

  .status-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .status-tab {
    padding-left: 6px;
    padding-right: 6px;
  }

  .result-summary {
    font-weight: 600;
    font-size: 0.9375rem;
  }
}

/* ---------- 品質階段 Q1：首頁帳單摘要、帳單期間、卡片照片列、客戶專區手機頂部 ---------- */
.bill-summary {
  display: grid;
  gap: 6px;
  margin: 4px 0 0;
}

.bill-summary-row {
  display: grid;
  grid-template-columns: 6.5em minmax(0, 1fr);
  gap: 4px 10px;
  align-items: baseline;
}

.bill-summary dt {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.bill-summary dd {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--ink);
}

.bill-summary .badge {
  margin-left: 4px;
}

/* 帳單期間可能含「（不限起日）」：在摘要格線中占兩格，不在「～」處被擠成兩行。 */
.meta-item:has(.date-range) {
  grid-column: span 2;
}

/* 客戶專區手機頂部：原本兩列加分頁約占手機畫面五分之一；隱藏重複的副標與說明字，窄手機只留品牌圖示（名稱仍供輔助工具）。 */
@media (max-width: 599px) {
  .portal-top .brand-sub,
  .portal-top .identity-label,
  .portal-top .account-role {
    display: none;
  }

  .portal-top-inner {
    padding: 8px 12px;
    gap: 8px 10px;
  }
}

/* 客戶貨品卡（手機）：原本內容欄只剩約 210px，每個號碼的「複製」都被擠到下一行。縮圖改小，品名、編號、狀態在縮圖旁；
   物流單號、日期與「詳情與照片」占整張卡片寬度（只用版面重排，DOM 與報讀順序不變）。 */
@media (max-width: 599px) {
  .portal-item {
    grid-template-columns: 44px 76px minmax(0, 1fr);
    grid-template-areas:
      "pick thumb title"
      "pick thumb ids"
      ".    thumb status"
      "numbers numbers numbers"
      "dates dates action";
    gap: 6px 10px;
  }

  .portal-item-body {
    display: contents;
  }

  .portal-item .pick {
    grid-area: pick;
  }

  .portal-item .thumb-button {
    grid-area: thumb;
  }

  .portal-item .portal-item-title {
    grid-area: title;
  }

  .portal-item .item-ids {
    grid-area: ids;
    margin: 0;
  }

  .portal-item .item-status {
    grid-area: status;
    margin: 0;
  }

  .portal-item .item-numbers {
    grid-area: numbers;
    min-width: 0;
    margin: 2px 0 0;
  }

  .portal-item .item-dates {
    grid-area: dates;
    align-self: center;
    margin: 0;
  }

  .portal-item .portal-item-body > button {
    grid-area: action;
    justify-self: end;
  }
}

@media (max-width: 440px) {
  .portal-top .brand-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
}

/* 登入逾時提示（app.js showSessionBanner）：固定在內容區頂端，捲動時仍看得到；提供另開分頁重新登入。 */
.session-banner {
  position: sticky;
  top: 8px;
  z-index: 25;
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--warning-line);
  border-left: 6px solid var(--warning-ink);
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--warning-ink);
  box-shadow: var(--shadow-2);
}

.session-banner-text {
  margin: 0;
  font-weight: 600;
}

@media (max-width: 1099px) {
  .layout-staff .session-banner {
    top: 68px;
  }
}

/* 員工頂部列（窄螢幕）：頁名較長時（例如「備註與加收」）不再把「選單」擠成兩行；頁名過長以省略號截斷，
   客戶標籤一律完整顯示（捲動後仍看得到正在操作哪一個客戶）。 */
@media (max-width: 1099px) {
  .nav-menu-button {
    flex: none;
    white-space: nowrap;
  }

  .topbar-title {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .topbar-page {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar .client-chip {
    flex: none;
  }
}

/* ---------- 品質階段 Q1：窄螢幕卡片表格（table.cardable；欄名由 app.js 自動標示）與寄出申請進度 ---------- */
@media (max-width: 640px) {
  .table-scroll:has(> table.cardable) {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: none;
  }

  .scroll-hint:has(+ .table-scroll > table.cardable) {
    display: none;
  }

  table.cardable {
    min-width: 0;
  }

  /* 表頭只對畫面隱藏（報讀仍可讀）：必須改成區塊，寬高與裁切才會生效；維持表頭列時會依自然寬度排開，
     在 320 寬把頁面撐寬 10px（a10 實測：歷史帳單、帳號頁）。 */
  table.cardable thead {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  table.cardable,
  table.cardable tbody,
  table.cardable tr {
    display: block;
  }

  table.cardable tr {
    margin: 0 0 10px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-1);
  }

  table.cardable td {
    display: grid;
    grid-template-columns: minmax(5.5em, 34%) minmax(0, 1fr);
    gap: 2px 10px;
    align-items: baseline;
    padding: 5px 0;
    border: 0;
    text-align: left;
    /* 表格模式的不換行（在捲動容器內）改成卡片後會把頁面撐寬（a7：長品名 496px），卡片內一律換行。 */
    white-space: normal;
    overflow-wrap: anywhere;
  }

  table.cardable td::before {
    content: attr(data-label);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
  }

  table.cardable td[data-label=""],
  table.cardable td.table-note,
  table.cardable td[colspan] {
    display: block;
  }

  table.cardable td[data-label=""]::before,
  table.cardable td.table-note::before,
  table.cardable td[colspan]::before {
    content: none;
  }

  /* 寄出申請進度：三個步驟在手機上並排成一列，不再各占一整列。 */
  .progress {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .progress-step {
    padding: 6px 8px;
  }

  .progress-label {
    font-size: 0.8125rem;
    line-height: 1.35;
  }

  .progress-time {
    font-size: 0.75rem;
  }

  /* 全站時間預設不換行；並排的窄進度步驟裡要換行，否則「2026/10/04 23:20（UTC+8）」會把頁面撐寬（a6 實測 154px）。 */
  .progress-step time,
  .progress-time {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* 卡片裡沒有內容的欄位（例如尚未寄出的「寄出日」）不占一列。 */
  table.cardable td:empty {
    display: none;
  }

  /* 卡片的值欄較窄：期間在「～」兩側換行、時間在日期與時刻之間換行（a11 實測：不換行時卡片內容超出 27px，320 寬把頁面撐寬 10px）。 */
  table.cardable td .date-range,
  table.cardable td time {
    white-space: normal;
  }
}

/* ---------- 品質階段 Q1：列印 ----------
   螢幕上的明細表在區塊內橫向捲動（最小寬度 760px），列印時不能捲動：A4 可印寬度內，11 欄的貨品明細右側被裁掉、
   事項表超出卡片（quality-phase/print/p1 實測）。列印時取消最小寬度，縮小字級與間距，全部印在紙張寬度內。 */
@media print {
  table,
  table.compact {
    min-width: 0 !important;
    width: 100% !important;
    font-size: 8.5pt;
  }

  th,
  td {
    padding: 3px 5px !important;
  }

  /* 員工帳單明細有 13 欄：表頭不換行時加總超過紙寬（print/p2 實測最右欄被切）；列印時表頭可換行。
     儲存格一律不換行時，長品名會把表格撐出卡片外框（print/p3 實測約 15px）；全部改成可換行則日期、單號會在連字號後斷開，
     每列變高、頁數加倍（print/p4 實測 7 頁變 18 頁）。只讓標為 cell-text 的文字欄（品名、舊備註）在格內折行。 */
  th {
    white-space: normal !important;
  }

  td.cell-text {
    white-space: normal;
    overflow-wrap: break-word;
  }

  /* 明細標題不單獨留在頁尾（print/p5 實測第 1 頁底只剩標題、表格從下一頁開始）。print/d1-break 比較：
     只設標題 break-after 無效；明細內容與表格也設 break-before: avoid 時，標題與表格一起換到下一頁。
     ::details-content 另寫一條，不支援的瀏覽器只忽略這一條。 */
  details.lines > summary {
    break-after: avoid;
  }

  details.lines .table-scroll,
  details.lines table {
    break-before: avoid;
  }

  details.lines::details-content {
    break-before: avoid;
  }

  .table-scroll {
    border: 0;
    background: none;
  }

  .scroll-hint,
  .session-banner {
    display: none !important;
  }
}

/* =========================================================================
   慢網路接續第 1 批（2026-10-05，Claude 自審）：quality-lowbw-01 實測（下載 0.4～1.6 Mbit/s、延遲 150～400ms）
   - 員工貨品與備註與加收清單在儲存後、搜尋、換頁重新查詢時沒有任何等待狀態（run-01／02 的 A2、B2）；
     改為與客戶庫存頁一致：清單變淡（aria-busy），畫面下方中央顯示「更新中…」（固定位置、不擋點擊、不推動版面）。
   ========================================================================= */
.items-list[aria-busy="true"],
.table-scroll[aria-busy="true"],
.request-list[aria-busy="true"],
.bill-list[aria-busy="true"],
.photo-grid[aria-busy="true"] {
  opacity: 0.6;
}

.list-busy {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 26;
  margin: 0;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(21, 37, 59, 0.25);
  pointer-events: none;
}

/* 寬版員工外殼左側有 256px 側欄：提示以主內容區置中（視窗中心往右半個側欄寬）。 */
@media (min-width: 1100px) {
  .layout-staff .list-busy {
    left: calc(50% + 128px);
  }
}

@media print {
  .list-busy {
    display: none !important;
  }
}

/* =========================================================================
   功能擴充第 1 批（2026-10-05，使用者需求；Claude 自審）
   - 首頁統計數字可點選：每格是連結（整塊可點），到對應畫面並套好篩選。
   ========================================================================= */
.stat-links {
  list-style: none;
  padding: 0;
}

.stat-links > li {
  display: flex;
}

a.stat {
  position: relative;
  display: block;
  flex: 1 1 auto;
  color: inherit;
  text-decoration: none;
}

a.stat:hover {
  border-color: var(--primary);
  background: var(--surface);
}

a.stat.is-attention:hover {
  background: var(--warning-soft);
  border-color: var(--warning-ink);
}

a.stat:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.stat-label {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted);
  font-weight: 600;
}

/* 「›」提示可點：放在格子右下角（數值那一列很短），不跟著標籤換行；報讀軟體不唸（替代文字為空；不支援替代文字語法的
   瀏覽器只顯示箭頭）。真瀏覽器 run-f03：放在標籤後面時「待處理寄出申請 ›」在窄格內換行、箭頭單獨落到下一行。 */
a.stat::after {
  content: "\203A";
  content: "\203A" / "";
  position: absolute;
  right: 12px;
  bottom: 8px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--muted);
}

a.stat:hover::after,
a.stat:focus-visible::after {
  color: var(--primary);
}

.stat-value {
  display: block;
  margin-top: 2px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.stat-value b {
  font-size: 1.375rem;
  color: var(--ink);
}

a.stat.is-attention .stat-value b {
  color: var(--warning-ink);
}

/* 貨品頁只列在庫：在庫筆數＋「已寄出紀錄」連結（不用手機上三格分區的格線）。 */
.status-tabs.scope-only {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.scope-current {
  font-weight: 700;
  color: var(--ink);
}

.status-tabs .scope-link {
  text-decoration: none;
}

/* 管理者代客申請的勾選框：放在品名左側（表格與卡片模式都一樣），觸控時點擊範圍至少 44px。 */
.pick-item {
  float: left;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  margin: -4px 8px 0 -6px;
  cursor: pointer;
}

.pick-item input {
  width: 20px;
  height: 20px;
  margin: 0;
}

@media (pointer: coarse) {
  .pick-item {
    min-width: 44px;
    min-height: 44px;
  }
}

@media print {
  .pick-item,
  #pick-bar {
    display: none !important;
  }
}

/* 客戶「已寄出紀錄」頁：已寄出不能申請，貨品卡不放勾選框，縮圖移到最左；
   手機版日期占縮圖下方到內容欄，「詳情與照片」仍在右側。 */
.portal-item.no-pick {
  grid-template-columns: 132px minmax(0, 1fr);
}

@media (max-width: 599px) {
  .portal-item.no-pick {
    grid-template-columns: 76px minmax(0, 1fr) auto;
    grid-template-areas:
      "thumb title title"
      "thumb ids ids"
      "thumb status status"
      "numbers numbers numbers"
      "dates dates action";
  }
}

/* 客戶申請進度：勾選刪除（只有可刪除的申請有勾選；勾選的卡片以紅框標示；刪除列沿用底部申請列）。 */
.request-pick-row {
  margin: -6px 0 6px;
}

.request-pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}

.request-pick input {
  width: 20px;
  height: 20px;
  margin: 0;
}

.request-pick-note {
  margin: 0 0 6px;
}

.request-card.is-picked {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.delete-bar .confirm-panel {
  margin-top: 8px;
}

.delete-bar .error-box {
  margin: 8px 0 0;
}

/* 預報（功能擴充第 1 批）：新增表單與預報卡片沿用申請卡片樣式；結果說明（已轉入／已取消）稍淡。 */
.preadvice-form {
  margin-bottom: 16px;
}

.preadvice-form > h2 {
  margin-top: 0; /* 卡片第一個元素：不再加標題預設的上邊距（run-f03 截圖：標題上方留白過大） */
}

.preadvice-outcome {
  margin: 6px 0 0;
  color: var(--ink-soft);
}

/* 客戶專區五個分頁：窄手機上字小一點、可換行（不擠出畫面、不需要橫向捲動）。 */
@media (max-width: 599px) {
  .portal-tab {
    font-size: 0.875rem;
    padding: 6px 2px;
    white-space: normal;
    text-align: center;
    line-height: 1.25;
  }
}

/* 側欄（功能擴充第 1 批多了「已寄出紀錄」「預報」兩項）：一般筆電高度（960px 以下）時導覽項目排緊一點，帳號與登出不必捲動
   就看得到（真瀏覽器 run-f03：1440×900 時側欄要捲動）；較高的螢幕維持原本的間距。觸控範圍仍有 38px 以上。 */
@media (min-width: 1100px) and (max-height: 960px) {
  .sidebar {
    gap: 12px;
    padding-top: 14px;
    padding-bottom: 12px;
  }

  .sidebar .nav-link {
    min-height: 38px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
}

/* 預報的四個分區（待到貨／已轉入庫／已取消／全部）：手機上排成 2×2，不讓「全部」單獨落到第二行（真瀏覽器 run-f03 截圖）。 */
@media (max-width: 599px) {
  .status-tabs.pa-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* 功能擴充第 2 批（使用者 2026/10/05）：客戶「我的庫存／已寄出／預報」可選「清單」或「圖示」。
   只換排版（同一份內容、勾選與已填內容都保留）；切換鈕兩顆都至少 44px，選中的一顆以底色與 aria-pressed 表示。 */
.list-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: 12px 0;
}

.list-tools > .status-tabs {
  flex: 1 1 auto;
  margin: 0;
}

.view-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.view-toggle button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  margin: 0;
  padding: 0 14px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: none;
}

.view-toggle button:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

.view-toggle button + button {
  border-left: 1px solid var(--line-strong);
}

.view-toggle button[aria-pressed="true"],
.view-toggle button[aria-pressed="true"]:hover {
  background: var(--primary);
  color: #fff;
}

.view-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: currentColor;
}

.no-photo-icon,
.preadvice-icon {
  display: none;
}

/* 圖示：貨品卡改成方格（縮圖在上、勾選框疊在縮圖左上角），只留品名、編號與狀態；物流單號、日期與「詳情」按鈕
   收起（按縮圖就能開啟詳情與照片）。手機固定兩欄。 */
.portal-list.is-grid {
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
}

.portal-list.is-grid .portal-item,
.portal-list.is-grid .portal-item.no-pick {
  position: relative;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: none;
  gap: 8px;
  padding: 8px;
}

.portal-list.is-grid .portal-item-body {
  display: block;
}

.portal-list.is-grid .portal-item .pick,
.portal-list.is-grid .portal-item .thumb-button {
  grid-area: auto;
}

.portal-list.is-grid .portal-item .pick {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  margin: 0;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.portal-list.is-grid .portal-item .thumb-button {
  aspect-ratio: 1 / 1;
}

.portal-list.is-grid .portal-item-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 1rem;
}

.portal-list.is-grid .portal-item .item-ids {
  margin: 2px 0 0;
  font-size: 0.8125rem;
}

.portal-list.is-grid .portal-item .item-status {
  margin: 6px 0 0;
}

.portal-list.is-grid .portal-item .item-numbers,
.portal-list.is-grid .portal-item .item-dates,
.portal-list.is-grid .portal-item .portal-item-body > button {
  display: none;
}

.portal-list.is-grid .no-photo {
  gap: 6px;
  align-content: center;
}

.portal-list.is-grid .no-photo-icon {
  display: block;
  width: 40%;
  max-width: 64px;
  height: auto;
  fill: var(--muted);
}

/* 圖示：預報卡改成方格，上方是箱子圖示；確認取消的區塊照常在卡片內展開。 */
.request-list.is-grid {
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  align-items: start;
}

.request-list.is-grid > .empty-state,
.request-list.is-grid > .table-note {
  grid-column: 1 / -1;
}

.request-list.is-grid .preadvice-icon {
  display: block;
  width: 44px;
  height: 44px;
  margin: 0 0 4px;
  fill: var(--primary);
}

.request-list.is-grid .preadvice-card,
.request-list.is-grid .preadvice-card .request-head {
  min-width: 0;
}

.request-list.is-grid .preadvice-card .request-head {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.request-list.is-grid .preadvice-card .request-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  max-width: 100%;
}

/* 方格很窄（手機兩欄約 140px）：建立時間可以換行，不撐寬頁面。 */
.request-list.is-grid .preadvice-card .request-meta,
.request-list.is-grid .preadvice-card .request-meta time {
  white-space: normal;
  overflow-wrap: anywhere;
}

.request-list.is-grid .preadvice-card .detail-fields {
  display: block;
  font-size: 0.875rem;
}

.request-list.is-grid .preadvice-card .detail-fields dt {
  margin-top: 6px;
  font-size: 0.8125rem;
}

.request-list.is-grid .preadvice-card .detail-fields dd {
  margin: 0;
}

/* LIST_COLUMNS_01：客戶專區「清單」顯示方式（一條一條、有欄位標題，如同管理員畫面）。清單容器只放一個表格（不分欄），
   並作為容器查詢的容器：清單區 920px 以下改成精簡卡片（沒有大照片），樣式與員工貨品清單相同（.items-table）。 */
.portal-list.is-table,
.request-list.is-table {
  display: block;
}

.portal-list.is-table {
  container-type: inline-size;
  container-name: itemslist;
}

.portal-list.is-table .cell-photo .chip-btn {
  min-height: 36px;
}

/* 預報的「清單」：一般資料表（欄位標題在上）；手機改成「欄名：內容」的卡片（table.cardable）。取消預報的確認面板在該列下方整列顯示。
   固定版面：短內容的欄固定寬度，商品／單號／託運單號／說明平分其餘寬度；清單區比最小寬度窄時在框內左右捲動（1024 寬實測：
   自動版面會把可換行的「商品」壓成一字一行）。 */
.pa-table {
  table-layout: fixed;
  min-width: 69rem;
}

.pa-table td {
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
}

.pa-table .col-pa,
.pa-table .col-status,
.pa-table .col-expected,
.pa-table .col-actions {
  white-space: nowrap;
  overflow-wrap: normal;
}

.pa-table th.col-pa {
  width: 5rem;
}

.pa-table th.col-status,
.pa-table th.col-expected {
  width: 6.5rem;
}

.pa-table th.col-created {
  width: 10rem;
}

.pa-table th.col-outcome {
  width: 13rem;
}

.pa-table th.col-actions {
  width: 7rem;
}

/* 建立時間、結果裡的時間（全站預設不換行，約 179px）在欄內換行，不壓到右邊一欄。 */
.pa-table td time {
  white-space: normal;
}

.pa-table .col-actions {
  text-align: right;
}

@media (max-width: 640px) {
  .pa-table td > .cell-value {
    justify-self: start;
  }

  .pa-table td.is-empty {
    display: none;
  }

  .pa-table .col-actions {
    text-align: left;
  }
}

.pa-table .pa-confirm-row > td {
  background: var(--surface-muted);
}

.pa-table .pa-confirm-row .confirm-panel {
  margin: 0;
}

.pa-table .button-row {
  margin: 0;
}

@media (max-width: 599px) {
  .portal-list.is-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .request-list.is-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .request-list.is-grid .preadvice-card {
    padding: 12px;
  }

  .view-toggle button {
    padding: 0 12px;
  }
}

/* ---------- UPLOAD_REPLAY_02：重新開啟頁面前送出、結果還沒確定的上傳（內容區最上方；與「上傳結果尚未確認」同一套樣式，
   確認已存好或重新上傳完成時改成功色，伺服器拒絕時改錯誤色） ---------- */
.upload-restore {
  margin: 0 0 16px;
}

.upload-restore .upload-pending {
  margin: 0 0 12px;
}

.upload-restore-item.is-done {
  background: var(--success-soft);
  border-color: var(--success-line);
  color: var(--success);
}

.upload-restore-item.is-failed {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: var(--danger);
}

.upload-pending p.upload-restore-time {
  margin-top: -6px;
  font-size: 0.8125rem;
  opacity: 0.85;
}

.upload-restore-picker {
  display: grid;
  gap: 6px;
  margin: 0 0 10px;
}

.upload-restore-picker label {
  font-weight: 700;
}

.upload-restore-picker input[type="file"] {
  max-width: 100%;
  min-height: 44px;
}

.upload-restore-problem {
  color: var(--danger);
  font-weight: 700;
}

/* 窄螢幕員工頂部列：頁名不再截斷（原本 320 寬只剩「貨」「待整理…」）。頁名可以換行，帳套標籤放不下時換到下一行；
   「選單」文字與圖示、語言「繁」「简」兩鍵與 44px 觸控都保留。窄手機（≤400px）縮小內距與間距，讓頁名多一些寬度。 */
@media (max-width: 1099px) {
  .topbar-title {
    flex-wrap: wrap;
    overflow: visible;
    row-gap: 2px;
  }

  .topbar-page {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    word-break: keep-all;
    overflow-wrap: anywhere;
    line-height: 1.25;
  }
}

@media (max-width: 400px) {
  .topbar {
    gap: 8px;
    padding: 8px 12px;
  }

  .nav-menu-button {
    gap: 8px;
    padding: 8px 10px;
  }
}

/* ---------- ADMIN_EXCEL_REPORTS（使用者 2026/10/06）：分頁列（跳頁、每頁筆數）、清單操作列（全選本頁、匯出）、
   Excel 批次新增面板、勾選列的多個按鈕（未勾選時只留一行提示） ---------- */
.pager-summary {
  font-weight: 600;
  color: var(--ink);
}

.pager-nav {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.pager-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 400;
}

.pager-field select {
  width: auto;
  min-width: 4.5rem;
  min-height: 36px;
}

.list-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin: 4px 0 8px;
}

.list-actions .check-row {
  min-height: 36px;
  margin-right: auto;
}

.list-actions .check-row input {
  width: 20px;
  height: 20px;
  margin: 0;
}

.bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.bar-actions > button {
  min-width: 8rem;
}

.request-bar.is-empty .bar-optional {
  display: none;
}

.sheet-import .si-steps {
  margin: 8px 0 12px;
  padding-left: 1.4em;
}

.sheet-import .si-steps li {
  margin: 6px 0;
}

.si-result {
  margin-top: 12px;
}

.si-summary {
  margin: 0 0 8px;
  font-weight: 700;
}

.si-table td {
  vertical-align: top;
}

.si-row.is-error td {
  background: var(--warning-soft);
}

.report-row {
  align-items: center;
}

.history-confirm {
  margin-top: 8px;
}

/* 觸控裝置：分頁列的選單與「全選本頁」整列至少 44px 高（與其他按鈕相同）。 */
@media (pointer: coarse) {
  .pager-field select,
  .list-actions .check-row {
    min-height: 44px;
  }
}

@media (max-width: 599px) {
  .bar-actions {
    width: 100%;
    margin-left: 0;
  }

  .bar-actions > button {
    flex: 1 1 auto;
  }

  .request-bar.is-empty .bar-actions {
    width: auto;
    flex: 0 0 auto;
  }

  .pager {
    gap: 6px;
  }

  .pager-summary {
    flex: 1 1 100%;
    text-align: center;
  }
}

/* ADMIN_LISTS_HISTORY（使用者 2026/10/06）：預報與寄出申請卡片標題左側的勾選框（換頁後保留，只用來匯出所選）。 */
.request-head-main {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.request-head-main .pick-item {
  float: none;
  flex: 0 0 auto;
  margin: 0 4px 0 -6px;
}

/* 備註與加收的操作欄：「編輯」與「修改紀錄」並排，窄畫面換行。 */
.row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* 事項修改紀錄：每筆異動列出欄位「由 原 改為 新」（建立與匯入列出當時的內容）。 */
.history-changes {
  margin: 6px 0 0;
  padding-left: 1.2em;
}

.history-list .history-changes li {
  margin: 2px 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
}

@media print {
  .request-head-main .pick-item,
  #sel-bar {
    display: none !important;
  }
}

/* 品質覆驗（states-03 目視，Claude 自審）：
   - 修改紀錄的建立內容：欄名淡色，與內容分開。
   - 窄畫面勾選後的選取列只有「清除選取」「匯出所選」兩個按鈕：並排成一列，選取列由三行縮成兩行，清單多一點空間。
     只套用在本批的選取列（預報、寄出申請的 #sel-bar 與已寄出紀錄的 #pick-bar），客戶專區的選取列不變。 */
.history-changes .meta-label {
  color: var(--ink-soft);
}

@media (max-width: 599px) {
  #sel-bar .bar-actions,
  #pick-bar .bar-actions {
    flex-wrap: nowrap;
  }

  #sel-bar .bar-actions > button,
  #pick-bar .bar-actions > button {
    flex: 1 1 0;
    min-width: 0;
  }
}

/* PDF_FEEDBACK_01（2026/10/13，Claude 自審）：使用者 3 份 PDF 標註的新元件。
   - 已寄出紀錄的排序選單：與匯出按鈕同一列。
   - 代客建立的篩選列與已勾選筆數；員工申請卡的「寄出準備」步驟清單、已登記的平台單號（可移除）、包裹數。
   - 待整理照片的資料夾卡（跨滿整列，裡面再排照片）；附到既有貨品的候選清單。
   - 直接寄出對話框的貨品清單（太多時在框內捲動）。 */
.list-actions .sort-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
}

.list-actions .sort-row select {
  width: auto;
}

.create-items-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 0 0 8px;
}

.create-items-tools input[type="search"] {
  flex: 1 1 12rem;
  min-width: 0;
  max-width: 24rem;
}

.prep-steps {
  margin: 8px 0;
}

.prep-step-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.prep-step {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.prep-step > .badge {
  flex: none;
  min-width: 4.5em;
  text-align: center;
}

.prep-step.is-next > span:last-child {
  font-weight: 600;
}

.registered-numbers li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ship-packages {
  margin: 4px 0 8px;
}

.pending-folder {
  grid-column: 1 / -1;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--surface-muted);
}

.pending-folder-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.pending-folder-head h3 {
  margin: 0 auto 0 0;
}

.pending-folder .pending-grid {
  margin-bottom: 0;
}

.folder-rename {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.folder-rename input {
  width: auto;
  min-width: 10rem;
  max-width: 100%;
}

.attach-candidates {
  margin: 8px 0;
}

.direct-items {
  max-height: 10rem;
  overflow: auto;
  margin-bottom: 8px;
}
