:root {
  --primary: #2b6cb0;
  --primary-dark: #1a4971;
  --bg: #f4f6f8;
  --panel-bg: #ffffff;
  --border: #dfe3e8;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #c0392b;
  --success: #1f8a4c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--primary-dark);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  font-weight: bold;
}

main {
  padding: 20px 16px;
  max-width: 1260px;
  margin: 0 auto;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel h3 {
  margin-top: 0;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 4px 4px 4px 0;
}

input, select, textarea {
  width: 100%;
  max-width: 360px;
  display: inline-block;
}

textarea {
  max-width: 100%;
  width: 100%;
  min-height: 60px;
  vertical-align: top;
}

button {
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: bold;
}

button:hover { background: var(--primary-dark); }

button.secondary {
  background: #eef2f6;
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover { background: #e2e8f0; }

.inline-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.hidden { display: none; }

.case-item-row, .bom-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr) auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.case-item-row input, .case-item-row select,
.bom-row input, .bom-row select {
  max-width: none;
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; }

.margin-box {
  font-size: 15px;
  line-height: 1.8;
  padding: 12px;
  background: #f8fafc;
  border-radius: 6px;
}

.margin-good { color: var(--success); font-weight: bold; }
.margin-bad { color: var(--danger); font-weight: bold; }

.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  background: #e2e8f0;
  font-size: 12px;
}

.remove-row-btn {
  background: var(--danger);
  padding: 6px 10px;
}

.small-note { color: var(--muted); font-size: 12px; margin: 4px 0; }

/* ===================== Demo 版新增：頂部提示 / 備份操作列 ===================== */
.demo-bar {
  background: #fff7e6;
  border-bottom: 1px solid #f0d999;
  color: #92610a;
  font-size: 13px;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.demo-bar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.demo-bar-actions button,
.demo-bar-actions .file-btn {
  padding: 6px 10px;
  font-size: 12px;
  margin: 0;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* ===================== 👑 老闆營運戰情室樣式 ===================== */
.tab-btn.highlight-tab {
  background: linear-gradient(135deg, #d69e2e, #b7791f);
  border-color: #f6e05e;
  color: #fff;
  font-weight: bold;
}
.tab-btn.highlight-tab.active {
  background: linear-gradient(135deg, #b7791f, #975a16);
  border-color: #fff;
  box-shadow: 0 0 8px rgba(214, 158, 46, 0.6);
}

.cockpit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.cockpit-title {
  margin: 0;
  font-size: 22px;
  color: #1a202c;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cockpit-desc {
  margin: 4px 0 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* 4大 KPI 數據指標卡 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

.kpi-card {
  background: #ffffff;
  border-radius: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}
.kpi-card.blue::before { background: #3182ce; }
.kpi-card.green::before { background: #38a169; }
.kpi-card.orange::before { background: #dd6b20; }
.kpi-card.purple::before { background: #805ad5; }

.kpi-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.kpi-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.kpi-icon {
  font-size: 18px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: #1a202c;
  margin: 4px 0 6px 0;
  letter-spacing: -0.5px;
}
.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 狀態標籤與徽章 */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}
.badge-excellent { background: #c6f6d5; color: #22543d; }
.badge-good { background: #bee3f8; color: #2b6cb0; }
.badge-warning { background: #feebc8; color: #744210; }
.badge-danger { background: #fed7d7; color: #9b2c2c; }
.badge-draft { background: #edf2f7; color: #4a5568; }

/* 缺料預警橫幅 */
.warning-banner {
  background: #fff5f5;
  border-left: 4px solid #e53e3e;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 14px;
  color: #9b2c2c;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.success-banner {
  background: #f0fff4;
  border-left: 4px solid #38a169;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 14px;
  color: #22543d;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 工程進度管線 Pipeline 樣式 */
.pipeline-steps {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 16px;
}
.pipeline-step {
  flex: 1;
  min-width: 100px;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.pipeline-step:hover {
  background: #edf2f7;
  border-color: #cbd5e0;
}
.pipeline-step.active {
  background: #ebf8ff;
  border-color: #3182ce;
  box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.2);
}
.pipeline-step-name {
  font-size: 12px;
  font-weight: 600;
  color: #4a5568;
  margin-bottom: 4px;
}
.pipeline-step-count {
  font-size: 18px;
  font-weight: 800;
  color: #2b6cb0;
}
.pipeline-step.active .pipeline-step-count {
  color: #2b6cb0;
}
.pipeline-step-amount {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* 收款進度條 */
.progress-bar-wrap {
  width: 100%;
  background: #e2e8f0;
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4299e1, #3182ce);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-bar-fill.complete {
  background: linear-gradient(90deg, #48bb78, #38a169);
}

/* 篩選按鈕列 */
.filter-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-pill {
  background: #edf2f7;
  border: 1px solid #e2e8f0;
  color: #4a5568;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 500;
  margin: 0;
}
.filter-pill:hover {
  background: #e2e8f0;
}
.filter-pill.active {
  background: #2b6cb0;
  color: #fff;
  border-color: #2b6cb0;
}

.chart-box {
  position: relative;
  height: 260px;
  margin-bottom: 16px;
}

/* ==========================================================================
   🏗️ 8 階段工程管線中心 (Case Pipeline Hub & 360° Workbench)
   ========================================================================== */

/* 管線頂部工具列 */
.pipeline-hub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.pipeline-hub-title {
  margin: 0;
  font-size: 22px;
  color: #1a202c;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pipeline-hub-desc {
  margin: 4px 0 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* 案場篩選與快速切換列 */
.case-filter-bar {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.stage-pill-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.stage-pill {
  border: 1px solid #cbd5e0;
  background: #f7fafc;
  color: #4a5568;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  margin: 0;
}

.stage-pill:hover {
  background: #edf2f7;
  border-color: #a0aec0;
}

.stage-pill.active {
  background: #2b6cb0;
  color: #ffffff;
  border-color: #2b6cb0;
  box-shadow: 0 1px 3px rgba(43, 108, 176, 0.3);
}

.case-search-input {
  max-width: 240px;
  padding: 6px 10px;
  font-size: 13px;
  margin: 0;
}

/* 案場卡片橫向導覽捲軸 (Case Carousel Strip) */
.case-cards-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 14px 2px;
  margin-bottom: 16px;
}

.case-strip-card {
  flex: 0 0 240px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: relative;
}

.case-strip-card:hover {
  border-color: #3182ce;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.case-strip-card.active {
  border: 2px solid #2b6cb0;
  background: #f8fafc;
  box-shadow: 0 4px 12px rgba(43, 108, 176, 0.15);
}

.case-strip-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.case-strip-no {
  font-size: 13px;
  font-weight: 700;
  color: #2b6cb0;
}

.case-strip-cust {
  font-size: 13px;
  font-weight: 600;
  color: #1a202c;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.case-strip-addr {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
}

.case-strip-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
}

/* 🌟 案場 360° 一站式工作台 (Case Workbench Card) */
.case-workbench-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.05);
  margin-bottom: 24px;
  overflow: hidden;
}

/* 工作台頂部身分條 */
.workbench-id-bar {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #ffffff;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.workbench-case-info h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workbench-case-meta {
  margin-top: 6px;
  font-size: 13px;
  color: #94a3b8;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.workbench-case-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.workbench-financial-badges {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.wb-stat-pill {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: right;
}

.wb-stat-label {
  font-size: 11px;
  color: #94a3b8;
  display: block;
}

.wb-stat-val {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.wb-stat-val.green { color: #4ade80; }
.wb-stat-val.amber { color: #fbbf24; }

/* 🌟 8 階段互動式進度步進器 (Interactive Pipeline Stepper) */
.pipeline-stepper-container {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: 18px 20px;
  overflow-x: auto;
}

.pipeline-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 780px;
  position: relative;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 1;
}

/* 步進器連接線 */
.step-item::after {
  content: "";
  position: absolute;
  top: 16px;
  left: 50%;
  width: 100%;
  height: 3px;
  background: #e2e8f0;
  z-index: -1;
}

.step-item:last-child::after {
  display: none;
}

.step-item.completed::after {
  background: #38a169;
}

.step-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #edf2f7;
  border: 2px solid #cbd5e0;
  color: #718096;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  transition: all 0.2s ease;
}

.step-item:hover .step-circle {
  transform: scale(1.1);
  border-color: #3182ce;
  color: #3182ce;
}

/* 已完成階段 */
.step-item.completed .step-circle {
  background: #38a169;
  border-color: #2f855a;
  color: #ffffff;
}

/* 當前進行中階段 */
.step-item.current .step-circle {
  background: #2563eb;
  border-color: #1d4ed8;
  color: #ffffff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.25);
  transform: scale(1.15);
}

.step-label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-align: center;
  white-space: nowrap;
}

.step-item.completed .step-label {
  color: #22543d;
}

.step-item.current .step-label {
  color: #1d4ed8;
  font-weight: 800;
}

.step-subtext {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
}

/* 🎯 當前階段情境引導卡 (Current Stage Action Card) */
.stage-action-card {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.stage-action-card.theme-draft {
  background: #f8fafc;
  border-left: 5px solid #64748b;
}

.stage-action-card.theme-good {
  background: #f0fdf4;
  border-left: 5px solid #16a34a;
}

.stage-action-card.theme-warning {
  background: #fffbeb;
  border-left: 5px solid #d97706;
}

.stage-action-card.theme-blue {
  background: #eff6ff;
  border-left: 5px solid #2563eb;
}

.stage-action-card.theme-excellent {
  background: #faf5ff;
  border-left: 5px solid #9333ea;
}

.stage-action-content {
  flex: 1;
  min-width: 280px;
}

.stage-action-headline {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.stage-action-desc {
  font-size: 13px;
  color: #475569;
  margin: 0;
  line-height: 1.5;
}

.stage-action-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary-action {
  background: #2563eb;
  color: #ffffff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
  transition: all 0.15s ease;
}

.btn-primary-action:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.btn-success-action {
  background: #16a34a;
  color: #ffffff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(22, 163, 74, 0.25);
}

.btn-success-action:hover {
  background: #15803d;
}

/* 工作台 6 大多維子標籤 (Workbench Tabs) */
.workbench-tabs-nav {
  display: flex;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.wb-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: #475569;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 0;
  margin: 0;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.wb-tab-btn:hover {
  color: #1e293b;
  background: rgba(255, 255, 255, 0.6);
}

.wb-tab-btn.active {
  background: #ffffff;
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 700;
}

/* 工作台主體內容區 */
.workbench-content-body {
  padding: 20px;
}

.tab-inner-section {
  animation: fadeIn 0.2s ease-in-out;
}

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

/* 快速表單容器 */
.quick-action-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.quick-action-box h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 768px) {
  .form-grid-3 { grid-template-columns: 1fr; }
}

/* 彈出視窗 (Modal) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: #1e293b;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  color: #64748b;
  cursor: pointer;
  padding: 4px 8px;
  margin: 0;
}

.modal-body {
  padding: 20px;
}

