/* ============================================
   LOS APOYOS NARANJA · DESIGN SYSTEM
   Subsidios Guadalajara · Hector Pina @YaNiPaper
   ============================================ */

:root {
  /* Paleta */
  --bg-0: #101010;
  --bg-1: #181818;
  --bg-2: #212529;
  --border: #343a40;
  --border-soft: #2a2e33;
  --text: #f3f3f3;
  --text-dim: #b6b6b6;
  --text-mute: #7a7f87;

  --accent-1: #fd8324;
  --accent-2: #ff4e00;
  /* Gradiente perceptualmente uniforme con OKLCH (mejor que RGB linear).
     Browsers viejos hacen fallback al hex via -webkit-* */
  --accent-grad: linear-gradient(in oklch 135deg, #fd8324 0%, #ff4e00 100%);

  --warn: #ffd166;
  --danger: #ef476f;

  /* Tipografía */
  --font-display: "Bungee Spice", "Roboto", system-ui, sans-serif;  /* solo título del sitio */
  --font-heading: "Bungee", "Roboto", system-ui, sans-serif;        /* h1/h2/h3 + números KPI */
  --font-body: "Roboto", system-ui, -apple-system, sans-serif;       /* todo lo demás */

  /* Layout */
  --header-h: 156px;
  --header-h-shrunk: 74px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.5);
  --maxw: 1600px;
}

/* ----------------- RESET & BASE ----------------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg-0);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  padding-top: var(--header-h);
  transition: padding-top .35s ease;
}
body.header-shrunk { padding-top: var(--header-h-shrunk); }

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

img, video { max-width: 100%; display: block; }

button { font-family: var(--font-body); cursor: pointer; }

/* Focus visible — WCAG 2.2 SC 2.4.11 / 2.4.12 / 2.4.13
   Outline naranja con offset para máxima visibilidad sobre fondo oscuro */
:focus-visible {
  outline: 2px solid #fd8324;
  outline-offset: 2px;
  border-radius: 3px;
}
/* Quita el outline default cuando se hace clic con mouse (no es focus de teclado) */
:focus:not(:focus-visible) { outline: none; }

h1, h2, h3, h4 { margin: 0; line-height: 1.15; font-weight: 700; }

code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--accent-1);
}

/* ----------------- HEADER FIJO ----------------- */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  height: var(--header-h);
  background: rgba(16, 16, 16, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  transition: height .35s ease, background .25s ease, box-shadow .25s ease;
}

/* Estado contraído al hacer scroll */
.site-header.shrunk {
  height: var(--header-h-shrunk);
  background: rgba(16, 16, 16, 0.96);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

.header-inner {
  position: relative;
  max-width: var(--maxw);
  margin: 0 auto;
  height: 100%;
  padding: 10px 24px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
  transition: padding .35s ease, gap .25s ease;
}
.site-header.shrunk .header-inner {
  padding-top: 8px;
  padding-bottom: 8px;
  gap: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: inherit;
  transition: opacity .2s;
}
.brand:hover { text-decoration: none; opacity: 0.92; }
.brand:hover .brand-subtitle { color: var(--accent-1); }

.brand-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 2.6vw, 2.4rem);
  letter-spacing: 0.5px;
  margin: 0;
  line-height: 1.05;
  transition: font-size .35s ease;
}
.site-header.shrunk .brand-title {
  font-size: clamp(1.4rem, 1.9vw, 1.7rem);
}

.brand-subtitle {
  font-family: var(--font-body);
  font-size: 0.76rem;
  color: var(--text-dim);
  margin: 2px 0 0;
  font-weight: 300;
  letter-spacing: 0.3px;
  transition: font-size .35s ease, opacity .25s ease;
}
.site-header.shrunk .brand-subtitle {
  font-size: 0.7rem;
  opacity: 0.75;
}

.main-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  max-height: 60px;
  overflow: hidden;
  transition: opacity .25s ease, max-height .35s ease, margin .25s ease, transform .25s ease;
}
.site-header.shrunk .main-nav {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.main-nav ul {
  list-style: none;
  margin: 0;
  padding: 3px;
  display: inline-flex;
  gap: 3px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.main-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 32px; /* WCAG 2.2 SC 2.5.8: target size mínimo */
  color: var(--text-dim);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  padding: 8px 18px;
  border-radius: 999px;
  text-decoration: none;
  transition: background .22s ease, color .22s ease, transform .15s ease;
}

.main-nav a:hover {
  color: var(--accent-1);
  background: rgba(253, 131, 36, 0.10);
  text-decoration: none;
  transform: translateY(-1px);
}

.main-nav a.active {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 4px 14px rgba(253, 131, 36, 0.35);
}
.main-nav a.active:hover {
  color: #fff;
  transform: translateY(-1px);
}

.credit {
  font-size: 0.72rem;
  color: var(--text-mute);
  letter-spacing: 0.3px;
  margin-top: 2px;
  font-style: italic;
  max-height: 30px;
  overflow: hidden;
  transition: opacity .25s ease, max-height .35s ease, margin .25s ease, transform .25s ease;
}
.credit a { color: var(--accent-1); font-style: normal; }
.site-header.shrunk .credit {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

/* Hamburger */
.hamburger {
  display: none;
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 42px; height: 42px;
  padding: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  z-index: 5;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  transition: transform .25s ease, opacity .25s ease;
}
.hamburger.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ----------------- SECCIONES ----------------- */
.section {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 24px 56px;
}

.dashboard-section { padding-top: 14px; padding-bottom: 32px; }

.section-header { margin-bottom: 24px; }

.section-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}

.section-sub {
  color: var(--text-dim);
  font-weight: 300;
  margin: 0;
}

/* ----------------- KPIs ----------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.kpi-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 12px;
  position: relative;
  overflow: hidden;
  text-align: center;
  transition: transform .25s ease, border-color .25s ease;
}
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 3px;
  background: var(--accent-grad);
  opacity: 0.7;
}
.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-1);
}

.kpi-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-mute);
  font-weight: 500;
  margin: 0 0 6px;
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: clamp(1.2rem, 1.7vw, 1.7rem);
  margin: 0 0 4px;
  line-height: 1.05;
  word-break: break-word;
  letter-spacing: -0.3px;
  background: linear-gradient(180deg, #ff4e00 0%, #fd8324 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.kpi-value-small {
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 4px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.kpi-foot {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.25;
}

/* KPI con desglose (personas morales / físicas) */
.kpi-split .kpi-value {
  font-size: clamp(1.1rem, 1.5vw, 1.5rem);
  margin-bottom: 6px;
}
.kpi-detail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.kpi-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.7rem;
}
.kpi-detail-label {
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 0.62rem;
}
.kpi-detail-value {
  font-family: var(--font-heading);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  color: #fd8324;
}

/* Tarjeta de evidencia destacada */
.kpi-evidencia {
  background: linear-gradient(135deg, rgba(253, 131, 36, 0.16) 0%, rgba(255, 78, 0, 0.06) 100%);
  border-color: var(--accent-1);
  cursor: pointer;
}
.kpi-evidencia::before { height: 5px; opacity: 1; }
.kpi-evidencia:hover { border-color: var(--accent-2); }
.kpi-foot-cta {
  color: #fd8324;
  font-weight: 600;
  margin-top: 6px;
}

/* ----------------- FILTROS ----------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1; }

.filter-group label {
  font-size: 0.66rem;
  text-transform: uppercase;
  color: var(--text-mute);
  letter-spacing: 0.7px;
  font-weight: 500;
}

.filter-group select,
.explorer-controls input[type="search"] {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  transition: border-color .2s;
}
.filter-group select:focus,
.explorer-controls input[type="search"]:focus {
  border-color: var(--accent-1);
}

.reset-btn,
.download-btn {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  min-height: 40px; /* WCAG 2.5.8 */
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter .2s, transform .2s, background .2s, color .2s, border-color .2s;
}
.download-btn svg, .reset-btn svg { display: block; }
.reset-btn:hover,
.download-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* Variante outline para "Descargar datos completos" */
.download-btn-secondary {
  background: transparent;
  color: var(--accent-1);
  border: 1px solid var(--accent-1);
}
.download-btn-secondary:hover {
  background: rgba(253, 131, 36, 0.10);
  filter: none;
  color: var(--accent-1);
}

/* ----------------- CHART CARDS ----------------- */
.chart-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.chart-header { margin-bottom: 6px; flex-shrink: 0; text-align: center; }

.chart-title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 400;
  margin: 0;
  line-height: 1.25;
  letter-spacing: 0;
  text-align: center;
}

.chart-sub {
  font-size: 0.7rem;
  color: var(--text-mute);
  margin: 2px 0 0;
  font-weight: 300;
  line-height: 1.3;
  text-align: center;
}

/* Botón flotante para descargar la gráfica como imagen */
.chart-download-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border);
  color: var(--text-mute);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  z-index: 5;
  opacity: 0.65;
  transition: opacity .2s, color .2s, border-color .2s, background .2s;
}
.chart-card:hover .chart-download-btn,
.chart-download-btn:focus-visible { opacity: 1; }
.chart-download-btn:hover,
.chart-download-btn:focus-visible {
  color: #fd8324;
  border-color: #fd8324;
  background: rgba(253, 131, 36, 0.15);
}
.chart-download-btn svg { display: block; }
/* En dispositivos sin hover (touch) el botón siempre visible */
@media (hover: none) {
  .chart-download-btn { opacity: 1; }
}

.chart-container {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* ========== Skeleton de carga inicial ========== */
@keyframes skeletonShimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
body.is-loading .kpi-value,
body.is-loading .kpi-value-small,
body.is-loading .chart-container::before {
  background: linear-gradient(90deg,
    rgba(253, 131, 36, 0.05) 0%,
    rgba(253, 131, 36, 0.18) 50%,
    rgba(253, 131, 36, 0.05) 100%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
  color: transparent !important;
  -webkit-background-clip: padding-box !important;
  background-clip: padding-box !important;
}
body.is-loading .chart-container::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* ========== Overlay de error global ========== */
.load-error-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(16, 16, 16, 0.94);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.load-error-overlay.show { display: flex; }
.load-error-card {
  max-width: 460px;
  background: var(--bg-1);
  border: 1px solid var(--accent-1);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}
.load-error-card h3 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 400;
  margin: 0 0 12px;
  background: linear-gradient(180deg, #ff4e00 0%, #fd8324 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.load-error-card p {
  color: var(--text-dim);
  margin: 0 0 20px;
  line-height: 1.55;
}

/* Estado vacío unificado para gráficas sin datos */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  background: rgba(16, 16, 16, 0.6);
  pointer-events: auto;
}
.empty-state p {
  margin: 0;
  color: var(--text-mute);
  font-size: 0.85rem;
  line-height: 1.4;
  max-width: 240px;
}
.empty-state .empty-reset {
  background: transparent;
  color: var(--accent-1);
  border: 1px solid var(--accent-1);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background .2s, color .2s;
  min-height: 32px;
}
.empty-state .empty-reset:hover {
  background: var(--accent-1);
  color: #fff;
}

.chart-footer {
  font-size: 0.62rem;
  color: var(--text-mute);
  text-align: right;
  font-style: italic;
  margin-top: 4px;
  flex-shrink: 0;
}

/* Grid 3 × 3 visual (6 cols base para permitir treemaps de 1.5 cols).
   Filas 1-2: bubble | tl1 | tl2  /  bubble | ámbito | modalidad
   Fila 3:    treemap1 (1.5 cols) | treemap2 (1.5 cols) */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 250px 250px 280px;
  gap: 14px;
  grid-template-areas:
    "bubble bubble tl1 tl1 tl2 tl2"
    "bubble bubble amb amb mod mod"
    "tm1    tm1    tm1 tm2 tm2 tm2";
}

.chart-area-bubble { grid-area: bubble; }
.chart-area-tl1    { grid-area: tl1; }
.chart-area-tl2    { grid-area: tl2; }
.chart-area-amb    { grid-area: amb; }
.chart-area-mod    { grid-area: mod; }
.chart-area-tm1    { grid-area: tm1; }
.chart-area-tm2    { grid-area: tm2; }

/* ----------------- D3 STYLES ----------------- */
.axis text {
  fill: var(--text-dim);
  font-family: var(--font-body);
  font-size: 11px;
}
.axis line,
.axis path {
  stroke: var(--border);
}
.axis-label {
  fill: var(--text-mute);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.grid line {
  stroke: var(--border-soft);
  stroke-dasharray: 2 3;
  shape-rendering: crispEdges;
}
.grid path { stroke: none; }

.bubble {
  cursor: pointer;
  transition: opacity .25s ease, stroke-width .2s;
}
.bubble.dimmed { opacity: 0.25; }
.bubble:hover { stroke-width: 3px; }

/* Overlay naranja translúcido en hover de la foto del alcalde */
.bubble-overlay {
  opacity: 0;
  transition: opacity .22s ease;
}
.bubble-g:hover .bubble-overlay { opacity: 1; }
.bubble-g:hover .bubble { stroke-width: 3px; }
/* Las burbujas atenuadas (filtro activo) no muestran el hover overlay */
.bubble-g:hover .bubble.dimmed + .bubble-overlay { opacity: 0.4; }

.bubble-label {
  fill: #fff;
  font-family: var(--font-body);
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.85);
  stroke-width: 3.5px;
  stroke-linejoin: round;
}

.bubble-amount {
  fill: var(--accent-1);
  font-family: var(--font-heading);
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.95);
  stroke-width: 3px;
}

.treemap-cell text {
  font-family: var(--font-body);
  pointer-events: none;
}
.treemap-cell rect { stroke: var(--bg-0); stroke-width: 1.5px; cursor: pointer; }
.treemap-cell:hover rect { stroke: #fff; }

.bar { cursor: pointer; transition: opacity .2s; }
.bar:hover { opacity: 0.85; }

.line-area { fill-opacity: 0.18; }

/* ----------------- TOOLTIP ----------------- */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(16, 16, 16, 0.97);
  border: 1px solid var(--accent-1);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  max-width: 320px;
  min-width: 200px;
  opacity: 0;
  transition: opacity .15s;
  z-index: 2000;
}
.tooltip.show { opacity: 1; }

.tooltip strong {
  display: block;
  font-family: var(--font-body);
  font-weight: 700;
  color: #f3f3f3;
  font-size: 0.92rem;
  letter-spacing: 0;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

/* Sub-línea opcional dentro del strong (ej. nombre del alcalde bajo el mes) */
.tooltip strong .tt-sub {
  display: block;
  margin-top: 4px;
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.2px;
  text-transform: none;
}

.tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  margin-top: 3px;
}
.tooltip .tt-row span:first-child {
  color: var(--text-mute);
  font-weight: 400;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tooltip .tt-row span:last-child {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.tooltip .tt-amount {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 400;
  display: block;
  margin: 10px 0 4px;
  color: #fd8324;
  letter-spacing: 0;
  text-align: center;
}

.tooltip .tt-hint {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  color: var(--accent-1);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  text-align: center;
}

/* ----------------- TABLA EXPLORADOR ----------------- */
.explorer-controls {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.explorer-controls input[type="search"] {
  flex: 1;
  min-width: 240px;
  padding: 12px 16px;
  font-size: 0.95rem;
}

.table-wrapper {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

#data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 1100px;
}

#data-table thead {
  background: var(--bg-1);
  position: sticky;
  top: 0;
  z-index: 5;
}

#data-table th {
  text-align: left;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-mute);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
#data-table th.num { text-align: right; }

#data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
  color: var(--text-dim);
}
#data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--accent-1);
  font-weight: 600;
  white-space: nowrap;
}
#data-table tbody tr:hover { background: rgba(253, 131, 36, 0.05); }

#data-table .doc-link {
  color: var(--accent-1);
  font-weight: 600;
  white-space: nowrap;
}

.table-footer {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-mute);
}
.table-footer span { color: var(--accent-1); font-weight: 600; }

/* Paginación de la tabla del explorador */
.table-pagination {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}
.table-info {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-mute);
}
.table-info span {
  color: var(--accent-1);
  font-weight: 700;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-btn {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  min-height: 40px; /* WCAG 2.2 target size */
  min-width: 40px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
}
.page-btn:hover:not(:disabled) {
  border-color: var(--accent-1);
  color: var(--accent-1);
  background: rgba(253, 131, 36, 0.06);
}
.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.82rem;
  color: var(--text-dim);
  min-width: 110px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Título de las secciones Explorador y Metodología centrado y en naranja */
.explorador-section .section-header,
.metodologia-section .section-header {
  text-align: center;
}
.explorador-section .section-title,
.metodologia-section .section-title {
  background: linear-gradient(180deg, #ff4e00 0%, #fd8324 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
}
.explorador-section .section-sub,
.metodologia-section .section-sub {
  text-align: center;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

/* ----------------- METODOLOGÍA ----------------- */
.methodology-content {
  max-width: 920px;
  margin: 0 auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
}
.methodology-content ol {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: 0;
}
.methodology-content li {
  counter-increment: step;
  position: relative;
  padding: 0 16px 0 32px;
  margin-bottom: 16px;
  color: var(--text-dim);
  font-size: 0.98rem;
}
.methodology-content li::before {
  content: counter(step) ".";
  position: absolute;
  left: 10px;
  top: 0;
  color: #fd8324;
  font-weight: 700;
  font-size: 1rem;
  line-height: inherit;
}
.methodology-content strong { color: var(--text); }

.methodology-content li.metodologia-warning {
  background: rgba(253, 131, 36, 0.08);
  border-left: 3px solid #fd8324;
  border-radius: var(--radius-sm);
  padding: 12px 16px 12px 32px;
}
.methodology-content li.metodologia-warning::before {
  top: 12px;
}

/* ----------------- CALL TO ACTION ----------------- */
.cta-banner {
  max-width: var(--maxw);
  margin: 12px auto 36px;
  padding: 0 24px;
}
.cta-content {
  background:
    radial-gradient(ellipse at top right, rgba(255, 78, 0, 0.22) 0%, transparent 60%),
    radial-gradient(ellipse at bottom left, rgba(253, 131, 36, 0.18) 0%, transparent 55%),
    linear-gradient(135deg, rgba(33, 37, 41, 0.95) 0%, rgba(16, 16, 16, 0.95) 100%);
  border: 1px solid var(--accent-1);
  border-radius: var(--radius);
  padding: 28px 32px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(255, 78, 0, 0.18);
}
.cta-content::before,
.cta-content::after {
  content: "";
  position: absolute;
  height: 3px;
  left: 0; right: 0;
  background: var(--accent-grad);
}
.cta-content::before { top: 0; }
.cta-content::after { bottom: 0; }

.cta-title {
  font-family: var(--font-heading);
  font-size: clamp(1.4rem, 2.2vw, 1.9rem);
  font-weight: 400;
  letter-spacing: 0;
  margin: 0 0 10px;
  background: linear-gradient(180deg, #ff4e00 0%, #fd8324 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cta-text {
  color: var(--text-dim);
  max-width: 720px;
  margin: 0 auto 22px;
  font-size: 1rem;
  line-height: 1.55;
}
.cta-text a {
  color: var(--accent-1);
  font-weight: 700;
}

.cta-share {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-grad);
  color: #fff;
  text-decoration: none;
  padding: 13px 26px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.4px;
  box-shadow: 0 8px 22px rgba(255, 78, 0, 0.4);
  transition: transform .15s, filter .2s, box-shadow .2s;
}
.cta-share:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
  text-decoration: none;
  color: #fff;
  box-shadow: 0 12px 28px rgba(255, 78, 0, 0.5);
}
.cta-share svg { display: block; }

@media (max-width: 600px) {
  .cta-content { padding: 24px 20px; }
  .cta-text { font-size: 0.92rem; }
}

/* ----------------- FOOTER ----------------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 32px 24px;
  text-align: center;
  color: var(--text-mute);
  font-size: 0.9rem;
}
.site-footer p { margin: 4px 0; }
.footer-small { font-size: 0.78rem; }

/* ----------------- MODAL EVIDENCIA ----------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal.open { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  background:
    radial-gradient(ellipse at top, rgba(255, 78, 0, 0.16) 0%, transparent 55%),
    radial-gradient(ellipse at bottom right, rgba(253, 131, 36, 0.10) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  border: 1px solid var(--accent-1);
  border-radius: var(--radius);
  max-width: 1100px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 40px 36px 36px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(255, 78, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.modal-dialog::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--accent-grad);
  border-radius: var(--radius) var(--radius) 0 0;
}
.modal-dialog::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent-grad);
  opacity: 0.55;
  border-radius: 0 0 var(--radius) var(--radius);
}

.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px; height: 38px;
  font-size: 1rem;
  z-index: 2;
  transition: border-color .2s, color .2s, background .2s, transform .15s;
}
.modal-close:hover {
  border-color: var(--accent-1);
  color: var(--accent-1);
  background: rgba(253, 131, 36, 0.12);
  transform: scale(1.05);
}

.modal-title {
  font-family: var(--font-heading);
  font-size: clamp(1.3rem, 2.2vw, 1.7rem);
  margin-bottom: 10px;
  background: linear-gradient(180deg, #ff4e00 0%, #fd8324 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 0;
  text-align: center;
  padding: 0 40px;
}
.modal-lead {
  color: var(--text-dim);
  margin: 0 auto 28px;
  text-align: center;
  max-width: 720px;
  font-size: 0.98rem;
  line-height: 1.55;
}

.modal-media {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
  align-items: start;
}
.modal-media figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.modal-media figcaption {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-mute);
  margin-bottom: 10px;
  text-align: center;
  width: 100%;
}
.modal-media img,
.modal-media video {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #000;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
/* Video con altura controlada — antes ocupaba todo el alto del recuadro */
.modal-media video {
  max-height: 380px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

/* ----- Modal de introducción ----- */
.modal-intro-dialog {
  max-width: 940px;
  padding: 36px 44px 32px;
}
/* Halos extra solo para el modal de intro — refuerzan el glow del recuadro */
.modal-intro .modal-dialog::before,
.modal-intro-dialog::before { height: 5px; }
.modal-intro-dialog {
  background:
    radial-gradient(ellipse at top, rgba(255, 78, 0, 0.20) 0%, transparent 50%),
    radial-gradient(circle at 15% 100%, rgba(253, 131, 36, 0.14) 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(255, 78, 0, 0.10) 0%, transparent 40%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
}

.modal-intro .modal-title {
  font-family: var(--font-heading);
  font-size: clamp(1.15rem, 2.1vw, 1.55rem);
  font-weight: 400;
  letter-spacing: 0;
  margin-bottom: 16px;
  padding: 0 40px;
  text-align: center;
}

.modal-body p {
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 12px;
}
.modal-body strong { color: var(--text); font-weight: 600; }
.modal-body em { color: var(--accent-1); font-style: normal; font-weight: 500; }
.modal-body a { color: var(--accent-1); font-weight: 500; }

.intro-links {
  list-style: none;
  margin: 4px 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.intro-links li {
  background:
    linear-gradient(135deg, rgba(253, 131, 36, 0.04) 0%, transparent 50%),
    var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-1);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.35;
  transition: border-color .2s, transform .15s, background .2s;
}
.intro-links li:hover {
  border-color: var(--accent-1);
  transform: translateX(2px);
  background:
    linear-gradient(135deg, rgba(253, 131, 36, 0.10) 0%, transparent 50%),
    var(--bg-2);
}
.intro-links a {
  color: var(--accent-1);
  font-weight: 600;
  margin-left: 4px;
  white-space: nowrap;
}

.modal-actions {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
}
.modal-cta {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: 0.4px;
  box-shadow: 0 6px 18px rgba(255, 78, 0, 0.35);
  transition: filter .2s, transform .2s, box-shadow .2s;
}
.modal-cta:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(255, 78, 0, 0.45);
}

/* ============================================
   VIEW TRANSITIONS API (cross-document, baseline 2026)
   Fade suave entre páginas; degrades gracefully en browsers viejos.
   ============================================ */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 220ms;
  animation-timing-function: ease;
}
::view-transition-old(root) { animation-name: fade-out; }
::view-transition-new(root) { animation-name: fade-in; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in  { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
}

/* ============================================
   BOTÓN VOLVER ARRIBA
   ============================================ */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 800;
  box-shadow: 0 8px 22px rgba(255, 78, 0, 0.45);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity .25s, transform .25s, filter .2s;
}
.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-to-top:hover { filter: brightness(1.12); }
.back-to-top svg { display: block; }

/* ============================================
   REVEAL ON SCROLL
   ============================================ */
.reveal-init {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity .55s ease, transform .55s ease;
}
.reveal-in {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .reveal-init { opacity: 1; transform: none; transition: none; }
}

/* ============================================
   ACCESIBILIDAD: prefers-reduced-motion
   Para usuarios con vestibular disorders, migrañas, autismo.
   WCAG 2.3.3 — Animation from interactions.
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Utility: solo lectores de pantalla (visualmente oculto pero accesible) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (min-width: 1900px) {
  :root { --maxw: 1820px; }
  body { font-size: 17px; }
  .chart-bubbles { min-height: 600px; }
}

@media (max-width: 1400px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .charts-grid { grid-template-rows: 230px 230px 260px; }
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  /* Tablet: 2 columnas. El bubble ocupa toda la primera fila;
     después tl1/tl2, amb/mod, y los treemaps a todo lo ancho */
  .charts-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: 360px 240px 240px 280px 280px;
    grid-template-areas:
      "bubble bubble"
      "tl1    tl2"
      "amb    mod"
      "tm1    tm1"
      "tm2    tm2";
  }
}

@media (max-width: 880px) {
  :root { --header-h: 108px; --header-h-shrunk: 64px; }

  /* Mobile: una columna apilada */
  .charts-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 380px repeat(6, 260px);
    grid-template-areas:
      "bubble"
      "tl1"
      "tl2"
      "amb"
      "mod"
      "tm1"
      "tm2";
  }

  .hamburger { display: flex; }

  .header-inner {
    padding: 14px 60px 12px;
    gap: 2px;
  }

  /* En mobile el nav se vuelve un drawer lateral, fuera del flujo */
  .main-nav {
    position: fixed;
    top: var(--header-h);
    right: 0;
    width: min(320px, 86vw);
    height: calc(100vh - var(--header-h));
    max-height: none;        /* anula el max-height de 60px del desktop */
    overflow-y: auto;        /* scroll interno si hace falta */
    background: var(--bg-1);
    border-left: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 28px 24px;
    gap: 0;
    transform: translateX(110%);
    transition: transform .3s ease;
    margin-top: 0;
    justify-content: flex-start;
  }
  .main-nav.open { transform: translateX(0); }
  /* En mobile el header NO contrae el drawer (deshabilita la transición) */
  .site-header.shrunk .main-nav {
    opacity: 1;
    max-height: none;
    margin-top: 0;
    transform: translateX(110%);
    pointer-events: auto;
  }
  .site-header.shrunk .main-nav.open { transform: translateX(0); }

  /* En mobile el ul vuelve a ser una lista vertical (no píldora) */
  .main-nav ul {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    width: 100%;
  }
  .main-nav a {
    display: block;
    width: 100%;
    text-align: left;
    font-size: 0.78rem;
    padding: 12px 16px;
    border: 1px solid var(--border);
  }
  .main-nav a.active { box-shadow: none; }

  .brand-title { font-size: 1.85rem; }
  .brand-subtitle { font-size: 0.74rem; }
  /* En mobile el credit se oculta del header (queda en el footer) */
  .credit { display: none; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-group { min-width: 0; width: 100%; }
  .reset-btn { width: 100%; }

  .modal-media { grid-template-columns: 1fr; }
  .modal-dialog { padding: 24px 18px; }
  .modal-title { font-size: 1.25rem; }

  .section { padding: 32px 18px 50px; }
  .header-inner { padding: 0 18px; }
}

@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .section-title { font-size: 1.5rem; }
  .methodology-content { padding: 22px 20px; }
}
