:root {
  --bg-app: #F0F4F8;
  --bg-sidebar: #0F172A;
  --bg-card: #FFFFFF;
  
  --primary: #0891B2;
  --primary-hover: #06B6D4;
  --primary-light: #E0F2FE;
  
  --text-main: #1E293B;
  --text-sub: #64748B;
  --text-white: #FFFFFF;
  
  --border: #E2E8F0;
  --line: #E2E8F0;
  
  --success-bg: #D1FAE5;
  --success-text: #047857;
  --warning-bg: #FEF3C7;
  --warning-text: #B45309;
  --danger-bg: #FEE2E2;
  --danger-text: #B91C1C;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --radius: 12px;
  --accent: #0f766e;
}

* { box-sizing: border-box; outline-color: var(--primary); }

body {
  margin: 0;
  font-family: 'Inter', 'IBM Plex Sans', "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.app {
  display: flex;
  min-height: 100vh;
}

.side {
  width: 260px;
  background: var(--bg-sidebar);
  color: var(--text-white);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  box-shadow: 4px 0 24px rgba(0,0,0,0.05);
}

.app-header {
  position: absolute;
  top: 0;
  right: 0;
  left: 260px; /* offset sidebar */
  height: 60px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: flex-end; /* Push to right */
  align-items: center;
  padding: 0 40px;
  z-index: 5;
}

.app-header .logo {
  display: none; /* Logo is already in sidebar */
}

.user-box {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sub);
}

.brand {
  text-align: center;
  margin-bottom: 28px;
}

.logo {
  max-width: 220px;
  height: auto;
  opacity: 0.9;
  margin-bottom: 12px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.brand h1 {
  font-family: 'Noto Serif SC', serif;
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  opacity: 0.95;
  letter-spacing: 0.5px;
}

.scene-selector {
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
}

.scene-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.4);
  margin: 0 0 8px 0;
  font-weight: 600;
}

.scene-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scene-btns-row {
  flex-direction: row;
}

.scene-btns-row .scene-btn {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
}

.scene-btn {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.scene-btn .scene-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  white-space: nowrap;
}

.scene-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-light);
}

.scene-btn.active {
  background: var(--primary);
  border-color: var(--primary);
}

.scene-btn.active .scene-name {
  color: #fff;
  font-weight: 600;
}

.scene-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  white-space: nowrap;
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.step-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.6);
  padding: 12px 16px;
  border-radius: 10px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.step-btn:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
  transform: translateX(3px);
}

.step-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

.foot {
  margin-top: auto;
  font-size: 12px;
  color: rgba(255,255,255,0.3);
  text-align: center;
  padding-top: 16px;
}

.main {
  flex: 1;
  padding: 88px 40px 28px 40px; /* add top padding for header */
  overflow-y: auto;
  height: 100vh;
}

.head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.head h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 6px 0;
}

#panel-sub {
  font-size: 14px;
  color: var(--text-sub);
  margin: 0;
}

.head-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

button { font-family: inherit; cursor: pointer; }

.mini {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-sub);
  transition: all 0.2s;
  text-decoration: none;
}

.mini:hover {
  background: var(--bg-app);
  color: var(--text-main);
}

.primary {
  background: linear-gradient(135deg, var(--primary), #0E7490);
  color: white;
  border: none;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(8, 145, 178, 0.2);
  transition: all 0.2s;
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(8, 145, 178, 0.25);
}

.status {
  font-size: 13px;
  color: var(--text-sub);
}

.panel {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.panel.hidden { display: none; }

.card {
  background: #fafbfc;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.card h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px 0;
  color: var(--text-main);
}

.legend {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: rgba(0,0,0,0.02);
  border-radius: 8px;
}

.tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 5px;
}

.tag.required { background: var(--danger-bg); color: var(--danger-text); }
.tag.optional { background: var(--warning-bg); color: var(--warning-text); }
.tag.optimize { background: var(--success-bg); color: var(--success-text); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.grid-4 {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-sub);
}

.field input,
.field select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.import-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.import-bar-left {
  display: flex;
  gap: 10px;
}

.import-action {
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.import-action-load {
  background: var(--primary);
  color: white;
}

.import-action-tpl {
  background: white;
  border: 1px solid var(--border);
  color: var(--text-sub);
}

.import-action:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.params-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.params-tab {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.2s;
}

.params-tab:hover {
  background: var(--bg-app);
}

.params-tab.active {
  background: var(--primary);
  color: white;
}

.params-content .grid.hidden { display: none; }

.summary-top {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.kpi {
  background: white;
  border-radius: 10px;
  padding: 18px;
  border: 1px solid var(--border);
  text-align: center;
}

.kpi-main {
  background: linear-gradient(135deg, var(--primary), #0E7490);
  color: white;
  border: none;
}

.kpi-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  border: none;
}

.kpi h3 {
  font-size: 12px;
  font-weight: 500;
  margin: 0 0 6px 0;
  opacity: 0.85;
}

.kpi p {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-sub);
  background: var(--bg-app);
}

table td {
  font-size: 13px;
}

.fee-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.fee-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-app);
  border-radius: 8px;
}

.fee-item .label {
  font-size: 12px;
  color: var(--text-sub);
}

.fee-item .value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.chart-row {
  display: flex;
  gap: 20px;
}

.chart-box {
  flex: 1;
  height: 280px;
}

.chart-container {
  height: 320px;
  position: relative;
}

.chart-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.chart-tab {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.2s;
}

.chart-tab:hover { background: var(--bg-app); }

.chart-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap table {
  min-width: 700px;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 16px;
}

.upload-grid label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

.upload-grid input {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.upload-grid .small {
  font-size: 11px;
  color: var(--text-sub);
  margin: 6px 0 0;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn-primary {
  padding: 9px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover { background: #0d655d; }

.btn-secondary {
  padding: 9px 18px;
  background: white;
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover { background: var(--bg-app); }

.hint {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 10px;
}

.data-preview {
  min-height: 120px;
  padding: 16px;
  background: var(--bg-app);
  border-radius: 8px;
}

.placeholder {
  text-align: center;
  color: var(--text-sub);
  padding: 30px;
}

.report-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.conclusion-box {
  padding: 16px;
  background: var(--bg-app);
  border-radius: 8px;
  min-height: 80px;
}

.ai-report-content {
  padding: 20px;
  background: var(--bg-app);
  border-radius: 8px;
  min-height: 200px;
}

.status-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.status-tag.ok { background: var(--success-bg); color: var(--success-text); }
.status-tag.high { background: var(--danger-bg); color: var(--danger-text); }
.status-tag.low { background: var(--warning-bg); color: var(--warning-text); }

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-overlay.hidden { display: none; }

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-text {
  color: white;
  margin-top: 12px;
  font-size: 14px;
}

.hidden { display: none !important; }

.info-banner {
  padding: 10px 16px;
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 13px;
  color: #0c5a6e;
  line-height: 1.6;
}

.kpi-caution {
  background: linear-gradient(135deg, #e0f2fe, #bae6fd);
  border: 1px solid #7dd3fc;
}

.startup-modal {
  background: white;
  padding: 40px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 400px;
  width: 90%;
}

.startup-modal h2 {
  color: var(--text-main);
  margin-bottom: 8px;
  font-size: 20px;
}

.startup-modal p {
  color: var(--text-sub);
  margin-bottom: 24px;
}

.startup-logo {
  max-width: 160px;
  margin-bottom: 16px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.startup-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.startup-actions button {
  padding: 12px 24px;
  font-size: 15px;
}

.startup-input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 15px;
  margin-bottom: 16px;
  box-sizing: border-box;
}

.mt-16 {
  margin-top: 16px;
}

/* ── AI Report Markdown Styles ── */
.ai-report-content {
  line-height: 1.7;
  color: var(--text-main);
  font-size: 15px;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.ai-report-content h3 {
  color: var(--primary);
  font-size: 18px;
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 8px;
  margin-top: 28px;
  margin-bottom: 16px;
}

.ai-report-content h3:first-child {
  margin-top: 0;
}

.ai-report-content h4 {
  color: var(--text-main);
  font-size: 16px;
  margin-top: 20px;
  margin-bottom: 12px;
}

.ai-report-content ul, .ai-report-content ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

.ai-report-content li {
  margin-bottom: 8px;
}

.ai-report-content strong {
  color: var(--accent);
  font-weight: 600;
}

.ai-report-content blockquote {
  border-left: 4px solid var(--primary);
  background: var(--bg-app);
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
  color: var(--text-sub);
}


.ai-report-content p {
  margin-bottom: 16px;
}

/* ── Mobile Responsiveness ── */
.mobile-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  transition: opacity 0.3s ease;
  opacity: 0;
}
.mobile-overlay.show {
  display: block;
  opacity: 1;
}

.mobile-menu-btn {
  display: none;
  font-size: 24px;
  background: none; border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

@media (max-width: 768px) {
  .app { flex-direction: column; }
  
  .side {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1001; /* Above overlay */
  }
  
  .side.open {
    transform: translateX(0);
  }
  
  .app-header {
    left: 0;
    padding: 0 16px;
    justify-content: space-between;
  }
  
  .app-header .logo {
    display: block; /* Show in header on mobile */
    height: 28px;
    margin-bottom: 0;
  }
  
  .mobile-menu-btn {
    display: block;
  }
  
  .main {
    padding: 80px 16px 20px 16px;
  }
  
  .summary-top {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .head {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }
  
  .head-actions {
    width: 100%;
    justify-content: flex-start;
  }
  
  .chart-row {
    flex-direction: column;
  }
  
  .chart-box {
    height: 240px;
  }
  
  .startup-modal {
    width: 95%;
    padding: 30px 20px;
  }
  
  .startup-actions {
    flex-direction: column;
  }
  
  .import-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .params-tabs {
    flex-wrap: wrap;
  }
  
  .fee-summary-grid {
    grid-template-columns: 1fr;
  }
}

