:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #1d4ed8;
  --primary-bg: #eff6ff;
  --success: #166534;
  --success-bg: #ecfdf5;
  --error: #991b1b;
  --error-bg: #fef2f2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.gate.hidden { display: none; }
.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 320px;
}
.gate-title { margin: 0 0 0.5rem; font-size: 1.25rem; font-weight: 700; color: var(--text); }
.gate-hint { margin: 0 0 1.25rem; font-size: 0.875rem; color: var(--text-muted); }
.gate-form { display: flex; flex-direction: column; gap: 0.75rem; }
.gate-input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
}
.gate-input:focus { outline: none; border-color: var(--primary); }
.gate-btn { width: 100%; }
.gate-error { margin: 0.75rem 0 0; font-size: 0.875rem; color: var(--error); }

.header {
  background: var(--text);
  color: #f8fafc;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.header h1 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.header-meta { display: flex; gap: 0.75rem; align-items: center; }
.model-badge, .scenario-badge { font-size: 0.8rem; padding: 0.25rem 0.5rem; border-radius: 4px; background: rgba(255,255,255,0.15); }

.main { display: flex; min-height: calc(100vh - 52px); }
.sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--surface);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}
.content { flex: 1; padding: 1.5rem; overflow-y: auto; }

.controls-section { margin-bottom: 1.25rem; }
.controls-section h2 { margin: 0 0 0.5rem; font-size: 0.875rem; font-weight: 700; color: var(--text-muted); }
.model-toggle, .scenario-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.btn {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.btn:hover { background: var(--border); }
.btn-toggle.active, .btn-scenario.active { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); width: 100%; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--surface); width: 100%; margin-top: 0.5rem; }
.sidebar-actions { margin-top: 1rem; }

.assumptions-panel { min-height: 0; }
.assumption-list { display: flex; flex-direction: column; gap: 0.5rem; }
.assumption-row { display: flex; flex-direction: column; gap: 0.25rem; }
.assumption-row label { font-size: 0.75rem; color: var(--text-muted); }
.assumption-row input { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.875rem; }
.assumption-row input:invalid { border-color: var(--error); }
.assumptions-content { display: flex; flex-direction: column; gap: 1rem; }
.assumptions-subsection { margin-top: 0.5rem; }
.assumptions-subsection h3 { margin: 0 0 0.5rem; font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.assumptions-table { width: 100%; font-size: 0.75rem; border-collapse: collapse; }
.assumptions-table th, .assumptions-table td { padding: 0.35rem 0.25rem; text-align: left; border-bottom: 1px solid var(--border); }
.assumptions-table th { color: var(--text-muted); font-weight: 600; }
.assumptions-table input { width: 100%; max-width: 4.5rem; padding: 0.25rem 0.35rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.75rem; }
.assumptions-table input.num { text-align: right; max-width: 3.5rem; }
.assumptions-table .segment-label { font-weight: 600; color: var(--text); }

.validation-message {
  margin-top: 1rem; padding: 0.75rem; border-radius: var(--radius);
  background: var(--error-bg); border: 1px solid #fca5a5; color: var(--error);
  font-size: 0.8rem;
}

.disclaimer { font-size: 0.8rem; color: var(--text-muted); margin: 0 0 1rem; }

.kpi-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.kpi-label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.kpi-value { font-size: 1.5rem; font-weight: 700; }

.chart-section, .tables-section { margin-bottom: 1.5rem; }
.chart-section h3, .tables-section h3 { margin: 0 0 0.75rem; font-size: 1rem; font-weight: 700; }
.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 220px;
  padding: 1rem;
  display: flex;
  align-items: flex-end;
  gap: 4px;
}
.chart-bar { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 4px; transition: height 0.2s; }
.table-wrapper { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--bg); font-weight: 600; color: var(--text-muted); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .main { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .kpi-cards { grid-template-columns: repeat(2, 1fr); }
}
