:root {
  --paper: #fbfaf7;
  --paper-2: #f3f1eb;
  --ink: #1a1917;
  --ink-2: #4d4a44;
  --ink-3: #7d786f;
  --rule: #d9d5cc;
  --rule-2: #b9b4a9;
  --good: #1f6b3a;
  --bad: #a52a21;
  --serif: "Instrument Serif", "Iowan Old Style", "Times New Roman", Georgia, serif;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Topbar */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 24px 0;
}
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand img { height: 30px; width: auto; display: block; }
.brand-mark { width: 22px; height: 22px; }
.brand-mark rect { fill: var(--ink); }
.brand-mark path { fill: none; stroke: var(--paper); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.nav { display: flex; gap: 18px; }
.nav-link {
  text-decoration: none;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 3px;
  border-bottom: 1px solid transparent;
}
.nav-link:hover { color: var(--ink); }
.nav-link.is-active { color: var(--ink); border-bottom-color: var(--ink); }

/* Layout */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* Controls */
.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 4px 16px;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 2px solid var(--ink);
}
.controls .bajada { grid-column: 1 / -1; }
.page-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 36px;
  line-height: 1.05;
  letter-spacing: -0.01em;
}
.actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn svg { width: 14px; height: 14px; fill: currentColor; }
.btn svg.stroke { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #000; }
.btn[disabled] { opacity: 0.5; cursor: progress; }

/* Panel: sin tarjeta, solo filetes */
.panel { padding: 0; }

/* Matriz: presidentes en columnas, indicadores en filas */
.table-wrap { overflow-x: auto; }
.matriz {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.matriz thead th.th-ind { width: 26%; }
.matriz th, .matriz td { padding: 8px 8px; vertical-align: middle; }
.matriz thead th { border-bottom: 1px solid var(--ink); }
.matriz tbody tr.fila + tr.fila th, .matriz tbody tr.fila + tr.fila td,
.matriz tbody tr.fila-detalle + tr.fila th, .matriz tbody tr.fila-detalle + tr.fila td { border-top: 1px solid var(--rule); }
.th-pres { padding: 10px 8px 8px; }
.th-pres, .celda { border-left: 1px solid var(--rule); }

.foto-wrap {
  position: relative;
  width: 100%;
  max-width: 120px;
  margin: 0 auto 6px;
  aspect-ratio: 1;
  background: var(--paper-2);
}
.foto {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.foto-color { opacity: 0; transition: opacity 0.3s ease; }
.th-pres:hover .foto-color, .foto-wrap:focus-within .foto-color { opacity: 1; }

.barra {
  position: relative;
  max-width: 120px;
  margin: 0 auto;
  height: 18px;
  overflow: hidden;
  background: var(--rule);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 18px;
}
.barra .tramo { position: absolute; inset: 0 auto 0 0; }
.bar-ini, .bar-fin { position: absolute; top: 0; color: #fff; }
.bar-ini { left: 6px; }
.bar-fin { right: 6px; }
.barra.en-curso .bar-fin { color: var(--ink-2); }

th.th-ind { text-align: left; font-weight: 400; }
tr.fila th.th-ind {
  box-shadow: inset 4px 0 0 var(--t);
  padding-left: 16px;
  white-space: nowrap;
}
.ind-unidad {
  display: block;
  white-space: normal;
  margin: 1px 0 0 34px;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}
.ind-nombre { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; }
.ind-texto {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: -0.005em;
  cursor: pointer;
}
.ind-texto:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.btn-mas {
  width: 24px;
  height: 24px;
  margin: 0 10px 0 0;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  transition: transform 0.15s, background 0.12s, color 0.12s;
}
.btn-mas svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.btn-mas:hover { background: var(--ink); color: var(--paper); }
tr.is-open .btn-mas { transform: rotate(45deg); background: var(--ink); color: var(--paper); }

.celda { text-align: center; }
.celda[data-tip] { cursor: help; }
.celda .valor {
  display: block;
  font-size: 25px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
}
.celda .valor.good { color: var(--good); }
.celda .valor.bad { color: var(--bad); }
.celda .valor.flat { color: var(--ink-2); }
.celda .sub {
  display: inline-block;
  margin-top: 5px;
  padding: 1px 6px;
  background: #fff;
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

/* Fila desplegable */
.fila-detalle > td { padding: 0; background: var(--paper-2); border-top: 1px solid var(--rule); }
.detalle { padding: 16px 18px 8px; }
.detalle-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: 12px; }
.detalle-tema { font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; }
.detalle-unidad { color: var(--ink-3); }
.detalle-fuente { margin: 6px 0 0; font-size: 12px; color: var(--ink-3); }

/* Tabla simple (serie, metodología) */
.tabla { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tabla th, .tabla td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
  white-space: nowrap;
  font-size: 13.5px;
}
.tabla thead th {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--ink);
}
.tabla tbody tr:last-child td { border-bottom: 0; }
.tabla .num { text-align: right; }
.src { font-size: 12px; color: var(--ink-3); }
.tabla-serie td.pres-col { font-weight: 500; }
.tabla-serie td.pres-col::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  background: var(--c);
  vertical-align: 1px;
}

/* Hint (signo de pregunta) */
.hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--rule-2);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  cursor: help;
  flex: none;
}
.hint:hover { border-color: var(--ink); color: var(--ink); }
.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 300px;
  padding: 9px 11px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12.5px;
  line-height: 1.45;
  pointer-events: none;
}

/* Gráfico */
.chart { margin: 4px 0 0; }
.chart svg { width: 100%; height: auto; display: block; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--ink-2);
}
.chart-legend:empty { display: none; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 18px; height: 3px; display: inline-block; }
.legend-item i.dash { background: repeating-linear-gradient(90deg, var(--ink-3) 0 4px, transparent 4px 7px); }
.axis text { font-size: 11px; fill: var(--ink-3); }
.grid line { stroke: var(--rule); stroke-dasharray: 2 3; }
.serie-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.serie-line.reconstruida { stroke-dasharray: 5 4; }
.serie-dot { stroke: var(--paper-2); stroke-width: 1.5; }
.band-label { font-size: 11px; font-weight: 600; fill: var(--ink-2); }
.band-line { stroke: var(--rule-2); stroke-dasharray: 3 3; }
.pt-label {
  font-size: 12px;
  font-weight: 600;
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--paper-2);
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* Exportación PNG: pie con fuentes y marca, sin controles */
.panel-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 10px 0 4px;
  border-top: 1px solid var(--ink);
  font-size: 12px;
  color: var(--ink-3);
}
.panel-foot p { margin: 0; }
.marca { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--ink); white-space: nowrap; }
.exporting .btn-mas, .exporting .hint { display: none; }
.exporting .matriz thead th.th-ind { width: 22%; vertical-align: top; padding: 10px 10px 0 4px; }
.exporting tr.fila th.th-ind { padding-left: 14px; }
.exporting .ind-unidad { margin-left: 0; white-space: nowrap; font-size: 10.5px; letter-spacing: 0; }
.exporting .export-marca { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-style: italic; font-size: 24px; line-height: 1; white-space: nowrap; }
.exporting .export-titulo { margin: 14px 0 0; font-family: var(--serif); font-size: 26px; line-height: 1.1; font-weight: 400; white-space: normal; }
.exporting .fila-detalle { display: none; }
.exporting .foto-color { display: none; }

/* Documento (metodología) */
.page-doc { max-width: 760px; }
.page-doc h1 { font-family: var(--serif); font-weight: 400; font-size: 44px; line-height: 1.05; margin: 0 0 24px; }
.page-doc h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; margin: 28px 0 8px; }
.page-doc p { margin: 8px 0; color: var(--ink-2); }
.page-doc section { padding: 0 0 8px; margin-bottom: 8px; border-bottom: 1px solid var(--rule); }
.page-doc section:last-child { border-bottom: 0; }
.page-doc a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.tabla-doc { margin: 10px 0; }
.tabla-doc th, .tabla-doc td { white-space: normal; font-size: 14px; }
.lista-colores { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.lista-colores li { display: flex; align-items: center; gap: 10px; color: var(--ink-2); }
.swatch { width: 14px; height: 14px; display: inline-block; }
code { font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace; font-size: 13px; background: var(--paper-2); padding: 1px 5px; }

/* Responsive */
@media (max-width: 820px) {
  .matriz { table-layout: auto; }
  .matriz th.th-ind {
    position: sticky;
    left: 0;
    background: var(--paper);
    z-index: 1;
    min-width: 0;
  }
  .fila-detalle > td { position: static; }
  .th-pres { min-width: 110px; }
  .ind-texto { font-size: 22px; white-space: nowrap; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px 0; }
  .brand { font-size: 22px; }
  .page { padding: 14px 16px 32px; }
  .page-title { font-size: 28px; }
  .controls { align-items: stretch; flex-direction: column; }
  .actions .btn { flex: 1; justify-content: center; }
  .foto-wrap { max-width: 84px; }
  .barra { max-width: 84px; font-size: 10px; }
  .bar-ini { left: 4px; }
  .bar-fin { right: 4px; }
  .celda .valor { font-size: 21px; }
  .detalle { padding: 12px 10px 4px; }
  .axis text, .band-label { font-size: 19px; }
  .pt-label { font-size: 21px; }
  .serie-line { stroke-width: 3.5; }
  .serie-dot { r: 4.5; }
}

/* Botón solo ícono */
.btn-icono { padding: 7px; }
.btn-icono svg { width: 16px; height: 16px; }
.actions .btn-icono { flex: none; }

/* Notas del detalle */
.detalle-notas { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--rule); }
.detalle-notas .nota { margin: 0 0 6px; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
.detalle-notas strong { font-weight: 600; color: var(--ink); }
.detalle-notas a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 3px; white-space: nowrap; }

/* Bajada bajo el título */
.bajada { margin: 4px 0 0; max-width: 800px; font-size: 14px; line-height: 1.45; color: var(--ink-2); }
@media (max-width: 640px) {
  .controls { grid-template-columns: 1fr; }
  .bajada { font-size: 13px; }
}
.exporting #panel { padding: 16px; }
