/* ============================================================
   Construction Tracker — Render-inspired redesign
   Reference: render.com 視覺風格
   Vibe: black+white full-black, sharp corners, single purple accent, light type
   ============================================================ */

:root {
  /* Render palette: black bg + white text + purple accent (dark theme) */
  --bg: #0D0D0D;              /* gray-900 — main bg */
  --bg-2: #141414;            /* gray-800 — elevated surface */
  --surface: #0D0D0D;         /* cards on black bg */
  --surface-2: #1A1A1A;       /* input bg, slightly raised */
  --surface-3: #272727;       /* gray-700 — strongest surface */

  --text: #FFFFFF;            /* primary on dark */
  --text-muted: #B3B3B3;      /* gray-300 */
  --text-subtle: #6B6B6B;     /* gray-500 */
  --text-on-accent: #0D0D0D;  /* dark text on light/accent bg */

  --border: #272727;          /* gray-700 — subtle on black */
  --border-strong: #FFFFFF;   /* white, for outline emphasis */
  --border-faint: #1A1A1A;    /* very subtle */

  /* Render purple: #C29EFF (purple-300) — high contrast on black */
  --accent: #C29EFF;
  --accent-hover: #D1B8FF;
  --accent-press: #AA77FD;
  --accent-soft: #2A0052;     /* purple-800 on black */
  --accent-ring: rgba(194, 158, 255, 0.32);

  --success: #1EFE9D;         /* green-300 — bright on black */
  --success-soft: #003924;    /* green-700 */
  --warning: #ECD60E;         /* yellow-200 — bright on black */
  --warning-soft: #614E00;    /* yellow-600 */
  --danger: #F0989E;          /* red-300 — bright on black */
  --danger-soft: #63080E;     /* red-700 */

  /* Render uses minimal shadows; mostly borders + flat color */
  --shadow-1: 0 1px 0 rgba(0, 0, 0, 0.4);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow-3: 0 8px 24px rgba(0, 0, 0, 0.6);
  --shadow-inset: inset 0 0 0 1px var(--border);

  /* Sharp corners — Render uses 0 everywhere except some pills */
  --r-input: 0;
  --r-button: 0;
  --r-card: 0;
  --r-pill: 0;

  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 40px;
  --space-5: 64px;
  --space-6: 96px;
  --space-7: 128px;

  /* Type scale */
  --fs-2xs: 11px;
  --fs-xs:  12px;
  --fs-sm:  13px;
  --fs-base: 15px;
  --fs-md:  16px;
  --fs-lg:  19px;
  --fs-xl:  23px;
  --fs-2xl: 32px;
  --fs-3xl: 48px;

  --header-h: 56px;
  --max-w: 980px;

  --ease-spring: cubic-bezier(0.9, 0.1, 0.1, 0.9);
  --ease-out: cubic-bezier(0.9, 0.1, 0.1, 0.9);
  --t-fast: 200ms;
  --t-base: 350ms;
  --t-slow: 600ms;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue",
               "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: 1.55;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  font-feature-settings: normal;
  min-height: 100vh;
}

.hidden { display: none !important; }

.app { width: 100%; min-height: 100vh; display: flex; flex-direction: column; }
@media (min-width: 720px) {
  .app { max-width: var(--max-w); margin: 0 auto; padding: var(--space-4); gap: var(--space-4); }
}

/* ============================================================
   Header (floating glass, wide horizontal layout)
   ============================================================ */

.app-header {
  background: var(--bg);
  color: var(--text);
  padding: 0 var(--space-3);
  height: var(--header-h);
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
}
@media (min-width: 720px) {
  .app-header {
    padding: 0 var(--space-4);
  }
}
.app-header h1 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--text);
}
.app-header h1::after {
  content: ".";
  color: var(--accent);
  font-weight: 700;
}
.sync-indicator {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
  white-space: nowrap;
  user-select: none;
  background: transparent;
  border: 0;
  padding: 4px 8px;
  border-radius: 0;
  cursor: pointer;
  font-family: inherit;
}
.sync-indicator.show {
  opacity: 1;
}
.sync-indicator:hover {
  color: var(--text);
  background: var(--surface-2);
}
.sync-indicator.syncing {
  opacity: 1;
  color: var(--accent);
}
.sync-indicator.syncing::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 4px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: sync-spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes sync-spin {
  to { transform: rotate(360deg); }
}

.icon-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-size: 16px;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 0;
  margin-left: auto;
  font-family: inherit;
  transition: all var(--t-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--text); color: var(--text-on-accent); border-color: var(--text); }

/* ============================================================
   Tabs (NOT numbered, NOT meta-labeled — just text)
   ============================================================ */

.tabs {
  display: flex;
  gap: 0;
  padding: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  z-index: 15;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 16px 12px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 400;
  letter-spacing: 0;
  font-family: inherit;
  border-bottom: 1px solid transparent;
  transition: color var(--t-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  font-weight: 500;
  border-bottom-color: var(--text);
}
.tab-content { display: none; padding: var(--space-3); }
.tab-content.active { display: block; }
@media (min-width: 720px) {
  .tab-content { padding: 0; }
}

/* === 手機：tab bar 移到底部（大拇指友善）===
   - desktop (@min-width: 720px) 維持上方 sticky 不動
   - 只在 mobile 把 tabs 變成 fixed bottom bar
   - tab active indicator 從 border-bottom 變 border-top
   - tab 內容 padding-bottom 預留 64px + safe-area-inset-bottom 避免被 bar 蓋住 */
@media (max-width: 700px) {
  .tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    z-index: 15;
    border-top: 1px solid var(--border);
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg);
  }
  .tab {
    border-top: 1px solid transparent;
    border-bottom: none;
    padding: 14px 8px 12px;
  }
  .tab.active {
    border-top-color: var(--text);
    border-bottom-color: transparent;
  }
  .tab-content { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}

/* ============================================================
   Card (Render: flat, bordered, no radius, no shadow)
   ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  position: relative;
  isolation: isolate;
}
.card h2 {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-lg);
  color: var(--text);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
@media (min-width: 700px) {
  .card { padding: var(--space-4); }
  .card h2 { font-size: var(--fs-xl); }
}

/* ============================================================
   Buttons (Render: black primary, outline secondary, sharp corners)
   ============================================================ */

.btn {
  font-family: inherit;
  font-size: var(--fs-sm);
  padding: 11px 18px;
  border-radius: 0;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  line-height: 1.2;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0;
  transition: background var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.btn--primary {
  background: var(--text);
  color: var(--text-on-accent);
  border-color: var(--text);
}
.btn--primary:hover {
  background: var(--text-muted);
  border-color: var(--text-muted);
}
.btn--secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn--secondary:hover {
  background: var(--text);
  color: var(--text-on-accent);
  border-color: var(--text);
}
.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn--ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn--danger:hover {
  background: var(--danger);
  color: var(--text-on-accent);
  border-color: var(--danger);
}
.btn--sm { padding: 7px 14px; font-size: 13px; }
.btn--block { width: 100%; }
.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ============================================================
   Forms
   ============================================================ */

label { display: block; margin-bottom: var(--space-3); flex: 1; }
label > span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: var(--fs-base);
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  letter-spacing: 0;
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); opacity: 1; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}
input[type="date"], input[type="number"] { font-variant-numeric: tabular-nums; }
textarea { resize: vertical; min-height: 84px; line-height: 1.6; }

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%233F3F46' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-position: right 14px center;
  background-repeat: no-repeat;
  background-size: 12px 8px;
  padding-right: 36px;
}

.helper { font-size: 12px; color: var(--text-subtle); margin: 8px 0 0; }
.field-error {
  font-size: 12px;
  color: var(--danger);
  margin: 8px 0 0;
  display: none;
  font-weight: 500;
}
.field-error.show { display: block; }
.is-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 4px rgba(185, 28, 28, 0.12) !important;
}

.row { display: flex; gap: var(--space-3); margin-bottom: var(--space-2); }
.row > label { margin-bottom: 0; }
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.filters label:last-child { grid-column: 1 / -1; }
@media (min-width: 700px) {
  .filters { grid-template-columns: 1fr 1fr 1fr; }
  .filters label:last-child { grid-column: auto; }
}

/* ============================================================
   Photo preview
   ============================================================ */

.photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 var(--space-3);
}
.photo-preview .thumb {
  width: 96px;
  height: 96px;
  border-radius: 0;
  background-size: cover;
  background-position: center;
  position: relative;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  transition: transform var(--t-fast) var(--ease-spring);
}
.photo-preview .thumb:hover { transform: scale(1.04); }
.photo-preview .thumb .del {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--text);
  color: var(--surface);
  border: 2px solid var(--surface);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  box-shadow: var(--shadow-1);
}

.progress-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
  gap: var(--space-2);
}
.progress-toolbar h2 { margin: 0; }
.progress-actions { display: flex; gap: 6px; }
.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 var(--space-3);
  max-width: 65ch;
}

/* ============================================================
   Matrix (bento-friendly: no fixed borders on edges)
   ============================================================ */

/* 戶別快速跳轉 chips */
.unit-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 2px 10px;
  margin: 0 0 10px;
  scrollbar-width: thin;
}
.unit-chips:empty { display: none; }   /* 沒戶別時不佔空間 */

.unit-chip {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms, border-color 120ms, color 120ms;
  font-family: inherit;
}
.unit-chip:hover {
  border-color: var(--accent, #000);
}
.unit-chip[aria-pressed="true"] {
  background: var(--text);
  color: var(--text-on-accent);
  border-color: var(--text);
}

/* 點 chip 時，目標 column 短暫閃一下 */
@keyframes col-flash-pulse {
  0%   { background-color: rgba(255, 215, 0, 0.0); }
  20%  { background-color: rgba(255, 215, 0, 0.55); }
  100% { background-color: rgba(255, 215, 0, 0.0); }
}
.matrix .col-flash {
  animation: col-flash-pulse 1200ms ease-out;
}

.matrix-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: 0;
  border: 1px solid var(--border);
}
.matrix th, .matrix td {
  border-bottom: 1px solid var(--border-faint);
  border-right: 1px solid var(--border-faint);
  padding: 12px 14px;
  text-align: center;
  vertical-align: middle;
  background: var(--surface);
}
.matrix thead th {
  background: var(--bg-2);
  font-weight: 500;
  color: var(--text);
  position: sticky;
  top: 0;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.matrix tbody th {
  background: var(--bg-2);
  text-align: left;
  font-weight: 400;
  white-space: nowrap;
  position: sticky;
  left: 0;
  z-index: 1;
}
.matrix {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 13px;
  min-width: 480px;
  font-feature-settings: "tnum" 1, "lnum" 1;
}
.matrix th:last-child, .matrix td:last-child { border-right: none; }
.matrix tr:last-child th, .matrix tr:last-child td { border-bottom: none; }
.matrix thead th:not(.col-avg) { vertical-align: bottom; text-align: center; }
.matrix thead th:not(.col-avg) .th-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.matrix tbody th .th-inner { display: flex; align-items: center; gap: 6px; }
.matrix tbody th .th-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.matrix .th-name--clickable {
  background: transparent;
  border: 0;
  padding: 2px 6px;
  margin: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: inherit;
  cursor: pointer;
  border-radius: 0;
  white-space: nowrap;
}
.matrix .th-name--clickable:hover {
  background: var(--bg-2);
  color: var(--accent);
}
.matrix tfoot th, .matrix tfoot td {
  background: var(--bg);
  font-weight: 600;
  color: var(--text);
}
.matrix .cell {
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-spring),
              background var(--t-fast) var(--ease-out);
  min-width: 64px;
  padding: 14px 8px;
  text-align: center;
}
.matrix .cell:hover { transform: scale(1.04); }

/* === Status 3-state colors (紅綠燈 — dark theme variants) === */
.matrix .cell-todo { background: var(--danger-soft); }
.matrix .cell-mid  { background: var(--warning-soft); }
.matrix .cell-done { background: var(--success-soft); }

/* cell 內部：彩色圓點 */
.matrix .cell-status {
  font-size: 14px;
  vertical-align: middle;
}

/* === Unit chips 兩層（floor parent + unit children）=== */
.unit-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 2px;
  align-items: center;
}
.unit-chips .chip-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-right: 4px;
}
.unit-chips .chip-floor {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--accent, #C29EFF);
  color: #0A0A0F;
  border: 1px solid var(--accent, #C29EFF);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  user-select: none;
}
.unit-chips .chip-floor:hover {
  background: #D4B4FF;
}
.unit-chips .chip-floor-name {
  font-size: var(--fs-xs);
}
.unit-chips .chip-floor-count {
  font-size: 9px;
  background: rgba(10,10,15,0.22);
  padding: 1px 5px;
  font-weight: 500;
  color: #0A0A0F;
}
.unit-chips .chip-children {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-left: 2px;
}

/* === Settings tab：floor parent row + sublist === */
.wt-list .wt-floor-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent, #C29EFF);
  color: #0A0A0F;
  border: 1px solid var(--border);
  margin-top: 6px;
}
.wt-list .wt-floor-row:first-child { margin-top: 0; }
.wt-list .wt-floor-row .wt-name--floor {
  font-weight: 600;
  letter-spacing: 0.02em;
  flex: 1;
}
.wt-list .wt-floor-row .wt-count {
  font-size: var(--fs-2xs);
  background: rgba(10,10,15,0.18);
  padding: 1px 6px;
  font-weight: 500;
}
.wt-list .wt-floor-row .wt-del--floor {
  color: #0A0A0F;
  opacity: 0.7;
}
.wt-list .wt-floor-row .wt-del--floor:hover { opacity: 1; }
.wt-list .wt-sublist {
  list-style: none;
  margin: 0;
  padding: 0 0 4px 16px;
  border-left: 2px solid var(--accent, #C29EFF);
}
.wt-list .wt-subrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-top: none;
  background: var(--surface, #16161D);
}
.wt-list .wt-subrow .wt-name { flex: 1; }

/* === Parent / Child row 樣式（大項/細項）=== */
.matrix tbody .row-parent {
  background: var(--bg-2);
}
.matrix tbody .row-parent th {
  background: var(--bg-2);
  border-top: 2px solid var(--border-strong);
}
.matrix .row-parent .th-name--parent {
  font-weight: 700;
  font-size: var(--fs-base);
  letter-spacing: -0.01em;
}
.matrix .row-parent .toggle {
  background: transparent;
  border: none;
  padding: 2px 4px;
  margin-right: 4px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-muted);
  border-radius: 4px;
  transition: background var(--t-fast) var(--ease-out);
}
.matrix .row-parent .toggle:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ============================================================
   Collapse Style Variants — switcher-driven (α Linear / β NoIcon / γ Label)
   α Linear: 8×8 chevron at END of row, smooth rotate, subtle
   β NoIcon: no per-row icons, bulk "全部展開/收合" only, default expanded
   γ Label: no icons, whole label is the toggle, subtle underline
   ============================================================ */

/* The chevron icon is always rendered; visibility controlled by body class */
.chev-end { display: none; }

/* === α: Linear chevron at END of row === */
.collapse-style-alpha .chev-end {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  color: var(--text-muted);
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1), color 120ms ease-out;
  flex-shrink: 0;
  vertical-align: -1px;
}
.collapse-style-alpha .toggle:hover .chev-end,
.collapse-style-alpha .chip-floor:hover .chev-end,
.collapse-style-alpha .wt-toggle:hover .chev-end {
  color: var(--text);
}
.collapse-style-alpha [aria-expanded="false"] .chev-end {
  transform: rotate(-90deg);
}
/* 在 flex container 裡推到底（matrix th-inner / wt-floor-row 等） */
.collapse-style-alpha .th-inner,
.collapse-style-alpha .wt-floor-row,
.collapse-style-alpha .chip-floor,
.collapse-style-alpha .unit-detail-cat-head {
  display: flex;
  align-items: center;
}
.collapse-style-alpha .th-inner > .toggle,
.collapse-style-alpha .unit-detail-cat-head > .toggle {
  margin-left: auto;
  order: 99;
  background: transparent;
  border: 0;
  padding: 0 4px;
  cursor: pointer;
}
.collapse-style-alpha .wt-floor-row > .wt-toggle--floor {
  margin-left: auto;
  order: 99;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.collapse-style-alpha .chip-floor .chev-end {
  order: 99;
  margin-left: 6px;
}

/* === β: No icons — bulk toggle only === */
.collapse-style-beta .chev-end { display: none !important; }
.collapse-style-beta .toggle,
.collapse-style-beta .chip-floor .chev-end,
.collapse-style-beta .wt-toggle--floor {
  /* keep clickable but no visual icon */
}
/* bulk toolbar (visible only in β) */
.collapse-style-beta .bulk-toggle-bar {
  display: flex;
  gap: 6px;
  margin: 0 0 var(--space-2);
}
.collapse-style-beta .bulk-toggle-bar button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  font: inherit;
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: border-color 120ms, color 120ms;
}
.collapse-style-beta .bulk-toggle-bar button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* === γ: Label-as-button with subtle underline === */
.collapse-style-gamma .chev-end { display: none !important; }
.collapse-style-gamma .toggle,
.collapse-style-gamma .chip-floor,
.collapse-style-gamma .wt-toggle--floor {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}
.collapse-style-gamma .chip-floor {
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 150ms, color 150ms;
}
.collapse-style-gamma .chip-floor:hover {
  text-decoration-color: var(--accent);
  color: var(--accent);
}
.collapse-style-gamma .th-name--parent {
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 150ms, color 150ms;
  cursor: pointer;
}
.collapse-style-gamma .row-parent:hover .th-name--parent {
  text-decoration-color: var(--accent);
  color: var(--accent);
}
.collapse-style-gamma .wt-name--floor {
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 4px;
  cursor: pointer;
  transition: text-decoration-color 150ms, color 150ms;
}
.collapse-style-gamma .wt-floor-row:hover .wt-name--floor {
  text-decoration-color: var(--accent);
  color: var(--accent);
}
.collapse-style-gamma .unit-detail-cat-head h4 {
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 4px;
  cursor: pointer;
  transition: text-decoration-color 150ms;
}
.collapse-style-gamma .unit-detail-cat-head:hover h4 {
  text-decoration-color: var(--accent);
}

/* Default: hide bulk bar (only β shows it) */
.bulk-toggle-bar { display: none; }

/* ============================================================
   New directions ι / κ / λ / μ / ν — fundamental redesigns
   ι: 永遠展開 — 沒有 collapse，用 typography 區分
   κ: 樹狀線條 — 沒有 chevron，vertical line 連接 parent-child
   λ: 側邊 panel — 沒有 inline expand，點 parent 開滑出 panel
   μ: 整列 + flow — 沒有 chevron，點整列 + max-height 動畫
   ν: 自動沈底 — 按 status 排序，做完的排到最下面（視覺摺疊）
   ============================================================ */

/* === ι: 永遠展開 === */
.collapse-style-iota .chev-end { display: none !important; }
.collapse-style-iota .row-parent { background: var(--bg-2); }
.collapse-style-iota .row-child .th-name--child {
  color: var(--text-muted);
  font-weight: 400;
}
.collapse-style-iota .row-child th {
  padding-left: 24px !important;
}

/* === κ: 樹狀線條 === */
.collapse-style-kappa .chev-end { display: none !important; }
.collapse-style-kappa .row-parent {
  position: relative;
  background: var(--bg-2);
}
.collapse-style-kappa .row-parent th::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 50%;
  bottom: -1000px;
  width: 1px;
  background: var(--border);
  opacity: 0.6;
}
.collapse-style-kappa .row-child th {
  padding-left: 32px !important;
  position: relative;
}
.collapse-style-kappa .row-child th::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 50%;
  width: 12px;
  height: 1px;
  background: var(--border);
  opacity: 0.6;
}
.collapse-style-kappa .row-parent .th-inner { cursor: pointer; }
.collapse-style-kappa .row-parent:hover { background: var(--surface-2); }

/* === λ: 側邊 panel === */
.collapse-style-lambda .chev-end { display: none !important; }
.collapse-style-lambda .row-parent {
  background: var(--bg-2);
  cursor: pointer;
  transition: background 120ms;
}
.collapse-style-lambda .row-parent:hover { background: var(--surface-2); }
.collapse-style-lambda .row-child { display: none; }   /* 預設不顯示 children */

/* 側邊 panel（從右滑出） */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 90vw);
  background: var(--bg-2);
  border-left: 1px solid var(--border-strong);
  transform: translateX(100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 8000;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-3);
}
.side-panel.open { transform: translateX(0); }
.side-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}
.side-panel-head h3 { margin: 0; font-size: 16px; font-weight: 500; }
.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) var(--space-3);
}
.side-panel-close {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}
.side-panel-close:hover { color: var(--text); }
.side-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border-faint);
}
.side-panel-row .name { color: var(--text); font-size: 13px; }
.side-panel-row .status {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border);
}

/* === μ: 整列 + flow 動畫（children 永遠 render，靠 CSS max-height 切換） === */
.collapse-style-mu .chev-end { display: none !important; }
.collapse-style-mu .row-parent { background: var(--bg-2); cursor: pointer; }
.collapse-style-mu .row-parent:hover { background: var(--surface-2); }
.collapse-style-mu .row-child-row {
  /* row 本身仍存在於 DOM，靠 max-height 切換 */
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 280ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 200ms ease-out;
}
.collapse-style-mu .row-parent.expanded + .row-child-row {
  max-height: 2000px;
  opacity: 1;
}

/* === ν: 自動沈底 — 按 status 排序 === */
.collapse-style-nu .chev-end { display: none !important; }
.collapse-style-nu .row-parent { background: var(--bg-2); }
.collapse-style-nu .row-done-section {
  /* done 的 section 摺在底部，用 divider 分隔 */
  border-top: 2px solid var(--border-strong);
  margin-top: var(--space-2);
}
.collapse-style-nu .row-parent.row-done {
  opacity: 0.7;
  background: var(--bg);
}
.collapse-style-nu .row-parent.row-done .th-name--parent {
  text-decoration: line-through;
  text-decoration-color: var(--text-subtle);
}
.collapse-style-nu .nu-summary {
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 12px;
  letter-spacing: 0.04em;
}

/* === Switcher panel (demo/dev) === */
.collapse-switcher {
  position: fixed;
  bottom: 96px;
  right: 16px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px 4px 4px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  font-size: 11px;
  font-family: inherit;
  letter-spacing: 0.05em;
  box-shadow: var(--shadow-2);
}
.collapse-switcher-label {
  color: var(--text-subtle);
  padding-right: 4px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.collapse-switcher button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 4px 8px;
  cursor: pointer;
  font: inherit;
  letter-spacing: inherit;
  transition: color 120ms, background 120ms, border-color 120ms;
}
.collapse-switcher button:hover { color: var(--text); }
.collapse-switcher button.active {
  color: #0D0D0D;
  background: var(--accent);
  border-color: var(--accent);
}
@media (max-width: 700px) {
  .collapse-switcher { bottom: 76px; right: 8px; padding: 3px 5px; }
  .collapse-switcher button { padding: 3px 7px; font-size: 10px; }
}
.matrix .row-parent .th-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: var(--fs-2xs);
  font-weight: 500;
  vertical-align: middle;
}

.matrix tbody .row-child th {
  background: var(--surface);
  font-weight: 400;
}
.matrix .row-child .th-name--child {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.matrix .row-child .th-indent {
  display: inline-block;
  color: var(--text-subtle);
  font-family: monospace;
  margin-right: 6px;
  opacity: 0.7;
}

.matrix .cell-parent-summary {
  cursor: default;
  opacity: 0.85;
}
.matrix .cell-parent-leaf {
  background: transparent;
}
.matrix .cell-parent-leaf::before {
  content: '·';
  color: var(--text-subtle);
}

.matrix .row-avg, .matrix .col-avg {
  background: var(--accent-soft) !important;
  font-weight: 500;
  color: var(--accent);
}
.matrix .grand-avg {
  background: var(--accent) !important;
  color: var(--text-on-accent);
  font-weight: 600;
}
.matrix .matrix-del {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 0;
  opacity: 0.5;
  font-family: inherit;
  transition: all var(--t-fast) var(--ease-out);
}
.matrix .matrix-del:hover { opacity: 1; color: var(--danger); }
.matrix thead .matrix-del { margin-left: 2px; }
.matrix tbody .matrix-del { margin-left: auto; }

/* ============================================================
   工項管理（bento panel — no meta label, just content）
   ============================================================ */

.wt-manager {
  margin-top: var(--space-3);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  text-align: left;
}
.wt-manager__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}
.wt-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.wt-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 6px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  transition: all var(--t-fast) var(--ease-spring);
}
.wt-row:hover { transform: translateY(-1px); box-shadow: var(--shadow-1); }
.wt-row .wt-name { font-weight: 500; }
.wt-row .wt-del {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  font-size: 14px;
  cursor: pointer;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  font-family: inherit;
  transition: all var(--t-fast) var(--ease-out);
}
.wt-row .wt-del:hover { opacity: 1; color: var(--danger); }
.wt-row .wt-del { cursor: pointer; }  /* 拖拉 row，但 × 按鈕顯示 pointer（提示可點） */
.wt-empty { color: var(--text-muted); font-size: 13px; padding: 4px 0; font-style: italic; }

/* ============================================================
   Modal (centered, spring entry)
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  /* z-index 必須 > .app-header (20) + .tabs (15)，不然 header 蓋住 modal card 頂部 */
  z-index: 30;
  padding: 20px;
  animation: modal-fade var(--t-base) var(--ease-out);
}
.modal.hidden { display: none; }

/* 各戶細項 modal：top 從 header+tabs 下方開始（user 要求上邊緣在 tabs 下方）
   不用 z-index trick（會被 tabs 蓋住），直接用 top 推開 */
.modal--below-tabs {
  top: var(--header-tabs-h, 0px);
}
.modal--below-tabs .modal-card {
  max-height: calc(100vh - var(--header-tabs-h, 0px) - 40px);
}
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: var(--space-4);
  width: 100%;
  max-width: 480px;
  /* 內容太長時 card 內部 scroll（避免被裁切、無法滑動） */
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-3);
  animation: modal-rise var(--t-slow) var(--ease-spring);
}
.modal-card h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-lg);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.modal-card label { display: block; margin-bottom: var(--space-3); }
.modal-card label > span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.modal-card input[type="range"] { width: 100%; padding: 0; }
.modal-card select,
.modal-card textarea,
.modal-card input[type="text"],
.modal-card input[type="date"],
.modal-card input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: var(--fs-base);
  font-family: inherit;
}
.modal-card input:focus,
.modal-card select:focus,
.modal-card textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.modal-card p { margin: 0 0 var(--space-3); color: var(--text); line-height: 1.6; }
.modal-card .note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
  background: var(--bg-2);
  padding: 6px 10px;
  border-radius: 0;
}
.modal-actions { display: flex; gap: 8px; margin-top: var(--space-4); }
.modal-actions .btn { flex: 1; }

/* unit detail modal 的 card 走 GSAP 控制（見 public/app.js animateUnitDetailIn/Out）；
   停掉 CSS 的 modal-rise 避免 scale(0.96) 跟 GSAP 的 y 動畫打架。 */
#unitDetailModal .modal-card { animation: none; }

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-rise {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   Entry list (staggered bento entry)
   ============================================================ */

.entry-list { margin-top: var(--space-3); }
.entry-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  position: relative;
  isolation: isolate;
  transition: transform var(--t-base) var(--ease-spring),
              box-shadow var(--t-base) var(--ease-out);
  /* Stagger entry animation (CSS cascade) */
  animation: entry-rise var(--t-slow) var(--ease-spring) both;
}
.entry-item:nth-child(1 of .entry-item) { animation-delay: 0ms; }
.entry-item:nth-child(2 of .entry-item) { animation-delay: 60ms; }
.entry-item:nth-child(3 of .entry-item) { animation-delay: 120ms; }
.entry-item:nth-child(4 of .entry-item) { animation-delay: 180ms; }
.entry-item:nth-child(5 of .entry-item) { animation-delay: 180ms; }
.entry-item:nth-child(6 of .entry-item) { animation-delay: 240ms; }
.entry-item:nth-child(n+7 of .entry-item) { animation-delay: 240ms; }

.entry-item:hover {
  border-color: var(--text);
}

/* ===== 批次選取 ===== */
.batch-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: var(--space-3);
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--border);
  border-radius: var(--r-card, 12px);
  font-size: 13px;
  animation: none;  /* batch bar 不要 stagger */
}
.batch-bar__select-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  color: var(--text, #111);
}
/* ===== 自訂 checkbox（appearance: none + 偽元素畫勾）===== */
input[type="checkbox"][data-act="select-all"],
input[type="checkbox"][data-act="pick"] {
  /* 隱藏 native 渲染，自己用偽元素畫 */
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  position: relative;
  background: var(--surface, #fff);
  border: 1.5px solid var(--surface-3, #d4d4d8);
  border-radius: 4px;
  /* 平滑過渡（背景 + border + scale） */
  transition:
    background-color var(--t-fast, 200ms) var(--ease-out, ease-out),
    border-color var(--t-fast, 200ms) var(--ease-out, ease-out),
    transform var(--t-fast, 200ms) var(--ease-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
  flex: 0 0 auto;
}
/* 偽元素：顯示 ✓ 字符（用 content 文字 + opacity transition）*/
input[type="checkbox"][data-act="select-all"]::after,
input[type="checkbox"][data-act="pick"]::after {
  content: '✓';
  position: absolute;
  /* 置中 + 微調位置 */
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  color: var(--surface, #fff);
  opacity: 0;
  transition:
    transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1) 60ms,
    opacity 120ms ease-out 60ms;
  pointer-events: none;
  user-select: none;
}
/* 按下回饋 */
input[type="checkbox"][data-act="select-all"]:active,
input[type="checkbox"][data-act="pick"]:active {
  transform: scale(0.88);
}
/* 勾選狀態：背景填色 + border + ✓ 顯示 */
input[type="checkbox"][data-act="select-all"]:checked,
input[type="checkbox"][data-act="pick"]:checked {
  background: var(--accent, #0F172A);
  border-color: var(--accent, #0F172A);
  animation: checkbox-bounce 360ms var(--ease-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
}
input[type="checkbox"][data-act="select-all"]:checked::after,
input[type="checkbox"][data-act="pick"]:checked::after {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}
.batch-bar__actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.batch-bar__actions .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 批次選取的 entry item：左邊 checkbox + 高亮 border */
.entry-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding-left: 12px;  /* 給 checkbox 留空間，但 stagger 動畫還在所以略縮 */
  position: relative;
  overflow: hidden;  /* 隱藏左側 stripe 動畫超出範圍 */
}
/* 勾選時左邊滑出 accent stripe */
.entry-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent, #0F172A);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--t-base, 360ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}
.entry-item--selected::before {
  transform: scaleX(1);
}
.entry-item__check {
  flex: 0 0 auto;
  padding-top: 2px;
  position: relative;
}
.entry-item__check input[type="checkbox"] {
  /* appearance:none 規則在上面 input[type="checkbox"][data-act="pick"] 群組選擇器 */
  width: 20px;
  height: 20px;
}
.entry-item__check input[type="checkbox"]::after {
  font-size: 15px;
}
/* 勾選時的脈衝 ripple 偽元素（在外層 .entry-item__check） */
.entry-item__check::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 0;
  background: var(--accent, #0F172A);
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}
.entry-item__check:has(input:checked)::after {
  animation: checkbox-ripple 500ms ease-out;
}
.entry-item__body {
  flex: 1 1 auto;
  min-width: 0;
}
.entry-item--selected {
  background: var(--bg-2);
  border-color: var(--text);
  transition:
    background-color var(--t-base, 360ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)),
    border-color var(--t-base, 360ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}

/* ===== 勾選動畫 keyframes ===== */
@keyframes checkbox-bounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(0.7); }
  60%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}
@keyframes checkbox-ripple {
  0%   { transform: scale(0.6); opacity: 0.4; }
  100% { transform: scale(1.8); opacity: 0; }
}
@keyframes entry-rise {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.entry-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-3);
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 6px;
}
.entry-head .meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.entry-head .meta strong { color: var(--text); font-weight: 600; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 0;
  font-size: 11px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 4px;
  background: var(--text-subtle);
  vertical-align: middle;
}
.badge--low,
.badge--todo { color: var(--danger); border-color: var(--danger); }
.badge--todo::before { background: var(--danger); }
.badge--mid { color: var(--warning); border-color: var(--warning); }
.badge--mid::before { background: var(--warning); }
.badge--done { color: var(--success); border-color: var(--success); }
.badge--done::before { background: var(--success); }
.badge .subcat-arrow { opacity: 0.5; margin: 0 2px; font-weight: 400; }
.entry-desc {
  font-size: var(--fs-md);
  margin: 12px 0;
  white-space: pre-wrap;
  line-height: 1.65;
  color: var(--text);
  letter-spacing: -0.005em;
}
.entry-photos {
  display: flex;
  gap: 6px;
  margin-top: var(--space-3);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.entry-photos img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 0;
  flex-shrink: 0;
  scroll-snap-align: start;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
  transition: width var(--t-slow) var(--ease-spring),
              background var(--t-fast) var(--ease-out);
}
.progress-bar.low > div { background: var(--danger); }
.progress-bar.mid > div { background: var(--warning); }
.progress-bar.done > div { background: var(--success); }
.entry-actions { display: flex; gap: 6px; margin-top: var(--space-3); }
.entry-actions .btn { flex: 1; }

/* ============================================================
   Empty state
   ============================================================ */

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-5) var(--space-4);
  background: var(--bg-2);
  border-radius: 0;
  border: 1px dashed var(--border);
}
.empty__icon {
  font-size: 28px;
  font-weight: 300;
  margin-bottom: var(--space-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 1px solid var(--border-strong);
  margin: 0 auto var(--space-3);
}
.empty__title {
  font-size: var(--fs-md);
  color: var(--text);
  font-weight: 500;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.empty__hint { font-size: 13px; margin: 0; color: var(--text-muted); }

/* ============================================================
   Skeleton (shimmer, no fade)
   ============================================================ */

.skeleton {
  background: linear-gradient(90deg, var(--bg-2) 0%, var(--surface) 50%, var(--bg-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 0;
}
.skeleton--line { height: 14px; margin: 6px 0; }
.skeleton--row { height: 80px; margin: 8px 0; }
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--text-on-accent);
  padding: 12px 20px;
  border-radius: 0;
  font-size: 13px;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow-3);
  transition: opacity var(--t-base) var(--ease-out),
              transform var(--t-base) var(--ease-spring);
  max-width: calc(100vw - 32px);
  text-align: center;
  letter-spacing: -0.01em;
  font-weight: 500;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { background: var(--danger); }

/* ============================================================
   Upload error
   ============================================================ */

.upload-error {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
  display: none;
  font-weight: 500;
}
.upload-error.show { display: block; }

/* ============================================================
   Lightbox
   ============================================================ */

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(10, 10, 15, 0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  font-family: inherit;
}
.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 0;
  box-shadow: var(--shadow-3);
  background: var(--surface);
  object-fit: contain;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(10, 10, 15, 0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.lightbox-nav.prev { left: 20px; }
.lightbox-nav.next { right: 20px; }
.lightbox-counter {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 10, 15, 0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: white;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 700px) {
  body { font-size: var(--fs-md); }   /* 16px on desktop, was 15px on mobile */
  .app-header h1 { font-size: var(--fs-2xl); }   /* 28px — was clamp(36-64px), too big */
  .tab { padding: 22px 14px; font-size: var(--fs-sm); }
  .row { gap: var(--space-3); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   手機版緊湊排版 — 收 padding/margin 讓進度矩陣能多塞幾列
   只在 <= 700px 啟用，桌機版不受影響
   ============================================================ */
@media (max-width: 700px) {
  .app { padding: 8px; gap: 8px; }
  .app-header { margin: 0 0 4px; padding: 10px 14px; }
  .app-header h1 { font-size: 20px; }

  .tab-content { padding: 10px 12px; }
  .tab-content.active { padding: 10px 12px; }

  .card { padding: 14px; margin-bottom: 12px; }
  .card h2 { font-size: 16px; margin: 0 0 8px; }

  .progress-toolbar { margin-bottom: 10px; gap: 8px; }
  .progress-toolbar h2 { font-size: 16px; }
  .progress-actions { gap: 4px; }
  .progress-actions .btn { padding: 4px 10px; font-size: 12px; }

  p.hint { font-size: 12px; margin: 0 0 8px; line-height: 1.4; }

  .unit-chips { padding: 0 0 8px; margin: 0 0 6px; }
  .unit-chip { padding: 5px 11px; font-size: 12px; }

  /* 矩陣本體：cell padding 縮、字稍小，讓一頁多塞 2-3 列 */
  .matrix { font-size: 12px; min-width: 0; }
  .matrix th, .matrix td { padding: 7px 8px; }
  .matrix .th-name { font-size: 12px; }
  .matrix .th-name--parent { font-size: 12px; }
  .matrix .th-count { font-size: 10px; padding: 0 5px; }
  .matrix .cell-status { font-size: 14px; }
  .matrix .toggle { font-size: 10px; padding: 1px 4px; }
  .matrix-wrap { border-radius: 0; }

  /* 紀錄頁面相關 */
  .stats { gap: 8px; margin-bottom: 10px; }
  .stat-box { padding: 10px 12px; }
  .stat-label { font-size: 10px; margin-bottom: 3px; }
  .stat-value { font-size: 22px; }

  .filters { gap: 8px; margin-bottom: 10px; }
  .filters label { gap: 3px; }
  .filters span { font-size: 11px; }
  .filters input, .filters select { padding: 7px 9px; font-size: 13px; }

  .toolbar { gap: 4px; margin: 8px 0; }
  .toolbar .btn { padding: 5px 10px; font-size: 12px; }

  .entry-item { padding: 10px 12px; }
  .entry-head { font-size: 12px; }
  .entry-desc { font-size: 13px; }
  .entry-photos .thumb { width: 64px; height: 64px; }
  .btn--sm { padding: 4px 9px; font-size: 12px; }
}

/* ============================================================
   設定 tab — 大類 / 細項 pill 管理
   ============================================================ */
.wt-name--btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--text, #111);
  cursor: pointer;
  text-align: left;
}
.wt-name--btn:hover { color: var(--accent, #2563eb); text-decoration: underline; }
.wt-row--selected { background: var(--surface-2, #eef2ff); border-color: var(--accent, #2563eb); }
.wt-row--selected .wt-name { color: var(--accent, #2563eb); font-weight: 600; }
.wt-row--sub .wt-name { padding-left: 12px; color: var(--text-2, #555); }
.wt-row--sub::before {
  content: '└';
  color: var(--text-3, #888);
  margin-right: 2px;
  font-family: monospace;
}
.wt-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--surface-2, #f1f5f9);
  color: var(--text-2, #555);
  font-size: 11px;
  font-weight: 600;
}

/* ============================================================
   設定 tab — 拖拉排序視覺回饋（SortableJS）
   ============================================================ */
/* 用 grab cursor 提示「這個 row 可以拖」（桌機）；手機靠長按觸發 */
.wt-row { cursor: grab; touch-action: pan-y; }  /* pan-y 讓垂直 scroll 仍能 work */
.wt-row:active { cursor: grabbing; }
/* SortableJS 的 ghostClass：拖曳中留在原位的「影子」 */
.wt-row--ghost {
  opacity: 0.4;
  background: var(--surface-2, #f1f5f9);
  border-style: dashed;
}
/* SortableJS 的 dragClass：使用者手指/滑鼠正在拖的那個 row */
.wt-row--dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-2);
  border-color: var(--accent, #2563eb);
  transform: scale(1.02);
  z-index: 10;
}
/* SortableJS 預設會給拖曳中的元素加 inline style（如 position: fixed），
   在手機版可能影響 touch scroll。SortableJS 自己有處理，這裡只是輔助備註。 */
/* 「選擇」狀態保留原本的 grab cursor（不要 grab + 別的顏色混亂視覺） */
.wt-row--selected { cursor: grab; }

/* === Modal：手機版也保持「浮動視窗」（不滿版，四邊看得到、內部可滾動） === */
/* iPhone 17 Safari 標準 viewport：393×852 large、URL bar 顯示時 small ≈ 715–730px。
   之前只 .modal--below-tabs 套用手機處理，導致 entryEditModal / editModal / imageLightbox
   在 Safari URL bar 顯示時底部被切掉（max-height 算 100vh=852 - 40=812，扣掉 URL bar 後 bottom 70–80px 看不到）。
   改用 100dvh（dynamic viewport，URL bar 縮放時跟著縮）並套用到所有 modal。
   還要扣 env(safe-area-inset-top)：iPhone 17 Dynamic Island + status bar ≈ 59px，否則 card top 會躲在 notch 後面。 */
@media (max-width: 700px) {
  /* 所有 modal：上下都要加 safe-area-inset（top=Dynamic Island/notch, bottom=home indicator） */
  .modal {
    padding: 12px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  /* 一般 modal card：dvh 扣掉上下 padding + 上下 safe-area，確保 card 完全在可見區 */
  .modal-card {
    border-radius: 0;
    height: auto;
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  /* 從 header+tabs 下方開始的 modal（unit detail）：再扣 header+tabs 高度 */
  .modal--below-tabs .modal-card {
    max-height: calc(100dvh - var(--header-tabs-h, 0px) - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
}

/* iOS 15.4+ 支援 dvh。15.3 以下的舊瀏覽器：dvh 整條 calc 無效，自然 fallback 到 base 的 100vh-40（行為等同今天）。 */

/* 含 select 的 row：手機版多個 select 被擠壓到 ~75px，垂直堆疊讓每個全寬
   套用範圍：modal 內（entryEditModal）跟 modal 外（新增紀錄 #entryForm）都要 */
@media (max-width: 700px) {
  .row--selects {
    flex-direction: column;
    gap: var(--space-3);
  }
  .row--selects > label {
    width: 100%;
  }
}

/* === 各戶細項 modal（unit detail）=== */
.modal-card--wide { max-width: 640px; }
.unit-detail-head,
.modal-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.unit-detail-head h3,
.modal-card-head h3 { margin: 0; }
.modal-close {
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 0;
}
.modal-close:hover { background: var(--surface-2, rgba(0,0,0,0.05)); }

.unit-detail-summary {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3);
  background: var(--surface-2, rgba(0,0,0,0.03));
  border-radius: 0;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.unit-detail-progress { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px; }
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--surface, #e5e7eb);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: var(--success, #16a34a);
  border-radius: 4px;
  transition: width 0.3s var(--ease-out);
}
.progress-label {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}
.unit-detail-stats { display: flex; gap: 6px; }
.stat-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.stat-pill.stat-done { background: rgba(22, 163, 74, 0.12); color: var(--success, #16a34a); }
.stat-pill.stat-mid  { background: rgba(234, 179, 8, 0.15); color: #b45309; }
.stat-pill.stat-todo { background: rgba(220, 38, 38, 0.12); color: var(--danger, #dc2626); }

.unit-detail-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.unit-detail-cat {
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
}
.unit-detail-cat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2, rgba(0,0,0,0.03));
  cursor: pointer;
  user-select: none;
}
.unit-detail-cat-head h4 { margin: 0; font-size: 15px; font-weight: 600; }
.unit-detail-cat-head .toggle {
  background: transparent;
  border: 0;
  font-size: 11px;
  cursor: pointer;
  padding: 0 4px;
  color: var(--text-2);
  font-family: monospace;
}
.cat-stats {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.unit-detail-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: none;  /* 收合時隱藏 */
}
.unit-detail-cat.expanded .unit-detail-rows { display: block; }
.unit-detail-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
}
.row-name { font-size: 14px; min-width: 0; }
.row-status {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface, #fff);
  cursor: pointer;
  min-width: 96px;
}
.row-status.status-done { color: var(--success, #16a34a); }
.row-status.status-mid  { color: #b45309; }
.row-status.status-todo { color: var(--danger, #dc2626); }
.row-note {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  background: var(--surface, #fff);
  font-family: inherit;
  min-width: 0;
}
.row-note:focus, .row-status:focus { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.row-del {
  background: transparent;
  border: 0;
  color: var(--text-3, #888);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.row-del:hover { color: var(--danger, #dc2626); background: rgba(220,38,38,0.08); }

@media (max-width: 700px) {
  .unit-detail-summary { gap: 10px; }
  .unit-detail-progress { min-width: 0; }
  .unit-detail-row { grid-template-columns: 1fr; gap: 4px; }
  .row-status, .row-note { width: 100%; min-width: 0; }
  .row-del { justify-self: end; }
}

/* ===== Print stylesheet（PDF 按鈕走 window.print()，user 選「另存 PDF」） ===== */
@media print {
  /* 隱藏導航、tab、工具列、新增/編輯/刪除按鈕、燈箱、modal */
  .app-header,
  .tabs,
  .toolbar,
  .batch-bar,
  .entry-actions,
  .modal,
  #syncIndicator,
  .filter-bar,
  .new-record-form,
  .pagination,
  .empty,
  .floating-action,
  .bottom-tab-bar,
  nav,
  button {
    display: none !important;
  }
  /* 強制白底黑字，避免黑色背景印一團黑 */
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .app {
    padding: 0 !important;
    max-width: 100% !important;
  }
  /* 紀錄列表攤平（隱藏 toolbar 包裝） */
  .records {
    box-shadow: none !important;
    border: 0 !important;
  }
  /* 每筆紀錄清楚分隔 */
  .entry-item, .record-card, [data-record-id] {
    break-inside: avoid;
    border: 1px solid #ccc !important;
    padding: 8px 12px !important;
    margin-bottom: 8px !important;
  }
  /* 照片縮圖維持可印 */
  img { max-width: 100% !important; page-break-inside: avoid; }
  /* GSAP animation 不要在列印時播 */
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
