/* 工程與請款管理系統：全站樣式（企業系統風格，規範見「2026-11-28-UI-設計規範」第二版）。
   所有顏色、圓角、間距、字級都只在 :root 定義；下面的規則只引用變數。 */
:root {
  /* 色彩 */
  --c-page: #F4F5F7;          /* 頁面底色 */
  --c-surface: #FFFFFF;       /* 內容區、表格底、頂部工具列 */
  --c-nav: #FAFAFB;           /* 左側選單底 */
  --c-text: #1F2328;          /* 主要文字 */
  --c-text-2: #5F6670;        /* 次要文字、欄位標題 */
  --c-text-3: #8C939D;        /* 停用、提示文字 */
  --c-line: #DCDFE3;          /* 線條、表格分隔 */
  --c-th: #F7F8FA;            /* 表格表頭底 */
  --c-row-hover: #F5F7FA;     /* 表格列滑過 */
  --c-brand: #B4674A;         /* 品牌色（陶土）：主要按鈕、選中的選單、選中的分頁底線 */
  --c-brand-press: #9C5640;   /* 品牌色按下 */
  --c-brand-soft: #F6ECE7;    /* 品牌淺底：選中的列、選單選中的底 */
  --c-link: #9C5640;          /* 連結、可點的文字 */
  --c-on-brand: #FFFFFF;      /* 品牌色上的文字 */
  --c-ok: #1E7B45;      --c-ok-bg: #E7F4EC;       /* 成功（已收、已請款） */
  --c-danger: #B42318;  --c-danger-bg: #FDECEA;   /* 警示（溢收、溢請、錯誤） */
  --c-warn: #8A5A00;    --c-warn-bg: #FFF4DB;     /* 提醒（待開立、未收） */
  --c-neutral: #5F6670; --c-neutral-bg: #EEF0F3;  /* 中性（草稿、作廢） */
  --c-line-login: #06C755;    /* LINE 登入按鈕（LINE 品牌規定的綠色，只用在登入頁） */
  --c-shadow: rgba(31, 35, 40, 0.12);   /* 對話框的一層淡陰影 */
  --c-backdrop: rgba(31, 35, 40, 0.40); /* 對話框背後的遮罩 */

  /* 字體 */
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;

  /* 圓角 */
  --r-control: 4px;  /* 按鈕、輸入框 */
  --r-panel: 6px;    /* 面板、對話框 */
  --r-tag: 3px;      /* 狀態標籤 */

  /* 間距（4 的倍數） */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-6: 24px; --s-8: 32px;

  /* 尺寸 */
  --topbar-h: 48px;
  --nav-w: 200px;
  --tag-h: 20px;
  --progress-h: 4px;
  --thumb: 56px;          /* 案子封面縮圖（手機 56、桌機 48） */
  --cover-h: 140px;       /* 案子頁封面（手機 140、桌機 180） */

  /* 手機（預設）：字級、按鈕、列高 */
  --fs-title: 18px;   --lh-title: 26px;
  --fs-section: 15px; --lh-section: 22px;
  --fs-body: 15px;    --lh-body: 22px;
  --fs-small: 13px;   --lh-small: 18px;
  --fs-kpi: 18px;     --lh-kpi: 26px;
  --fs-tag: 12px;
  --fs-input: 16px;   /* iPhone 輸入框小於 16px 會自動放大畫面 */
  --btn-h: 44px; --btn-h-primary: 44px; --btn-h-sm: 44px;
  --control-h: 44px;
  --row-h: 48px;
  --tab-h: 44px;
}
@media (min-width: 1024px) {
  :root {
    --fs-title: 20px;   --lh-title: 28px;
    --fs-section: 16px; --lh-section: 24px;
    --fs-body: 14px;    --lh-body: 20px;
    --fs-small: 12px;   --lh-small: 18px;
    --fs-kpi: 20px;     --lh-kpi: 28px;
    --fs-input: 14px;
    --btn-h: 32px; --btn-h-primary: 36px; --btn-h-sm: 28px;
    --control-h: 32px;
    --row-h: 40px;
    --tab-h: 40px;
    --thumb: 48px;
    --cover-h: 180px;
  }
}

/* ---------- 基本 ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--c-page); color: var(--c-text);
  font-family: var(--font); font-size: var(--fs-body); line-height: var(--lh-body);
  overflow-x: hidden;
}
a { color: var(--c-link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 700; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 1px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.hint { color: var(--c-text-3); font-size: var(--fs-small); line-height: var(--lh-small); }
.text-danger { color: var(--c-danger); }
.text-ok { color: var(--c-ok); }
.only-desktop { display: none !important; }
@media (min-width: 1024px) {
  .only-mobile { display: none !important; }
  .only-desktop { display: block !important; }
}

/* ---------- 頂部工具列、左側選單、內容區 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h); padding: 0 var(--s-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  background: var(--c-surface); border-bottom: 1px solid var(--c-line);
}
.brand { display: flex; align-items: center; gap: var(--s-2); min-width: 0; min-height: 44px; color: var(--c-text); font-weight: 700; }
.brand:hover { text-decoration: none; }
.co-badge {
  flex: none; width: 28px; height: 28px; border-radius: var(--r-control);
  display: grid; place-items: center;
  background: var(--c-brand); color: var(--c-on-brand); font-size: var(--fs-small); font-weight: 700;
}
.co-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user { flex: none; display: flex; align-items: center; gap: var(--s-1); color: var(--c-text-2); font-size: var(--fs-small); }
.user-name { max-width: 8em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout { display: block; }
.sidenav { display: none; }
.content { min-width: 0; padding: var(--s-4); }
@media (min-width: 1024px) {
  .layout { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
  .sidenav { display: block; background: var(--c-nav); border-right: 1px solid var(--c-line); padding: var(--s-3) var(--s-2); }
  .content { padding: var(--s-6) var(--s-8); max-width: 1440px; }
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-1); position: sticky; top: calc(var(--topbar-h) + var(--s-3)); }
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  height: 36px; padding: 0 var(--s-3); border-radius: var(--r-control);
  color: var(--c-text); font-size: 14px; border-left: 3px solid transparent;
}
.nav-item:hover { text-decoration: none; background: var(--c-row-hover); }
.nav-item.active { background: var(--c-brand-soft); color: var(--c-brand-press); font-weight: 500; border-left-color: var(--c-brand); }
.nav-item.disabled { color: var(--c-text-3); cursor: not-allowed; }
.nav-item.disabled:hover { background: transparent; }
.nav-soon { font-size: var(--fs-tag); color: var(--c-text-3); }

/* ---------- 頁首：麵包屑、標題、動作 ---------- */
.page-head { margin-bottom: var(--s-4); }
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); margin-bottom: var(--s-1); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.breadcrumb .sep { color: var(--c-text-3); }
.title-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); }
.page-title { font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.page-sub { margin-top: var(--s-1); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-3); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.page-desc { margin-top: var(--s-1); color: var(--c-text-2); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.cover-banner { display: block; width: 100%; height: var(--cover-h); margin-top: var(--s-3); object-fit: cover; border-radius: var(--r-panel); border: 1px solid var(--c-line); background: var(--c-neutral-bg); }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-1);
  height: var(--btn-h); min-width: 44px; padding: 0 var(--s-3);
  border: 1px solid var(--c-line); border-radius: var(--r-control);
  background: var(--c-surface); color: var(--c-text);
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1;
  white-space: nowrap; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; background: var(--c-row-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { height: var(--btn-h-primary); background: var(--c-brand); border-color: var(--c-brand); color: var(--c-on-brand); }
.btn-primary:hover, .btn-primary:active { background: var(--c-brand-press); border-color: var(--c-brand-press); }
.btn-danger { color: var(--c-danger); border-color: var(--c-danger); }
.btn-danger:hover { background: var(--c-danger-bg); }
.btn-text { border-color: transparent; background: transparent; color: var(--c-link); padding: 0 var(--s-2); }
.btn-text:hover { background: var(--c-brand-soft); }
.btn-sm { height: var(--btn-h-sm); padding: 0 var(--s-2); font-size: 13px; }

/* ---------- 表單 ---------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; height: var(--control-h); padding: 0 var(--s-2);
  border: 1px solid var(--c-line); border-radius: var(--r-control);
  background: var(--c-surface); color: var(--c-text);
  font: inherit; font-size: var(--fs-input);
}
textarea { height: auto; min-height: 88px; padding: var(--s-2); resize: vertical; }
input[type="file"] { font: inherit; font-size: var(--fs-small); max-width: 100%; min-height: var(--control-h); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c-brand); outline-offset: -1px; border-color: var(--c-brand); }
[aria-invalid="true"] { border-color: var(--c-danger) !important; }
select.select-sm { width: auto; max-width: 12em; height: var(--btn-h-sm); font-size: 13px; }
.field { margin-bottom: var(--s-3); min-width: 0; }
.field > label { display: block; margin-bottom: var(--s-1); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; }
.req { color: var(--c-danger); margin-left: 2px; }
.field-error { white-space: pre-line; margin-top: var(--s-1); color: var(--c-danger); font-size: var(--fs-small); line-height: var(--lh-small); }
.field-hint { margin-top: var(--s-1); color: var(--c-text-3); font-size: var(--fs-small); line-height: var(--lh-small); }
.form-note { margin-bottom: var(--s-3); padding: var(--s-2) var(--s-3); border-radius: var(--r-control); background: var(--c-th); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.form-grid { display: grid; gap: 0 var(--s-3); }
@media (min-width: 600px) { .form-grid.cols-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* ---------- 狀態標籤 ---------- */
.tag {
  display: inline-flex; align-items: center; height: var(--tag-h); padding: 0 6px;
  border-radius: var(--r-tag); font-size: var(--fs-tag); line-height: 1; font-weight: 500;
  white-space: nowrap; vertical-align: middle;
}
.tag-ok { color: var(--c-ok); background: var(--c-ok-bg); }
.tag-danger { color: var(--c-danger); background: var(--c-danger-bg); }
.tag-warn { color: var(--c-warn); background: var(--c-warn-bg); }
.tag-neutral { color: var(--c-neutral); background: var(--c-neutral-bg); }
.tags { display: inline-flex; flex-wrap: wrap; gap: var(--s-1); align-items: center; }

/* ---------- 面板、區塊 ---------- */
.panel { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-panel); min-width: 0; }
.panel + .panel, .stack > * + * { margin-top: var(--s-4); }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-line); }
.panel-title { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 500; }
.panel-meta { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.panel-body { padding: var(--s-4); }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2); padding: var(--s-4) var(--s-4) var(--s-2); }
.section-title { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 500; }
.empty { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-4) var(--s-4); color: var(--c-text-2); }
.grid-2 { display: grid; gap: var(--s-4); }
.grid-2 > .panel + .panel { margin-top: 0; }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* 基本資料 */
.kv { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: var(--s-2) var(--s-3); margin: 0; }
.kv dt { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-body); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (min-width: 1024px) { .kv { grid-template-columns: 88px minmax(0, 1fr) 88px minmax(0, 1fr); } }

/* ---------- 摘要列（KPI strip） ---------- */
.kpi { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-bottom: 1px solid var(--c-line); }
.kpi-item { padding: var(--s-3) var(--s-4); min-width: 0; }
.kpi-item:nth-child(odd) { border-right: 1px solid var(--c-line); }
.kpi-item:nth-child(-n+2) { border-bottom: 1px solid var(--c-line); }
@media (min-width: 1024px) {
  .kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi-item:nth-child(n) { border-right: 0; border-bottom: 0; }
  .kpi-item + .kpi-item { border-left: 1px solid var(--c-line); }
  /* 總覽的半寬面板：維持兩欄兩列，金額才放得下 */
  .kpi.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi.compact .kpi-item + .kpi-item { border-left: 0; }
  .kpi.compact .kpi-item:nth-child(odd) { border-right: 1px solid var(--c-line); }
  .kpi.compact .kpi-item:nth-child(-n+2) { border-bottom: 1px solid var(--c-line); }
}
.kpi-label { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.kpi-value { font-size: var(--fs-kpi); line-height: var(--lh-kpi); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { margin-top: 2px; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-2); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.kpi-foot { padding: var(--s-2) var(--s-4); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.progress { height: var(--progress-h); margin-top: var(--s-1); background: var(--c-neutral-bg); border-radius: var(--progress-h); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--c-ok); }
.kpi-sub .progress { flex-basis: 100%; margin: var(--s-1) 0 2px; }

/* ---------- 表格（桌機）與兩行清單（手機） ---------- */
.table-wrap { overflow-x: auto; }
.dt { width: 100%; border-collapse: collapse; font-size: var(--fs-body); line-height: var(--lh-body); }
.dt th {
  height: 32px; padding: 0 var(--s-3); text-align: left; white-space: nowrap;
  background: var(--c-th); color: var(--c-text-2); font-size: var(--fs-small); font-weight: 500;
  border-top: 1px solid var(--c-line); border-bottom: 1px solid var(--c-line);
}
.dt th.num { text-align: right; }
.dt td { height: var(--row-h); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--c-line); vertical-align: middle; }
.dt th:first-child, .dt td:first-child { padding-left: var(--s-4); }
.dt th:last-child, .dt td:last-child { padding-right: var(--s-4); }
.dt tbody tr:last-child td { border-bottom: 0; }
.dt tbody tr:hover { background: var(--c-row-hover); }
.dt tr.clickable { cursor: pointer; }
.dt .c-act { text-align: right; white-space: nowrap; }
.dt .c-act > * + * { margin-left: var(--s-2); }
.dt .c-thumb { width: 1%; padding-right: 0; }
.dt .cell-sub { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.dt .c-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.dt .cell-strong { font-weight: 500; color: var(--c-text); }
.dt tr.voided td:not(.c-status):not(.c-act) { text-decoration: line-through; color: var(--c-text-3); }

.mlist { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--c-line); }
.mrow { padding: var(--s-2) var(--s-4); border-bottom: 1px solid var(--c-line); min-height: var(--row-h); }
.mrow:last-child { border-bottom: 0; }
.mrow-1, .mrow-2 { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.mrow-2 { margin-top: var(--s-1); flex-wrap: wrap; }
.mrow-main { min-width: 0; overflow-wrap: anywhere; }
.mrow-amt { flex: none; font-weight: 500; }
.mrow-status { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-2); min-width: 0; }
.mrow-act { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); margin-left: auto; }
.mrow-sub { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.hist { list-style: none; margin: var(--s-3) 0 0; padding: 0; }
.hist-item { border-top: 1px solid var(--c-line); padding: var(--s-3) 0; }
.hist-head { font-size: 14px; font-weight: 500; }
.hist-sub { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); margin-top: var(--s-1); }
.hist-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.hist-change { margin-top: var(--s-1); }
.mrow-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: var(--s-1); }
.mrow.voided .mrow-1 { text-decoration: line-through; color: var(--c-text-3); }
.void-reason { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }

/* ---------- 案子列表 ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); }
.toolbar .search { flex: 1 1 220px; }
@media (min-width: 1024px) { .toolbar .search { flex: 0 1 320px; } }
.seg { display: inline-flex; border: 1px solid var(--c-line); border-radius: var(--r-control); overflow: hidden; }
.seg button { height: var(--btn-h); min-width: 44px; padding: 0 var(--s-3); border: 0; background: var(--c-surface); color: var(--c-text-2); font: inherit; font-size: 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--c-line); }
.seg button[aria-pressed="true"] { background: var(--c-brand-soft); color: var(--c-brand-press); font-weight: 500; }
.thumb {
  flex: none; width: var(--thumb); height: var(--thumb); border-radius: var(--r-control);
  display: grid; place-items: center; overflow: hidden;
  background: var(--c-neutral-bg); color: var(--c-text-2); font-weight: 700; font-size: 18px;
}
img.thumb { object-fit: cover; display: block; }
.pct { display: inline-block; min-width: 72px; text-align: right; }
.pct .progress { margin-top: 2px; }
.case-row { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-line); color: var(--c-text); min-height: 44px; }
.case-row:last-child { border-bottom: 0; }
.case-item { border-bottom: 1px solid var(--c-line); }
.case-item:last-child { border-bottom: 0; }
.case-item > .case-row { border-bottom: 0; }
.case-row-todo { display: flex; align-items: center; gap: var(--s-2); min-height: 44px; padding: 0 var(--s-4) var(--s-2) calc(var(--s-4) + var(--thumb) + var(--s-3)); color: var(--c-text); }
.case-row-todo:hover { text-decoration: none; background: var(--c-row-hover); }
.seg button:disabled { color: var(--c-text-2); opacity: 0.6; cursor: not-allowed; }
.case-row:hover { text-decoration: none; background: var(--c-row-hover); }
.case-row-body { flex: 1; min-width: 0; }
.case-row-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.case-row-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-row-pct { display: flex; flex-wrap: wrap; gap: 0 var(--s-3); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.case-row-pct b { color: var(--c-text); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- 分頁 ---------- */
.tabs { display: flex; gap: var(--s-1); margin: var(--s-4) 0; border-bottom: 1px solid var(--c-line); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; height: var(--tab-h); margin-bottom: -1px; padding: 0 var(--s-3);
  border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--c-text-2); font: inherit; font-size: var(--fs-body); cursor: pointer;
}
.tab:hover { color: var(--c-text); }
.tab[aria-selected="true"] { color: var(--c-text); font-weight: 500; border-bottom-color: var(--c-brand); }

/* ---------- 主要動作列（手機固定在底部） ---------- */
.actionbar { display: flex; flex-wrap: wrap; gap: var(--s-2); }
@media (max-width: 1023px) {
  .actionbar.sticky {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; flex-wrap: nowrap;
    padding: var(--s-2) var(--s-4) calc(var(--s-2) + env(safe-area-inset-bottom));
    background: var(--c-surface); border-top: 1px solid var(--c-line);
  }
  .actionbar.sticky .btn { flex: 1 1 0; }
  body.has-actionbar .content { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* ---------- 付款節點編輯 ---------- */
.ms-row { display: grid; grid-template-columns: minmax(0, 1fr) 88px 44px; gap: var(--s-2); margin-bottom: var(--s-2); }
.ms-row .btn { height: var(--control-h); padding: 0; }
.preset-row { margin-bottom: var(--s-3); }
.ms-sum { margin-top: var(--s-2); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- 對話框 ---------- */
dialog.dlg {
  width: min(560px, calc(100vw - 32px)); max-width: none; max-height: calc(100vh - 64px);
  padding: 0; border: 1px solid var(--c-line); border-radius: var(--r-panel);
  background: var(--c-surface); color: var(--c-text); box-shadow: 0 8px 24px var(--c-shadow);
}
dialog.dlg::backdrop { background: var(--c-backdrop); }
.dlg-form { display: flex; flex-direction: column; max-height: calc(100vh - 66px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); padding: var(--s-1) var(--s-2) var(--s-1) var(--s-4); border-bottom: 1px solid var(--c-line); }
.dlg-title { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 500; }
.dlg-body { padding: var(--s-4); overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--c-line); }
@media (max-width: 599px) {
  dialog.dlg { width: 100%; margin: auto 0 0; max-height: 92vh; border-radius: var(--r-panel) var(--r-panel) 0 0; border-bottom: 0; }
  .dlg-form { max-height: 92vh; }
  .dlg-foot { padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom)); }
  .dlg-foot .btn { flex: 1 1 0; }
}

/* ---------- 專案檔案 ---------- */
.files-layout { display: block; }
.file-main { min-width: 0; }
.file-cats { display: flex; gap: var(--s-1); padding: 0 var(--s-4); border-bottom: 1px solid var(--c-line); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.file-cats::-webkit-scrollbar { display: none; }
.file-cat {
  flex: none; display: inline-flex; align-items: center; gap: var(--s-1);
  height: var(--tab-h); margin-bottom: -1px; padding: 0 var(--s-2);
  border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--c-text-2); font: inherit; font-size: var(--fs-body); white-space: nowrap; cursor: pointer;
}
.file-cat:hover { color: var(--c-text); }
.file-cat[aria-pressed="true"] { color: var(--c-text); font-weight: 500; border-bottom-color: var(--c-brand); }
.fc-count { color: var(--c-text-3); font-size: var(--fs-small); font-weight: 400; }
@media (min-width: 1024px) {
  .files-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); }
  .file-cats { flex-direction: column; gap: 2px; padding: var(--s-2); border-bottom: 0; border-right: 1px solid var(--c-line); overflow: visible; }
  .file-cat { height: 36px; margin: 0; padding: 0 var(--s-3); justify-content: space-between; border-bottom: 0; border-left: 3px solid transparent; border-radius: var(--r-control); }
  .file-cat:hover { background: var(--c-row-hover); }
  .file-cat[aria-pressed="true"] { background: var(--c-brand-soft); color: var(--c-brand-press); border-left-color: var(--c-brand); }
}
.file-link {
  display: inline-flex; align-items: center; min-height: var(--control-h); padding: 0; border: 0; background: none;
  color: var(--c-link); font: inherit; text-align: left; overflow-wrap: anywhere; cursor: pointer;
}
.file-link:hover { text-decoration: underline; }
.file-meta { margin-bottom: var(--s-3); }
.link-url { overflow-wrap: anywhere; word-break: break-all; } /* B25-1：雲端連結的完整網址，手機上要能換行 */
/* ---------- 照片縮圖格狀（B2-I4） ---------- */
.view-toggle { display: flex; justify-content: flex-end; padding: var(--s-2) var(--s-4) 0; }
.photo-groups { padding: var(--s-1) var(--s-4) var(--s-4); }
.photo-group-head { margin: var(--s-2) 0; color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-1); }
.photo-tile {
  position: relative; display: block; aspect-ratio: 1; min-width: 0; padding: 0; overflow: hidden;
  border: 1px solid var(--c-line); border-radius: 4px; background: #F7F8FA; font: inherit; color: var(--c-text); cursor: pointer;
}
.photo-tile:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 2px; }
.photo-img { display: block; width: 100%; height: 100%; object-fit: cover; }
.photo-tile-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s-1); padding: var(--s-2); }
.photo-tile-name {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 100%;
  font-size: 12px; line-height: 16px; color: var(--c-text-2); overflow-wrap: anywhere; text-align: center;
}
.photo-tile-ver { position: absolute; top: var(--s-1); left: var(--s-1); }
@media (min-width: 1024px) {
  .photo-group-head { margin: var(--s-3) 0 var(--s-2); }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(144px, 1fr)); gap: var(--s-2); }
}
.file-image { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; object-fit: contain; }
.file-image-slot { min-height: 44px; }
.upload-fail { margin: var(--s-2) 0 0; padding-left: 1.4em; color: var(--c-danger); font-size: var(--fs-small); line-height: var(--lh-small); }
.cm-list { border: 1px solid var(--c-line); border-radius: var(--r-panel); }
.cm-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-3); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--c-line); }
.cm-row:last-child { border-bottom: 0; }
.cm-name { flex: 1 1 8em; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.cm-check { display: inline-flex; align-items: center; gap: var(--s-1); min-height: var(--control-h); color: var(--c-text-2); font-size: var(--fs-small); }
.cm-check input { width: 18px; height: 18px; margin: 0; }
.cm-add { display: flex; align-items: flex-end; gap: var(--s-2); margin-top: var(--s-3); }
.cm-add .field { flex: 1; margin-bottom: 0; }
.dlg-foot.wrap { flex-wrap: wrap; }
@media (max-width: 599px) { .dlg-foot.wrap .btn { flex: 1 1 40%; } }
@media (min-width: 600px) { dialog.dlg.dlg-wide { width: min(720px, calc(100vw - 32px)); } }

/* ---------- 廠商名冊與廠商報價 ---------- */
.field > .field-label, .qd-section > .field-label { display: block; margin-bottom: var(--s-1); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; }
.trade-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s-3); }
@media (min-width: 600px) { .trade-checks { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.trade-check { display: flex; align-items: center; gap: var(--s-2); min-height: 44px; font-size: var(--fs-body); }
.trade-check input { flex: none; width: 18px; height: 18px; margin: 0; }
.vendor-active { margin-top: var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--c-line); }
.vendor-active .field-hint { margin-top: var(--s-2); }
.kpi.kpi-3 .kpi-item:nth-child(3) { border-right: 0; }
@media (min-width: 1024px) { .kpi.kpi-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.quote-files { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-line); background: var(--c-warn-bg); }
.quote-files-title { margin-bottom: var(--s-1); color: var(--c-warn); font-size: var(--fs-small); font-weight: 500; }
.quote-todo { padding: var(--s-2) var(--s-4); border-bottom: 1px solid var(--c-line); background: var(--c-warn-bg); color: var(--c-warn); font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; }
.qf-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2); min-height: 44px; }
.qf-add { margin: calc(-1 * var(--s-2)) 0 var(--s-2); }
.quote-attach { max-height: 220px; overflow-y: auto; margin-bottom: var(--s-3); }
.quote-trade + .quote-trade { margin-top: var(--s-2); border-top: 1px solid var(--c-line); }
.qd-section { margin-top: var(--s-3); }
.qd-files { list-style: none; margin: 0; padding: 0; }
.qd-files li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2); min-height: 44px; border-bottom: 1px solid var(--c-line); }
.quote-totals { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s-4); max-width: 320px; margin: var(--s-3) 0 0 auto; font-variant-numeric: tabular-nums; }
.quote-totals dt { color: var(--c-text-2); }
.quote-totals dd { margin: 0; text-align: right; }
.quote-totals .total { margin-top: var(--s-1); padding-top: var(--s-1); border-top: 1px solid var(--c-line); color: var(--c-text); font-weight: 700; }

/* 明細編輯：桌機左邊原始檔、右邊編輯；手機只有編輯（每列是一張卡片），底部固定合計和儲存 */
dialog.dlg.dlg-full { width: 100%; height: 92vh; max-height: 92vh; }
dialog.dlg.dlg-full .dlg-form { height: 100%; max-height: none; }
@media (min-width: 1024px) { dialog.dlg.dlg-full { width: min(1240px, calc(100vw - 32px)); height: calc(100vh - 48px); max-height: calc(100vh - 48px); } }
.qe-layout { display: block; }
.qe-src { display: none; }
.qe-img { display: block; width: 100%; max-width: none; height: auto; cursor: zoom-in; }
.qe-img.zoomed { cursor: zoom-out; }
.qe-mobile-src { margin-bottom: var(--s-3); }
@media (min-width: 1024px) {
  .qe-layout { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(0, 2fr); gap: var(--s-4); align-items: start; }
  .qe-src { display: flex; flex-direction: column; position: sticky; top: 0; height: calc(100vh - 180px); min-height: 240px; }
  .qe-src-head { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2); }
  .qe-src-head:empty { display: none; }
  .qe-src-view { flex: 1 1 auto; min-height: 0; overflow: auto; border: 1px solid var(--c-line); border-radius: var(--r-control); background: var(--c-page); }
  .qe-zoom { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); flex: 1 1 auto; }
  .qe-zoom-label { min-width: 5em; text-align: center; color: var(--c-text-2); font-size: var(--fs-small); }
  .qe-zoom-newtab { margin-left: auto; }
  .qe-src-slot { min-height: 100%; }
  .qe-src-slot > .btn, .qe-src-slot > .muted { margin: var(--s-2); }
  .qe-mobile-src { display: none; }
}
.qe-banner { margin-bottom: var(--s-2); padding: var(--s-2) var(--s-3); border-radius: var(--r-control); background: var(--c-warn-bg); color: var(--c-warn); font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; }
.qe-warns { margin: 0 0 var(--s-2); padding-left: 1.4em; color: var(--c-warn); font-size: var(--fs-small); line-height: var(--lh-small); }
.qe-warns:empty { display: none; }
.qe-diff { margin-bottom: var(--s-3); font-size: var(--fs-small); }
.qe-diff:empty { display: none; }
.qe-row { margin-bottom: var(--s-3); padding: var(--s-3); border: 1px solid var(--c-line); border-radius: var(--r-panel); }
.qe-row-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-2); }
.qe-no { color: var(--c-text-2); font-size: var(--fs-small); font-weight: 500; }
.qe-del { min-width: 44px; }
.qe-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.qe-cell { display: block; min-width: 0; }
.qe-cell.c-name { grid-column: 1 / -1; }
.qe-label { display: block; color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.qe-row-warn { margin-top: var(--s-2); color: var(--c-warn); font-size: var(--fs-small); line-height: var(--lh-small); }
.qe-row-warn:empty { display: none; }
@media (min-width: 1024px) {
  .qe-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .qe-cell.c-name { grid-column: span 4; }
  .qe-cell.c-qty, .qe-cell.c-unit, .qe-cell.c-price, .qe-cell.c-amount { grid-column: span 2; }
  .qe-cell.c-spec, .qe-cell.c-note { grid-column: span 6; }
}
.qe-add { margin-bottom: var(--s-3); display: flex; flex-wrap: wrap; gap: var(--s-2); }
.qe-row-warn-host { margin-top: var(--s-2); }
.qe-row-err { color: var(--c-danger); font-weight: 500; }
/* 桌機明細表格：一列一行，每格都是輸入框；提醒和錯誤寫在每列下面的一條 */
.qe-list { margin-bottom: var(--s-3); }
.qe-table { table-layout: auto; }
.qe-table th { position: sticky; top: 0; z-index: 1; padding: 0 var(--s-1); }
.qe-table th:first-child { padding-left: var(--s-1); }
.qe-table th:last-child { padding-right: var(--s-1); }
.qe-table td { height: auto; padding: 3px var(--s-1); border-bottom: 0; }
.qe-table td:first-child { padding-left: var(--s-1); }
.qe-table td:last-child { padding-right: var(--s-1); }
.qe-table .qe-line td { border-top: 1px solid var(--c-line); }
.qe-table .qe-hint-row td { padding: 0 var(--s-1) var(--s-1) 36px; }
.qe-table td input { min-width: 0; }
.qe-seq { width: 32px; text-align: center; color: var(--c-text-3); font-size: var(--fs-small); }
.qe-c-name { min-width: 130px; }
.qe-c-spec { min-width: 80px; }
.qe-c-unit { width: 64px; }
.qe-c-quantity { width: 64px; }
.qe-c-unitPrice, .qe-c-amount { width: 92px; }
.qe-c-note { min-width: 80px; }
.qe-del-cell { width: 36px; text-align: center; }
.qe-num { text-align: right; font-variant-numeric: tabular-nums; }
@media (min-width: 1280px) { .qe-table-wrap { overflow: visible; } }
.qe-foot { align-items: center; }
.qe-foot-total { margin-right: auto; font-size: var(--fs-section); font-variant-numeric: tabular-nums; }

/* ---------- 通知 ---------- */
.toasts { position: fixed; top: calc(var(--topbar-h) + var(--s-2)); bottom: auto; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; height: auto; left: var(--s-4); right: var(--s-4); z-index: 100; display: flex; flex-direction: column; gap: var(--s-2); pointer-events: none; }
@media (min-width: 1024px) { .toasts { left: auto; width: 380px; } }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--s-2);
  min-height: 40px; padding: var(--s-1) var(--s-1) var(--s-1) var(--s-3);
  border: 1px solid var(--c-line); border-left: 3px solid var(--c-ok); border-radius: var(--r-control);
  background: var(--c-surface); color: var(--c-text); font-size: 14px; line-height: 20px;
}
.toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: var(--s-1) 0; }
.toast.error { border-color: var(--c-danger); border-left-color: var(--c-danger); background: var(--c-danger-bg); color: var(--c-danger); }
.toast .btn { flex: none; color: inherit; }

/* ---------- 整頁訊息（找不到、還不是成員）與登入頁 ---------- */
.fullmsg { min-height: 100vh; display: grid; place-items: center; padding: var(--s-6) var(--s-4); }
.fullmsg-box { width: min(440px, 100%); padding: var(--s-6); background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-panel); }
.fullmsg-box h1 { font-size: var(--fs-title); line-height: var(--lh-title); margin-bottom: var(--s-2); }
.fullmsg-box p + p { margin-top: var(--s-2); }
.fullmsg-box .actions { margin-top: var(--s-4); }
.code-box {
  display: block; margin: var(--s-3) 0 0; padding: var(--s-2) var(--s-3);
  background: var(--c-th); border: 1px solid var(--c-line); border-radius: var(--r-control);
  font-family: var(--font-mono); font-size: 13px; word-break: break-all; user-select: all;
}
.product { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-6); color: var(--c-text-2); font-size: var(--fs-small); font-weight: 500; }
.btn-line { width: 100%; height: 44px; margin-top: var(--s-4); background: var(--c-line-login); border-color: var(--c-line-login); color: var(--c-on-brand); font-size: 15px; font-weight: 700; }
.btn-line:hover { background: var(--c-line-login); filter: brightness(0.95); }

/* ---------- 列印頁工具列（明細表本身在 iframe 裡，保留它自己的列印版面） ---------- */
.print-bar {
  position: sticky; top: 0; z-index: 5; min-height: var(--topbar-h); padding: var(--s-1) var(--s-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  background: var(--c-surface); border-bottom: 1px solid var(--c-line);
}
.print-bar .bar-title { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.print-frame { display: block; width: 100%; height: calc(100vh - 56px); border: 0; background: var(--c-surface); }
/* B25-4：請款單印哪個帳戶的匯款資訊（只有負責人看得到） */
.print-opts { padding: var(--s-2) var(--s-4); border-bottom: 1px solid var(--c-line); background: var(--c-surface); }
.print-opts label { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.print-opts select { max-width: 100%; }

/* ---------- 匯入 ---------- */
.steps { margin: 0; padding-left: 1.4em; color: var(--c-text-2); }
.steps li + li { margin-top: var(--s-1); }
.error-list { margin: 0; padding: 0 var(--s-4) var(--s-4) 2.4em; color: var(--c-danger); }

@media print { .topbar, .sidenav, .print-bar, .print-opts, .toasts { display: none !important; } }

/* ---------- 工程估價單（B2-3）：只引用上面的色票與間距 ---------- */
.only-desktop-inline { display: none !important; }
@media (min-width: 1024px) { .only-desktop-inline { display: inline-flex !important; } }
.est-warn { color: var(--c-warn); font-size: var(--fs-small); line-height: var(--lh-small); }
.kpi-foot.est-warn { background: var(--c-warn-bg); }
.est-line { border-bottom: 1px solid var(--c-line); }
.est-extra-title { margin: var(--s-4) 0 var(--s-2); padding-top: var(--s-4); border-top: 1px solid var(--c-line); color: var(--c-text-2); font-size: var(--fs-small); font-weight: 500; }
.est-section { margin-top: var(--s-4); }
.est-sections > .est-section:first-child { margin-top: var(--s-4); }
.est-section-head { border-bottom: 1px solid var(--c-line); padding-bottom: var(--s-2); }
.est-head-nums { margin-left: auto; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: flex-end; gap: var(--s-1) var(--s-3); font-variant-numeric: tabular-nums; font-weight: 500; }
.est-sub { color: var(--c-text-2); font-size: var(--fs-small); font-weight: 400; }
.est-sec-trade { display: inline-flex; align-items: center; gap: var(--s-1); }
.est-sec-trade select { width: 160px; height: 32px; }
@media (max-width: 1023px) {
  .est-sec-trade { display: flex; width: 100%; }
  .est-sec-trade select { flex: 1; width: auto; height: 44px; }
}
.est-table .est-trade.is-missing { border-color: var(--c-warn); color: var(--c-warn); }
.est-addrow { padding: var(--s-3) var(--s-4); }
.est-table { min-width: 960px; table-layout: auto; }
.est-table td { vertical-align: top; padding: var(--s-1) var(--s-2); }
.est-table td.num { padding-top: var(--s-2); }
.est-table th, .est-table td { white-space: nowrap; }
.est-table input:not([type="checkbox"]), .est-table select { min-width: 0; width: 100%; }
.est-table td:nth-child(2) { min-width: 200px; white-space: normal; }
.est-table td:nth-child(3) { min-width: 110px; }
.est-table td:nth-child(4) { min-width: 64px; }
.est-table input.num { text-align: right; font-variant-numeric: tabular-nums; min-width: 84px; }
.est-table .est-trade { margin-top: var(--s-1); height: 26px; font-size: 12px; color: var(--c-text-2); }
.est-table td.c-idx { padding-top: var(--s-2); text-align: center; color: var(--c-text-2); }
.est-card-btn { display: block; width: 100%; min-height: 44px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.est-card-name { font-weight: 500; overflow-wrap: anywhere; }
.est-card-amt { flex: none; font-weight: 500; }
.est-total { display: grid; gap: var(--s-2); max-width: 480px; margin-left: auto; }
.est-total-row { display: flex; justify-content: space-between; gap: var(--s-4); }
.est-total-row.strong { font-weight: 700; }
.est-sep { width: 100%; border: 0; border-top: 1px solid var(--c-line); margin: var(--s-1) 0; }
.est-bar-total { flex: 1 1 auto; align-self: center; font-weight: 700; font-size: var(--fs-section); white-space: nowrap; }
@media (max-width: 1023px) { .actionbar.sticky.est-bar .btn { flex: 0 0 auto; min-width: 120px; } }
.import-list { margin-bottom: var(--s-3); }
.import-trade { margin: var(--s-2) 0 var(--s-1); color: var(--c-text-2); font-size: var(--fs-small); font-weight: 500; }
.import-row { display: flex; width: 100%; justify-content: space-between; gap: var(--s-2); height: auto; min-height: 44px; padding: var(--s-2) var(--s-3); margin-bottom: var(--s-1); text-align: left; white-space: normal; }
.import-row.selected { background: var(--c-brand-soft); border-color: var(--c-brand); }
.cm-markup { display: inline-flex; align-items: center; gap: var(--s-1); }
.cm-markup .markup-input { width: 5em; text-align: right; }

/* ---------- 估驗單（B2-4）：只引用上面的色票與間距 ---------- */
.num-neg { color: var(--c-danger); }
.only-mobile-inline { display: inline; }
@media (min-width: 1024px) { .only-mobile-inline { display: none !important; } }
.cost-table { min-width: 1240px; }
.cost-table th, .cost-table td { white-space: nowrap; }
.cost-table td.cost-vendors { white-space: normal; min-width: 7em; max-width: 14em; overflow-wrap: anywhere; }
.cost-right { justify-content: flex-end; }
.cost-table tfoot td { background: var(--c-th); font-weight: 700; border-top: 1px solid var(--c-line); border-bottom: 0; }
.cost-table tr.cost-detail > td { padding: var(--s-3) var(--s-4); background: var(--c-th); white-space: normal; height: auto; }
.cost-detail-box { overflow-x: auto; }
.cost-inner { min-width: 720px; background: var(--c-surface); }
.cost-inner td { height: auto; }
.cost-refs { margin-top: var(--s-2); }
.cost-preview { margin-top: var(--s-3); min-height: var(--lh-body); font-weight: 500; font-variant-numeric: tabular-nums; }
.cost-award-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s-2); }
.cost-award-row > .field { flex: 1 1 12em; }
.cost-award-row > .btn { margin-top: calc(var(--lh-small) + var(--s-1)); }
.cost-pay-1 { display: flex; justify-content: space-between; gap: var(--s-2); }
.cost-change-actions { margin: var(--s-2) 0; }
@media (max-width: 1023px) { .cost-change-apply { min-height: 44px; } }
.mrow.cost-total { background: var(--c-th); font-weight: 700; }
.dt .cost-row.clickable:hover { background: var(--c-row-hover); }

/* ---------- 支票與匯款查詢頁 ---------- */
.pay-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s-3); padding: var(--s-3) var(--s-4) 0; }
.pay-filters .field { min-width: 0; }
.pay-filters .actionbar { grid-column: 1 / -1; padding-bottom: var(--s-3); }
@media (min-width: 1024px) { .pay-filters { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.pay-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1024px) { .pay-kpi { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.pay-kpi .kpi-item:nth-child(n) { border-bottom: 1px solid var(--c-line); }
@media (min-width: 1024px) { .pay-kpi .kpi-item:nth-child(n) { border-bottom: 0; } }

/* ---------- 追加減單（B2-5）：只引用上面的色票與間距 ---------- */
.kpi.kpi-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1024px) { .kpi.kpi-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.co-buttons { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.co-deduct-table { min-width: 880px; }
.co-deduct-table input.num { text-align: right; font-variant-numeric: tabular-nums; min-width: 84px; }
.co-pick { max-height: 50vh; overflow-y: auto; margin-bottom: var(--s-3); }
.co-pick-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); min-height: 48px; padding: 0 var(--s-1); border-bottom: 1px solid var(--c-line); }
.co-pick-row input { flex: none; width: 24px; height: 24px; }
.co-pick-main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.co-pick-left { flex: none; color: var(--c-text-2); font-size: var(--fs-small); }
.c-bill { white-space: nowrap; }

/* ---------- 案子列表合計列 ---------- */
.dt tfoot td { background: var(--c-th); font-weight: 700; border-top: 1px solid var(--c-line); border-bottom: 0; }
.dt tfoot .cell-sub { font-weight: 400; }
.list-total { padding: var(--s-2) var(--s-4); border-bottom: 1px solid var(--c-line); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.list-total b { color: var(--c-text); font-weight: 700; }
.toolbar .sort { width: auto; }

/* ---------- 大按鈕選單（記收款選合約、拍照存檔選分類） ---------- */
.pick-list { display: grid; gap: var(--s-2); }
.pick-btn {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px;
  width: 100%; min-height: 56px; padding: var(--s-2) var(--s-3);
  border: 1px solid var(--c-line); border-radius: 4px; background: var(--c-surface); color: var(--c-text);
  font: inherit; font-weight: 500; text-align: left; cursor: pointer;
}
.pick-btn:hover { background: var(--c-row-hover); }
.pick-btn-sub { color: var(--c-text-2); font-size: var(--fs-small); font-weight: 400; }
.pick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.pick-grid .btn { min-height: 44px; height: auto; white-space: normal; }
.pick-btn-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); width: 100%; }
.capture-note { margin-bottom: var(--s-3); }
.capture-more { margin-top: var(--s-2); }
.capture-grid { margin-top: var(--s-2); }

/* 分頁列還有看不到的分頁時，那一邊淡出（只是透明度漸層，不加顏色、陰影或箭頭） */
.tabs.fade-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
.tabs.fade-left { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); }
.tabs.fade-left.fade-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); }

/* ---------- 大圖檢視（B2-I4） ---------- */
dialog.dlg.photo-viewer [hidden] { display: none !important; }
.pv-meta { min-height: var(--lh-small); margin-bottom: var(--s-2); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.pv-stage {
  display: flex; align-items: center; justify-content: center; min-height: 240px; padding: var(--s-2);
  background: #F4F5F7; border-radius: 4px; touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.pv-img { display: block; max-width: 100%; max-height: 60vh; object-fit: contain; -webkit-user-drag: none; }
.pv-msg { margin: 0; padding: var(--s-4); text-align: center; }
.pv-nav { display: flex; align-items: center; justify-content: center; gap: var(--s-2); flex: 1 1 100%; }
.pv-nav .btn { flex: 1 1 0; }
.pv-count { flex: none; min-width: 4em; text-align: center; color: var(--c-text-2); }
@media (min-width: 1024px) {
  dialog.dlg.photo-viewer { width: min(1200px, calc(100vw - 32px)); }
  .pv-img { max-height: calc(100vh - 200px); }
  .pv-nav { flex: 0 1 auto; }
  .pv-nav .btn { flex: none; }
  .dlg-foot.wrap .pv-nav { margin-right: auto; }
}
@media (max-width: 1023px) {
  dialog.dlg.photo-viewer { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  dialog.dlg.photo-viewer .dlg-form { height: 100%; max-height: none; }
  dialog.dlg.photo-viewer .dlg-head { padding-top: calc(var(--s-1) + env(safe-area-inset-top)); }
  dialog.dlg.photo-viewer .dlg-body { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; padding: var(--s-2) var(--s-3); }
  dialog.dlg.photo-viewer .pv-stage { flex: 1 1 auto; min-height: 0; }
  dialog.dlg.photo-viewer .pv-img { max-height: 100%; height: auto; }
  dialog.dlg.photo-viewer .dlg-foot { padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom)); }
}

/* ---------- 單價庫（B2-I6）：只引用上面的色票與間距 ---------- */
.price-mode-hint { line-height: 1.2; }
.row-inactive td, .row-inactive .mrow-main { color: var(--c-text-3); }
.empty-hint { padding: 0 var(--s-4) var(--s-4); text-align: center; }
.pi-preview { margin-top: calc(-1 * var(--s-2)); margin-bottom: var(--s-3); font-weight: 500; color: var(--c-text-2); }
.pi-pick-tools { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-3); }
.pi-pick-tools input { flex: 1 1 180px; }
.pi-pick-tools select { flex: 0 1 12em; width: auto; }
.pi-pick-list { max-height: 50vh; overflow-y: auto; }
.pi-pick { padding: var(--s-1) var(--s-3); margin-bottom: var(--s-1); border: 1px solid var(--c-line); border-radius: var(--r-control); }
.pi-pick.selected { background: var(--c-brand-soft); border-color: var(--c-brand); }
.pi-pick-line { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); min-height: 44px; }
.pi-pick-main { display: flex; align-items: center; gap: var(--s-2); flex: 1 1 auto; min-width: 0; min-height: 44px; cursor: pointer; }
.pi-pick-main input { flex: none; width: 18px; height: 18px; margin: 0; }
.pi-pick-text { min-width: 0; overflow-wrap: anywhere; }
.pi-pick-price { flex: none; text-align: right; }
.pi-pick-qty { display: flex; align-items: center; gap: var(--s-2); padding-bottom: var(--s-2); }
.pi-pick-qty input { width: 8em; text-align: right; }

/* 從 Excel 貼上（共用對話框） */
@media (min-width: 600px) { dialog.dlg.dlg-paste { width: min(960px, calc(100vw - 32px)); } }
.paste-intro { margin: 0 0 var(--s-3); }
.paste-text { width: 100%; font-variant-numeric: tabular-nums; white-space: pre; overflow: auto; }
.paste-opts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-3); }
.paste-delim { display: inline-flex; align-items: center; gap: var(--s-2); }
.paste-summary { margin-bottom: var(--s-2); font-weight: 500; }
.paste-section { margin-top: var(--s-3); }
.paste-h { margin: 0 0 var(--s-1); color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; }
.paste-map td, .paste-map th { vertical-align: top; min-width: 120px; height: auto; }
.paste-map select { width: 100%; max-width: none; }
.paste-samples { margin: var(--s-1) 0 0; padding: 0; list-style: none; color: var(--c-text-3); font-size: var(--fs-small); line-height: var(--lh-small); }
.paste-samples li { overflow-wrap: anywhere; }
.paste-preview td { height: auto; overflow-wrap: anywhere; }
.paste-preview td.num, .paste-preview th.num { text-align: right; font-variant-numeric: tabular-nums; }
.paste-warn { color: var(--c-warn); font-size: var(--fs-small); }
.paste-skipped { margin: 0; padding-left: 1.4em; color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }

.paste-checks p { margin: 0 0 var(--s-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.paste-notes { margin: 0 0 var(--s-2); padding-left: 1.4em; color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); }

/* 付款明細從 Excel 貼上：第二步「核對付款明細」 */
select.pimp-select { width: 100%; max-width: none; }
.only-mobile select.pimp-select { height: 44px; font-size: 16px; }
.pimp-name { overflow-wrap: anywhere; }
.pimp-warn { margin: var(--s-3) 0 0; padding: var(--s-2) var(--s-3); background: var(--c-warn-bg); border-radius: var(--r-panel); }
.pimp-table td, .pimp-table th { height: auto; vertical-align: top; }
.pimp-table td { overflow-wrap: anywhere; }
.pimp-status { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-1); }
.pimp-mrow { display: flex; align-items: flex-start; gap: var(--s-2); padding-left: var(--s-2); padding-right: var(--s-3); }
.pimp-check { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 44px; min-height: 44px; }
.pimp-check input { width: 20px; height: 20px; margin: 0; }
.pimp-mbody { flex: 1 1 auto; min-width: 0; }
.pimp-mbody .pimp-status { margin-top: var(--s-1); }
.pimp-table input[type="checkbox"] { width: 18px; height: 18px; margin: 0; }

/* ---------- 附證明（B2-I15）：選證明、縮圖列 ---------- */
.ev-picker { margin-top: var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--c-line); }
.ev-pick-title { margin: 0 0 var(--s-1); font-size: var(--fs-body); font-weight: 500; }
.ev-pick-buttons { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: var(--s-2) 0; }
.ev-pick-buttons .btn { min-height: 44px; }
.ev-pick-list { list-style: none; margin: 0 0 var(--s-2); padding: 0; }
.ev-pick-row { display: flex; align-items: center; gap: var(--s-2); min-height: 44px; border-bottom: 1px solid var(--c-line); }
.ev-pick-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.ev-strip { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ev-tile {
  position: relative; display: block; flex: none; width: 64px; height: 64px; min-width: 44px; padding: 0; overflow: hidden;
  border: 1px solid var(--c-line); border-radius: 4px; background: #F7F8FA; font: inherit; color: var(--c-text); cursor: pointer;
}
.ev-tile:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 2px; }
.ev-tile-off { cursor: default; color: var(--c-text-3); }
.ev-tile-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; font-size: 12px; line-height: 16px; text-align: center; overflow-wrap: anywhere; }
.ev-tile-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 100%; font-size: 11px; line-height: 14px; color: var(--c-text-2); }
.ev-tile-ver { position: absolute; top: 2px; right: 2px; }
.ev-tile .photo-img { display: block; width: 100%; height: 100%; object-fit: cover; }
@media (min-width: 1024px) { .ev-tile { width: 72px; height: 72px; } }
.ev-remove-note { margin-top: var(--s-1); }

/* B25-2：從首頁「待確認收款」點進來時標出的請款單；案子總覽的「收款最後更新」 */
.dt tr.row-focus td, .mrow.row-focus { background: var(--c-brand-soft); }
.receipt-fresh { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); overflow-wrap: anywhere; }

/* B25-3：原始檔檢視（照片可以放大、好幾個檔案左右翻）、列上的「原始檔」按鈕、檔案分頁的「用在：…」 */
dialog.dlg.source-viewer [hidden] { display: none !important; }
.sv-meta { margin-bottom: var(--s-2); font-size: var(--fs-small); line-height: var(--lh-small); overflow-wrap: anywhere; }
.sv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); margin-bottom: var(--s-2); }
.sv-bar:empty { display: none; }
.sv-bar .qe-zoom-label { min-width: 5em; text-align: center; color: var(--c-text-2); font-size: var(--fs-small); }
.sv-bar .qe-zoom-newtab { margin-left: auto; }
.sv-view { height: 60vh; min-height: 240px; overflow: auto; border: 1px solid var(--c-line); border-radius: var(--r-control); background: var(--c-page); }
.sv-slot { min-height: 100%; }
.sv-slot > .btn, .sv-slot > .muted { margin: var(--s-3); }
@media (min-width: 1024px) {
  dialog.dlg.source-viewer { width: min(1100px, calc(100vw - 32px)); }
  .sv-view { height: calc(100vh - 260px); }
  .dlg-foot.wrap .pv-nav { margin-right: auto; }
  dialog.dlg.source-viewer .pv-nav { flex: 0 1 auto; }
  dialog.dlg.source-viewer .pv-nav .btn { flex: none; }
}
.file-used-in { color: var(--c-text-2); font-size: var(--fs-small); line-height: var(--lh-small); overflow-wrap: anywhere; }
/* B25-5：報表定稿 */
.report-box { display: grid; gap: var(--s-2); min-width: 0; }
.report-checks { margin: 0; padding-left: 1.2em; overflow-wrap: anywhere; }
.report-checks li + li { margin-top: var(--s-1); }
.report-list { list-style: none; margin: 0; padding: 0; }
.report-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); padding: var(--s-2) 0; border-bottom: 1px solid var(--c-line); min-width: 0; }
.report-row:last-child { border-bottom: 0; }
.report-main { min-width: 0; overflow-wrap: anywhere; }
/* B25-6：回收區的一批：手機上按鈕換到下一行 */
.trash-row { flex-wrap: wrap; }
.trash-row .actions { flex-shrink: 0; margin-left: auto; }
/* B25-7：匯入資料夾的預覽（每個資料夾一張卡片；手機上分類選單換到下一行） */
.imp-group { padding: var(--s-2) 0; border-bottom: 1px solid var(--c-line); }
.imp-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.imp-name { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.imp-folder { font-weight: 500; }
.imp-choice { flex: 0 1 240px; min-width: 0; }
.imp-choice select { width: 100%; }
.imp-sub { margin-top: 2px; overflow-wrap: anywhere; }
.imp-big, .imp-links, .imp-detail ul { margin: var(--s-1) 0 0; padding-left: 1.4em; font-size: var(--fs-small); line-height: var(--lh-small); overflow-wrap: anywhere; }
.imp-big { color: var(--c-warn); }
.imp-links li { margin-bottom: var(--s-1); }
.imp-totals { margin-top: var(--s-3); }
.imp-result { font-weight: 500; }
.imp-progress .progress { --progress-h: 8px; margin: var(--s-2) 0; }
.imp-detail { margin-top: var(--s-3); }
.imp-foot { display: contents; }
