/* Tokens ---------------------------------------------------------------- */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f4f6fb;
  --line: #e1e5ee;
  --line-strong: #c8cfde;
  --text: #12141c;
  --muted: #586074;
  /* azul-celeste, en la gama de #2121E2 pero más suave y más claro */
  --accent: #3d72e4;
  --accent-strong: #2a54c2;
  --accent-soft: #e7eefc;
  --accent-grad: linear-gradient(135deg, #6da3f7, #3563d8);
  --ok: #059669; --ok-soft: #d1fae5;
  --bad: #dc2626; --bad-soft: #fee2e2;
  --warn: #7c4a03; --warn-soft: #fef3c7;
  --warm: #d9822b;
  /* colores de gráficos y mapas (el tema de otro sitio puede redefinirlos) */
  --c-main: #3d72e4; --c-soft: #c8d9fa; --c-alt: #8b93a7; --c-warm: #d9822b; --c-borde-sel: #12141c; --sin-dato: #e4e8f0;
  --r0: #eaf0fd; --r1: #c8d9fa; --r2: #9fbcf5; --r3: #729bee; --r4: #4577e0; --r5: #2a54c2;
  --bar: rgba(255, 255, 255, .8);
  --glow: rgba(61, 114, 228, .18);
  --grid-dot: rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-card: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 30px -14px rgba(15, 23, 42, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 20px;
}

/* Base ------------------------------------------------------------------ */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; font-feature-settings: 'cv11', 'ss01'; min-height: 100vh;
}
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 45% at 50% -8%, var(--glow), transparent 70%),
    radial-gradient(var(--grid-dot) 1px, transparent 1px) 0 0 / 22px 22px;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 55%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 55%, transparent 100%);
}
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 26px; font-weight: 750; letter-spacing: -0.025em; margin: 56px 0 16px; }
main { counter-reset: sec; }
main > section[id] > h2 { display: flex; align-items: center; gap: 12px; counter-increment: sec; }
main > section[id] > h2::before {
  content: counter(sec, decimal-leading-zero); font-size: 11.5px; font-weight: 700; letter-spacing: .12em;
  color: var(--accent-strong); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-soft); border-radius: 999px; padding: 3px 9px; font-variant-numeric: tabular-nums;
}
main > section[id] > h2::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); }
h3 { font-size: 16px; font-weight: 650; margin-bottom: 12px; }
h4 { font-size: 14px; font-weight: 650; margin: 18px 0 6px; }
p { margin: 0 0 10px; }
a { color: var(--accent-strong); }
a:hover { color: var(--accent); }
.muted, .sd { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; }

/* Barra superior -------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 1000; background: var(--bar); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-grad); flex: none; position: relative; box-shadow: 0 0 0 1px rgba(255,255,255,.4) inset, 0 6px 18px -6px var(--glow); }
.brand-mark::after { content: ''; position: absolute; inset: 9px 8px; border-left: 3px solid #fff; border-bottom: 3px solid #fff; transform: rotate(-45deg) scale(.6); }
.brand strong { font-size: 16px; font-weight: 700; display: block; line-height: 1.2; }
.brand span.sub { font-size: 12px; color: var(--muted); }
nav.toc { display: flex; gap: 4px; flex-wrap: wrap; }
nav.toc a { color: var(--text); text-decoration: none; font-size: 13.5px; font-weight: 500; padding: 6px 12px; border-radius: 999px; transition: background .15s, color .15s; }
nav.toc a:hover { background: var(--accent-soft); color: var(--accent-strong); }

/* Hero ------------------------------------------------------------------ */
.hero { position: relative; padding: 56px 0 44px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 650; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-strong); margin: 0 0 18px; }
.eyebrow::before { content: ''; width: 22px; height: 2px; border-radius: 2px; background: var(--accent); }
.hero-title { font-size: clamp(32px, 5.4vw, 56px); line-height: 1.04; font-weight: 800; letter-spacing: -0.035em; margin: 0 0 20px; max-width: 20ch; }
.hero-title .grad { background: linear-gradient(100deg, #5b93f2, #2a54c2 75%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-lead { font-size: 16.5px; line-height: 1.65; color: color-mix(in srgb, var(--text) 82%, transparent); max-width: 70ch; margin: 0 0 14px; }
.hero-lead em { color: var(--text); font-style: normal; font-weight: 600; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 0; }
.btn-primary { display: inline-flex; align-items: center; font: inherit; font-size: 14px; font-weight: 650; text-decoration: none; color: #fff; background: var(--accent-grad); border-radius: var(--radius-sm); padding: 11px 18px; box-shadow: 0 8px 24px -10px var(--glow), 0 0 0 1px rgba(255,255,255,.25) inset; border: 0; cursor: pointer; }
.btn-primary:hover { filter: brightness(1.06); color: #fff; }
.btn-ghost { display: inline-flex; align-items: center; font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--text); border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 11px 18px; cursor: pointer; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-strong); }
.pills, .chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 26px 0 0; padding: 0; list-style: none; }
.pills li, .chip { font-size: 12.5px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; }
.pills li b, .chip b { color: var(--accent-strong); font-weight: 700; }


/* Tarjetas y avisos ----------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 20px; }
.card + .card { margin-top: var(--gap); }
.card > h3:first-child { margin-top: 0; }
.card .sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; max-width: 80ch; }
.notice { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13.5px; margin: 12px 0 0; }
.notice.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--accent-strong); }

/* Layout simulador ------------------------------------------------------ */
.grid-sim { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--gap); align-items: start; }
.col-res { align-self: stretch; }
.col-res .live { position: sticky; top: 84px; }
/* Si el panel no entra en la altura de la pantalla, no se fija: evita que quede cortado */
@media (max-height: 820px) { .col-res .live { position: static; } }
@media (max-width: 1020px) {
  .grid-sim { grid-template-columns: minmax(0, 1fr); }
  .col-res .live { position: static; }
  .col-res { order: -1; }
}

/* Controles ------------------------------------------------------------- */
.label, label.label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 14px; }
select, input[type="number"], input[type="search"], input[type="text"] {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 9px 11px; min-height: 40px;
}
select:focus, input:focus, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.range-row { display: grid; grid-template-columns: 1fr 84px; gap: 12px; align-items: center; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checks label { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; cursor: pointer; min-height: 30px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 17px; height: 17px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 999px; padding: 3px; gap: 2px; max-width: 100%; flex-wrap: wrap; }
.seg button { font: inherit; font-size: 13px; font-weight: 600; border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.seg button[aria-pressed="true"] { background: var(--accent-grad); color: #fff; box-shadow: 0 2px 8px -2px rgba(42, 84, 194, .55); }
button.ghost { font: inherit; font-size: 13.5px; font-weight: 600; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: var(--radius-sm); padding: 9px 14px; cursor: pointer; min-height: 40px; }
button.ghost:hover { border-color: var(--accent); color: var(--accent-strong); }

/* Parámetros ------------------------------------------------------------ */
.param { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.param:first-of-type { border-top: 0; padding-top: 0; }
.param .head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.param .head strong { font-size: 13.5px; }
.param .head .val { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent-strong); font-size: 14px; }
.param .controls { display: grid; grid-template-columns: minmax(120px, 1fr) 84px 118px; gap: 12px; align-items: center; margin: 8px 0 4px; }
.param .controls .mini { display: block; font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.param .controls input[type=number] { min-height: 34px; padding: 4px 8px; }
.param details { margin: 6px 0 2px; }
.param summary { cursor: pointer; color: var(--accent-strong); font-weight: 600; font-size: 12.5px; padding: 4px 0; }
.param .explain { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13.5px; margin-top: 6px; }
.param .explain h4 { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.param .explain h4:first-child { margin-top: 0; }
.param .explain p, .param .explain ul { margin: 0 0 6px; }
.param .explain ul { padding-left: 18px; }
.param .explain li { margin-bottom: 4px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; background: var(--accent-soft); color: var(--accent-strong); border-radius: 6px; padding: 1px 7px; margin-left: 4px; }

/* Panel en vivo --------------------------------------------------------- */
.live { background-image: var(--accent-grad); background-size: 100% 3px; background-repeat: no-repeat; }
.live-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.live-head h3 { margin: 0; }
.pulso { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.pulso::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(5, 150, 105, .5); }
[aria-busy="true"] .pulso::before { background: var(--warm); animation: latido .8s ease-in-out infinite; }
@keyframes latido { 0% { box-shadow: 0 0 0 0 rgba(217, 130, 43, .55); } 100% { box-shadow: 0 0 0 8px rgba(217, 130, 43, 0); } }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.kpi.main { grid-column: span 2; }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.kpi .k { font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.kpi .v { font-size: 19px; font-weight: 750; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .ic { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.main { background: var(--accent-grad); border-color: transparent; color: #fff; box-shadow: 0 10px 24px -14px rgba(42, 84, 194, .8); }
.kpi.main .k, .kpi.main .ic { color: rgba(255, 255, 255, .85); }
.kpi.main .v { color: #fff; font-size: 24px; }
.delta { display: inline-block; font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 1px 8px; margin-top: 4px; background: rgba(255, 255, 255, .22); color: #fff; }
.kpi:not(.main) .delta { background: var(--accent-soft); color: var(--accent-strong); }
.delta.sube::before { content: '▲ '; } .delta.baja::before { content: '▼ '; }
.flash { animation: destello .7s ease-out; }
@keyframes destello { 0% { box-shadow: 0 0 0 0 rgba(61, 114, 228, .55); } 100% { box-shadow: 0 0 0 10px rgba(61, 114, 228, 0); } }
.tabs { margin: 14px 0 8px; }
.viz { min-height: 250px; }
.viz[hidden] { display: none; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { font: 11px var(--font); fill: var(--muted); }
svg.chart .ejes line { stroke: var(--line); }
svg.chart .t { font-weight: 600; fill: var(--text); }
.leyenda { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.leyenda i { display: inline-block; width: 18px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
button.png { font: inherit; font-size: 12.5px; font-weight: 600; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button.png:hover { border-color: var(--accent); color: var(--accent-strong); }
button.png::before { content: '↓'; font-weight: 700; }
button.png[disabled] { opacity: .5; cursor: progress; }
.tabs-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 14px 0 8px; }
.tabs-row .tabs { margin: 0; }
#mapaVivo { height: 250px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); }

/* Tablas ---------------------------------------------------------------- */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-top: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; vertical-align: top; }
th:first-child, td:first-child, td.l, th.l { text-align: left; }
th { background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 240px; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.badge { display: inline-block; border-radius: 999px; font-size: 11.5px; font-weight: 650; padding: 2px 9px; white-space: nowrap; }
.badge.si { background: var(--ok-soft); color: var(--ok); }
.badge.no { background: var(--bad-soft); color: var(--bad); }
.badge.sd { background: var(--line); color: var(--muted); }

/* Mapas ----------------------------------------------------------------- */
.maptools { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin: 14px 0; align-items: end; }
#map { height: min(72vh, 640px); min-height: 380px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); }
.leaflet-container { font-family: var(--font); background: var(--surface-2); }
.leaflet-tooltip { font-family: var(--font); font-size: 12.5px; border-radius: 8px; border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text); background: var(--surface); }
.legend { background: rgba(255, 255, 255, .94); color: var(--text); padding: 8px 10px; border-radius: 10px; font-size: 11.5px; box-shadow: var(--shadow); line-height: 1.6; border: 1px solid var(--line); }
.legend i { display: inline-block; width: 14px; height: 10px; margin-right: 6px; border-radius: 2px; vertical-align: middle; }
.legend b { font-weight: 650; display: block; margin-bottom: 2px; }

/* Texto largo ----------------------------------------------------------- */
.prose h3, .prose p, .prose ul, .prose .formula { max-width: 880px; }
.prose h3 { margin-top: 22px; }
.prose li { margin-bottom: 5px; }
.formula { font: 13px/1.7 var(--mono); background: var(--surface-2); border: 1px solid var(--line); padding: 14px 16px; border-radius: var(--radius-sm); overflow-x: auto; white-space: pre; }
footer { margin: 56px 0 32px; color: var(--muted); font-size: 12.5px; }
footer .wrap { border-top: 1px solid var(--line); padding-top: 16px; }

@media (max-width: 720px) {
  .param .controls { grid-template-columns: 1fr 84px; }
  .param .controls .sdwrap { grid-column: 1 / -1; }
  #map { height: 62vh; }
  .hero { padding: 36px 0 32px; }
  nav.toc a { padding: 5px 9px; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .flash, .pulso::before { animation: none !important; } }
