/* ─── QS管理系統 — 主樣式表 ─────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 56px;
  --header-h:  60px;
  --transition: 0.2s ease;

  --accent:       #3b82f6;
  --accent-dark:  #2563eb;
  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --info:         #06b6d4;
  --btn-on-accent: #ffffff;
}

/* ─── Dark Mode（預設 · 夜間辦公）── */
[data-theme="dark"] {
  color-scheme: dark;

  --bg-primary:   #0d1117;
  --bg-secondary: #161b22;
  --bg-card:      #1c2230;
  --bg-hover:     #242b3a;
  --bg-input:     #1a2133;

  --accent-light: #60a5fa;
  --accent-glow:  rgba(59, 130, 246, 0.22);
  --accent-border: rgba(59, 130, 246, 0.28);

  --success-bg:   rgba(16, 185, 129, 0.12);
  --warning-bg:   rgba(245, 158, 11, 0.12);
  --danger-bg:    rgba(239, 68, 68, 0.12);
  --info-bg:      rgba(6, 182, 212, 0.12);

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #5c6370;

  --border:       rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.16);

  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md:  0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 20px var(--accent-glow);

  --overlay-bg:        rgba(0, 0, 0, 0.65);
  --loading-overlay:   rgba(13, 17, 23, 0.82);
  --doc-viewer-canvas: #1a1a1a;
  --doc-viewer-frame:  #525659;
  --chart-grid:        #21262d;
  --chart-text:        #8b949e;
  --chart-label:       #e6edf3;
  --chart-unpaid:      #374151;
}

/* ─── Light Mode（日間辦公 · 清爽專業）── */
[data-theme="light"] {
  color-scheme: light;

  --bg-primary:   #eef1f6;
  --bg-secondary: #ffffff;
  --bg-card:      #ffffff;
  --bg-hover:     #f1f5f9;
  --bg-input:     #f8fafc;

  --accent-light: #2563eb;
  --accent-glow:  rgba(37, 99, 235, 0.1);
  --accent-border: rgba(37, 99, 235, 0.22);

  --success-bg:   rgba(16, 185, 129, 0.1);
  --warning-bg:   rgba(245, 158, 11, 0.1);
  --danger-bg:    rgba(239, 68, 68, 0.08);
  --info-bg:      rgba(6, 182, 212, 0.1);

  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;

  --border:       rgba(15, 23, 42, 0.09);
  --border-hover: rgba(15, 23, 42, 0.16);

  --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md:  0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg:  0 12px 40px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 4px 16px rgba(37, 99, 235, 0.15);

  --overlay-bg:        rgba(15, 23, 42, 0.45);
  --loading-overlay:   rgba(255, 255, 255, 0.88);
  --doc-viewer-canvas: #e2e8f0;
  --doc-viewer-frame:  #cbd5e1;
  --chart-grid:        #e2e8f0;
  --chart-text:        #64748b;
  --chart-label:       #334155;
  --chart-unpaid:      #cbd5e1;
}

html.theme-animate,
html.theme-animate *,
html.theme-animate *::before,
html.theme-animate *::after {
  transition: background-color 0.28s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.28s ease !important;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── 捲動條 ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── 佈局 ─── */
.layout {
  display: flex;
  height: 100vh;
}

/* ─── 側邊欄 ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; margin-bottom: 10px;
  box-shadow: var(--shadow-glow);
}
.sidebar-logo h1 {
  font-size: 14px; font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.sidebar-logo p {
  font-size: 11px; color: var(--text-secondary);
  margin-top: 2px;
}

/* 項目選擇器 */
.project-selector {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.project-selector label {
  display: block;
  font-size: 10px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.8px;
  margin-bottom: 6px;
}
.project-selector select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  padding: 8px 28px 8px 10px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
[data-theme="light"] .project-selector select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
.project-selector select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* 導航菜單 */
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}
.nav-section-title {
  font-size: 10px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.8px;
  padding: 8px 10px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
  font-size: 13px; font-weight: 500;
  margin-bottom: 2px;
  border: 1px solid transparent;
  user-select: none;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent-light);
  border-color: var(--accent-border);
}
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 20px; text-align: center;
}
.nav-item-sub {
  padding-left: 34px;
  font-size: 12px;
  margin-top: -2px;
}
.nav-item-sub .nav-icon { font-size: 14px; width: 18px; }
.staff-usage-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-light);
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.staff-usage-link:hover { color: var(--accent); }
.nav-item-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.nav-item-disabled:hover {
  background: transparent;
  color: var(--text-secondary);
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-collapse-toggle {
  width: 100%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.sidebar-toggle-icon { line-height: 1; }

/* 側欄收合 */
html.sidebar-collapsed {
  --sidebar-w: var(--sidebar-w-collapsed);
}
html.sidebar-collapsed .sidebar-expand-only {
  display: none !important;
}
html.sidebar-collapsed .sidebar-logo {
  padding: 16px 10px;
  display: flex;
  justify-content: center;
}
html.sidebar-collapsed .sidebar-logo .logo-icon {
  margin-bottom: 0;
}
html.sidebar-collapsed .sidebar-nav {
  padding: 8px 6px;
}
html.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 10px 8px;
  gap: 0;
  position: relative;
}
html.sidebar-collapsed .nav-item-sub {
  padding-left: 8px;
}
html.sidebar-collapsed .nav-label {
  display: none;
}
html.sidebar-collapsed .nav-item .nav-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 8px;
  height: 8px;
  padding: 0;
  font-size: 0;
  border-radius: 50%;
}
html.sidebar-collapsed .sidebar-collapse-toggle {
  padding: 8px;
}
html.sidebar-collapsed .sidebar-collapse-toggle .sidebar-toggle-icon {
  transform: rotate(180deg);
}

.sidebar-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.sidebar-toggle-btn:hover {
  color: var(--accent-light);
  border-color: var(--accent-border);
  background: var(--accent-glow);
}
html.sidebar-collapsed .sidebar-toggle-btn {
  transform: rotate(180deg);
}

/* ─── 主內容區 ─── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
  transition: margin-left var(--transition);
}

/* 頂部欄 */
.topbar {
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left {
  display: flex; align-items: center; gap: 12px;
}
.topbar-title {
  font-size: 16px; font-weight: 700;
  color: var(--text-primary);
}
.topbar-subtitle {
  font-size: 12px; color: var(--text-secondary);
}
.topbar-right {
  display: flex; align-items: center; gap: 8px;
}

/* ─── 主題切換 ─── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  gap: 2px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: calc(var(--radius-md) - 2px);
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}
.theme-toggle-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-card);
}
.theme-toggle-btn.active {
  background: var(--bg-card);
  color: var(--accent-light);
  box-shadow: var(--shadow-sm);
}
[data-theme="light"] .theme-toggle-btn[data-theme-pick="light"].active {
  background: #fff;
}
[data-theme="dark"] .theme-toggle-btn[data-theme-pick="dark"].active {
  background: var(--bg-card);
}

/* 內容區 */
.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  max-width: 100%;
  position: relative;
}

.content-loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(13, 17, 23, 0.45);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

[data-theme="light"] .content-loading-overlay {
  background: rgba(255, 255, 255, 0.55);
}

.content.content-loading .content-loading-overlay {
  display: flex;
}

.content-loading-overlay .spinner {
  width: 32px;
  height: 32px;
}

.content-loading-overlay span {
  font-size: 13px;
  color: var(--text-secondary);
}

.idle-warn-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--warning-bg, rgba(234, 179, 8, 0.12));
  border-bottom: 1px solid var(--warning, #eab308);
  font-size: 13px;
  color: var(--text-primary);
}

.idle-warn-banner[hidden] {
  display: none !important;
}

.dash-recent-row {
  cursor: pointer;
}

.dash-recent-row:hover td {
  background: var(--bg-hover);
}

/* ─── 頁面 ─── */
.page { display: none; animation: fadeIn 0.25s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── 統計卡片 ─── */
.dash-project-hero {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}
.dash-project-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--info), transparent);
}
.dash-hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.dash-hero-title-block {
  flex: 1;
  min-width: 0;
}
.dash-hero-code-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.dash-hero-code {
  display: inline-block;
  font-family: monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-light);
  background: var(--accent-glow);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  letter-spacing: 0.5px;
  margin-bottom: 0;
}
.dash-hero-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px !important;
  font-weight: 600;
  padding: 4px 12px !important;
}
.dash-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}
.badge-success .dash-status-dot { box-shadow: 0 0 6px var(--success); }
.badge-info .dash-status-dot { box-shadow: 0 0 6px var(--info); }
.badge-warning .dash-status-dot { box-shadow: 0 0 6px var(--warning); }
.dash-hero-status-badge.is-active .dash-status-dot {
  animation: statusPulse 2s ease-in-out infinite;
}
@keyframes statusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}
.dash-hero-status-detail {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dash-hero-status-detail-en {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
}
.dash-hero-name {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
  margin: 0;
  word-break: break-word;
}
.dash-hero-name .proj-name-en {
  display: block;
  font-size: inherit;
  font-weight: inherit;
}
.dash-hero-name .proj-name-zh {
  display: block;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
}
.proj-name-block .proj-name-en {
  display: block;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
}
.proj-name-block .proj-name-zh {
  display: block;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
  margin-top: 3px;
}
.td-company-name {
  max-width: 180px;
  vertical-align: top;
}
.td-company-name .proj-name-block .proj-name-en {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}
.td-company-name .proj-name-block .proj-name-zh {
  font-size: 11px;
  margin-top: 2px;
}
.dash-hero-amount {
  text-align: right;
  flex-shrink: 0;
}
.dash-hero-amount-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin: 4px 0;
  white-space: nowrap;
}
.dash-hero-amount-sub {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.4px;
}
.dash-hero-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px 32px;
}
.dash-hero-meta-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.dash-hero-meta-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
  word-break: break-word;
}
@media (max-width: 768px) {
  .dash-hero-top {
    flex-direction: column;
    gap: 16px;
  }
  .dash-hero-amount {
    text-align: left;
    width: 100%;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
    padding-top: 16px;
  }
  .dash-hero-meta {
    grid-template-columns: 1fr;
  }
  .dash-hero-amount-value {
    font-size: 20px;
  }
}

.dashboard-stats {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 24px;
}
.dash-stat-hidden { display: none !important; }
.stats-block-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
  margin-bottom: 10px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.stats-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 900px) {
  .stats-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .stats-grid-3 { grid-template-columns: 1fr; }
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.stat-card.success::before { background: linear-gradient(90deg, var(--success), transparent); }
.stat-card.warning::before { background: linear-gradient(90deg, var(--warning), transparent); }
.stat-card.danger::before  { background: linear-gradient(90deg, var(--danger), transparent); }
.stat-card.info::before    { background: linear-gradient(90deg, var(--info), transparent); }

.stat-label {
  font-size: 11px; font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.stat-value {
  font-size: 26px; font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-value.small { font-size: 18px; }
.stat-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ─── 卡片 ─── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 14px; font-weight: 600;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.card-body { padding: 20px; }

/* ─── 按鈕 ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; outline: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--btn-on-accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: 0 0 12px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card);
  border-color: var(--border-hover);
}

.btn-success {
  background: var(--success);
  color: var(--btn-on-accent);
}
.btn-success:hover:not(:disabled) {
  background: #059669;
  box-shadow: 0 0 12px rgba(16,185,129,0.3);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger-bg);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-bg);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }

/* ─── 表格 ─── */
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.table-wrap.table-scroll-y {
  overflow-y: auto;
  max-height: min(72vh, 780px);
}

.table-wrap.table-scroll-y thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-hover);
  box-shadow: 0 1px 0 var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead tr {
  background: var(--bg-hover);
}
thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px; font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody td {
  padding: 10px 12px;
  color: var(--text-primary);
  vertical-align: middle;
}
.td-muted { color: var(--text-secondary) !important; }
.td-mono  { font-family: 'Courier New', monospace; font-size: 12px; }
.td-amount { font-weight: 600; text-align: right; white-space: nowrap; }

/* 付款登記列表 — 與分判合約編號相同：100% 寬 + 欄位自適應 */
.pay-records-table {
  table-layout: fixed;
  width: 100%;
  font-size: 12px;
}
.pay-records-table thead th {
  padding: 8px 8px;
  font-size: 10px;
}
.pay-records-table tbody td {
  padding: 8px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pay-records-table .pay-col-seq { width: 40px; }
.pay-records-table .pay-col-date { width: 86px; }
.pay-records-table .pay-col-inv { width: 96px; }
.pay-records-table .pay-col-sc { width: 108px; }
.pay-records-table .pay-col-co { width: 16%; }
.pay-records-table .pay-col-desc { width: 14%; }
.pay-records-table .pay-col-amt { width: 100px; }
.pay-records-table .pay-col-oa { width: 56px; }
.pay-records-table .pay-col-act { width: 120px; }
.pay-records-table .pay-act-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.pay-records-table .pay-amt-void {
  color: var(--text-muted);
}
.pay-records-table .pay-col-desc,
.pay-records-table .td-company-name {
  white-space: nowrap;
  max-width: none;
}
.pay-records-table .td-company-name .proj-name-en,
.pay-records-table .td-company-name .proj-name-zh {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pay-records-table td:last-child {
  overflow: visible;
}
.pay-records-table .pay-col-hidden,
.col-hidden {
  display: none !important;
}

/* 表格欄位顯示設定 */
.col-picker-wrap {
  position: relative;
}
/* 僅在扁平 toolbar（如付款登記）時靠右；toolbar-right 內勿用，避免換行 */
.toolbar > .col-picker-wrap {
  margin-left: auto;
}
.toolbar-right .col-picker-wrap {
  margin-left: 0;
}
.col-picker-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 120;
  min-width: 168px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.col-picker-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.col-picker-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}
.col-picker-panel input[type="checkbox"] {
  accent-color: var(--accent);
}
.col-picker-reset {
  width: 100%;
  margin-top: 8px;
}
.td-amount.positive,
.stat-value.positive,
strong.positive,
.calc-value.positive { color: var(--success); }
.td-amount.negative,
.stat-value.negative,
strong.negative,
.calc-value.negative { color: var(--danger); }

/* ─── 標籤 ─── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  }
.badge-info    { background: var(--info-bg);    color: var(--info);    }
.badge-muted   { background: var(--bg-hover);   color: var(--text-secondary); }

/* ─── 表單 ─── */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.form-input::placeholder { color: var(--text-muted); }
select.form-input {
  cursor: pointer;
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
[data-theme="light"] select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
textarea.form-input { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* ─── 搜尋/篩選欄 ─── */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.search-wrap {
  position: relative;
  flex: 1; min-width: 200px;
}
.search-wrap input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  padding: 9px 12px 9px 36px;
  outline: none;
  transition: border-color var(--transition);
}
.search-wrap input:focus { border-color: var(--accent); }
.search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 15px;
}

/* ─── 模態框 ─── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 90%; max-width: 720px;
  max-height: 90vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
.modal-lg { max-width: 900px; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; transition: all var(--transition);
}
.modal-close:hover { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

/* ─── OCR上傳區 ─── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.drop-zone input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.drop-icon { font-size: 48px; margin-bottom: 12px; }
.drop-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.drop-sub { font-size: 12px; color: var(--text-secondary); }

/* OCR結果預覽 */
.ocr-doc-type-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.ocr-doc-type-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ocr-doc-conf {
  font-size: 11px;
  color: var(--text-muted);
}
.ocr-doc-type-pick {
  display: flex;
  gap: 14px;
  font-size: 12px;
}
.ocr-type-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-secondary);
}
.ocr-sc-suggest {
  font-size: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.ocr-sc-suggest strong { color: var(--accent-light); }
.ocr-sc-suggest button {
  margin-left: 8px;
  font-size: 11px;
}
.ocr-new-sc-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.ocr-new-sc-row .ocr-sc-prefix {
  flex: 0 0 148px;
  min-width: 0;
}
#scModal .ocr-new-sc-row .ocr-sc-prefix {
  flex-basis: 128px;
}
.ocr-new-sc-row input.form-input {
  flex: 1;
  min-width: 0;
}
.sc-doc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sc-doc-link {
  font-size: 12px;
  color: var(--accent-light);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.2);
}
.sc-doc-link:hover {
  background: rgba(59, 130, 246, 0.15);
}
.sc-desc-block {
  margin-top: 4px;
}
.sc-desc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.sc-desc-title {
  margin-bottom: 8px;
  font-size: 13px;
}
.sc-desc-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
}
.sc-items-wrap {
  max-height: 240px;
}
.sc-doc-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
.sc-doc-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}
.sc-pdf-upload-btn {
  white-space: nowrap;
}
.sc-doc-none {
  font-size: 11px;
  color: var(--text-muted);
}
.sc-pdf-chip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.sc-pdf-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), border-color var(--transition);
}
.sc-pdf-remove:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
}
.sc-pdf-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-light);
  font-size: 11px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  font-family: inherit;
  position: relative;
  z-index: 2;
}
.sc-pdf-chip:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent);
}
.sc-pdf-icon {
  font-size: 14px;
  line-height: 1;
}
.sc-pdf-label {
  white-space: nowrap;
}

/* ─── 文件預覽器（PDF / 圖片）── */
.doc-viewer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 12000;
  background: var(--overlay-bg);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.doc-viewer-backdrop.open {
  display: flex;
}
.doc-viewer-panel {
  position: relative;
  width: min(96vw, 1100px);
  height: min(92vh, 900px);
  max-width: 96vw;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.doc-viewer-resize-e,
.doc-viewer-resize-s,
.doc-viewer-resize-se {
  position: absolute;
  z-index: 3;
  touch-action: none;
}
.doc-viewer-resize-e {
  top: 0;
  right: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
}
.doc-viewer-resize-s {
  left: 0;
  bottom: 0;
  width: 100%;
  height: 10px;
  cursor: ns-resize;
}
.doc-viewer-resize-se {
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
}
.doc-viewer-resize-e:hover,
.doc-viewer-resize-s:hover,
.doc-viewer-resize-se:hover {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}
.doc-viewer-resize-se::after {
  content: '';
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  opacity: 0.65;
  pointer-events: none;
}
.doc-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.doc-viewer-heading {
  min-width: 0;
  flex: 1;
}
.doc-viewer-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-viewer-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.doc-viewer-body {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--doc-viewer-canvas);
}
.doc-viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 13px;
}
.doc-viewer-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--doc-viewer-frame);
}
.doc-viewer-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
  object-fit: contain;
}
.doc-viewer-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.doc-viewer-theme-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
  flex-shrink: 0;
}
.doc-viewer-theme-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.doc-viewer-bar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}
.doc-viewer-appendix-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.doc-viewer-appendix-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
.doc-viewer-theme-select {
  max-width: 280px;
  font-size: 12px;
  padding: 6px 10px;
}
.sc-fac-theme-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 12px;
}
.data-table .td-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.sc-fac-theme-bar label {
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}
.sc-fac-theme-bar select {
  max-width: 300px;
  font-size: 12px;
}
.sc-fac-appendix-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border);
  font-size: 12px;
}
.sc-fac-appendix-label {
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}
.sc-fac-appendix-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.sc-fac-appendix-hint {
  color: var(--text-muted);
  font-size: 11px;
}
.sc-fac-appendix-bar-on {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, var(--bg-secondary, #f8fafc));
}
.sc-fac-appendix-active {
  color: var(--primary);
  font-weight: 600;
  font-size: 11px;
}
.sc-contract-registry-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border);
  font-size: 12px;
}
.sc-contract-registry-label {
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.sc-contract-registry-meta {
  color: var(--text-muted);
  font-size: 11px;
}
.sc-contract-align-summary {
  color: var(--text-secondary);
  font-size: 11px;
}
.sc-contract-warn {
  color: #b45309;
}
.sc-contract-orphan-hint {
  color: var(--text-muted);
  font-size: 11px;
}
.sc-contract-orphan-details {
  width: 100%;
  font-size: 11px;
  color: var(--text-muted);
}
.sc-contract-orphan-details ul {
  margin: 6px 0 0 18px;
  padding: 0;
}
.sc-contract-no-cell {
  font-size: 11px;
  white-space: nowrap;
}
.sc-contract-no-cell code,
.sc-contract-no-cell {
  font-family: ui-monospace, monospace;
}
.sc-contract-badge {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}
.sc-contract-aligned {
  color: #15803d;
  background: #dcfce7;
}
.sc-contract-missing {
  color: #b45309;
  background: #fef3c7;
}
.sc-contract-na {
  color: var(--text-muted);
  background: var(--bg-hover);
}
.sc-ms-c-hint-ok {
  color: var(--success, #059669);
}
.sc-ms-c-hint-warn {
  color: var(--warning, #d97706);
}
.scr-table-wrap {
  /* 與 proj-summary-table 相同：100% 寬度 + 必要時橫向捲動 */
  overflow-x: auto;
  max-width: 100%;
}
.scr-toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.scr-filter-select {
  min-width: 130px;
  max-width: 200px;
  font-size: 12px;
}
.scr-registry-table {
  table-layout: fixed;
  width: 100%;
  font-size: 12px;
}
.scr-registry-table tbody tr {
  cursor: default;
}
.scr-registry-table thead th {
  padding: 8px 10px;
  font-size: 10px;
  white-space: nowrap;
}
.scr-registry-table tbody td {
  padding: 8px 10px;
  vertical-align: top;
  line-height: 1.35;
}
.scr-registry-table .scr-col-ms { width: 118px; }
.scr-registry-table .scr-col-co { width: 13%; }
.scr-registry-table .scr-col-works { width: 26%; }
.scr-registry-table .scr-col-proj { width: 112px; }
.scr-registry-table .scr-col-person { width: 92px; }
.scr-registry-table .scr-col-amt { width: 108px; }
.scr-registry-table .scr-col-flag { width: 50px; text-align: center; }
.scr-registry-table .scr-col-actions { width: 72px; }
.scr-registry-table .cell-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.scr-registry-table .cell-clip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scr-registry-table .scr-col-co .proj-name-block { overflow: hidden; }
.scr-registry-table .scr-col-co .proj-name-en,
.scr-registry-table .scr-col-co .proj-name-zh {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
  font-size: inherit;
  font-weight: normal;
  color: inherit;
}
.scr-registry-table .scr-col-ms code {
  font-size: 11px;
  word-break: break-all;
}
.scr-registry-table .scr-col-amt {
  white-space: nowrap;
  text-align: right;
}
.scr-registry-table .scr-col-flag {
  white-space: nowrap;
}
.scr-registry-table .scr-col-actions .scr-row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}
.scr-registry-table .scr-col-actions .btn-icon {
  padding: 5px 7px;
  font-size: 13px;
}
#scrTableHead .th-sortable {
  cursor: pointer;
  user-select: none;
}
#scrTableHead .th-sortable .sort-icon {
  margin-left: 4px;
  opacity: 0.45;
  font-size: 10px;
}
#scrTableHead .th-sortable.sort-asc .sort-icon,
#scrTableHead .th-sortable.sort-desc .sort-icon {
  opacity: 1;
  color: var(--accent-light);
}
.sc-ms-c-hint-manual {
  color: var(--primary, #2563eb);
}
.form-hint-inline {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}
.ocr-amount-warn,
.ocr-dup-warn {
  font-size: 12px;
  padding: 8px 10px;
  margin-top: 8px;
  border-radius: var(--radius-sm);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--warning);
}
.ocr-dup-warn {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--danger);
  margin-bottom: 10px;
}
.ocr-save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.ocr-preview {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 16px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: var(--text-secondary);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.ocr-method-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.ocr-method-badge.gemini     { background: #7c3aed22; color: #a78bfa; }
.ocr-method-badge.quark_handwritten,
.ocr-method-badge.quark_general,
.ocr-method-badge.quark_invoice { background: #0ea5e922; color: #38bdf8; }
.ocr-method-badge.rapidocr   { background: rgba(16,185,129,0.12); color: #10b981; }
.ocr-method-badge.paddleocr  { background: rgba(6,182,212,0.12); color: #06b6d4; }
.ocr-method-badge.easyocr    { background: rgba(245,158,11,0.12); color: #f59e0b; }
.ocr-method-badge.pdfplumber { background: var(--info-bg); color: var(--info); }
.ocr-method-badge.failed     { background: var(--danger-bg); color: var(--danger); }

/* ─── 進度條 ─── */
.progress-bar-wrap {
  background: var(--bg-hover);
  border-radius: 20px;
  height: 8px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.6s ease;
}

/* ─── 圖表 ─── */
.chart-wrap { position: relative; height: 300px; }

/* ─── 空白狀態 ─── */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-secondary);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state .empty-title { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.empty-state .empty-sub { font-size: 13px; }

/* ─── 載入中 ─── */
.loading-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--loading-overlay);
  backdrop-filter: blur(2px);
  z-index: 500;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
}
.loading-overlay.show { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast通知 */
.toast-container {
  position: fixed; right: 20px; bottom: 20px;
  z-index: 600;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  max-width: 320px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.25s ease;
  cursor: pointer;
}
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--info); }

[data-theme="light"] .stat-card,
[data-theme="light"] .card,
[data-theme="light"] .dash-project-hero {
  box-shadow: var(--shadow-sm);
}
[data-theme="light"] .sidebar {
  box-shadow: 2px 0 12px rgba(15, 23, 42, 0.04);
}
[data-theme="light"] .topbar {
  box-shadow: 0 1px 0 var(--border);
}
[data-theme="light"] .loading-overlay .spinner {
  border-color: var(--border);
  border-top-color: var(--accent);
}
[data-theme="light"] .loading-overlay #loadingText {
  color: var(--text-secondary);
}

/* ─── 響應式 ─── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  html.sidebar-collapsed { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); width: 240px !important; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle-btn { display: inline-flex; }
  .main { margin-left: 0 !important; }
  .form-row, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ─── 可點擊表格列 ─── */
.table-wrap tbody tr.row-clickable { cursor: pointer; }
.table-wrap tbody tr.row-clickable:hover td { background: var(--bg-hover); }

/* ─── 分判及支出父級分組 ─── */
.table-wrap tbody tr.sc-group-header {
  cursor: pointer;
  user-select: none;
}
.table-wrap tbody tr.sc-group-header td {
  background: var(--bg-card);
  border-top: 2px solid var(--border);
  padding-top: 10px;
  padding-bottom: 10px;
}
.table-wrap tbody tr.sc-group-header:hover td { background: var(--bg-hover); }
.sc-group-toggle {
  display: inline-block;
  width: 14px;
  margin-right: 6px;
  color: var(--accent-light);
  font-size: 10px;
  vertical-align: middle;
}
.table-wrap tbody tr.sc-group-child td:first-child { padding-left: 28px; }
.table-wrap tbody tr.sc-group-child td { font-size: 12px; }

/* ─── 除外合約收費項目 (C) ─── */
.table-wrap tbody tr.sc-row-excluded td {
  background: rgba(255, 193, 7, 0.14);
  border-top-color: rgba(255, 193, 7, 0.22);
  border-bottom-color: rgba(255, 193, 7, 0.22);
}
.table-wrap tbody tr.sc-row-excluded td:first-child {
  box-shadow: inset 3px 0 0 #ffc107;
}
.table-wrap tbody tr.sc-row-excluded:hover td {
  background: rgba(255, 193, 7, 0.22);
}

/* ─── 特殊欄位 ─── */
.sc-no-chip {
  display: inline-block;
  padding: 2px 8px;
  background: var(--info-bg);
  color: var(--info);
  border-radius: 4px;
  font-family: monospace;
  font-size: 11px;
  font-weight: 600;
}
.ref-no-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.ref-type-badge {
  font-size: 10px !important;
  padding: 1px 6px !important;
  font-weight: 500;
}

/* ─── Excel 合約結算表 ─── */
.contract-calc-table {
  width: 100%;
  max-width: 520px;
  margin-left: auto;
  border-collapse: collapse;
  font-size: 13px;
}
.contract-calc-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.contract-calc-table .calc-label {
  color: var(--text-secondary);
  text-align: left;
}
.contract-calc-table .calc-value {
  text-align: right;
  font-family: monospace;
  font-weight: 600;
  color: var(--text-primary);
}
.contract-calc-table .calc-value.highlight {
  color: #f59e0b;
}
.contract-calc-table .calc-value.negative {
  color: var(--danger);
}
.contract-calc-table .calc-value.positive {
  color: var(--success);
}
.contract-calc-table tr.calc-total td {
  border-top: 2px solid var(--border);
  font-weight: 700;
}

/* ─── 地盤糧期狀況 ─── */
.pay-page-tabs {
  margin-bottom: 16px;
}
.pay-panel-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.5;
}
.ip-period-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.ip-period-totals-editable {
  align-items: center;
}
.ip-period-totals-editable .ip-totals-edit {
  margin-left: auto;
}
.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}
.form-hint .btn-link {
  border: none;
  background: none;
  padding: 0 0 0 6px;
  color: var(--primary);
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
}
.form-hint .btn-link:hover {
  opacity: 0.85;
}
.master-trade-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.master-trade-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.master-eng-cat-collapsed {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg-muted, #f4f5f7);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
}
.master-eng-cat-summary {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
}
.master-eng-cat-summary strong {
  color: var(--text);
  font-weight: 600;
}
.master-eng-cat-expanded .master-eng-cat-collapse-btn {
  margin-top: 6px;
}
[data-theme="dark"] .master-eng-cat-collapsed {
  background: rgba(255, 255, 255, 0.04);
}
.ip-period-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.ip-period-table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
  font-size: 12px;
}
.ip-period-table th {
  background: var(--bg-card);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ip-period-table th.th-num { text-align: right; }
.ip-period-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ip-period-table tbody tr:hover td { background: var(--bg-hover); }
/* 糧期狀況 — 表頭上項目標題（對齊項目概覽 hero） */
.ip-period-hero {
  margin-bottom: 16px;
  padding: 18px 20px;
}
.ip-period-hero-top {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
/* 糧期主表／表單：暫隱藏申請與分包支出欄 */
.ip-col-frozen-hidden { display: none !important; }
.ip-period-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding-top: 4px;
  font-size: 13px;
}
.ip-period-totals .label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.ip-period-table .th-sub {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}
.ip-receipt-cell {
  font-size: 12px;
  max-width: 200px;
  vertical-align: middle;
}
.ip-receipt-cell-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ip-receipt-text {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  word-break: break-word;
  flex: 1 1 auto;
  min-width: 0;
}
.ip-receipt-clip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.ip-receipt-clip:hover {
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  transform: scale(1.05);
}
[data-theme="dark"] .ip-receipt-clip {
  background: color-mix(in srgb, var(--primary) 20%, transparent);
}
.ip-receipt-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.ip-cert-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.ip-cert-cell {
  text-align: center;
  vertical-align: middle;
}
.ip-receipt-attach-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.ip-receipt-attach-list {
  margin-top: 8px;
}
.ip-receipt-attach-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.ip-bank-combo {
  position: relative;
}
.ip-bank-combo.is-open {
  z-index: 6;
}
.modal-body.ip-bank-dropdown-open {
  overflow: visible;
}
.ip-bank-combo-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: var(--bg-input, var(--bg-card));
}
.ip-bank-combo-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.ip-bank-chevron {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 12px;
}
.ip-bank-dropdown {
  position: fixed;
  z-index: 300;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  background: var(--bg-card);
  box-shadow: var(--shadow-md, 0 8px 24px rgba(0, 0, 0, 0.18));
}
.ip-bank-search {
  margin-bottom: 6px;
  font-size: 13px;
}
.ip-bank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.ip-bank-option {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}
.ip-bank-option:hover,
.ip-bank-option.active {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}
.ip-bank-empty {
  padding: 12px 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.ip-bank-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.ip-bank-custom-label {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.ip-bank-custom {
  flex: 1;
  max-width: 160px;
  font-size: 13px;
  font-family: var(--font-mono, ui-monospace, monospace);
}
.ip-sc-matrix tfoot td {
  background: var(--bg-card);
  border-top: 2px solid var(--border);
  font-weight: 500;
}
.ip-sc-matrix-foot td:first-child {
  color: var(--text-secondary);
}
.ip-sc-matrix .ip-sc-col-head {
  vertical-align: bottom;
  padding-bottom: 4px;
  border-bottom: none;
}
.ip-sc-matrix .ip-sc-col-co {
  font-weight: 400;
  font-size: 10px;
  color: var(--text-muted);
  vertical-align: top;
  padding-top: 0;
  min-width: 88px;
  max-width: 140px;
}
.ip-sc-matrix .ip-sc-col-co .proj-name-en,
.ip-sc-matrix .ip-sc-col-co .proj-name-zh {
  font-size: 10px;
  line-height: 1.3;
  white-space: normal;
  word-break: break-word;
}
.ip-sc-matrix-meta td {
  font-size: 11px;
}
.ip-sc-matrix .td-amount.warn {
  color: var(--warning, #d97706);
  font-weight: 600;
}
.ip-sc-matrix-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.ip-sc-view-toggle {
  display: flex;
  gap: 6px;
}
.ip-sc-matrix .ip-sc-col-trade {
  font-weight: 500;
  font-size: 11px;
  color: var(--text-secondary);
  vertical-align: top;
  padding-top: 0;
  border-bottom: none;
}
.ip-sc-cell-click {
  cursor: pointer;
  transition: background 0.12s;
}
.ip-sc-cell-click:hover {
  background: var(--bg-hover);
  outline: 1px solid var(--accent);
}
.ip-sc-row-label {
  min-width: 120px;
  max-width: 160px;
  vertical-align: top;
}
.ip-sc-row-trade {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.ip-sc-row-co .proj-name-en,
.ip-sc-row-co .proj-name-zh {
  font-size: 10px;
  line-height: 1.3;
}
.ip-sc-drill-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
}
.ip-sc-drill-summary .label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ─── 可排序表頭 ─── */
.th-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s;
}
.th-sortable:hover {
  color: var(--accent-light);
}
.th-sortable .sort-icon {
  display: inline-block;
  font-size: 10px;
  margin-left: 4px;
  opacity: 0.35;
  vertical-align: middle;
}
.th-sortable.sort-asc .sort-icon,
.th-sortable.sort-desc .sort-icon {
  opacity: 1;
  color: var(--accent-light);
}
.th-sortable.th-num {
  text-align: right;
}
.amount-input-wrap { position: relative; }
.amount-input-wrap::before {
  content: 'HK$';
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--text-muted);
}
.amount-input-wrap input { padding-left: 40px; }

/* 分隔線 */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* 段落標題 */
.section-title {
  font-size: 13px; font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

/* OCR 項目明細表格 */
.ocr-items-wrap {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.ocr-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.ocr-items-table th {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.ocr-items-table td {
  padding: 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ocr-items-table input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-primary);
  padding: 5px 6px;
  font-size: 12px;
  font-family: inherit;
}
.ocr-items-table input:focus {
  border-color: var(--accent);
  outline: none;
}
.ocr-items-table .btn-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  line-height: 1;
}
.ocr-items-table .btn-del:hover { color: var(--danger); }
.ocr-items-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px !important;
  font-size: 12px;
}
.ocr-items-total {
  font-size: 12px;
  color: var(--text-secondary);
}
.ocr-items-total strong {
  color: var(--success);
  margin-left: 4px;
}

/* Master List */
.master-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.master-toolbar .toolbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1;
}
.master-toolbar .toolbar-right {
  display: flex;
  gap: 8px;
}
.master-quot-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.master-quot-input-row .form-input {
  flex: 1;
  min-width: 0;
}
.master-quot-input-row .btn {
  flex-shrink: 0;
}
.table-row-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  align-items: center;
  justify-content: flex-end;
}
#page-master-list table td[data-col="act"] .table-row-actions,
#page-staff table td:last-child .table-row-actions {
  min-width: 72px;
}
#page-master-list table td[data-col="act"] .btn-icon,
#page-staff table td:last-child .btn-icon {
  padding: 5px 7px;
  font-size: 13px;
}
.master-search { min-width: 220px; max-width: 320px; }
.master-filter { width: 120px; }
.master-type-filter { width: 108px; }
.master-scope-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-light);
  background: var(--accent-glow);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-md);
}
.master-scope-banner[hidden] { display: none !important; }
.master-scope-icon { font-size: 14px; line-height: 1; opacity: 0.9; }
.master-scope-text { line-height: 1.4; }
.master-checklist {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 4px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.master-check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  line-height: 1.45;
}
.master-check-item input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.master-check {
  font-size: 12px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.master-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
}
.master-page-info { font-size: 12px; color: var(--text-muted); }
.th-sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition), background var(--transition);
}
.th-sortable:hover { color: var(--text-primary); background: var(--bg-card); }
.th-sort-active { color: var(--accent); }
.th-sort-icon {
  display: inline-block;
  margin-left: 4px;
  font-size: 9px;
  opacity: 0.45;
  vertical-align: middle;
}
.th-sort-active .th-sort-icon { opacity: 1; }
.master-preview-summary { display: flex; flex-wrap: wrap; gap: 8px; }
.master-preview-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
  margin-top: 8px;
}
.row-muted td { opacity: 0.55; }
.master-preview-table th,
.master-preview-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.master-finance-panel {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.master-finance-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.master-fin-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.ip-reconcile-hint {
  margin-bottom: 10px;
}
.ip-reconcile-note {
  color: var(--text-muted);
  font-size: 11px;
}
.ip-reconcile-wrap {
  max-height: 280px;
  overflow: auto;
}
.ip-reconcile-table th {
  font-size: 11px;
  white-space: nowrap;
}
.ip-reconcile-th-site {
  background: rgba(59, 130, 246, 0.08);
  text-align: center;
}
.ip-reconcile-th-admin {
  background: rgba(234, 179, 8, 0.1);
  text-align: center;
}
.interim-cert-preview {
  padding: 20px 24px;
  background: #fff;
  color: #111;
  font-size: 8pt;
  line-height: 1.35;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
[data-theme="dark"] .interim-cert-preview {
  background: #fff;
  color: #111;
}
.ic-line-remark-hint {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.vo-remark-list {
  margin-top: 4px;
}
.vo-remark-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.vo-remark-table th,
.vo-remark-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  vertical-align: top;
}
.vo-remark-table th {
  background: var(--bg-muted, #f1f5f9);
  font-weight: 600;
  text-align: left;
}
.vo-remark-table .vo-remark-amt {
  text-align: right;
  white-space: nowrap;
  width: 110px;
}
.vo-remark-table .vo-remark-input {
  margin-bottom: 0;
}
.ic-vo-remark-empty {
  padding: 8px 0;
}

.interim-cert-preview .ic-header {
  margin-bottom: 8px;
}
.interim-cert-preview .ic-logo {
  display: block;
  width: 75.6mm;
  height: auto;
  max-width: 75.6mm;
  object-fit: contain;
  object-position: left center;
  margin: 0 0 2.6em;
}
.interim-cert-preview .ic-title {
  text-align: center;
  font-size: 11pt;
  font-weight: 700;
  margin: 0 0 10px;
}
.interim-cert-preview .ic-subtitle {
  text-align: center;
  font-size: 11px;
  color: #475569;
  margin-bottom: 14px;
}
.interim-cert-preview table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 8pt;
}
.interim-cert-preview th,
.interim-cert-preview td {
  border: 1px solid #cbd5e1;
  padding: 4px 6px;
  vertical-align: top;
}
.interim-cert-preview th {
  background: #e2e8f0;
  color: #1e293b;
  font-weight: 700;
  text-align: center;
}
.interim-cert-preview th.ic-th-left {
  text-align: left;
}
.interim-cert-preview .ic-c1 { width: 24.19%; }
.interim-cert-preview .ic-c2 { width: 41.67%; }
.interim-cert-preview .ic-c3 { width: 17.20%; }
.interim-cert-preview .ic-c4 { width: 16.94%; }
.interim-cert-preview .ic-a1 { width: 24.19%; }
.interim-cert-preview .ic-a2 { width: 13.44%; }
.interim-cert-preview .ic-a3 { width: 14.78%; }
.interim-cert-preview .ic-a4 { width: 13.44%; }
.interim-cert-preview .ic-a5 { width: 34.14%; }
.interim-cert-preview .ic-meta:not(.ic-sig) td:nth-child(1),
.interim-cert-preview .ic-meta:not(.ic-sig) td:nth-child(3) {
  background: #f8fafc;
  font-weight: 600;
}
.interim-cert-preview .ic-meta:not(.ic-sig) td:nth-child(3),
.interim-cert-preview .ic-meta:not(.ic-sig) td:nth-child(4) {
  text-align: right;
}
.interim-cert-preview .ic-num {
  text-align: right;
  white-space: nowrap;
}
.interim-cert-preview .ic-amt-c {
  text-align: center;
  white-space: nowrap;
}
.interim-cert-preview .ic-ded td {
  color: #b91c1c;
}
.interim-cert-preview .ic-sum td {
  font-weight: 700;
  background: #f1f5f9;
}
.interim-cert-preview .ic-sum td:first-child {
  text-align: center;
}
.interim-cert-preview .ic-sig td {
  text-align: center;
  vertical-align: middle;
}
.interim-cert-preview .ic-sig tr:first-child td,
.interim-cert-preview .ic-sig td:first-child {
  background: #f8fafc;
}
.interim-cert-preview .ic-sig tr:first-child td:first-child {
  font-weight: 700;
}
.interim-cert-preview .ic-sig tr:nth-child(2) td {
  height: 48px;
}
@media print {
  body * { visibility: hidden; }
  #payCertPreview, #payCertPreview * { visibility: visible; }
  #payCertPreview {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .interim-cert-preview,
  .interim-cert-preview th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .interim-cert-preview .ic-logo {
    width: 75.6mm !important;
    height: auto !important;
    max-height: none !important;
    max-width: 75.6mm !important;
    object-fit: contain !important;
  }
  .interim-cert-preview th {
    background: #e2e8f0 !important;
    color: #1e293b !important;
  }
  .modal-backdrop, .modal-header, .modal-footer { display: none !important; }
}

.sc-vo-pick-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-secondary);
}
.sc-vo-pick-group-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 8px 12px 4px;
  border-top: 1px solid var(--border);
}
.sc-vo-pick-group-title:first-child {
  border-top: none;
}
.sc-vo-pick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.sc-vo-pick-item:last-child {
  border-bottom: none;
}
.sc-vo-pick-item:hover {
  background: var(--bg-hover);
}
.sc-vo-pick-item input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.sc-vo-pick-tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}
.sc-vo-pick-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sc-vo-pick-amt {
  flex-shrink: 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}
.sc-vo-pick-item-std .std-amt-input {
  width: 100px;
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 12px;
}
.sc-vo-pick-empty {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.sv-quick-add .btn-sm {
  font-size: 11px;
}

/* ─── 分判變更以及扣款登記 · p16 矩陣表 ─── */
.svr-matrix-wrap { overflow-x: auto; }
.svr-matrix-table { min-width: 960px; }
.svr-matrix-table .svr-th-vo {
  background: color-mix(in srgb, var(--success) 12%, var(--bg-card));
  border-bottom-color: color-mix(in srgb, var(--success) 25%, var(--border));
}
.svr-matrix-table .svr-th-ded {
  background: color-mix(in srgb, var(--warning) 12%, var(--bg-card));
  border-bottom-color: color-mix(in srgb, var(--warning) 25%, var(--border));
}
.svr-matrix-table .svr-vo-col { border-left: none; }
.svr-matrix-table .svr-ded-col {
  border-left: 2px solid color-mix(in srgb, var(--warning) 35%, var(--border));
}
.svr-matrix-table .svr-sc-cell,
.svr-matrix-table .svr-company-cell {
  vertical-align: top;
  background: color-mix(in srgb, var(--bg-elevated) 80%, transparent);
}
.svr-matrix-table .svr-desc-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.svr-matrix-table .svr-pdf-col { font-size: 11px; }
.svr-pdf-link { color: var(--primary); text-decoration: none; font-size: 11px; }
.svr-pdf-link:hover { text-decoration: underline; }
.svr-applied-link {
  display: inline-block;
  max-width: 100%;
  padding: 2px 8px;
  border: none;
  border-radius: 999px;
  background: var(--badge-muted-bg, rgba(128, 128, 128, 0.15));
  color: var(--primary);
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  white-space: normal;
}
.svr-applied-link:hover { text-decoration: underline; }

.svr-tpl-modal .modal-body { max-height: 72vh; overflow-y: auto; }
.svr-tpl-tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.svr-tpl-tab.active {
  background: var(--accent);
  color: var(--btn-on-accent);
  border-color: var(--accent);
}
.svr-tpl-hint { margin-bottom: 10px; }
.svr-tpl-toolbar { margin-bottom: 10px; }
.svr-tpl-table-wrap { margin-bottom: 16px; max-height: 280px; overflow: auto; }
.svr-tpl-table { width: 100%; font-size: 13px; }
.svr-tpl-table th { font-size: 11px; white-space: nowrap; }
.svr-tpl-row-off td { opacity: 0.55; }
.svr-tpl-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.svr-tpl-form-panel {
  margin-top: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-hover);
}
.svr-tpl-active-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin: 12px 0;
  cursor: pointer;
}
.svr-tpl-form-actions { display: flex; gap: 8px; justify-content: flex-end; }

.sc-vo-migrate-banner {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--primary) 10%, var(--bg-card));
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
  font-size: 12px;
  color: var(--text-secondary);
}
.sc-vo-migrate-banner a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.sc-vo-migrate-banner a:hover { text-decoration: underline; }

/* ─── 主合約最終結算（PPT p19） ─── */
.mcf-works {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.5;
}
.mcf-works-en {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}
.mcf-table-wrap { border: none; }
.mcf-table { width: 100%; }
.mcf-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.mcf-table .mcf-label {
  font-size: 13px;
  color: var(--text-primary);
  width: 55%;
}
.mcf-table .mcf-code {
  width: 36px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}
.mcf-table .mcf-amt,
.mcf-table .mcf-amt-input {
  text-align: right;
  white-space: nowrap;
}
.mcf-row-total .mcf-label,
.mcf-row-total .mcf-amt {
  font-weight: 700;
}
.mcf-formula {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
}
.mcf-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 4px;
}
.mcf-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}
.mcf-input-wrap .form-input { text-align: right; }
.mcf-asat { font-size: 12px; }
.mcf-upload-row {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.mcf-pdf-link {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
}
.mcf-pdf-link:hover { text-decoration: underline; }
.mcf-dates-table .mcf-label { width: auto; }

/* ─── 工程項目 · Cover Page 表單 ─── */
.proj-modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.proj-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.proj-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.proj-tab.active {
  color: var(--accent-light);
  background: var(--accent-glow);
}
.settle-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .settle-grid { grid-template-columns: 1fr; }
}
.settle-calc-table { width: 100%; }
.settle-side .form-group { margin-bottom: 12px; }
.settle-fac-hub {
  border-color: color-mix(in srgb, var(--primary) 22%, var(--border));
}
.settle-fac-hub-body {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.settle-fac-hub-desc {
  margin: 0;
  flex: 1;
  min-width: 220px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
}
.settle-fac-hub-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.proj-view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.proj-view-btn {
  border: none;
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
}
.proj-view-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.proj-view-btn.active {
  background: var(--accent-glow);
  color: var(--accent-light);
  font-weight: 600;
}
.proj-card-grid {
  border-top: 1px solid var(--border);
}

/* Summary 列表 — 精簡欄位 */
.proj-summary-table {
  table-layout: fixed;
  font-size: 12px;
}
.proj-summary-table thead th {
  padding: 8px 10px;
  font-size: 10px;
}
.proj-summary-table tbody td {
  padding: 8px 10px;
  vertical-align: top;
  line-height: 1.35;
}
.proj-summary-table .col-code { width: 92px; }
.proj-summary-table .col-account { width: 52px; }
.proj-summary-table .col-title { width: 28%; }
.proj-summary-table .col-parties { width: 22%; }
.proj-summary-table .col-person { width: 88px; }
.proj-summary-table .col-amt { width: 108px; }
.proj-summary-table .col-rate { width: 64px; }
.proj-summary-table .col-status { width: 68px; }
.proj-summary-table .col-actions { width: 88px; }
.proj-summary-table .cell-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.proj-summary-table .cell-party-mc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.proj-summary-table .cell-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.proj-summary-table .col-actions .proj-row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}
.proj-summary-table .col-actions .btn-icon {
  padding: 5px 7px;
  font-size: 13px;
}
.proj-summary-table tr.proj-mp-group-header {
  cursor: pointer;
  user-select: none;
}
.proj-summary-table tr.proj-mp-group-header td {
  background: var(--bg-card);
  border-top: 2px solid var(--border);
}
.proj-summary-table tr.proj-mp-group-header:hover td { background: var(--bg-hover); }
.proj-summary-table tr.proj-mp-group-child td:first-child {
  padding-left: 28px;
  border-left: 2px solid var(--accent-glow);
}
.proj-summary-table tr.proj-mp-group-child td {
  font-size: 12px;
  background: var(--bg-secondary);
}
.proj-mp-card-head {
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.proj-mp-card-head:hover { color: var(--text-secondary); }
.proj-mp-card-children {
  margin-top: 6px;
  padding-left: 18px;
  border-left: 2px solid var(--accent-glow);
}
.proj-mp-card-child {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 2px 0;
}

/* 工程項目表單 — PPT 排版 */
.proj-form-ppt .proj-form-divider {
  border-top: 1px solid var(--border);
  margin: 18px 0 16px;
}
.proj-form-ppt .proj-inline-field {
  display: flex;
  gap: 8px;
  align-items: center;
}
.proj-form-ppt .proj-inline-field .form-input { flex: 1; min-width: 0; }
.proj-doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.proj-doc-filelist { margin-top: 6px; }
.proj-doc-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 3px 0;
}
.proj-doc-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--accent-light);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
}
.proj-doc-file-name:hover { text-decoration: underline; }
.proj-doc-view {
  flex-shrink: 0;
  padding: 2px 6px !important;
  font-size: 12px !important;
}
.proj-doc-del {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}
.proj-doc-del:hover { color: var(--danger); }
.proj-retention-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.proj-retention-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.proj-retention-opt input[type="radio"],
.proj-retention-opt input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.proj-retention-opt-date {
  display: grid;
  grid-template-columns: 16px minmax(128px, auto) 150px;
  gap: 8px 10px;
  align-items: center;
}
.proj-retention-opt-date input[type="radio"],
.proj-retention-opt-date input[type="checkbox"] {
  grid-column: 1;
}
.proj-retention-label {
  grid-column: 2;
  white-space: nowrap;
}
.proj-retention-opt-date .proj-retention-date {
  grid-column: 3;
  width: 100%;
  max-width: 150px;
  margin-left: 0;
  font-size: 12px;
  padding: 6px 8px;
}
.proj-retention-date:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* MP 合約編號 — 多選標籤 */
.mp-codes-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  padding: 8px;
}
.mp-codes-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  margin-bottom: 8px;
}
.mp-codes-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 2px;
}
.mp-codes-add {
  display: flex;
  gap: 8px;
  align-items: center;
}
.mp-codes-add .form-input {
  flex: 1;
  min-width: 0;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}
.mp-code-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  font-family: 'Courier New', monospace;
  font-size: 12px;
}
.mp-code-chip.is-primary {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.mp-code-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  line-height: 1.2;
}
.mp-code-promote,
.mp-code-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 3px;
  font-size: 12px;
  line-height: 1;
}
.mp-code-promote:hover { color: var(--accent-light); }
.mp-code-remove:hover { color: var(--danger); }

/* 文件管理設定（系統設定頁） */
.settings-page-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 960px;
}
.settings-doc-card { max-width: 960px; }
.settings-doc-intro {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 14px;
  line-height: 1.45;
}
.settings-doc-table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.settings-doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.settings-doc-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-secondary);
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.settings-doc-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.settings-doc-code { white-space: nowrap; font-weight: 600; font-size: 11px; }
.settings-doc-name { max-width: 180px; }
.settings-doc-table .setting-doc-proj-url {
  font-size: 11px;
  min-width: 280px;
  padding: 6px 8px;
}

/* ISO 文件登記 */
.iso-docs-body { padding-top: 8px; }
.iso-docs-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.iso-docs-toolbar .btn { text-decoration: none; }

.iso-docs-progress {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.iso-progress-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.iso-progress-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.iso-progress-pct {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-light);
  line-height: 1;
}
.iso-progress-bar {
  height: 8px;
  background: var(--bg-primary);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.iso-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 999px;
  transition: width 0.35s ease;
}
.iso-progress-bar-fill.iso-progress-low {
  background: linear-gradient(90deg, var(--warning), #fbbf24);
}
.iso-progress-bar-fill.iso-progress-complete {
  background: linear-gradient(90deg, var(--success), #34d399);
}
.iso-progress-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.iso-stat {
  font-size: 12px;
  color: var(--text-secondary);
}
.iso-stat strong {
  display: block;
  font-size: 15px;
  color: var(--text-primary);
  margin-top: 2px;
}
.iso-stat-label { font-size: 11px; color: var(--text-muted); }
.iso-stat-ok { color: var(--success) !important; }
.iso-stat-warn { color: var(--warning) !important; }

.iso-docs-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 6px;
}
.iso-docs-filter-note {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 12px;
  font-style: italic;
}
.iso-docs-table-wrap {
  overflow: auto;
  max-height: min(70vh, 640px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}
.iso-docs-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
.iso-docs-table .iso-th {
  white-space: nowrap;
  min-width: 108px;
  max-width: 160px;
  font-size: 11px;
  font-weight: 600;
  vertical-align: bottom;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  line-height: 1.35;
  position: sticky;
  top: 0;
  z-index: 2;
  cursor: help;
}
.iso-docs-table .iso-th-optional {
  color: var(--text-muted);
  font-weight: 500;
}
.iso-docs-table .iso-th.iso-sticky-col {
  z-index: 4;
}
.iso-docs-table td {
  vertical-align: top;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border-subtle, var(--border));
  background: var(--bg-card);
}
.iso-docs-table tr:last-child td { border-bottom: none; }

/* Sticky 首兩欄（橫向捲動） */
.iso-sticky-col.iso-sticky-0 {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 160px;
  max-width: 220px;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .iso-sticky-col.iso-sticky-0 {
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.35);
}
.iso-sticky-col.iso-sticky-1 {
  position: sticky;
  left: 160px;
  z-index: 3;
  min-width: 108px;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.04);
}
[data-theme="dark"] .iso-sticky-col.iso-sticky-1 {
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
}
.iso-docs-table thead .iso-sticky-col {
  background: var(--bg-secondary);
}
.iso-docs-table tbody .iso-sticky-col {
  background: var(--bg-card);
}

.iso-label-cell { min-width: 160px; font-weight: 600; }
.iso-label-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.iso-row-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  line-height: 1.2;
}
.iso-row-badge-ok {
  background: var(--success-bg);
  color: var(--success);
}
.iso-row-badge-warn {
  background: var(--warning-bg);
  color: var(--warning);
}
.iso-cell-sub { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-top: 4px; }
.iso-amt-cell { text-align: right; white-space: nowrap; min-width: 108px; }
.iso-amt-input {
  width: 110px;
  text-align: right;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12px;
}

/* 附件格狀態色 */
.iso-file-cell { min-width: 120px; max-width: 200px; }
.iso-file-cell-done {
  background: var(--success-bg) !important;
  border-left: 3px solid var(--success);
}
.iso-file-cell-missing {
  background: var(--warning-bg) !important;
  border-left: 3px solid var(--warning);
}
.iso-file-cell-optional {
  background: var(--bg-primary) !important;
  border-left: 3px solid transparent;
}
.iso-file-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.iso-file-item-done .iso-file-actions {
  display: flex;
  gap: 4px;
}
.iso-file-link {
  background: none;
  border: none;
  color: var(--accent-light);
  cursor: pointer;
  font-size: 11px;
  text-align: left;
  padding: 0;
  word-break: break-all;
  line-height: 1.35;
}
.iso-file-link:hover { text-decoration: underline; }
.iso-file-date {
  font-size: 10px;
  color: var(--text-muted);
}
.iso-file-action {
  flex-shrink: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 2px 6px;
}
.iso-file-action:hover { border-color: var(--accent-border); color: var(--accent-light); }
.iso-file-del:hover { border-color: var(--danger); color: var(--danger); }
.iso-upload-btn {
  background: var(--bg-secondary);
  border: 1px dashed var(--warning);
  border-radius: var(--radius-sm);
  color: var(--warning);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 12px;
  width: 100%;
}
.iso-upload-btn:hover {
  border-color: var(--accent-border);
  color: var(--accent-light);
  background: var(--accent-glow);
}
.iso-upload-optional {
  border-color: var(--border);
  color: var(--text-muted);
  font-weight: 500;
}
.iso-upload-optional:hover {
  border-color: var(--accent-border);
  color: var(--accent-light);
}
.iso-file-placeholder {
  color: var(--text-muted);
  font-size: 11px;
}
.iso-cell-pending .iso-upload-btn { display: none; }
.iso-cell-pending .iso-slot-drop-hint { display: none; }
.iso-docs-hint-warn { color: var(--warning, #d97706); }

/* ISO Sprint B — Tab / 卡片 / 拖放 */
.iso-view-tabs { margin-bottom: 12px; }
.iso-main-subtabs { margin-bottom: 14px; }
.iso-main-meta {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.iso-meta-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.iso-meta-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.iso-slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.iso-slot-grid-compact {
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.iso-slot-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--bg-card);
  min-height: 108px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.iso-slot-tile.iso-file-cell-done {
  border-color: rgba(16, 185, 129, 0.45);
  background: var(--success-bg);
}
.iso-slot-tile.iso-file-cell-missing {
  border-color: rgba(245, 158, 11, 0.45);
  background: var(--warning-bg);
}
.iso-slot-tile.iso-file-cell-optional {
  background: var(--bg-primary);
}
.iso-slot-tile.iso-drop-hover {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 2px var(--accent-glow);
  background: var(--accent-glow);
}
.iso-slot-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.iso-slot-label {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-primary);
}
.iso-slot-opt {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
}
.iso-slot-body { flex: 1; }
.iso-slot-body .iso-upload-btn { width: 100%; }
.iso-slot-drop-hint {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.85;
}
.iso-slot-tile.iso-file-cell-done .iso-slot-drop-hint { display: none; }

.iso-sc-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.iso-sc-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  overflow: hidden;
}
.iso-sc-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}
.iso-sc-card-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  white-space: nowrap;
}
.iso-sc-amt {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.iso-sc-empty {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}
.iso-table-fallback {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
}
.iso-table-fallback summary {
  cursor: pointer;
  padding: 8px 0;
  color: var(--accent-light);
  user-select: none;
}
.iso-table-fallback[open] summary { margin-bottom: 12px; }

/* ISO Sprint C — 連結 / 歷史版本 */
.iso-empty-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.iso-link-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  padding: 6px 10px;
  width: 100%;
}
.iso-link-btn:hover {
  border-color: var(--accent-border);
  color: var(--accent-light);
  background: var(--accent-glow);
}
.iso-versions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(50vh, 400px);
  overflow-y: auto;
}
.iso-version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}
.iso-version-main { flex: 1; min-width: 0; }
.iso-version-date {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
}
.iso-versions-loading,
.iso-versions-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 720px) {
  .iso-progress-stats { grid-template-columns: repeat(2, 1fr); }
  .iso-sticky-col.iso-sticky-1 { left: 140px; }
  .iso-sticky-col.iso-sticky-0 { min-width: 140px; }
  .iso-meta-row { grid-template-columns: 1fr; }
  .iso-slot-grid { grid-template-columns: 1fr; }
}
