:root {
  --bg-main: #F7F8FA;
  --bg-card: #FFFFFF;
  --bg-subtle: #F0F3F7;
  --bg-hover: #EBF0F5;
  --text-primary: #17212F;
  --text-secondary: #697586;
  --text-muted: #9AA4B2;
  --brand-primary: #243B53;
  --brand-hover: #1B2D40;
  --brand-light: #E6EEF6;
  --color-success: #10B981;
  --color-success-bg: #ECFDF5;
  --color-cost: #D97706;
  --color-cost-bg: #FFFBEB;
  --color-danger: #DC2626;
  --color-danger-bg: #FEF2F2;
  --border-color: #E8ECF0;
  --border-strong: #CBD5E1;
  --shadow-sm: 0 1px 2px rgba(23, 33, 47, 0.04);
  --shadow-card: 0 2px 8px rgba(23, 33, 47, 0.04), 0 1px 2px rgba(23, 33, 47, 0.03);
  --shadow-modal: 0 16px 36px rgba(23, 33, 47, 0.24);
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-card: 14px;
  --focus-ring: 0 0 0 3px rgba(36, 59, 83, 0.16);
}

[data-theme="dark"] {
  --bg-main: #0F141C;
  --bg-card: #18202C;
  --bg-subtle: #222C3C;
  --bg-hover: #2A3648;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --brand-primary: #3B82F6;
  --brand-hover: #60A5FA;
  --brand-light: rgba(59, 130, 246, 0.18);
  --color-success: #34D399;
  --color-success-bg: rgba(16, 185, 129, 0.14);
  --color-cost: #FBBF24;
  --color-cost-bg: rgba(217, 119, 6, 0.15);
  --color-danger: #F87171;
  --color-danger-bg: rgba(220, 38, 38, 0.15);
  --border-color: #263142;
  --border-strong: #37455C;
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.25);
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.28);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding-top: 64px;
  padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  overflow-x: clip;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.num-tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex-shrink: 0;
}
.icon-sm { width: 16px; height: 16px; }

.app-container {
  max-width: 560px;
  margin: 0 auto;
  min-height: calc(100vh - 64px);
}

/* 頂部導覽列 */
.top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  z-index: 45;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.icon-button {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.icon-button:hover { background: var(--bg-subtle); }
.icon-button:active { transform: scale(0.97); }

.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.brand-page-suffix {
  font-weight: 600;
  color: var(--text-primary);
}

.role-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--brand-light);
  color: var(--brand-primary);
}

.theme-switch-btn {
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1;
  flex-shrink: 0;
  cursor: pointer;
}
#themeIcon, #themeLabel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
#themeIcon svg { display: block; }

/* 側邊抽屜導覽 */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  z-index: 60;
  transform: translateX(-100%);
  transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-shadow: var(--shadow-modal);
}
.drawer-panel.open { transform: translateX(0); }

.drawer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 12px;
}
.drawer-brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.drawer-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.drawer-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
}
.drawer-link:hover { background: var(--bg-subtle); color: var(--text-primary); }
.drawer-link.active {
  background: var(--brand-light);
  color: var(--brand-primary);
  font-weight: 600;
}
.drawer-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* 通用卡片結構 */
.main-content { padding: 14px; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-header-stack { margin-bottom: 14px; }
.card-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 32px;
}
/* 問題一：統一所有卡片主標題高度、間距與 18px 圖示大小，確保絕對水平齊平 */
.card-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1.35;
}
.card-title svg,
.card-title .icon {
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
  stroke-width: 1.9;
  flex-shrink: 0;
}
.card-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 5px;
  line-height: 1.4;
}

/* 篩選膠囊與日期觸發器 */
.preset-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.preset-pills::-webkit-scrollbar { display: none; }
.pill-btn {
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}
.pill-btn.active {
  background: var(--brand-primary);
  color: #FFFFFF;
  border-color: var(--brand-primary);
}

.date-picker-trigger {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 0.92rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.date-picker-trigger:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.date-trigger-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.date-trigger-hint {
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  white-space: nowrap;
  flex-shrink: 0;
}

/* 經營數據 KPI 卡片 (保留三大卡片，隱藏底部次要說明排) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media (max-width: 370px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  padding: 14px 12px;
  box-shadow: var(--shadow-card);
  min-width: 0;
}
.kpi-label {
  font-size: 0.74rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value.surplus-pos { color: var(--color-success); }
.kpi-value.cost-val { color: var(--color-cost); }

/* ⚡ 隱藏底部的次要說明排 (區間總入帳、工資支出比例等) */
.kpi-meta {
  display: none !important;
}

/* 環圈圖與摘要區 */
.chart-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: center;
}
@media (min-width: 500px) {
  .chart-layout {
    grid-template-columns: 156px 1fr;
  }
}
.doughnut-box {
  width: 156px;
  height: 156px;
  margin: 0 auto;
  position: relative;
}
.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
}
.breakdown-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-weight: 500;
}
.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.breakdown-right {
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}
.breakdown-pct {
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin-left: 6px;
  font-weight: 400;
}

/* 表單元件 (保留原生箭頭與自訂輸入體驗) */
.form-section-divider {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin: 14px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.form-group {
  margin-bottom: 14px;
  min-width: 0;
}
.form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
}
.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.req-star { color: var(--color-danger); margin-left: 2px; }

.input-with-action {
  display: flex;
  gap: 8px;
  align-items: stretch;
  width: 100%;
}
.input-control, .select-control {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.input-control:focus, .select-control:focus {
  border-color: var(--brand-primary);
  box-shadow: var(--focus-ring);
}
.input-control.input-error {
  border-color: var(--color-danger);
}
.field-error-msg {
  font-size: 0.78rem;
  color: var(--color-danger);
  margin-top: 4px;
  display: none;
}
.field-error-msg.visible { display: block; }

.btn-add-inline {
  height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--brand-primary);
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
}
.btn-add-inline:hover { background: var(--brand-light); border-color: var(--brand-primary); }

/* 師傅多選下拉選單 */
.multiselect-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}
.multiselect-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  text-align: left;
}
.multiselect-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.multiselect-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  z-index: 35;
  max-height: 220px;
  overflow-y: auto;
  padding: 6px;
  display: none;
}
.multiselect-dropdown.open { display: block; }
.multiselect-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-primary);
  user-select: none;
}
.multiselect-option:hover { background: var(--bg-subtle); }
.ms-checkbox {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1.5px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: transparent;
  flex-shrink: 0;
  transition: all 0.12s;
}
.multiselect-option.selected .ms-checkbox {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #FFFFFF;
}

/* 工時步進器與快捷鍵列 */
.stepper-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.quick-hours-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.quick-chip {
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.quick-chip:hover, .quick-chip:active {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  background: var(--brand-light);
}
.quick-chip-add {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px dashed var(--brand-primary);
  background: transparent;
  color: var(--brand-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.quick-chip-add:hover { background: var(--brand-light); }

.wage-preview-banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.btn-primary {
  width: 100%;
  height: 46px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--brand-primary);
  color: #FFFFFF;
  font-size: 0.95rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  margin-top: 8px;
}
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

/* 統一小型按鈕與下拉選單規格 (高度 32px) */
.btn-secondary-sm {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary-sm:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

/* 「公司盈餘」下拉選單：外觀、高度與「複製上次」完全齊平 */
select.btn-secondary-sm {
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  padding-right: 28px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23697586' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 8px center !important;
  background-size: 14px 14px !important;
  line-height: 30px;
  outline: none;
}

[data-theme="dark"] select.btn-secondary-sm {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
}

/* 等寬網格 */
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.filter-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* 明細列表與小卡片 (單行頂部標籤排列) */
.record-list { display: flex; flex-direction: column; gap: 10px; }
.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  gap: 8px;
}
.record-card-v2 {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}
.record-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: nowrap;
}
.record-top-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.record-top-left::-webkit-scrollbar { display: none; }
.record-top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: -5px;
  flex-shrink: 0;
}
.record-date-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-right: 2px;
  white-space: nowrap;
  flex-shrink: 0;
}
.record-row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
}
.record-bottom-title {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 0;
  line-height: 1.4;
}
.record-bottom-amount {
  font-size: 0.96rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.record-row-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.record-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.record-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.record-sub { font-size: 0.76rem; color: var(--text-secondary); }
.record-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-hours {
  min-width: 52px;
  text-align: center;
}
.badge-neutral { background: var(--bg-subtle); color: var(--text-secondary); }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-cost { background: var(--color-cost-bg); color: var(--color-cost); }
.badge-brand { background: var(--brand-light); color: var(--brand-primary); }

.edit-icon-btn, .del-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.del-icon-btn { margin-right: -5px; }
.record-top-actions .del-icon-btn { margin-right: 0; }
.edit-icon-btn:hover, .edit-icon-btn:active {
  background: var(--brand-light);
  color: var(--brand-primary);
}
.del-icon-btn:hover, .del-icon-btn:active {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}
.edit-icon-btn svg, .del-icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* 案場卡片與整頁切換明細卡 */
.site-card-v2 {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}
.site-row-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.site-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 1px;
}
.site-name-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 0;
  line-height: 1.35;
}
.site-address-line {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.site-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.site-kpi-box {
  background: var(--bg-subtle);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  min-width: 0;
}
.site-kpi-box:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.site-kpi-box.active {
  border-color: var(--brand-primary);
  background: var(--brand-light);
  box-shadow: var(--shadow-sm);
}
.site-kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.site-kpi-box.active .site-kpi-top {
  color: var(--brand-primary);
}
.site-kpi-val {
  text-align: right;
  font-weight: 700;
  font-size: clamp(0.8rem, 3.3vw, 0.96rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
}
.site-detail-divider {
  border-bottom: 1px dashed var(--border-strong);
  margin: 8px 0 12px;
}
.site-ledger-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.site-ledger-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.site-ledger-summary {
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

/* 底部導覽列 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  display: flex;
  justify-content: space-around;
}
.bottom-nav-inner {
  width: 100%;
  max-width: 540px;
  display: flex;
  justify-content: space-around;
}
.nav-item {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
}
.nav-item.active { color: var(--brand-primary); font-weight: 700; }
.nav-indicator {
  width: 16px;
  height: 3px;
  border-radius: 99px;
  background: transparent;
  margin-top: 1px;
}
.nav-item.active .nav-indicator { background: var(--brand-primary); }

/* 彈窗元件 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#calendarModal { z-index: 90; }
.modal-backdrop.open { display: flex; }
.modal-card {
  width: 100%;
  max-width: 390px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  padding: 18px;
  box-shadow: var(--shadow-modal);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

/* ⚡ 統一全系統所有 Modal 底部操作按鈕高度為 38px，徹底消除高低不一 */
.modal-actions button,
.modal-actions .btn-secondary-sm,
.modal-actions .btn-primary {
  height: 38px !important;
  line-height: 38px;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.cal-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-month-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-primary);
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.cal-days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  row-gap: 4px;
}
.cal-day-cell {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 8px;
  user-select: none;
  position: relative;
}
.cal-day-cell:hover { background: var(--bg-hover); }
.cal-day-cell.empty { pointer-events: none; }
.cal-day-cell.today {
  border: 1px dashed var(--brand-primary);
  font-weight: 700;
}
.cal-day-cell.in-range {
  background: var(--brand-light);
  color: var(--brand-primary);
  border-radius: 0;
}
.cal-day-cell.range-start {
  background: var(--brand-primary);
  color: #FFFFFF;
  font-weight: 700;
  border-radius: 8px 0 0 8px;
}
.cal-day-cell.range-end {
  background: var(--brand-primary);
  color: #FFFFFF;
  font-weight: 700;
  border-radius: 0 8px 8px 0;
}
.cal-day-cell.range-single {
  background: var(--brand-primary);
  color: #FFFFFF;
  font-weight: 700;
  border-radius: 8px;
}

.toast-bar {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text-primary);
  color: var(--bg-card);
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-modal);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 95;
  white-space: nowrap;
}
.toast-bar.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 電腦版大螢幕常駐側邊欄與寬版配置 */
@media (min-width: 960px) {
  body {
    padding-left: 280px;
  }
  .top-header {
    left: 280px;
    padding: 0 24px;
  }
  .menu-open-btn,
  .drawer-close-btn {
    display: none !important;
  }
  .drawer-overlay {
    display: none !important;
  }
  .drawer-panel {
    transform: translateX(0) !important;
    width: 280px;
    box-shadow: none;
    z-index: 48;
  }
  .app-container {
    max-width: 860px;
  }
  .main-content {
    padding: 20px 24px;
  }
  .bottom-nav {
    left: 280px;
  }
  .bottom-nav-inner {
    max-width: 860px;
  }
  .toast-bar {
    left: calc(50% + 140px);
  }
}

/* 手機版與電腦版圖表展示切換 */
.mobile-chart-view { display: block; }
.desktop-chart-view { display: none; }

@media (min-width: 960px) {
  /* 電腦版隱藏下拉選單，隱藏手機版單卡，開啟 3 卡向下滾動瀏覽 */
  #metricSelect {
    display: none !important;
  }
  .mobile-chart-view {
    display: none !important;
  }
  .desktop-chart-view {
    display: block !important;
  }
}

/* === 問題二 & 問題三：個人資料與權限管理卡片樣式 === */
.profile-info-list {
  display: flex;
  flex-direction: column;
}
.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}
.profile-row:last-child {
  border-bottom: none;
}
.profile-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 52px;
  flex-shrink: 0;
}
.profile-value-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1;
}

/* 權限等級說明矩陣卡 */
.permissions-matrix-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.matrix-row {
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}
.matrix-role-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.matrix-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* === 權限管理：精準水平居中、身分圖示框與即時未儲存警示樣式 === */
.perm-target-card {
  margin-top: 14px;
}

.perm-selector-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.perm-selector-card:hover {
  border-color: var(--brand-primary);
}

.perm-selector-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.perm-selector-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* 身分專屬 SVG 圖示外框 */
.perm-selector-left-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.perm-role-icon-box {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--brand-light);
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.perm-role-icon-box svg {
  width: 22px;
  height: 22px;
  stroke: var(--brand-primary);
  stroke-width: 2;
  fill: none;
}

.perm-selector-texts {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.perm-selector-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.perm-selector-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.perm-selector-arrow-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.perm-selector-arrow-wrap svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-muted);
  stroke-width: 2.2;
  fill: none;
}

.perm-hidden-select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  z-index: 2;
}

/* 雙大按鈕切換導覽區 */
.perm-area-nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 12px;
}

.perm-area-btn {
  height: 42px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.perm-area-btn:hover {
  border-color: var(--brand-primary);
  background: var(--bg-hover);
}
.perm-area-btn.active {
  background: var(--brand-primary);
  color: #FFFFFF;
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

/* 專業手風琴列表與垂直置中校正 */
.perm-modules-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.perm-accordion-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease;
}
.perm-accordion-card:hover {
  border-color: var(--border-strong);
}

/* 強制手風琴標題高度 48px，垂直置中對齊 */
.perm-accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  height: 48px;
  padding: 0 14px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-subtle);
  box-sizing: border-box;
}

.perm-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
}

.perm-header-icon-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.perm-header-icon-box svg {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

.perm-section-title {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
  display: flex;
  align-items: center;
  margin: 0;
}

/* 右側箭頭容器與幾何中心點對齊 */
.perm-header-right {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.perm-arrow-icon {
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  stroke-width: 2.2;
  fill: none;
  display: block;
  transform-origin: 50% 50%;
  transition: transform 0.2s ease;
}
.perm-accordion-card.open .perm-arrow-icon {
  transform: rotate(180deg);
}

.perm-accordion-body {
  padding: 12px 14px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
}

.perm-leafs-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.perm-leaf-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-primary);
  user-select: none;
}
.perm-leaf-item input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--brand-primary);
  cursor: pointer;
}

.perm-sub-group {
  padding: 8px 10px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.perm-sub-group-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.perm-chips-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 未儲存變更即時高亮與提示狀態 */
.perm-save-footer-card {
  margin-top: 16px;
  padding: 14px;
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all 0.25s ease;
}

.perm-save-footer-card.has-unsaved {
  border-color: #F59E0B;
  background: rgba(245, 158, 11, 0.08);
}

.perm-save-hint-box {
  display: flex;
  flex-direction: column;
}

.perm-save-hint-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.unsaved-dot {
  color: #F59E0B;
  font-size: 0.85rem;
  animation: pulseDot 1.4s infinite ease-in-out;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.perm-save-hint-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.perm-submit-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--brand-primary);
  color: #FFFFFF;
  font-size: 0.94rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.perm-submit-btn.btn-pulse {
  background: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(36, 59, 83, 0.22);
}
.perm-submit-btn svg {
  stroke: #FFFFFF !important;
}

/* === 介面偏好獨立大卡片：三大主題按鈕排版 === */
.theme-select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.theme-card-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.theme-card-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.theme-card-btn.active {
  background: var(--brand-primary);
  color: #FFFFFF;
  border-color: var(--brand-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.theme-card-btn.active svg {
  stroke: #FFFFFF;
}

/* === 🏷️ 類目管理專屬樣式 === */
.cat-section-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 14px;
}

.cat-chip-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.cat-chip-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.cat-chip-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.cat-del-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.cat-del-btn:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.cat-del-btn svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 2.2;
}

/* 返回原身分按鈕醒目標記樣式 (尺寸與複製上次一致) */
.return-role-btn {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
  background: var(--brand-light);
  font-weight: 600;
  transition: all 0.15s ease;
}
.return-role-btn:hover {
  background: var(--brand-primary);
  color: #FFFFFF;
}
.return-role-btn:hover svg {
  stroke: #FFFFFF;
}

/* 問題一：視角切換膠囊按鈕 (文字在左、眼睛圖標在右) */
.role-switch-btn-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  cursor: pointer;
  user-select: none;
}
.role-switch-btn-wrap select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  z-index: 2;
}

/* === 🏷️ 類目管理：強化版雙卡片與拖曳排序樣式 === */
.cat-input-distinct {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background-color: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: all 0.15s ease;
  outline: none;
}
.cat-input-distinct:focus {
  border-color: var(--brand-primary);
  box-shadow: var(--focus-ring);
}
.cat-input-distinct::placeholder {
  color: var(--text-muted);
}

/* === 類目管理：新增按鈕 (調整為與「儲存派遣紀錄」相同的實心深色樣式) === */
.cat-submit-btn {
  width: 100%;
  height: 44px;
  margin-top: 10px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--brand-primary);
  color: #FFFFFF;
  font-size: 0.92rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.cat-submit-btn:active {
  transform: scale(0.99);
}

.cat-submit-btn svg {
  stroke: #FFFFFF !important;
}

/* 現有設定項目清單：單列卡片樣式 */
.cat-list-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cat-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  user-select: none;
  transition: all 0.15s ease;
}
.cat-item-row:hover {
  border-color: var(--border-strong);
}
.cat-item-row.dragging {
  opacity: 0.65;
  background: var(--brand-light) !important;
  border: 1.5px dashed var(--brand-primary) !important;
  transform: scale(1.02);
  box-shadow: var(--shadow-modal);
}

.cat-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.cat-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  padding: 6px 8px; /* 加大手機手指觸控熱區 */
  margin: -4px 0 -4px -4px;
  flex-shrink: 0;
  touch-action: none;              /* 關鍵：禁止手機在手柄上觸發畫面滾動 */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.cat-drag-handle:active {
  cursor: grabbing;
  color: var(--brand-primary);
}

.cat-item-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* === 📊 報表模組：精美匯出與 A4 列印操作按鈕排版 === */
.report-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
@media (max-width: 480px) {
  .report-actions-grid {
    grid-template-columns: 1fr;
  }
}

.btn-report-action {
  height: 44px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0 12px;
  border: 1px solid transparent;
}
.btn-report-excel-primary {
  background: var(--brand-primary);
  color: #FFFFFF;
}
.btn-report-excel-primary:hover {
  background: var(--brand-hover);
}
.btn-report-excel-success {
  background: #10B981;
  color: #FFFFFF;
}
.btn-report-excel-success:hover {
  background: #059669;
}
.btn-report-print {
  background: var(--bg-card);
  border: 1.5px solid var(--border-strong);
  color: var(--text-primary);
}
.btn-report-print:hover {
  border-color: var(--brand-primary);
  background: var(--brand-light);
  color: var(--brand-primary);
}

/* 側邊欄抽屜：登出按鈕靠底對齊 (無框線、乾淨極簡自然融入) */
.drawer-link.drawer-logout {
  margin-top: auto;
  color: var(--color-danger);
  border: none !important;
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
}
.drawer-link.drawer-logout:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* === 權限管理：員工個別設定專屬操作按鈕列 (雙欄對稱、融入主題配色、手機不折行) === */
.perm-user-aux-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  padding: 0;
  background: transparent;
  border: none;
}

.perm-aux-btn {
  position: relative;
  height: 38px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  overflow: hidden;
}

.perm-aux-btn:hover {
  border-color: var(--brand-primary);
  background: var(--bg-hover);
}

.perm-aux-btn:active {
  transform: scale(0.98);
}

/* 左側：變更身份按鈕 */
.perm-aux-role-btn {
  justify-content: space-between;
  padding: 0 10px;
}

.perm-aux-role-btn select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  z-index: 2;
}

/* 右側：恢復初始密碼按鈕 (品牌強調色) */
.perm-aux-pwd-btn {
  background: var(--brand-light);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.perm-aux-pwd-btn:hover {
  background: var(--brand-primary);
  color: #FFFFFF;
}

.perm-aux-pwd-btn:hover svg {
  stroke: #FFFFFF !important;
}


/* === 📊 報表模組：三大卡片滿版大按鈕樣式 === */
.btn-report-action-card {
  width: 100%;
  height: 46px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--brand-primary);
  color: #FFFFFF;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.btn-report-action-card:active {
  transform: scale(0.99);
}

.btn-report-action-card svg {
  stroke: #FFFFFF !important;
}

/* === 統一全站下拉選單右側箭頭符號 (完全對齊多選按鈕的向量箭頭、位置與顏色) === */
select.select-control {
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  padding-right: 36px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23697586' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  background-size: 16px 16px !important;
  cursor: pointer;
}

[data-theme="dark"] select.select-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
}

/* === 📸 案場管理：現場照片雙按鈕、縮圖牆與全螢幕放大檢視器樣式 === */
.site-photo-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.btn-site-photo-action {
  height: 38px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.btn-site-photo-action svg {
  stroke: currentColor;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ⚡ 左側：查看現場照片 (次要操作：淡藍質感背景 + 品牌藍線條與文字) */
.btn-site-photo-action.view-btn {
  background: var(--brand-light);
  border: 1.5px solid var(--brand-primary);
  color: var(--brand-primary);
}

.btn-site-photo-action.view-btn:hover {
  background: var(--brand-primary);
  color: #FFFFFF;
}

/* ⚡ 右側：上傳現場照片 (主要操作：實心品牌深藍背景 + 白字) */
.btn-site-photo-action.upload-btn {
  background: var(--brand-primary);
  border: 1.5px solid var(--brand-primary);
  color: #FFFFFF;
}

.btn-site-photo-action.upload-btn:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn-site-photo-action:active {
  transform: scale(0.98);
}

.photo-path-preview-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.photo-path-label {
  font-size: 0.74rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 2px;
}

.photo-path-code {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--brand-primary);
  word-break: break-all;
  line-height: 1.4;
}

.photo-select-dropzone {
  width: 100%;
  min-height: 82px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.photo-select-dropzone:hover {
  border-color: var(--brand-primary);
  background: var(--brand-light);
}

.photo-upload-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
  max-height: 210px;
  overflow-y: auto;
}

.upload-thumb-item {
  position: relative;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-subtle);
}

.upload-thumb-item img {
  width: 100%;
  height: 76px;
  object-fit: cover;
  display: block;
}

.upload-thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.72);
  color: #FFFFFF;
  font-size: 0.72rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-thumb-caption {
  font-size: 0.68rem;
  padding: 3px 5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--bg-card);
}

/* 查看現場照片：可滾動縮圖牆 */
.site-gallery-scroll-area {
  flex: 1;
  overflow-y: auto;
  min-height: 180px;
  max-height: 55vh;
  padding-right: 2px;
}

.site-photo-gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 520px) {
  .site-photo-gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.gallery-thumb-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.gallery-thumb-card:hover {
  border-color: var(--brand-primary);
  transform: translateY(-2px);
}

.gallery-thumb-img-wrap {
  position: relative;
  width: 100%;
  height: 120px;
  background: var(--bg-subtle);
}

.gallery-thumb-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-thumb-del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: rgba(220, 38, 38, 0.85);
  color: #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-thumb-del-btn svg {
  width: 14px;
  height: 14px;
  stroke: #FFFFFF;
  stroke-width: 2;
  fill: none;
}

.gallery-thumb-info {
  padding: 7px 9px;
}

.gallery-thumb-filename {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-thumb-meta {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* 全螢幕放大檢視器 (Lightbox) */
.photo-lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, 0.92);
  z-index: 120;
  display: none;
  flex-direction: column;
  justify-content: space-between;
}

.photo-lightbox-backdrop.open {
  display: flex;
}

.photo-lightbox-top {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #FFFFFF;
  background: rgba(0, 0, 0, 0.4);
}

.photo-lightbox-title {
  font-size: 0.92rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-lightbox-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lightbox-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
}

.photo-lightbox-body {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 48px;
  min-height: 0;
}

.photo-lightbox-body img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.lightbox-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-nav-btn.prev { left: 10px; }
.lightbox-nav-btn.next { right: 10px; }

.photo-lightbox-footer {
  padding: 12px 16px;
  text-align: center;
  color: #CBD5E1;
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.45);
}

/* === ☁️ 案場管理：Google Drive 剩餘容量顯示條樣式 === */
.gdrive-quota-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.gdrive-quota-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gdrive-quota-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.gdrive-quota-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
}

.gdrive-quota-bar-track {
  width: 100%;
  height: 7px;
  background: var(--border-color);
  border-radius: 99px;
  overflow: hidden;
}

.gdrive-quota-bar-fill {
  height: 100%;
  background: var(--brand-primary);
  border-radius: 99px;
  transition: width 0.35s ease;
}

.gdrive-quota-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  gap: 8px;
  flex-wrap: wrap;
}

/* === 📊 報表管理：薪資條大卡片「先加(+) 後減(-)」直列排版樣式 === */
.payslip-card-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease;
}

.payslip-card-item:hover {
  border-color: var(--border-strong);
}

.payslip-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.payslip-emp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.payslip-emp-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.payslip-card-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 2px;
}

.payslip-breakdown-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.payslip-line-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.payslip-bar-symbol {
  color: var(--text-muted);
  font-weight: 700;
  user-select: none;
}

.payslip-line-add {
  color: var(--text-secondary);
}

.payslip-line-add strong {
  color: var(--color-success);
  font-weight: 600;
}

.payslip-line-deduct {
  color: var(--text-secondary);
}

.payslip-line-deduct strong {
  color: var(--color-danger);
  font-weight: 600;
}

.payslip-net-col {
  text-align: right;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
}

.payslip-net-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.payslip-net-amount {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-success);
  letter-spacing: -0.02em;
}