/* =====================================================================
   Riesgos & Resiliencia del Perú — estilos
   Paleta peruana moderna: rojo terracota, blanco cálido, ocre,
   turquesa Pacífico, verde Amazonas. Modo claro y oscuro.
   ===================================================================== */

:root {
  --rojo-peru:      #C8102E;
  --rojo-dark:      #8B0A1F;
  --ocre:           #D88C2A;
  --turquesa:       #1E9AA4;
  --amazonas:       #2F8F4F;
  --andes:          #6B4F3A;

  /* Tema oscuro (default) */
  --bg:             #0F1419;
  --bg-elev:        #181F28;
  --bg-card:        #1E2632;
  --border:         #2A3441;
  --text:           #E8EEF4;
  --text-muted:     #93A1B0;
  --text-dim:       #6A7884;
  --accent:         var(--rojo-peru);
  --accent-soft:    rgba(200, 16, 46, 0.15);
  --shadow:         0 6px 24px rgba(0, 0, 0, 0.4);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  --sidebar-w: 240px;
  --topbar-h: 60px;
}

body[data-theme="light"] {
  --bg:             #FAF7F2;
  --bg-elev:        #FFFFFF;
  --bg-card:        #FFFFFF;
  --border:         #E8E0D4;
  --text:           #1A1F26;
  --text-muted:     #4A5563;
  --text-dim:       #8A95A2;
  --shadow:         0 4px 16px rgba(70, 50, 30, 0.08);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip-link {
  position: absolute; left: -9999px;
  background: var(--accent); color: #fff;
  padding: 8px 12px; z-index: 9999;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ========== TOPBAR ========== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-flag { font-size: 1.5rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-weight: 800; font-size: 1rem; }
.brand-text small { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.6px; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.region-pick {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px 8px;
  font-size: 0.85rem;
}
.region-pick span { color: var(--text-muted); font-size: 0.75rem; }
.region-pick select {
  background: transparent; border: none; color: var(--text);
  font: inherit; outline: none; cursor: pointer;
  min-width: 130px;
}

.icon-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text); width: 36px; height: 36px;
  border-radius: var(--r-sm); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.icon-btn:hover { background: var(--bg-card); border-color: var(--accent); }

.nav-toggle {
  display: none; background: transparent; border: none;
  width: 36px; height: 36px; cursor: pointer; padding: 8px;
  flex-direction: column; justify-content: space-between;
}
.nav-toggle span { display: block; height: 2px; background: var(--text); border-radius: 1px; }

/* ========== SIDEBAR ========== */
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  color: var(--text); border-radius: var(--r-sm);
  font-size: 0.9rem; font-weight: 500;
  transition: all 0.15s ease;
}
.nav-item:hover { background: var(--bg-card); text-decoration: none; }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.highlight {
  background: linear-gradient(135deg, rgba(216, 140, 42, 0.1), rgba(30, 154, 164, 0.1));
  border: 1px dashed rgba(216, 140, 42, 0.4);
  margin: 8px 0;
}
.nav-item .ico { font-size: 1.05rem; }

.sidebar-foot {
  padding: 16px 16px 24px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.sidebar-foot p { margin-bottom: 6px; }
.sidebar-foot .muted { color: var(--text-dim); }

/* ========== MAIN ========== */
.main {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 24px;
  max-width: 1400px;
}

.section { display: none; animation: fadein 0.25s ease; }
.section.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-head { margin-bottom: 24px; }
.eyebrow {
  display: inline-block;
  font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--accent);
  padding: 4px 10px;
  background: var(--accent-soft);
  border-radius: 999px;
  margin-bottom: 12px;
}

h1, h2, h3, h4 { line-height: 1.25; }
h1 { font-size: 2.2rem; font-weight: 800; margin-bottom: 12px; letter-spacing: -0.5px; }
h1 em { color: var(--accent); font-style: normal; }
h2 { font-size: 1.8rem; font-weight: 800; margin-bottom: 8px; letter-spacing: -0.3px; }
h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 12px; }
h4 { font-size: 0.95rem; font-weight: 700; margin-bottom: 8px; }

.lede { font-size: 1.05rem; color: var(--text-muted); max-width: 65ch; }
.small { font-size: 0.85rem; }
.muted { color: var(--text-muted); }

/* ========== HERO ========== */
.hero {
  display: grid; grid-template-columns: 1fr 1.1fr;
  gap: 24px; align-items: center;
  margin-bottom: 24px;
}
.hero-text h1 { margin-top: 8px; }
.hero-actions { margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; }
.hero-map { position: relative; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px;
  border-radius: var(--r-sm);
  font-weight: 600; font-size: 0.92rem;
  border: 1px solid transparent; cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--rojo-dark); text-decoration: none; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 6px 12px; font-size: 0.82rem; }

/* ========== MAP ========== */
.map {
  width: 100%; height: 340px;
  background: var(--bg-card);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}
.map.tall { height: 380px; }
@media (max-width: 720px) { .map, .map.tall { height: 260px; } }

/* ========== CHART CONTAINER ========== */
/* Forzar altura controlada para que Chart.js no haga crecer el canvas */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
}
.chart-wrap.sm { height: 200px; }
.chart-wrap.lg { height: 320px; }
.card > canvas, .sim-result canvas {
  max-height: 260px !important;
}
@media (max-width: 720px) {
  .chart-wrap, .chart-wrap.sm, .chart-wrap.lg { height: 220px; }
  .card > canvas, .sim-result canvas { max-height: 220px !important; }
}

.map-layers {
  margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 0.82rem; color: var(--text-muted);
  align-items: center;
}
.map-layers strong { color: var(--text); }
.map-layers label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* ========== KPI ========== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--ocre));
}
.kpi-num { font-size: 1.8rem; font-weight: 800; color: var(--accent); line-height: 1; }
.kpi-label { font-weight: 600; font-size: 0.88rem; color: var(--text); }
.kpi-sub { font-size: 0.74rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }

/* ========== CARD / GRID ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card.hidden { display: none; }
.card h3 { margin-bottom: 14px; }

.two-col {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 16px; margin-bottom: 16px;
}
.three-col {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px; margin-bottom: 16px;
}
.three-col .card h4 { color: var(--accent); }

/* ========== REGION GRID ========== */
.region-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px; margin-top: 12px;
}
.region-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  transition: all 0.15s ease;
}
.region-chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.region-chip.active { background: var(--accent-soft); border-color: var(--accent); }
.region-chip-name { font-weight: 600; }
.region-chip-cat { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; }

.profile-card h3 span { color: var(--accent); }
.profile-risks { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-top: 12px; }
.profile-risk {
  background: var(--bg);
  border-left: 3px solid var(--ocre);
  border-radius: var(--r-sm);
  padding: 10px 12px;
}
.profile-risk-name { font-weight: 600; font-size: 0.85rem; }
.profile-risk-level { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; }
.profile-risk-level.alta { color: var(--rojo-peru); font-weight: 700; }
.profile-risk-level.media { color: var(--ocre); font-weight: 700; }
.profile-risk-level.baja { color: var(--amazonas); }

/* ========== TIMELINE ========== */
.timeline { list-style: none; }
.timeline li {
  border-left: 3px solid var(--accent);
  padding: 8px 0 12px 14px;
  margin-left: 4px;
  position: relative;
}
.timeline li::before {
  content: ''; position: absolute; left: -7px; top: 14px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-card);
}
.timeline-year { font-weight: 800; color: var(--accent); margin-right: 6px; }

.timeline-horizontal {
  display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px;
}
.timeline-horizontal .event {
  flex: 0 0 220px;
  background: var(--bg);
  border-radius: var(--r-md);
  padding: 12px;
  border-top: 3px solid var(--accent);
}
.timeline-horizontal .event-year { font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.timeline-horizontal .event-name { font-weight: 700; margin-top: 2px; }
.timeline-horizontal .event-body { font-size: 0.82rem; color: var(--text-muted); margin-top: 6px; }

/* ========== HOW-TO ========== */
.howto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.howto-grid h4 { font-size: 1rem; margin-bottom: 8px; }
.howto-grid ul { padding-left: 18px; font-size: 0.88rem; }
.howto-grid li { margin-bottom: 6px; color: var(--text-muted); }
.howto-grid li strong { color: var(--text); }

/* ========== TABLES & LISTS ========== */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { font-weight: 700; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.4px; }

.risk-list { list-style: none; }
.risk-list li {
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.risk-list li:last-child { border-bottom: none; }
.risk-list strong { color: var(--accent); }

.forecast-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; }
.forecast-card {
  background: var(--bg); border-radius: var(--r-sm); padding: 12px;
  text-align: center; border-top: 3px solid var(--turquesa);
}
.forecast-prob { font-size: 1.6rem; font-weight: 800; color: var(--turquesa); }
.forecast-label { font-size: 0.78rem; color: var(--text-muted); }

/* ========== SIMULADOR ========== */
.sim-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px;
}
.sim-tab {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text); padding: 8px 14px;
  border-radius: var(--r-sm); cursor: pointer;
  font-size: 0.88rem; font-weight: 500;
  transition: all 0.15s ease;
}
.sim-tab:hover { border-color: var(--accent); }
.sim-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.sim-disclaimer {
  background: rgba(216, 140, 42, 0.12);
  border-left: 4px solid var(--ocre);
  padding: 12px 16px;
  border-radius: var(--r-sm);
  margin-bottom: 16px;
  font-size: 0.88rem;
}

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

.sim-grid {
  display: grid; grid-template-columns: 320px 1fr;
  gap: 16px;
}
.sim-controls label {
  display: block; margin-bottom: 12px;
  font-size: 0.85rem; color: var(--text-muted);
}
.sim-controls input[type="range"],
.sim-controls select,
.sim-controls input[type="text"] {
  display: block; width: 100%; margin-top: 4px;
  padding: 6px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text); font: inherit;
}
.sim-controls output {
  display: inline-block; min-width: 40px;
  font-weight: 700; color: var(--accent);
}
.sim-controls .btn { margin-top: 6px; width: 100%; justify-content: center; }
.sim-controls .btn.small { width: auto; margin-top: 4px; }

.sim-output {
  margin-top: 14px;
  font-size: 0.9rem;
}
.sim-output h4 {
  color: var(--accent); margin-bottom: 10px; font-size: 1rem;
  display: flex; align-items: center; gap: 6px;
}

/* KPI heroes — grandes números arriba del resultado */
.sim-heroes {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px; margin-bottom: 12px;
}
.sim-hero {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px; text-align: center;
  position: relative; overflow: hidden;
}
.sim-hero::before {
  content: ''; position: absolute; top:0; left:0; right:0; height: 3px;
  background: var(--accent);
}
.sim-hero.crit::before { background: var(--rojo-peru); }
.sim-hero.warn::before { background: var(--ocre); }
.sim-hero.ok::before   { background: var(--amazonas); }
.sim-hero-num {
  font-size: 1.5rem; font-weight: 800;
  color: var(--accent);
  line-height: 1; margin: 2px 0;
}
.sim-hero.crit .sim-hero-num { color: var(--rojo-peru); }
.sim-hero.warn .sim-hero-num { color: var(--ocre); }
.sim-hero.ok   .sim-hero-num { color: var(--amazonas); }
.sim-hero-lbl {
  font-size: 0.7rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  line-height: 1.2;
}
.sim-hero-icon { font-size: 1.1rem; margin-bottom: 4px; display:block; }

/* Detalle de métricas (sigue lo que ya había) */
.sim-detail {
  background: var(--bg); border-radius: var(--r-sm);
  padding: 10px 14px; margin-bottom: 10px;
}
.sim-detail .metric {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px dashed var(--border);
  font-size: 0.88rem;
}
.sim-detail .metric:last-child { border-bottom: none; }
.sim-detail .metric-label { color: var(--text-muted); }
.sim-detail .metric-value { font-weight: 700; }

/* Barras comparativas (para canasta básica, etc.) */
.sim-bars { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.sim-bar {
  display: grid; grid-template-columns: 100px 1fr 60px; align-items: center;
  gap: 8px; font-size: 0.82rem;
}
.sim-bar-label { color: var(--text); font-weight: 500; }
.sim-bar-track {
  background: var(--border); height: 10px; border-radius: 999px;
  position: relative; overflow: hidden;
}
.sim-bar-fill {
  position: absolute; top:0; left:0; bottom:0;
  background: linear-gradient(90deg, var(--ocre), var(--rojo-peru));
  border-radius: 999px;
  transition: width 0.4s ease;
}
.sim-bar-val { text-align: right; font-weight: 700; color: var(--accent); }

/* Mini-table para listas dentro del simulador */
.sim-mini-table { width:100%; font-size:0.84rem; margin: 8px 0; }
.sim-mini-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
.sim-mini-table tr:last-child td { border-bottom: none; }
.sim-mini-table .num { text-align: right; font-weight: 700; color: var(--accent); }

/* Cascada / timeline temporal (apagón) */
.sim-cascade { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.sim-cascade-row {
  display: grid; grid-template-columns: 60px 1fr; align-items: center;
  gap: 10px; padding: 6px 8px;
  background: var(--bg); border-left: 3px solid var(--ocre);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: 0.84rem;
}
.sim-cascade-row.crit { border-left-color: var(--rojo-peru); }
.sim-cascade-row.ok { border-left-color: var(--amazonas); }
.sim-cascade-time { font-weight: 700; color: var(--accent); font-size: 0.78rem; }

/* Disclaimer y meta */
.sim-meta { font-size: 0.78rem; color: var(--text-dim); margin-top: 6px; }
.sim-tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
  margin-right: 4px;
}
.sim-tag.warn { background: rgba(216,140,42,.18); color: var(--ocre); }
.sim-tag.crit { background: rgba(200,16,46,.22); color: var(--rojo-peru); }
.sim-tag.ok   { background: rgba(47,143,79,.22); color: var(--amazonas); }

/* ========== RESILIENCIA ========== */
.checklist { list-style: none; max-height: 320px; overflow-y: auto; padding-right: 8px; }
.checklist li {
  padding: 6px 0; display: flex; align-items: center; gap: 10px;
  font-size: 0.88rem; cursor: pointer;
}
.checklist input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer;
}
.checklist li.done { color: var(--text-dim); text-decoration: line-through; }

.progress {
  width: 100%; height: 8px;
  background: var(--bg); border-radius: 999px;
  margin: 12px 0 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--ocre), var(--amazonas));
  width: 0%; transition: width 0.3s ease;
}

.plan-form { display: flex; flex-direction: column; gap: 10px; }
.plan-form label { font-size: 0.82rem; color: var(--text-muted); }
.plan-form input, .plan-form textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text); font: inherit;
}

.emergency-list { list-style: none; }
.emergency-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.emergency-list strong {
  display: inline-block; min-width: 48px;
  color: var(--accent); font-size: 1.1rem;
}

.quiz-q { background: var(--bg); padding: 12px; border-radius: var(--r-sm); margin-bottom: 10px; }
.quiz-q .opts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.quiz-q label { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; cursor: pointer; }
.quiz-result { padding: 16px; background: var(--accent-soft); border-radius: var(--r-md); margin-top: 12px; text-align: center; }
.quiz-result h4 { color: var(--accent); font-size: 1.4rem; }

/* ========== FOOTER ========== */
.footer {
  margin-top: 40px; padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.82rem;
  text-align: center;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 16px; }
  .nav-toggle { display: flex; }
  .hero { grid-template-columns: 1fr; }
  .two-col, .sim-grid { grid-template-columns: 1fr; }
  .brand-text small { display: none; }
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.4rem; }
  .region-pick span { display: none; }
  .region-pick select { min-width: 100px; }
}

@media (max-width: 480px) {
  .topbar-actions .icon-btn:not(#themeToggle) { display: none; }
  .kpi-num { font-size: 1.4rem; }
}

/* ========== UTIL ========== */
.hidden { display: none !important; }
.text-center { text-align: center; }
code {
  background: var(--bg);
  padding: 2px 6px; border-radius: 4px;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.85em;
}
