/* 後台各頁面（v1.3）：日期欄位、篩選列、上傳區、沒有資料畫面等頁面層級的調整
   顏色一律用 /assets/base.css 的變數（深色模式才會正確） */

/* ---------- 篩選列（各清單頁共用的排法） ----------
   fb-split：電腦上篩選欄位在左邊（放不下自己換行）、按鈕固定在右上角，不會被擠到最下面一列；
   手機照 <filter-bar> 原本的樣子：「篩選」按鈕＋常用按鈕一列，欄位收起來 */
@media (min-width: 641px) {
  .filter-bar.fb-split { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; column-gap: 16px; }
  .filter-bar.fb-split > .fb-body { grid-column: 1; grid-row: 1; }
  .filter-bar.fb-split > .fb-head { grid-column: 2; grid-row: 1; margin-left: 0; }
  .filter-bar.fb-split:not(:has(.fb-actions)) { grid-template-columns: minmax(0, 1fr); }
}
/* 頁首裡的篩選列：跟頁籤同一列，放不下就整組換到下一列；手機上頁籤一列、篩選列一列 */
.page-head > .filter-bar { flex: 1 1 auto; min-width: 0; margin-bottom: 0; }
@media (max-width: 640px) {
  .page-head > .filter-bar { flex-basis: 100%; }
  /* 「篩選」和常用按鈕排同一列：按鈕左右留白收一點、高度至少 40px；
     真的放不下時，常用按鈕整組放到上面一列（靠右），「篩選」留在下面、緊貼著展開的篩選欄位（wrap-reverse） */
  .filter-bar.fb-split > .fb-head { flex-wrap: wrap-reverse; row-gap: 8px; }
  .filter-bar.fb-split > .fb-head .btn { min-height: 40px; padding-left: 10px; padding-right: 10px; }
  .filter-bar.fb-split > .fb-head > .fb-actions { margin-left: auto; justify-content: flex-end; }
  /* 手機上只留圖示的次要按鈕（例如「匯出今年請款」），文字仍在 aria-label 與 title */
  .filter-bar .fb-actions > .btn.fb-phone-icon { width: 40px; padding: 0; gap: 0; }
  .filter-bar .fb-actions > .btn.fb-phone-icon > span { display: none; }
}

/* 篩選列裡的搜尋框（前面有放大鏡） */
.fb-search { position: relative; display: flex; align-items: center; width: 230px; max-width: 100%; }
.fb-search > svg { position: absolute; left: 12px; color: var(--icon-muted); pointer-events: none; transition: color .15s; }
.fb-search > .input { width: 100%; padding-left: 36px; -webkit-appearance: none; appearance: none; }
.fb-search:focus-within > svg { color: var(--brand); }
/* 篩選用的下拉選單：名稱很長的（客戶｜專案）限制寬度，手機上滿版 */
.fb-body > select.input.fb-wide { max-width: 260px; }
.fb-body > .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.fb-body > .seg button { white-space: nowrap; }
/* 「清除篩選」：只有套用了條件才出現 */
.fb-clear { color: var(--muted); }
@media (max-width: 640px) {
  .fb-search { width: 100%; }
  .fb-body > select.input.fb-wide { max-width: none; }
  .fb-body > .seg { display: flex; }
  .fb-body > .seg button { flex: 1; }
  .fb-clear { align-self: flex-start; }
}


/* ---------- 日期區間前面的其他常用期間（近 90 天、今年…），外觀和快速選擇一樣 ---------- */
.dr-group { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px 4px; min-width: 0; max-width: 100%; }
.dr-extra { display: inline-flex; flex-wrap: wrap; gap: 4px; }
@media (max-width: 640px) {
  .fb-body .dr-group { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .fb-body .dr-extra { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- 上傳區：銀行對帳的大型拖放區（置中、比較高） ---------- */
.file-drop.fd-hero .fd-zone { flex-direction: column; justify-content: center; gap: 10px; padding: 30px 20px; text-align: center; border-radius: 16px; }
.file-drop.fd-hero .fd-tx { align-items: center; }
.file-drop.fd-hero .fd-tx b { font-size: 15px; font-weight: 600; }
.file-drop.fd-hero.busy .fd-zone { cursor: progress; }
@media (max-width: 640px) { .file-drop.fd-hero .fd-zone { padding: 22px 16px; } }

/* ---------- 卡片裡的淺色區塊（收款紀錄、折讓、加扣項…） ---------- */
.sub-panel { background: var(--surface-2); }
/* 紀錄審核：交通津貼與審核意見的區塊，淡淡的主色底 */
.review-box { border-color: var(--brand-100); background: color-mix(in srgb, var(--brand) 3%, var(--card)); }
/* 客戶在線上確認報價時的簽名：深色筆跡，深色模式也維持白底 */
.quote-sig { max-height: 48px; background: #fff; border-radius: 6px; }

/* ---------- 專案損益：收入與成本結構（長條與圖例同一組顏色） ---------- */
.pf-c1 { --pf: color-mix(in srgb, var(--brand) 62%, var(--card)); }
.pf-c2 { --pf: color-mix(in srgb, var(--warn-fill) 82%, var(--card)); }
.pf-c3 { --pf: color-mix(in srgb, var(--purple) 55%, var(--card)); }
.pf-c4 { --pf: color-mix(in srgb, var(--mint) 75%, var(--card)); }
.pf-c5 { --pf: color-mix(in srgb, var(--gray) 55%, var(--card)); } /* 專案費用（未稅） */
:root[data-theme="dark"] .pf-c1 { --pf: var(--brand); }
:root[data-theme="dark"] .pf-c2 { --pf: var(--warn-fill); }
:root[data-theme="dark"] .pf-c3 { --pf: var(--purple); }
:root[data-theme="dark"] .pf-c4 { --pf: var(--mint); }
:root[data-theme="dark"] .pf-c5 { --pf: var(--gray); }
.pf-kv .pf-link { margin-left: 8px; font-weight: 400; white-space: nowrap; }
.margin-bar > i[class*="pf-c"] { background: var(--pf); }
/* 損益、收款狀況：項目名稱在左、金額靠右，名稱長也不會被擠成好幾行 */
.kv.pf-kv { grid-template-columns: minmax(0, 1fr) auto; }
.pf-dot { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; background: var(--pf); vertical-align: 1px; }
/* 滿意度星星 */
.stars-on { color: var(--star); }
.stars-off { color: var(--star-off); }

/* ---------- 合約與文件：上傳列 ---------- */
.pd-upload { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line-2); }
.pd-upload-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pd-upload-row > select { width: auto; }
.pd-upload-row > .input:not(select) { flex: 1; min-width: 180px; }
@media (max-width: 640px) {
  .pd-upload-row > select, .pd-upload-row > .input:not(select), .pd-upload-row > .btn { flex: 1 1 100%; }
  .pd-upload-row > .btn { min-height: 42px; }
}

/* ---------- 薪資結算：頁首（結算月份是這一頁的主題，手機上也一直顯示；匯出類按鈕在手機排成兩欄） ---------- */
.pay-period { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.pay-period > .input { width: auto; }
.pay-tools { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .pay-head .pay-period { flex: 1 1 100%; }
  .pay-head .pay-period > .input { flex: 1; min-width: 0; }
  .pay-head > .btn-primary { flex: 1 1 100%; min-height: 44px; }
  .pay-head > .grow { display: none; }
  .pay-tools { flex: 1 1 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pay-tools > .btn { min-width: 0; padding-left: 10px; padding-right: 10px; }
}

/* ---------- 費用明細：收據區 ---------- */
.rcpt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.rcpt-add { margin-top: 10px; }

/* ---------- 卡片裡的精簡「沒有資料」：左右留白少一點 ---------- */
.card-b > .empty.small:only-child { padding: 18px 8px; }

/* =====================================================================
   v1.4 表格：排序、固定表頭、疏密；名字前面的頭像；動作完成後整列亮一下
   ===================================================================== */

/* ---------- 固定表頭（app.js 判斷放得下才加 .sticky-head；樣式本體在 base.css） ----------
   表頭有底色時（固定表頭往下捲要蓋住下面的列、可排序的表頭滑過時）：表格在卡片最上面，左右兩格跟著卡片的圓角，不會露出方角 */
.card > .table-wrap:first-child > .table > thead > tr > th:first-child { border-top-left-radius: calc(var(--radius-lg) - 1px); }
.card > .table-wrap:first-child > .table > thead > tr > th:last-child { border-top-right-radius: calc(var(--radius-lg) - 1px); }
/* 表格外框在卡片最上／最下面：外框本身也跟著圓角（左右捲動提示的淡色邊緣、手機派工清單的底色才不會蓋住卡片圓角） */
.card > .table-wrap:first-child { border-top-left-radius: calc(var(--radius-lg) - 1px); border-top-right-radius: calc(var(--radius-lg) - 1px); }
.card > .table-wrap:last-child { border-bottom-left-radius: calc(var(--radius-lg) - 1px); border-bottom-right-radius: calc(var(--radius-lg) - 1px); }
/* 卡片最下面的合計列（淺灰底）、滑過的最後一列：左右下角也跟著卡片圓角 */
.card > .table-wrap:last-child > .table > tfoot > tr:last-child > td:first-child,
.card > .table-wrap:last-child > .table > tbody:last-child > tr:last-child > td:first-child { border-bottom-left-radius: calc(var(--radius-lg) - 1px); }
.card > .table-wrap:last-child > .table > tfoot > tr:last-child > td:last-child,
.card > .table-wrap:last-child > .table > tbody:last-child > tr:last-child > td:last-child { border-bottom-right-radius: calc(var(--radius-lg) - 1px); }
/* 可排序的表頭：游標停在上面時整格淡淡一層底色（--hover 是不透明色，固定表頭時也蓋得住下面的列），看得出可以點 */
.table th.th-sortable:hover { background-color: var(--hover); }
/* 排序箭頭不佔欄寬：箭頭（約 4px 間距＋11px 字寬）伸進表頭右邊的留白，欄位不會因為多了箭頭而變寬、把別欄擠成好幾行；
   數字欄（靠右）的欄名也因此剛好和下面的數字對齊 */
.table .th-sort > .th-arrow { margin-right: -15px; }
/* 筆電上欄間留白收成 12px（admin.css）：箭頭伸進留白的距離跟著縮 */
@media (min-width: 641px) and (max-width: 1280px) { .table .th-sort > .th-arrow { margin-right: -12px; } }
@media (min-width: 641px) and (max-width: 1180px) { .table .th-sort > .th-arrow { margin-right: -10px; } }
/* 列印：表頭不固定（每一頁上方本來就會重複印表頭） */
@media print { .table.sticky-head thead th { position: static !important; box-shadow: none !important; } }
@media (max-width: 640px) {
  /* 手機是卡片版面：不固定表頭（保險起見，app.js 在手機上也不會加 class） */
  .table.sticky-head thead th { position: static; box-shadow: none; }
  /* 沒有變卡片的表格（no-cards）：第一欄、最後一欄的表頭和內容對齊 */
  .table th.th-sortable:first-child .th-sort { padding-left: 16px; }
  .table th.th-sortable:last-child .th-sort { padding-right: 16px; }
}

/* ---------- 名字前面的頭像（表格、清單） ----------
   <div class="av-cell"><avatar>＋<div><b>姓名</b><div class="small">帳號</div></div></div>：頭像在左、兩行字在右
   <span class="with-av"><avatar>姓名</span>：一行（樣式在 base.css） */
.av-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.av-cell > .av { flex: none; }
.av-cell > div { min-width: 0; line-height: 1.45; }
.table .with-av { gap: 8px; }
/* 沒有人的那一格（公司直接支付、未指派）：灰色圓形小圖示，和頭像同樣大小，名字才會對齊 */
.av.av-ic { width: 30px; height: 30px; }
.av.av-ic svg { color: var(--av7-fg); }
/* 專案的顧問：重疊的頭像＋名字 */
.members { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; }
.members > span:last-child { min-width: 0; }
/* 緊湊表格：頭像小一點，列高才真的變矮 */
html.dense .table .av-cell > .av { width: 26px !important; height: 26px !important; font-size: 12px !important; }
html.dense .table .with-av > .av { width: 22px !important; height: 22px !important; font-size: 11px !important; }
html.dense .table .av-cell > div { line-height: 1.35; }
@media (max-width: 640px) {
  /* 手機卡片：標題列的頭像小一點，和 15px 的標題對齊 */
  .table:not(.no-cards):not(.dispatch-tbl) td[data-role="title"] .av-cell { gap: 9px; }
  .table:not(.no-cards):not(.dispatch-tbl) td[data-role="title"] .av-cell > .av { width: 30px !important; height: 30px !important; font-size: 13.5px !important; }
  .table:not(.no-cards):not(.dispatch-tbl) td .members { gap: 6px; }
}

/* ---------- 表格「緊湊」（帳號選單 → 表格：緊湊，<html class="dense">；上下留白由 base.css 縮小） ----------
   電腦上行高再收一點、狀態旁的「查核提示」小標籤放得下就排在同一行，一個畫面多看幾列；手機卡片不受影響 */
@media (min-width: 641px) {
  html.dense .table td { line-height: 1.45; }
  html.dense .table td .small { line-height: 1.4; }
  html.dense .table td > .rec-hint { display: inline-block; margin: 0 0 0 6px; vertical-align: middle; }
  html.dense .table td .fill-tags { row-gap: 3px; }
}

/* ---------- 動作完成（核准、確認、發放…）：那一列淡淡亮一下綠色再褪掉（table-sort.js 的 useRowFlash） ---------- */
@keyframes row-flash { from { background-color: var(--green-bg); } }
.table tbody tr.document-selected { outline: 2px solid var(--primary, currentColor); outline-offset: -2px; }
.table tbody tr.row-flash > td { animation: row-flash 1.6s var(--ease-out); }
@media (max-width: 640px) {
  /* 手機卡片：整張卡片亮 */
  .table:not(.no-cards):not(.dispatch-tbl) tbody tr.row-flash { animation: row-flash 1.6s var(--ease-out); }
  .table:not(.no-cards):not(.dispatch-tbl) tbody tr.row-flash > td { animation: none; }
}
@media (prefers-reduced-motion: reduce) {
  .table tbody tr.row-flash, .table tbody tr.row-flash > td { animation: none; }
}

/* ---------- 銀行對帳：交易是一張張卡片，排序用下拉選單 ---------- */
.fb-body > select.input.fb-sort { width: auto; max-width: 180px; }
@media (max-width: 640px) { .fb-body > select.input.fb-sort { max-width: none; } }

/* =====================================================================
   v1.5 老闆：系統設定「目標與規則」、專案清單的健康燈號
   ===================================================================== */

/* ---------- 審核規則：每條一列——開關｜名稱、白話說明、金額、在哪裡檢查 ---------- */
.rules { display: flex; flex-direction: column; }
.rule { display: flex; align-items: flex-start; gap: 14px; padding: 16px 20px; border-top: 1px solid var(--line-2); }
.rule:first-child { border-top: 0; }
.rule-b { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.rule-b > b { font-size: 15px; font-weight: 600; color: var(--ink); line-height: 1.5; }
.rule-b > p { margin: 0; max-width: 680px; font-size: 13.5px; line-height: 1.65; color: var(--ink-2); }
.rule-amt { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 4px; font-size: 14px; color: var(--ink-2); }
.rule-amt .money-input { width: 170px; }
.rule-where { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.rule-where svg { flex: none; }
/* 開關（role="switch"）：關＝淺底＋灰色圓鈕、開＝主色實心＋白色圓鈕；整顆 46×28，外面再留點擊範圍 */
.switch {
  flex: none; position: relative; width: 46px; height: 28px; margin-top: 1px; padding: 0; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--sunken); box-shadow: inset 0 0 0 1.5px var(--line-strong); transition: background .18s, box-shadow .18s;
}
.switch::before { content: ""; position: absolute; inset: -8px -6px; } /* 手指好按：點擊範圍比外觀大一圈 */
.switch-k { position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .18s var(--ease-out), background .18s; }
.switch[aria-checked="true"] { background: var(--brand-solid); box-shadow: none; }
.switch[aria-checked="true"] .switch-k { transform: translateX(18px); background: var(--on-brand); }
.switch:hover:not([aria-checked="true"]) { box-shadow: inset 0 0 0 1.5px var(--input-line-hover); }
@media (max-width: 640px) {
  .rule { gap: 12px; padding: 14px 16px; }
  .rule-amt .money-input { flex: 1 1 140px; width: auto; min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { .switch, .switch-k { transition: none; } }

/* ---------- 專案管理：「有風險／要注意」篩選、燈號欄 ---------- */
.hl-chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 12px; border: 1px solid var(--input-line); border-radius: 999px;
  background: var(--input-bg); font: inherit; font-size: 14px; color: var(--ink-2); white-space: nowrap; cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.hl-chip:hover { border-color: var(--input-line-hover); color: var(--ink); }
.hl-chip.on { background: var(--amber-bg); border-color: color-mix(in srgb, var(--amber) 45%, transparent); color: var(--amber-ink); font-weight: 600; }
.hl-dots { display: inline-flex; align-items: center; }
.hl-dots i { width: 8px; height: 8px; border-radius: 50%; }
.hl-dots i.r { background: var(--red); }
.hl-dots i.w { margin-left: -2px; background: var(--warn-fill); box-shadow: 0 0 0 1.5px var(--input-bg); }
.hl-chip.on .hl-dots i.w { box-shadow: 0 0 0 1.5px var(--amber-bg); }
.hl-n { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--line-2); font-size: 12px; font-weight: 600; line-height: 20px; text-align: center; color: var(--ink-2); }
.hl-chip.on .hl-n { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber-ink); }
/* 燈號欄只放一顆小圓點：左右留白收窄，專案名稱那欄才不會被擠成好幾行 */
.table td.proj-health { width: 1%; min-width: 0; padding-left: 6px; padding-right: 6px; text-align: center; }
.table th.proj-health-th .th-sort { padding-left: 6px; padding-right: 14px; white-space: nowrap; }
@media (max-width: 640px) {
  .hl-chip { min-height: 40px; align-self: flex-start; }
  /* 手機卡片：燈號直接寫出「有風險／要注意／正常」（電腦版只有小圓點，滑過才看得到原因） */
  .proj-health .health.compact .h-pill { padding: 1px 10px 1px 8px; }
  .proj-health .health.compact .sr-only { position: static; width: auto; height: auto; margin: 0; clip: auto; overflow: visible; }
}
