@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  /* Tema claro (lectura): base de todo el sitio */
  color-scheme: light;
  --ground: #F6F5F1;
  --paper: #FFFFFF;
  --ink: #16181A;
  --ink-2: #3F4448;
  --muted: #5C6166;
  --line: #D9D7D0;
  --track: #ECEAE4;
  --accent: #1F5C4F;
  --accent-2: #C2703D;
  --accent-2-text: #9A5226;
  --cat-3: #8A8F94;
  --cat-4: #B9BCC0;
  --cat-5: #D9D7D0;
  --strong-bg: #16181A;
  --strong-ink: #F6F5F1;
  --strong-text: #D6D8DA;
  --strong-muted: #B9BCC0;
  --strong-label: #B9BCC0;
  --strong-border: #16181A;
}

/* Tema oscuro (datos): inicio, observatorio y tableros */
body.tema-oscuro {
  color-scheme: dark;
  --ground: #111315;
  --paper: #191C1F;
  --ink: #ECEDEE;
  --ink-2: #C4C8CB;
  --muted: #9AA0A5;
  --line: #2E3236;
  --track: #25292D;
  --accent: #5FBFA6;
  --accent-2: #E39A68;
  --accent-2-text: #E9A97C;
  --cat-3: #8C9399;
  --cat-4: #5E656B;
  --cat-5: #3E4449;
  --strong-bg: #0F2A24;
  --strong-ink: #ECEDEE;
  --strong-text: #C4C8CB;
  --strong-muted: #9AA0A5;
  --strong-label: #5FBFA6;
  --strong-border: #5FBFA6;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: Inter, system-ui, sans-serif; line-height: 1.5; }
a { color: var(--ink); }
a:hover { color: var(--accent); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.mono { font-family: 'IBM Plex Mono', monospace; }
.display { font-family: 'Space Grotesk', sans-serif; }

/* Header */
.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; padding-top: 18px; padding-bottom: 18px; }
.logo { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 26px; letter-spacing: -0.02em; text-decoration: none; }
.logo span { color: var(--accent); }
.nav { display: flex; flex-wrap: wrap; gap: 22px; font-size: 14px; }
.nav a { text-decoration: none; }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

main.wrap { padding-top: 32px; padding-bottom: 64px; display: flex; flex-direction: column; gap: 40px; }

/* Page head */
.crumb { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.page-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; justify-content: space-between; }
h1 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: clamp(44px, 8vw, 64px); line-height: 1; letter-spacing: -0.03em; }
.lede { margin: 10px 0 0; font-size: 17px; color: var(--ink-2); max-width: 640px; }
.badges { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.badge { font-family: 'IBM Plex Mono', monospace; font-size: 12px; padding: 6px 10px; border: 1px solid var(--accent); color: var(--accent); text-transform: uppercase; }
.stamp { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); }

/* KPI grid */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); border-top: 1px solid var(--ink); border-left: 1px solid var(--line); }
.kpi { padding: 20px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.kpi .k-label { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.kpi .k-value { font-family: 'Space Grotesk', sans-serif; font-size: 40px; font-weight: 500; letter-spacing: -0.02em; line-height: 1.1; }
.kpi .k-value.accent { color: var(--accent); }
.kpi .k-detail { font-size: 14px; color: var(--ink-2); line-height: 1.45; }

/* Panels */
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 24px; }
@media (max-width: 400px) { .panels { grid-template-columns: 1fr; } }
.panel { background: var(--paper); border: 1px solid var(--line); padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.panel h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 500; }
.panel .sub { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.panel .more { font-size: 13px; }
.panel.dark { background: var(--strong-bg); color: var(--strong-ink); border-color: var(--strong-border); }
.panel.dark .k-label { font-family: 'IBM Plex Mono', monospace; font-size: 11px; letter-spacing: 0.04em; color: var(--strong-label); text-transform: uppercase; }
.panel.dark .big { font-family: 'Space Grotesk', sans-serif; font-size: 56px; font-weight: 500; letter-spacing: -0.02em; line-height: 1; }
.panel.dark p { margin: 0; color: var(--strong-text); }
.panel.dark .note { font-size: 13px; color: var(--strong-muted); }
.panel.dark a { color: var(--strong-ink); }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 52px minmax(0, 1fr) 56px; gap: 10px; align-items: center; }
.bar-row .d { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); }
.bar-row .v { font-family: 'IBM Plex Mono', monospace; font-size: 13px; text-align: right; line-height: 1.3; }
.bar-row .v .b { color: var(--accent-2-text); font-size: 12px; }
.track { height: 14px; background: var(--track); }
.fill { height: 100%; background: var(--accent); }
.pair { display: flex; flex-direction: column; gap: 3px; }
.pair .fill { height: 8px; }
.pair .fill.b { background: var(--accent-2); }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--ink-2); }
.legend span { display: flex; gap: 6px; align-items: center; }
.sw { width: 12px; height: 12px; display: inline-block; flex: none; }

.stack { display: flex; height: 28px; gap: 2px; }
.stack div { height: 28px; }
.cat-list { display: flex; flex-direction: column; gap: 6px; }
.cat { display: grid; grid-template-columns: 14px minmax(0, 1fr) 40px; gap: 10px; align-items: center; font-size: 14px; color: var(--ink-2); }
.cat .n { font-family: 'IBM Plex Mono', monospace; font-size: 13px; text-align: right; color: var(--ink); }
.panel .foot { margin: 0; font-size: 14px; color: var(--ink-2); border-top: 1px solid var(--track); padding-top: 12px; }

/* Reading notes */
.reading { border-top: 1px solid var(--ink); padding-top: 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; font-size: 13px; color: var(--ink-2); }
.reading .k-label { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; }

/* Home */
.hero h1 { font-size: clamp(40px, 7vw, 72px); max-width: 900px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; }
.card { background: var(--paper); border: 1px solid var(--line); padding: 24px; display: flex; flex-direction: column; gap: 10px; text-decoration: none; }
.card:hover { border-color: var(--accent); }
.card h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 500; }
.card p { margin: 0; font-size: 14px; color: var(--ink-2); }

.placeholder { background: var(--paper); border: 1px dashed var(--line); padding: 32px; color: var(--ink-2); max-width: 720px; }

/* Footer */
.site-footer { border-top: 1px solid var(--line); }
.site-footer .wrap { padding-top: 20px; padding-bottom: 32px; display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; font-size: 13px; color: var(--muted); }

/* Fichas de indicadores */
.toc { display: flex; flex-wrap: wrap; gap: 8px 20px; border-top: 1px solid var(--ink); padding-top: 16px; font-size: 14px; }
.ficha { background: var(--paper); border: 1px solid var(--line); padding: 28px; scroll-margin-top: 24px; max-width: 880px; }
.ficha-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.ficha h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 26px; font-weight: 500; }
.estado { font-family: 'IBM Plex Mono', monospace; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); border: 1px solid var(--accent); padding: 4px 8px; }
.estado.en-construccion { color: var(--accent-2-text); border-color: var(--accent-2); }
.ficha dl { margin: 0; display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 12px 24px; }
.ficha dt { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); text-transform: uppercase; padding-top: 3px; }
.ficha dd { margin: 0; font-size: 15px; color: var(--ink-2); line-height: 1.6; }
@media (max-width: 600px) { .ficha dl { grid-template-columns: 1fr; gap: 4px; } .ficha dd { margin-bottom: 10px; } .ficha { padding: 20px; } }
.ficha:target { border-color: var(--accent); }
.kpi .k-label a { color: inherit; text-decoration: none; }
.kpi .k-label a:hover { color: var(--accent); }

/* Notas */
.filtros { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; border-top: 1px solid var(--ink); padding-top: 16px; }
.filtros label { display: flex; flex-direction: column; gap: 4px; font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.filtros select, .filtros input { font: inherit; font-family: Inter, sans-serif; font-size: 14px; text-transform: none; color: var(--ink); background: var(--paper); border: 1px solid var(--line); padding: 10px 12px; min-height: 44px; min-width: 180px; }
.filtros button { font: inherit; font-size: 14px; min-height: 44px; padding: 0 14px; background: transparent; color: var(--ink); border: 1px solid var(--line); cursor: pointer; }
.filtros button:hover { border-color: var(--accent); color: var(--accent); }
.conteo { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); }
.notas { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.nota { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 24px; padding: 20px 0; border-bottom: 1px solid var(--line); }
.nota .meta { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.nota .tipo { color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; font-size: 11px; }
.nota h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 500; line-height: 1.3; }
.nota h3 a { text-decoration: none; }
.nota h3 a:hover { text-decoration: underline; }
.nota .fuente { font-size: 13px; color: var(--muted); margin-top: 2px; }
.nota p { margin: 8px 0 0; font-size: 15px; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font: inherit; font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--ink-2); background: transparent; border: 1px solid var(--line); padding: 4px 8px; cursor: pointer; text-decoration: none; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 600px) { .nota { grid-template-columns: 1fr; } .nota .meta { flex-direction: row; gap: 12px; } }
.vacio { padding: 32px 0; color: var(--ink-2); }
.relacionadas { display: flex; flex-direction: column; gap: 12px; }
.relacionadas h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 500; }
.relacionadas[hidden] { display: none; }

/* Día por día */
.historial { display: flex; flex-direction: column; gap: 16px; }
.historial[hidden] { display: none; }
.historial h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 26px; font-weight: 500; }
.historial .sub { margin: 6px 0 0; font-size: 14px; color: var(--muted); max-width: 760px; }
.tabla-scroll { overflow-x: auto; border: 1px solid var(--line); background: var(--paper); }
.tabla-scroll:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.tabla { border-collapse: collapse; width: 100%; min-width: 860px; font-size: 14px; }
.tabla th, .tabla td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; line-height: 1.5; }
.tabla thead th { font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 400; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.tabla thead th a { color: inherit; text-decoration: none; }
.tabla thead th a:hover { color: var(--accent); }
.tabla thead th span { display: block; text-transform: none; }
.tabla tbody th { text-align: left; font-family: 'IBM Plex Mono', monospace; font-weight: 500; white-space: nowrap; }
.tabla tbody tr:first-child th, .tabla tbody tr:first-child td { color: var(--ink); }
.tabla td { font-family: 'IBM Plex Mono', monospace; color: var(--ink-2); white-space: nowrap; }
.tabla th:first-child { text-align: left; }
.delta { font-size: 11px; color: var(--muted); margin-left: 4px; }
.nota-fila { display: block; font-family: Inter, sans-serif; font-weight: 400; font-size: 12px; color: var(--muted); white-space: normal; max-width: 220px; margin-top: 4px; }
.tabla tbody tr:last-child th, .tabla tbody tr:last-child td { border-bottom: 0; }

/* Galería de gráficas */
.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 24px; }
.grafica { background: var(--paper); border: 1px solid var(--line); display: flex; flex-direction: column; }
.grafica-img { display: block; border-bottom: 1px solid var(--line); background: var(--track); }
.grafica-img img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 5; object-fit: cover; }
.grafica-img:hover img { opacity: 0.9; }
.grafica-txt { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.grafica h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-weight: 500; line-height: 1.3; }
.grafica p { margin: 0; font-size: 14px; color: var(--ink-2); }
.grafica-links { margin-top: auto; padding-top: 8px; display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; }
.filtros .conteo { align-self: center; }

/* Mapa */
.mapa-sec { display: flex; flex-direction: column; gap: 14px; }
.mapa-sec[hidden] { display: none; }
.mapa-sec h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 26px; font-weight: 500; }
.mapa-sec .sub { margin: 6px 0 0; font-size: 14px; color: var(--muted); max-width: 820px; }
.mapa { position: relative; height: 580px; border: 1px solid var(--line); background: var(--paper); }
.mapa svg { display: block; width: 100%; height: 100%; }
@media (max-width: 600px) { .mapa { height: 440px; } }
.mapa-partido { fill: var(--track); stroke: var(--muted); stroke-dasharray: 6 5; }
.mapa-hex { fill-opacity: 0.85; cursor: pointer; }
.mapa-hex.sin-dato { stroke-dasharray: 3 3; }
.mapa-hex:hover, .mapa-hex:focus { fill-opacity: 1; outline: none; stroke: var(--ink) !important; }
.mapa-ref { fill: var(--ink-2); }
.mapa-ref.principal { fill: var(--accent-2); }
.mapa-lugar { fill: var(--ink-2); font-family: 'IBM Plex Mono', monospace; paint-order: stroke; stroke: var(--ground); stroke-linejoin: round; pointer-events: none; }
.mapa-lugar.principal { fill: var(--ink); font-weight: 500; }
.mapa-ref { pointer-events: none; stroke: var(--ground); }
.mapa-tip { position: absolute; pointer-events: none; background: var(--ground); color: var(--ink); border: 1px solid var(--line); padding: 8px 10px; font-size: 13px; line-height: 1.45; max-width: 220px; }
.mapa-controles { display: flex; flex-wrap: wrap; gap: 8px; }
.mapa-controles .chip { min-height: 40px; padding: 8px 12px; font-size: 12px; }
.mapa-controles .chip.activo { border-color: var(--accent); color: var(--accent); }
.mapa-leyenda { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--ink-2); align-items: center; }
.mapa-leyenda strong { font-weight: 500; color: var(--ink); margin-right: 6px; }
.mapa-leyenda span { display: flex; gap: 6px; align-items: center; }
.sw.sin-dato { border: 1px dashed #5E656B; background: transparent; }

.mapa-barrio { fill: none; stroke: #F2F3F4; stroke-opacity: 0.9; pointer-events: none; }
.mapa-barrio-nombre { fill: var(--ink); font-family: Inter, sans-serif; font-weight: 500; paint-order: stroke; stroke: var(--ground); stroke-linejoin: round; pointer-events: none; }
.mapa-check { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); min-height: 32px; cursor: pointer; }
.mapa-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.barrios-tabla { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.barrios-tabla[hidden] { display: none; }
.barrios-tabla h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 500; }
.barrios-tabla .tabla { min-width: 720px; }
.barrios-tabla .tabla tbody th { font-family: Inter, sans-serif; white-space: normal; }
.barrios-tabla .tabla tr.agrupado th, .barrios-tabla .tabla tr.agrupado td { color: var(--muted); font-style: italic; }
