:root {
  --bg: #07111f;
  --panel: #0d1b2e;
  --panel-2: #11243a;
  --panel-3: #162f4b;
  --text: #eef5ff;
  --muted: #9fb2c9;
  --muted-2: #71839b;
  --line: rgba(255,255,255,0.12);
  --blue: #5fa8ff;
  --cyan: #5ee1d0;
  --amber: #ffbf4d;
  --red: #ff6b6b;
  --green: #76d275;
  --grey: #93a4b8;
  --purple: #b68cff;
  --shadow: 0 18px 50px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, rgba(95,168,255,0.18), transparent 34rem), var(--bg);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 288px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: rgba(5, 13, 24, 0.82);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: white; font-weight: 800; letter-spacing: 0.04em;
  box-shadow: var(--shadow);
}
.brand h1 { font-size: 18px; line-height: 1.1; margin: 0 0 5px; }
.brand p, .sidebar-panel p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.nav-list { display: grid; gap: 8px; }
.nav-item {
  color: var(--muted); text-align: left; border: 1px solid transparent;
  background: transparent; border-radius: 14px; padding: 12px 14px;
}
.nav-item:hover, .nav-item.active { color: var(--text); background: rgba(95,168,255,0.12); border-color: rgba(95,168,255,0.28); }
.sidebar-panel { position: absolute; left: 18px; right: 18px; bottom: 20px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,0.04); }
.eyebrow { margin: 0 0 8px; color: var(--cyan); text-transform: uppercase; font-weight: 800; font-size: 11px; letter-spacing: 0.12em; }

.main { min-width: 0; padding: 20px; }
.top-strip { position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, minmax(130px,1fr)); gap: 10px; padding-bottom: 14px; background: linear-gradient(to bottom, var(--bg) 70%, rgba(7,17,31,0)); }
.metric, .card, .hero-card, .assumption-card, .notice, .toolbar, .slide-deck { border: 1px solid var(--line); background: rgba(13, 27, 46, 0.86); box-shadow: var(--shadow); }
.metric { border-radius: 18px; padding: 14px; min-width: 0; }
.metric span, .metric em { display: block; color: var(--muted); font-size: 12px; font-style: normal; }
.metric strong { display: block; margin: 4px 0; font-size: 22px; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric.mini strong { font-size: 19px; }
.notice { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: 16px; margin-bottom: 18px; color: var(--muted); }
.notice strong { color: var(--amber); }
.view { display: none; animation: fadeIn 180ms ease-out; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.hero-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr); gap: 16px; margin-bottom: 16px; }
.hero-card, .assumption-card { border-radius: 24px; padding: 22px; }
.hero-card h2, .split-header h2 { margin: 0 0 10px; font-size: clamp(24px, 3vw, 38px); line-height: 1.06; }
.hero-card p, .split-header p { color: var(--muted); line-height: 1.55; margin: 0; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--muted); border-radius: 999px; padding: 7px 10px; font-size: 12px; }

.card-grid { display: grid; gap: 14px; margin-bottom: 16px; }
.card-grid.five { grid-template-columns: repeat(5, minmax(130px, 1fr)); }
.card { border-radius: 22px; padding: 16px; min-width: 0; }
.card.large { min-height: 330px; }
.card-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card h3, .scenario-card h3 { margin: 0; font-size: 16px; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chart { min-height: 270px; width: 100%; overflow: hidden; }
.small-chart { min-height: 230px; }
.tag { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 8px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.official { color: var(--cyan); border-color: rgba(94,225,208,0.35); }
.tag.model { color: var(--amber); border-color: rgba(255,191,77,0.35); }
.tag.placeholder { color: var(--grey); border-color: rgba(147,164,184,0.35); }
.tag.override { color: var(--purple); border-color: rgba(182,140,255,0.35); }
.tag.locked { color: var(--green); border-color: rgba(118,210,117,0.35); }

.split-header { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; margin: 8px 0 16px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.secondary, .file-label {
  border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--text); border-radius: 12px; padding: 10px 12px;
}
.secondary:hover, .file-label:hover { background: rgba(95,168,255,0.13); border-color: rgba(95,168,255,0.35); }
.file-label input { display: none; }
.scenario-grid { display: grid; grid-template-columns: 320px minmax(0,1fr); gap: 16px; margin-bottom: 16px; }
.scenario-buttons { display: grid; gap: 8px; }
.scenario-btn { text-align: left; border: 1px solid var(--line); color: var(--muted); background: rgba(255,255,255,0.04); border-radius: 14px; padding: 11px; }
.scenario-btn.active { color: var(--text); border-color: rgba(94,225,208,0.45); background: rgba(94,225,208,0.1); }
.slider-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 12px; }
.slider-control { padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,0.035); }
.slider-control label { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.slider-control strong { color: var(--text); }
.slider-control input[type="range"] { width: 100%; accent-color: var(--blue); }
.slider-control input[type="number"] { width: 120px; background: rgba(0,0,0,0.25); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 7px; }

.toolbar { display: flex; gap: 10px; padding: 12px; border-radius: 18px; margin-bottom: 12px; }
.toolbar input, .toolbar select { background: rgba(0,0,0,0.22); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; }
.toolbar input { min-width: 300px; flex: 1; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 20px; background: rgba(13,27,46,0.65); box-shadow: var(--shadow); max-height: calc(100vh - 270px); }
table { width: 100%; border-collapse: collapse; min-width: 1220px; }
th, td { border-bottom: 1px solid rgba(255,255,255,0.08); padding: 10px 12px; text-align: left; font-size: 13px; }
th { position: sticky; top: 0; z-index: 2; background: #102238; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
tr { cursor: pointer; }
tr:hover td { background: rgba(95,168,255,0.08); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.risk-high { color: var(--red); }
.risk-medium { color: var(--amber); }
.risk-low { color: var(--green); }
.scope-chip { border-radius: 999px; padding: 4px 8px; border: 1px solid var(--line); white-space: nowrap; }
.scope-in_scope { color: var(--cyan); }
.scope-excluded { color: var(--grey); }
.scope-watchlist { color: var(--amber); }

.detail-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 96vw); z-index: 30;
  transform: translateX(105%); transition: transform 220ms ease;
  background: #0b1728; border-left: 1px solid var(--line); box-shadow: -20px 0 60px rgba(0,0,0,0.45);
  padding: 22px; overflow: auto;
}
.detail-panel.open { transform: translateX(0); }
.close-btn { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--text); font-size: 24px; }
.detail-panel h2 { margin: 26px 0 6px; font-size: 26px; }
.detail-panel p { color: var(--muted); line-height: 1.55; }
.detail-block { border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin: 12px 0; background: rgba(255,255,255,0.035); }
.detail-row { display: grid; grid-template-columns: 160px 1fr; gap: 10px; padding: 6px 0; color: var(--muted); }
.detail-row strong { color: var(--text); }
.detail-panel input[type="number"] { width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 8px; }
.detail-panel textarea { width: 100%; min-height: 90px; background: rgba(0,0,0,0.3); border: 1px solid var(--line); color: var(--text); border-radius: 12px; padding: 10px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.function-table { overflow: auto; }
.function-row { display: grid; grid-template-columns: 1fr 150px 150px; gap: 12px; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.08); padding: 10px 0; }
.bar-track { height: 11px; background: rgba(255,255,255,0.08); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--amber), var(--red)); border-radius: inherit; }

.slide-deck { min-height: 620px; border-radius: 28px; padding: 26px; background: radial-gradient(circle at top right, rgba(95,168,255,0.16), transparent 28rem), rgba(13,27,46,0.92); }
.slide { min-height: 560px; display: flex; flex-direction: column; justify-content: center; }
.slide h2 { font-size: clamp(32px, 5vw, 64px); line-height: 1; margin: 0 0 18px; }
.slide h3 { font-size: 28px; margin: 0 0 16px; }
.slide p, .slide li { color: var(--muted); font-size: 20px; line-height: 1.45; }
.slide ul { margin: 0; padding-left: 24px; }
.slide-stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 24px; }
.slide-stat { border: 1px solid var(--line); border-radius: 20px; padding: 18px; background: rgba(255,255,255,0.05); }
.slide-stat span { display: block; color: var(--muted); }
.slide-stat strong { display: block; margin-top: 8px; font-size: 34px; }
.slide-counter { color: var(--muted); margin-top: auto; }

.tooltip { position: fixed; pointer-events: none; z-index: 100; background: #050b13; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; max-width: 270px; box-shadow: var(--shadow); display: none; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar-panel { position: static; margin-top: 16px; }
  .top-strip, .card-grid.five { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .hero-grid, .chart-grid, .chart-grid.two, .scenario-grid { grid-template-columns: 1fr; }
  .slider-grid { grid-template-columns: 1fr; }
}
@media print {
  body { background: white; color: #111; }
  .sidebar, .top-strip, .notice, .slide-tools, .detail-panel { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .view { display: none !important; }
  #slides { display: block !important; }
  .slide-deck, .slide { box-shadow: none; border: 0; background: white; color: #111; }
  .slide p, .slide li, .slide-counter { color: #444; }
}


/* v2 additions */
.top-strip { grid-template-columns: repeat(6, minmax(120px, 1fr)); }
.compact-grid .card { min-height: 190px; }
.insight-panel { display: grid; gap: 10px; color: var(--muted); line-height: 1.5; }
.insight-panel strong { color: var(--text); }
.insight-panel .warning { color: #ffbf4d; }
.insight-panel .danger { color: #ff7c7c; }
.insight-list { display: grid; gap: 8px; margin: 0; padding-left: 20px; }
.quick-model-grid { display: grid; gap: 10px; grid-template-columns: repeat(5, minmax(160px, 1fr)); }
.quick-model-card { text-align: left; border: 1px solid var(--line); border-radius: 18px; padding: 12px; color: var(--text); background: rgba(255,255,255,0.04); cursor: pointer; }
.quick-model-card:hover { border-color: rgba(95,168,255,0.7); background: rgba(95,168,255,0.09); }
.quick-model-card strong { display: block; margin-bottom: 6px; }
.quick-model-card span { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; }
.quick-model-card em { display: inline-block; margin-top: 8px; color: var(--amber); font-style: normal; font-size: 12px; }
.full-width { grid-column: 1 / -1; }
.cost-note-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cost-note { border: 1px solid var(--line); border-radius: 16px; padding: 12px; background: rgba(255,255,255,0.035); }
.cost-note span { color: var(--muted); display: block; margin-bottom: 4px; }
.cost-note strong { font-size: 18px; }
@media (max-width: 1200px) {
  .top-strip { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .quick-model-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .quick-model-grid, .cost-note-grid { grid-template-columns: 1fr; }
}
@media print {
  .quick-model-grid, #aiCostControls, #aiCostScenarioButtons { display: none !important; }
}

/* v2.1 additions */
.card-grid.three { grid-template-columns: repeat(3, minmax(180px, 1fr)); }
.code-box { margin: 0; min-height: 220px; padding: 16px; border-radius: 16px; border: 1px solid var(--line); background: rgba(2,8,20,0.72); color: var(--text); overflow: auto; white-space: pre-wrap; font-size: 12px; line-height: 1.5; }
.cost-warning { color: var(--amber); }
.population-pill { border-color: rgba(118,210,117,0.35); background: rgba(118,210,117,0.08); }
@media (max-width: 950px) { .card-grid.three { grid-template-columns: 1fr; } }
