/* components.css — 歲玥靜好 康復之家 交班系統
 * 共用元件：card、chip、button、input、modal、toast、skeleton
 */

/* === 全域 box-sizing reset：避免 input padding 撐爆容器 === */
*, *::before, *::after { box-sizing: border-box; }

/* === 表單 input 統一寬度 === */
input.input, select.input, textarea.input,
input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  width: 100%;
  max-width: 100%;
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
}

/* === 日期 / 時間類 input：預設全寬、與其他表單欄位一致（全域 box-sizing 已 border-box）。
   查詢頁 filter 日期不要全寬 → 由 .filter-chip 自管 width:auto（pages.css）。 === */
input[type="date"], input[type="datetime-local"], input[type="time"] {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

/* ═══════════════════════════════════
   工具 class
   ═══════════════════════════════════ */
.hidden { display: none !important; }

/* ═══════════════════════════════════
   CARD（藍綠金 2px 頂條）
   ═══════════════════════════════════ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-md);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-sm);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--brand-gradient-bar);
  pointer-events: none;
}

/* ═══════════════════════════════════
   CHIP（標籤）— 全站唯一版本
   2026-07 批次二：原 pages.css 有重複定義（因載入序在後，實際生效值以該版為準）；
   已合併到此處單一來源，pages.css 重複區塊已移除。數值與原生效版一致，無視覺變動。
   ═══════════════════════════════════ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--font-micro);
  color: var(--text-primary);
}

/* ── CHIP 變體 — filter chip／status chip 統一高度（2026-07 美編拍板）
   疊加於 .chip 之上使用：class="chip chip-filter" / class="chip chip-status"。
   目前僅 search 頁時間 chips 示範接上；其餘頁面既有 .chip 用法不變，主包批次遷移。── */
.chip-filter,
.chip-status {
  min-height: 30px;
  box-sizing: border-box;
}

/* ═══════════════════════════════════
   SEGMENTED TABS（頂部分頁標籤，等寬互斥切換）
   2026-07 批次二：由 pages.css 查詢頁段落移入共用層（原僅 search 頁單一使用者，
   數值原封不動移植，無視覺變動）。供未來新頁面直接複用。
   ═══════════════════════════════════ */
.seg-tabs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  margin-bottom: 14px;
}
.seg-tab {
  flex: 1;
  text-align: center;
  padding: 9px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: #fff;
  border-left: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
}
.seg-tab:first-child { border-left: none; }
.seg-tab.on { color: #fff; }
.seg-tab.on.t-item   { background: var(--brand-1); }
.seg-tab.on.t-rent   { background: var(--brand-gold); }
.seg-tab.on.t-repair { background: #1a6e6e; }
.seg-tab.on.t-handover { background: var(--brand-2); }
.seg-tab.on.t-reminder { background: #1f9f9f; }
/* 佔位維（如帳務明細，待元件交付）：灰階不可互動，區別於一般 hover/on 態 */
.seg-tab.disabled { color: var(--muted); opacity: 0.45; cursor: default; }

/* 5 顆時等寬不橫捲：縮字體/padding 塞滿一列 */
.seg-tabs.seg5 { overflow: hidden; }
.seg-tabs.seg5 .seg-tab {
  flex: 1 1 0;
  min-width: 0;
  font-size: 12px;
  padding: 9px 0;
  white-space: nowrap;
}

/* ═══════════════════════════════════
   BUTTON
   ═══════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-primary);
  font-size: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  border: none;
  outline: none;
  transition: opacity var(--dur-fast), transform var(--dur-fast);
  text-decoration: none;
}

.btn:active {
  opacity: 0.88;
  transform: scale(0.98);
}

.btn[disabled],
.btn.loading {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── BUTTON 變體 — primary/ghost/danger（2026-07 美編拍板：全系統按鈕長寬儘量一致）
   疊加於 .btn 之上使用：class="btn btn-primary"。統一高度／padding／圓角／字級。
   既有頁面沿用 .submit-btn（同尺寸邏輯，未migrate）；主包批次逐頁換上，本批次僅定義。── */
.btn-primary,
.btn-ghost,
.btn-danger {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: var(--font-body);
  font-weight: 600;
}
.btn-primary {
  background: var(--brand-gradient);
  color: var(--text-on-accent);
  border: none;
}
.btn-ghost {
  background: var(--bg-card);
  color: var(--brand-primary);
  border: 1px solid var(--brand-primary);
}
.btn-danger {
  background: var(--bad);
  color: var(--text-on-accent);
  border: none;
}

/* ═══════════════════════════════════
   INPUT / FORM
   ═══════════════════════════════════ */
.input,
.textarea,
.select {
  display: block;
  width: 100%;
  background: var(--surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: var(--font-primary);
  font-size: var(--font-body);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  box-sizing: border-box;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(31, 127, 159, 0.12);
}

.input.error,
.textarea.error {
  border-color: var(--bad);
}

.textarea {
  min-height: 80px;
  resize: vertical;
}

.input[readonly],
.input[disabled] {
  background: var(--border-subtle);
  color: var(--text-secondary);
  cursor: default;
}

.form-error {
  font-size: var(--font-micro);
  color: var(--bad);
  margin-top: 4px;
}

/* ═══════════════════════════════════
   MODAL
   ═══════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 22, 0.5);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 1024px) {
  .modal-overlay {
    align-items: center;
  }
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}

@media (min-width: 1024px) {
  .modal {
    border-radius: var(--radius-lg);
    max-height: 80vh;
  }
}

.modal-title {
  font-size: var(--font-h3);
  font-weight: 700;
  color: var(--text-primary);
}

/* ═══════════════════════════════════
   TOAST
   ═══════════════════════════════════ */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-sm));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 420px;
}

.toast {
  background: var(--text-primary);
  color: var(--text-on-accent);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: var(--font-caption);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: toastIn var(--dur-base) var(--ease-out) forwards;
  pointer-events: auto;
}

.toast.ok   { background: var(--ok); }
.toast.warn { background: var(--warn); }
.toast.bad  { background: var(--bad); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-12px); }
}

/* ═══════════════════════════════════
   SKELETON（shimmer 動畫）
   ═══════════════════════════════════ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--border-subtle) 25%,
    var(--surface-elevated) 50%,
    var(--border-subtle) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-card {
  height: 80px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
}

@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position:  200% 0; }
}

/* ── 報修狀態條（P24 5 段進度，供 repair-card.js 用）──
   contact → contacted → repairing → done_wait → settled（5 節點＋連線）。
   目前段大圓高亮（teal）；已結單走滿格藍 brand-secondary。 */
.repair-progress {
  display: flex;
  align-items: center;
  margin: 10px 0 4px;
}
.repair-progress .rpg-node {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border-default, #d1d5db);
  flex-shrink: 0;
}
.repair-progress .rpg-line {
  flex: 1;
  height: 2px;
  background: var(--border-default, #d1d5db);
}
.repair-progress .rpg-node.is-done {
  background: #1a6e6e;
}
.repair-progress .rpg-line.is-done {
  background: #1a6e6e;
}
.repair-progress .rpg-node.is-current {
  width: 16px;
  height: 16px;
  background: #1a6e6e;
  box-shadow: 0 0 0 3px rgba(26, 110, 110, 0.18);
}
.repair-progress.is-settled .rpg-node,
.repair-progress.is-settled .rpg-line {
  background: var(--brand-secondary, #2b7fb8);
}
.repair-progress.is-settled .rpg-node.is-current {
  box-shadow: 0 0 0 3px rgba(43, 127, 184, 0.18);
}
.repair-progress-label {
  font-size: 12px;
  color: var(--muted, #6b7785);
  margin-bottom: 6px;
}
.repair-progress-label strong { color: #1a6e6e; }
.repair-progress-label.is-settled strong { color: var(--brand-secondary, #2b7fb8); }

/* ── 交班頂部「未完成」聚合 chip（D-A）──
   未還租借（金）／未結報修（teal）連到各管理頁；不混排卡進 timeline。 */
#track-rental {
  background: #fffdf8;
  color: #9a7d3a;
  border-color: #e8dcc0;
}
#track-repair {
  background: #f3fbfb;
  color: #1a6e6e;
  border-color: #cfe4e4;
}

/* ============================================================
   交班確認頁逐項確認清單（P22）+ 交接班入口鈕（P7 .shift-btn）
   批次1 原誤放 _common/components.css（未被 shell 載入），搬到 live 檔生效。
   ============================================================ */
.confirm-list {
  border: 1px solid var(--line, var(--border-subtle));
  border-radius: var(--radius-md);
  overflow: hidden;
}
.confirm-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.confirm-item:last-child { border-bottom: 0; }
.confirm-item.checked { background: #f3f9f6; }
.confirm-item input[type=checkbox] {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  flex-shrink: 0;
  accent-color: var(--brand-1, var(--brand-primary));
}
.confirm-item .ci-body {
  flex: 1;
  font-size: 13px;
  line-height: var(--line-normal);
  color: var(--text-primary);
}
.confirm-item .ci-type {
  display: inline-block;
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 8px;
  margin-right: 5px;
  font-weight: 600;
}

/* ============================================================
   交班確認頁 變更 8：分區標題列（勾選在外）+ 連續軸線輕量列（對齊 preview #p7e 改法B）。
   報修 #1a6e6e / 事項 #2b7fb8 / 租借 #cf9326；緊急報修 #c0392b（紅點+紅字，不做厚卡 tint）。
   每筆列由 confirm.js itemToListRow 本地自畫（inline style，色點需依資料動態算）；
   本區保留分區標題列(.hc-sec-head)、勾選框(.hc-cat-*)、外卡(.hc-board)、軸線(.hc-axis)。
   ============================================================ */
/* 分區標題列（非卡）：● 類別名（N） + 右側單一勾選框；下細線分隔 */
.hc-sec-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 8px;
  margin-top: 14px;
  border-bottom: 1px solid var(--line, var(--border-subtle));
}
.hc-sec-head:first-of-type { margin-top: 0; }
.hc-sec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--border-default);
}
.hc-sec-head--repair .hc-sec-dot { background: #1a6e6e; }
.hc-sec-head--entry  .hc-sec-dot { background: #2b7fb8; }
.hc-sec-head--rental .hc-sec-dot { background: #cf9326; }
.hc-sec-name, .hc-sec-count {
  font-size: 12.5px;
  font-weight: 800;
}
.hc-sec-count { opacity: 0.78; }
.hc-sec-head--repair .hc-sec-name, .hc-sec-head--repair .hc-sec-count { color: #1a6e6e; }
.hc-sec-head--entry  .hc-sec-name, .hc-sec-head--entry  .hc-sec-count { color: #2b7fb8; }
.hc-sec-head--rental .hc-sec-name, .hc-sec-head--rental .hc-sec-count { color: #cf9326; }
.hc-sec-spacer { flex: 1; }

/* 交班內容：一張乾淨外卡（對齊 preview #p7e 改法B），內含分區標題 + 連續軸線列群。 */
.hc-board {
  background: var(--bg-card, #fff);
  border: 1px solid var(--line, var(--border-subtle));
  border-radius: 10px;
  padding: 2px 14px 8px;
  margin-bottom: 4px;
}
/* 連續左軸線容器：色點掛在軸上（列內 dot left:-17px 對齊此軸）。 */
.hc-axis { position: relative; padding-left: 18px; }
.hc-axis-line {
  position: absolute; left: 4px; top: 8px; bottom: 8px;
  width: 2px; background: var(--line, var(--border-subtle)); border-radius: 2px;
}
.hc-axis > div:last-child { border-bottom: none; }

/* 整類勾選框（標題列右側；button，無原生 checkbox） */
.hc-cat-check {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.hc-cat-lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary, #64748b);
}
.hc-cat-check.is-on .hc-cat-lbl { color: var(--brand-1, var(--brand-primary)); }
.hc-cat-box {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid #b6c4cf;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}
.hc-cat-check.is-on .hc-cat-box {
  background: var(--brand-1, var(--brand-primary));
  border-color: var(--brand-1, var(--brand-primary));
  box-shadow: 0 2px 6px rgba(31, 127, 159, 0.30);
}
.hc-cat-box svg {
  width: 15px;
  height: 15px;
  stroke: #fff;
  stroke-width: 3.2;
  fill: none;
  display: none;
}
.hc-cat-check.is-on .hc-cat-box svg { display: block; }

.shift-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--bg-card);
  border-radius: 18px;
  padding: 5px 14px;
  font-size: 13px;
  color: var(--brand-1, var(--brand-primary));
  text-decoration: none;
  font-weight: 700;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.18);
}

/* ════════════════════════════════════════════════════════════
 * HvDropdown — v2 色塊自訂下拉（取代原生 <select>）
 * 由 core/dropdown.js 產出 <details class="dd"> 結構
 * 全裝置可用（從 pages.css 行動版 @media 移出，桌機亦套樣式）
 * ════════════════════════════════════════════════════════════ */
details.dd {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm, 6px);
  background: var(--bg-card, #fff);
}
details.dd > summary {
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  min-height: 44px;
}
details.dd > summary::-webkit-details-marker { display: none; }
details.dd > summary::after {
  content: "▼";
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
}
details.dd[open] > summary::after { content: "▲"; }
details.dd .dd-current {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}
details.dd .dd-list {
  background: var(--surface-elevated, #fafbfc);
  border-top: 1px solid var(--line);
  max-height: 280px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
details.dd .dd-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
}
details.dd .dd-item:last-child { border-bottom: 0; }
details.dd .dd-item:hover,
details.dd .dd-item:focus { background: #eef4f8; outline: none; }
details.dd .dd-item.active {
  background: #e3f2fd;
  color: var(--brand-2, #2f6f9c);
  font-weight: 600;
}
details.dd .dd-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ════════════════════════════════════════════════════════════
 * HvConfirm — brand 確認彈窗（取代原生 confirm()）
 * 由 core/confirm-modal.js 產出 .hv-confirm 結構（遮罩 + 置中卡片）
 * brand = 藍綠；danger = 紅
 * ════════════════════════════════════════════════════════════ */
.hv-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: var(--z-modal, 500);
}
.hv-confirm-card {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 40px);
  max-width: 360px;
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  z-index: calc(var(--z-modal, 500) + 1);
  border-top: 4px solid var(--brand-1, #1f7f9f);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.hv-confirm-card.danger { border-top-color: var(--bad, #c8584a); }
.hv-confirm-card.brand  { border-top-color: var(--brand-1, #1f7f9f); }
.hv-confirm-title {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--brand-1, #1f7f9f);
}
.hv-confirm-card.danger .hv-confirm-title { color: var(--bad, #c8584a); }
.hv-confirm-target {
  background: #f7f9fb;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-weight: 600;
  margin: 10px 0;
}
.hv-confirm-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 14px;
}
.hv-confirm-btns {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.hv-confirm-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  min-height: 44px;
  cursor: pointer;
  font-family: inherit;
}
.hv-confirm-btn.cancel  { background: #eef1f5; color: var(--text); }
.hv-confirm-btn.confirm { background: var(--brand-1, #1f7f9f); color: #fff; }
.hv-confirm-btn.confirm.danger { background: var(--bad, #c8584a); }

/* ════════════════════════════════════════════════════════════
 * 住民詳細頁 — 活動彙整（FR-017）手機版樣式
 * 分頁按鈕列、每筆列（類別色標+內容 clamp+箭頭）、查看全部連結
 * 變更歷程收合 <details> summary 樣式
 * 僅手機版面，不加桌機兩欄 RWD
 * ════════════════════════════════════════════════════════════ */

/* 分頁按鈕列 */
.rd-act-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

/* 變更歷程收合 <details> summary 樣式 */
.rd-timeline-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 6px 2px;
  list-style: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
}

.rd-timeline-summary::-webkit-details-marker {
  display: none;
}

#rd-timeline-details > .rd-timeline-summary::before {
  content: "▶";
  font-size: 10px;
  color: var(--text-secondary);
  display: inline-block;
  transition: transform var(--dur-fast);
}

#rd-timeline-details[open] > .rd-timeline-summary::before {
  transform: rotate(90deg);
}
