/* 派工排程（v1.3）：派工看板（顧問 × 日期）與派工視窗
   顏色一律用 /assets/base.css 的變數（深色模式才會正確） */

/* 只給報讀軟體念的文字（畫面上不顯示） */
.dsp-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- 頁首：週切換｜清單・看板｜顧問篩選｜新增派工 ---------- */
.dsp-range { margin-left: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dsp-head .dsp-who { width: auto; }
.dsp-view { flex: none; padding: 2px; }
.dsp-view button { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 6px 13px; }
.dsp-view button svg { flex: none; }

/* ---------- 換週時資料還沒到：內容淡一點（很快載完就不會閃） ---------- */
.dsp-card { transition: opacity .15s; }
.dsp-card.busy { opacity: .55; transition: opacity .2s ease .12s; }
.dsp-card.board { overflow: hidden; } /* 看板的格子跟著卡片圓角 */

/* ---------- 清單（每天一段的版面在 admin.css）：那裡有幾處寫死的淺色，這裡改用變數，深色模式才不會出現白條 ---------- */
.dsp-card .day-head { background: var(--surface-2); }
.dsp-card .day-head.quiet { background: var(--card); }
.dsp-card .day-head.today, .dsp-card .day-head.quiet.today { background: var(--brand-50); }
.dsp-card .day-none { color: var(--placeholder); }
.dsp-card .leave-row { background: color-mix(in srgb, var(--red-bg) 55%, var(--card)); }
.dsp-form .member-pick { background: var(--surface-2); }
/* 整週沒有派工：提示下面列出這週有誰請假 */
.dsp-leaves { border-top: 1px solid var(--line-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); overflow: hidden; }
.dsp-leaves .leave-row:last-child { border-bottom: 0; }
.dsp-lw { margin-right: 6px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
/* 請假那一行的文字放在同一段裡，窄螢幕上照一般文字換行（不會被擠成一欄一欄） */
.dsp-card .leave-row > svg { flex: none; align-self: flex-start; margin-top: 3px; }
.dsp-lt { flex: 1; min-width: 0; line-height: 1.55; }

/* ---------- 看板：一列一位顧問、一欄一天 ---------- */
.db-note { display: flex; align-items: center; gap: 8px; padding: 10px 16px; font-size: 14px; color: var(--brand); background: var(--brand-50); border-bottom: 1px solid var(--line-2); }
.db-note svg { flex: none; }
/* 放不下七天時左右捲（欄寬由 dispatch-board.js 算好放在 --db-col：畫面上剛好整數天），顧問那欄固定在左邊 */
.db-wrap { position: relative; }
.db-wrap::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 18px; pointer-events: none; opacity: 0;
  background: linear-gradient(to left, var(--scroll-shadow), transparent); transition: opacity .15s;
}
.db-wrap.more-r::after { opacity: 1; } /* 右邊還有沒看到的天 */
.db-wrap.more-l .db-who, .db-wrap.more-l .db-corner { box-shadow: 6px 0 8px -6px var(--scroll-shadow); } /* 已往右捲：顧問欄浮起來 */
.db-scroll {
  --db-who: 140px;
  overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity; scroll-padding-left: var(--db-who);
}
.db-grid { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.db-grid.fit { width: calc(var(--db-who) + 7 * var(--db-col, 112px)); }
.db-col-who { width: var(--db-who); }
.db-grid th, .db-grid td { border-bottom: 1px solid var(--line-2); border-left: 1px solid var(--line-2); }
.db-grid tr > :first-child { border-left: 0; }
.db-grid tbody tr:last-child > * { border-bottom: 0; }

/* 表頭：日期＋星期；今天藍色底線、週末淡灰 */
.db-grid thead th { padding: 9px 10px 8px; text-align: left; vertical-align: bottom; font-weight: 400; background: var(--surface-2); border-bottom-color: var(--line); }
.db-corner { position: sticky; left: 0; z-index: 3; font-size: 13px; color: var(--muted); }
.db-dd { display: block; font-size: 14.5px; font-weight: 600; line-height: 1.35; color: var(--ink); font-variant-numeric: tabular-nums; }
.db-dw { display: block; font-size: 12.5px; line-height: 1.4; color: var(--muted); white-space: nowrap; }
.db-day { scroll-snap-align: start; }
.db-day.weekend { background: color-mix(in srgb, var(--bg) 60%, var(--surface-2)); }
.db-day.today { background: var(--brand-50); box-shadow: inset 0 -2px 0 var(--brand); }
.db-day.today .db-dd, .db-day.today .db-dw { color: var(--brand); }
.db-day.today .db-dw { font-weight: 600; }

/* 每一列的顧問：左右捲動時固定在左邊；名字下面是這週的場次與時數 */
.db-who { position: sticky; left: 0; z-index: 2; padding: 10px 12px; text-align: left; vertical-align: top; font-weight: 400; background: var(--card); }
/* 名字前面是頭像（顏色依名字固定，和總覽、紀錄審核同一色）；下面的場次與時數對齊名字 */
.db-name { display: flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 600; line-height: 1.4; color: var(--ink); }
.db-av { flex: none; }
.db-nm { min-width: 0; overflow-wrap: anywhere; }
.db-sum { display: block; margin-top: 2px; padding-left: 34px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.db-sum.none { color: var(--placeholder); }
.db-sum > span { white-space: nowrap; }
.db-sum > .h::before { content: "・"; }

/* 格子：底下整塊是「新增派工」按鈕，派工與請假疊在上面 */
.db-cell { position: relative; height: 70px; padding: 6px; vertical-align: top; }
.db-cell.weekend { background-color: color-mix(in srgb, var(--bg) 70%, var(--card)); }
.db-cell.today { background-color: color-mix(in srgb, var(--brand-50) 75%, var(--card)); }
/* 整天請假：斜線底紋 */
.db-cell.off { background-image: repeating-linear-gradient(135deg, color-mix(in srgb, var(--ink) 10%, transparent) 0 1px, transparent 1px 7px); }
.db-add {
  position: absolute; inset: 0; z-index: 0; display: flex; align-items: flex-end; justify-content: flex-end; width: 100%; height: 100%;
  margin: 0; padding: 6px 7px; border: 0; border-radius: 0; background: transparent; color: var(--brand); font: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: background-color .12s;
}
.db-add svg { opacity: 0; transition: opacity .12s; }
.db-add:hover { background-color: color-mix(in srgb, var(--brand) 7%, transparent); }
.db-add:active { background-color: color-mix(in srgb, var(--brand) 12%, transparent); }
.db-add:hover svg, .db-add:focus-visible svg { opacity: 1; }
.db-add:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.db-cell:not(.blank) { padding-bottom: 24px; } /* 已有派工的格子下面留一條空白，可以再加一筆（滑過時右下角出現＋） */
.db-cell.blank .db-add { align-items: center; justify-content: center; }
@media (hover: none) { .db-cell.blank .db-add svg { opacity: .4; } } /* 手機沒有滑鼠：空白格子直接看得到＋ */

.db-items { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 4px; pointer-events: none; } /* 空隙點下去仍是「新增」 */
.db-chip {
  --c: var(--gray); --cb: var(--gray-bg);
  pointer-events: auto; display: flex; flex-direction: column; width: 100%; min-width: 0; margin: 0; padding: 4px 7px 5px 8px;
  border: 0; border-left: 3px solid var(--c); border-radius: 7px; background: var(--cb); color: var(--ink);
  font: inherit; font-size: 13px; line-height: 1.4; text-align: left; cursor: pointer; transition: box-shadow .12s;
}
/* 顏色和清單的狀態標籤相同：已派工 橘、已確認 藍、已完成 綠、已取消 灰 */
.db-chip.amber { --c: var(--amber); --cb: var(--amber-bg); }
.db-chip.blue { --c: var(--blue); --cb: var(--blue-bg); }
.db-chip.green { --c: var(--green); --cb: var(--green-bg); }
.db-chip.red { --c: var(--red); --cb: var(--red-bg); }
.db-chip.purple { --c: var(--purple); --cb: var(--purple-bg); }
.db-chip:hover { box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 45%, transparent), var(--shadow-xs); }
.db-chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.db-t { display: flex; align-items: center; gap: 4px; overflow: hidden; font-weight: 600; color: var(--c); font-variant-numeric: tabular-nums; white-space: nowrap; }
.db-t svg { flex: none; color: var(--red); } /* 顧問回報行程有問題 */
.db-c { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-chip.cancel { opacity: .75; }
.db-chip.cancel .db-c { text-decoration: line-through; }
/* 拖曳改期（2026-12-02 第二輪巡檢 C4b）：可以拖的派工顯示抓取游標；拖動中的派工變淡；可以放下的格子框起來 */
.db-chip[draggable="true"] { cursor: grab; }
.db-chip[draggable="true"]:active { cursor: grabbing; }
.db-chip.dragging { opacity: .45; }
.db-cell.drop { background-color: color-mix(in srgb, var(--brand) 10%, var(--card)); box-shadow: inset 0 0 0 2px var(--brand); }
.db-leave {
  align-self: flex-start; max-width: 100%; padding: 1px 7px; border-radius: 6px; background: var(--red-bg); color: var(--red);
  font-size: 12.5px; font-weight: 500; line-height: 1.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 看板下方：操作說明＋顏色說明 */
.db-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 18px; padding: 10px 16px; border-top: 1px solid var(--line-2); font-size: 13px; color: var(--muted); }
.db-legend { display: inline-flex; flex-wrap: wrap; gap: 4px 14px; margin-left: auto; }
.db-legend > span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.db-legend i { --c: var(--gray); width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.db-legend i.amber { --c: var(--amber); }
.db-legend i.blue { --c: var(--blue); }
.db-legend i.green { --c: var(--green); }
.db-legend i.off { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--ink) 40%, transparent) 0 1px, transparent 1px 3.5px); box-shadow: inset 0 0 0 1px var(--line-strong); }

/* ---------- 新增／編輯派工：日期＋時間同一列（時間欄夠寬，「上午 09:30」不會被切掉） ---------- */
.dsp-when { display: flex; flex-wrap: wrap; gap: 15px; min-width: 0; }
.dsp-when > .dsp-date { flex: 1 1 12.5em; } /* 「2026/10/22（四）」完整顯示 */
.dsp-when > .dsp-time { flex: 999 1 20.5em; } /* 兩個時間欄各至少 9.5em；放不下（手機、大字）就整個換到下一行 */
.dsp-times { display: flex; align-items: center; gap: 6px; min-width: 0; }
.dsp-times > .input { flex: 1 1 0; min-width: 9.5em; padding-left: 10px; padding-right: 8px; font-variant-numeric: tabular-nums; }
.dsp-times > span { flex: none; color: var(--muted); }
/* 日期、時間和同一張表單的其他輸入框一樣高（44px） */
.dsp-form .dsp-date .date-field { min-height: 44px; }
.dsp-times > input.input { height: 44px; padding-top: 0; padding-bottom: 0; }

/* ---------- 手機 ---------- */
@media (max-width: 640px) {
  /* 頁首第二行放得下「清單｜看板」「全部顧問」「新增派工」：切換鈕在手機上只留文字 */
  .dsp-view button { min-height: 40px; padding: 6px 14px; }
  .dsp-view button svg { display: none; }
  /* 看板：顧問那欄窄一點（還放得下小頭像＋三個字的名字），一次看得到兩天，左右滑動換天 */
  .db-scroll { --db-who: 100px; }
  .db-grid { font-size: 13px; }
  .db-who { padding: 9px 6px 9px 10px; }
  .db-name { font-size: 14px; gap: 5px; }
  .db-av { width: 22px !important; height: 22px !important; font-size: 11px !important; }
  .db-sum { padding-left: 27px; }
  .db-sum > span { display: block; } /* 「1 場」「4 小時」各一行，不會斷在數字中間 */
  .db-sum > .h::before { content: none; }
  .db-cell { height: 66px; padding: 5px; }
  .db-chip { padding: 4px 6px 5px 7px; }
  .db-foot { padding: 10px 14px; }
  .db-legend { margin-left: 0; }
}
/* ---------- 手機清單：本週稍早的派工收成一列；每筆派工精簡成三、四行 ---------- */
.dsp-early {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; margin: 0; padding: 8px 14px 8px 18px;
  border: 0; border-bottom: 1px solid var(--line-2); border-radius: 16px 16px 0 0; background: var(--surface-2);
  color: var(--ink-2); font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.dsp-early > svg:first-child { flex: none; color: var(--icon-muted); }
.dsp-early .grow { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
.dsp-early-sub { font-weight: 400; font-size: 13px; color: var(--muted); }
.dsp-early-chev { flex: none; color: var(--icon-muted); transition: transform .2s var(--ease-out); }
.dsp-early[aria-expanded="true"] .dsp-early-chev { transform: rotate(180deg); }
.dsp-early:active { background: var(--press); }
.dsp-early:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
@media (max-width: 640px) {
  /* 客戶名稱一行、專案名稱一行（不顯示專案編號）；工作內容一行（地點在派工視窗裡）；還沒到的派工不顯示「尚無紀錄」 */
  .dispatch-tbl .d-code, .dispatch-tbl .d-loc, .dispatch-tbl .d-rec-later { display: none !important; }
  .dispatch-tbl tr { padding: 10px 16px; }
  .dispatch-tbl .col-main { margin-top: 2px; font-weight: 500; }
  .dispatch-tbl .col-main .small { font-weight: 400; }
}
@media (prefers-reduced-motion: reduce) { .dsp-early-chev { transition: none; } }
@media (max-width: 359px) { .dsp-times > .input { min-width: 0; padding-left: 8px; padding-right: 4px; } }
@media (prefers-reduced-motion: reduce) { .dsp-card, .dsp-card.busy, .db-add, .db-add svg, .db-chip, .db-wrap::after { transition: none; } }
/* 定期派工（v1.15）：重複設定、預覽日期清單、編輯時的套用範圍 */
.dsp-repeat { display: flex; flex-direction: column; gap: 8px; }
.dsp-days { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dsp-days .dr-chip { min-width: 2.4em; text-align: center; }
.dsp-end { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.dsp-end .dsp-count { width: 5.5em; }
.dsp-plan { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.dsp-plan-h { margin-bottom: 8px; }
.dsp-plan-list { list-style: none; margin: 0 0 6px; padding: 0; max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.dsp-plan-list li { padding: 6px 10px; border-bottom: 1px solid var(--line-2); }
.dsp-plan-list li:last-child { border-bottom: 0; }
.dsp-plan-list li.off { background: var(--surface-2); color: var(--ink-2); }
.dsp-plan-list .checkbox { flex-wrap: wrap; align-items: baseline; }
.dsp-series-note .dsp-scope { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
