:root {
  --fondo: #ffffff;
  --fondo-suave: #f5f6f8;
  --texto: #1d2127;
  --texto-suave: #5b6472;
  --borde: #dfe3e8;
  --acento: #0b5cad;
  --acento-fondo: #e7f0fa;
  --barra: rgb(255 255 255 / 0.94);
  --error: #b42318;
  --ancho: 720px;
  --indice: 250px;
  color-scheme: light;
}

:root[data-tema="oscuro"] {
  --fondo: #0e1014;
  --fondo-suave: #161920;
  --texto: #e7e9ee;
  --texto-suave: #9aa2b1;
  --borde: #2a2f3a;
  --acento: #7cc4ff;
  --acento-fondo: #17354d;
  --barra: rgb(14 16 20 / 0.94);
  --error: #ff8f8f;
  color-scheme: dark;
}

/* Cada gráfico viene dibujado en los dos temas (el archivo descargado no tiene scripts para
   redibujarlo): se muestra el que corresponde. */
.tema-oscuro,
:root[data-tema="oscuro"] .tema-claro {
  display: none;
}

:root[data-tema="oscuro"] .tema-oscuro {
  display: block;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-padding-top: 72px;
}

body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 17px/1.7 Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  -webkit-text-size-adjust: 100%;
}

button,
summary,
.herramientas,
.indice,
.datos,
.tabla,
.vista-cita,
.lista-fuentes,
.aviso-muestra,
figcaption,
h1,
h2,
h3,
h4 {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: var(--acento);
}

.conexion {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 30;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 8px 14px;
  border: 1px solid var(--borde);
  border-radius: 999px;
  background: var(--fondo);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
  font: 0.875rem system-ui, sans-serif;
  transform: translateX(-50%);
}

.herramientas {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--borde);
  background: var(--barra);
  backdrop-filter: blur(6px);
}

.volver {
  color: var(--texto);
  font-weight: 600;
  text-decoration: none;
}

.botones {
  display: flex;
  gap: 8px;
}

.boton {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  background: var(--fondo);
  color: var(--texto);
  font-size: 0.875rem;
  cursor: pointer;
}

.boton:hover:not(:disabled) {
  border-color: var(--acento);
  color: var(--acento);
}

.boton:disabled {
  opacity: 0.5;
  cursor: default;
}

a.boton {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.aviso-muestra {
  max-width: var(--ancho);
  margin: 16px auto 0;
  padding: 0 16px;
  color: var(--texto-suave);
  font-size: 0.875rem;
}

.aviso {
  max-width: var(--ancho);
  margin: 12px auto 0;
  padding: 0 16px;
  color: var(--error);
  font: 0.9rem system-ui, sans-serif;
}

.hoja {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: calc(var(--ancho) + 32px);
  margin: 0 auto;
  padding: 0 16px 64px;
}

.documento {
  min-width: 0;
}

.estado {
  margin: 48px 0;
  color: var(--texto-suave);
  font-family: system-ui, sans-serif;
}

.portada {
  padding: 40px 0 24px;
  border-bottom: 1px solid var(--borde);
}

.sobretitulo {
  margin: 0 0 8px;
  color: var(--texto-suave);
  font: 600 0.75rem system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 20px;
  font-size: 2rem;
  line-height: 1.2;
}

h2 {
  margin: 2.4em 0 0.6em;
  padding-top: 0.4em;
  border-top: 1px solid var(--borde);
  font-size: 1.45rem;
  line-height: 1.3;
}

h3 {
  margin: 1.8em 0 0.5em;
  font-size: 1.15rem;
}

h4 {
  margin: 1.4em 0 0.4em;
  font-size: 1rem;
}

/* La portada ya cierra con una línea: el primer título no lleva otra. */
.cuerpo > h2:first-child {
  margin-top: 1.2em;
  padding-top: 0;
  border-top: 0;
}

.datos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px 20px;
  margin: 0;
  font-size: 0.875rem;
}

.datos dt {
  color: var(--texto-suave);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.datos dd {
  margin: 2px 0 0;
  font-weight: 600;
}

.pedido {
  margin-top: 20px;
  font: 0.875rem system-ui, sans-serif;
}

.pedido summary {
  color: var(--texto-suave);
  cursor: pointer;
}

.pedido pre {
  margin: 8px 0 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--fondo-suave);
  font: 0.85rem/1.6 ui-monospace, "SFMono-Regular", Menlo, monospace;
  white-space: pre-wrap;
}

.cuerpo p,
.cuerpo li {
  hyphens: auto;
}

blockquote {
  margin: 1.2em 0;
  padding: 0.2em 1em;
  border-left: 3px solid var(--borde);
  color: var(--texto-suave);
}

code {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: var(--fondo-suave);
  font-size: 0.88em;
}

pre {
  overflow-x: auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--fondo-suave);
}

pre code {
  padding: 0;
  background: none;
}

/* MathML que dibuja el navegador: las fórmulas largas se desplazan en vez de salirse de la hoja.
   La genérica "math" sola, en Chromium sobre Linux, pierde acentos como el punto de ṁ: van
   antes las fuentes matemáticas de cada sistema (macOS/iOS, Windows, Linux, Android). */
math {
  font-family:
    "Latin Modern Math", "STIX Two Math", "Cambria Math", "DejaVu Math TeX Gyre", "Noto Sans Math",
    math, serif;
  font-size: 1.05em;
}

.formula.destacada {
  display: block;
  margin: 0.8em 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
}

.tabla {
  overflow-x: auto;
  margin: 1.2em 0;
  border: 1px solid var(--borde);
  border-radius: 8px;
}

.tabla table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  line-height: 1.45;
}

.tabla th,
.tabla td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--borde);
  text-align: left;
  vertical-align: top;
}

.tabla th {
  background: var(--fondo-suave);
  font-weight: 600;
}

.tabla tr:last-child td {
  border-bottom: 0;
}

.grafico {
  margin: 1.4em 0;
}

.grafico svg {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
}

.grafico.imagen img {
  display: block;
  max-width: 100%;
  max-height: 480px;
  border-radius: 8px;
}

.grafico figcaption {
  margin-top: 6px;
  color: var(--texto-suave);
  font-size: 0.82rem;
  line-height: 1.45;
}

.imagen-no-disponible {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--borde);
  border-radius: 8px;
  color: var(--texto-suave);
  font-size: 0.875rem;
}

a.cita {
  display: inline-block;
  min-width: 1.5em;
  margin: 0 1px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--acento-fondo);
  color: var(--acento);
  font: 600 0.7em/1.6 system-ui, sans-serif;
  text-align: center;
  text-decoration: none;
  vertical-align: 0.25em;
}

a.cita:hover,
a.cita:focus-visible {
  background: var(--acento);
  color: var(--fondo);
}

.vista-cita {
  position: absolute;
  z-index: 20;
  width: min(340px, calc(100vw - 24px));
  padding: 12px 14px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  background: var(--fondo);
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.16);
  font-size: 0.875rem;
  line-height: 1.45;
}

.vista-cita .titulo-fuente {
  margin: 0 0 4px;
  font-weight: 600;
}

.vista-cita .sitio,
.lista-fuentes .sitio {
  color: var(--texto-suave);
  font-size: 0.8rem;
}

.vista-cita .enlaces {
  display: flex;
  gap: 14px;
  margin-top: 8px;
}

.seguimiento .pregunta {
  margin: 1.6em 0 0.6em;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--fondo-suave);
  font-family: system-ui, sans-serif;
}

.seguimiento .pregunta strong {
  display: block;
  color: var(--texto-suave);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lista-fuentes {
  padding-left: 2.4em;
  font-size: 0.9rem;
  line-height: 1.5;
}

.lista-fuentes li {
  margin-bottom: 0.6em;
  overflow-wrap: anywhere;
}

.estado-pendiente {
  display: block;
  margin-top: 2px;
  color: var(--texto-suave);
  font-size: 0.82rem;
}

.error-pendiente {
  margin: 4px 0 0;
  color: var(--error);
  font-size: 0.82rem;
}

.boton.principal {
  border-color: var(--acento);
  background: var(--acento);
  color: var(--fondo);
}

.boton.principal:hover:not(:disabled) {
  color: var(--fondo);
  opacity: 0.9;
}

.boton.chico {
  display: block;
  min-height: 28px;
  margin-top: 6px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.agregar-contenido {
  display: grid;
  gap: 8px;
  margin: 8px 0 4px;
  font-size: 0.85rem;
}

.agregar-contenido textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  background: var(--fondo-suave);
  color: var(--texto);
  font: 0.85rem/1.5 system-ui, sans-serif;
  resize: vertical;
}

.agregar-contenido input[type="file"] {
  max-width: 100%;
  font-size: 0.8rem;
}

.botones-pendiente {
  display: flex;
  gap: 8px;
}

.rehacer {
  margin: 0 0 1em;
}

.rehaciendo {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--acento-fondo);
  font: 0.9rem system-ui, sans-serif;
}

.lista-fuentes li:target {
  background: var(--acento-fondo);
  outline: 6px solid var(--acento-fondo);
}

.indice {
  font-size: 0.875rem;
  line-height: 1.4;
}

.indice summary {
  padding: 10px 0;
  font-weight: 600;
  cursor: pointer;
}

.indice ol {
  margin: 0;
  padding: 0 0 12px;
  list-style: none;
}

.indice a {
  display: block;
  padding: 5px 10px;
  border-left: 2px solid var(--borde);
  color: var(--texto-suave);
  text-decoration: none;
}

.indice a:hover {
  color: var(--texto);
}

.indice a[aria-current="true"] {
  border-left-color: var(--acento);
  color: var(--acento);
  font-weight: 600;
}

.indice .fila {
  display: flex;
  align-items: stretch;
}

.indice .fila a {
  flex: 1;
  min-width: 0;
}

.indice .plegar {
  flex: none;
  width: 28px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--texto-suave);
  cursor: pointer;
}

.indice .plegar::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

.indice .plegar[aria-expanded="true"]::before {
  transform: rotate(45deg);
}

.indice .plegar:hover {
  background: var(--acento-fondo);
  color: var(--texto);
}

.indice .sub {
  padding: 0 0 4px;
}

.indice .sub a {
  padding: 3px 10px 3px 22px;
  font-size: 0.8125rem;
}

.indice .sub a[aria-current="true"] {
  font-weight: 500;
}

@media (max-width: 1099px) {
  .indice {
    border-bottom: 1px solid var(--borde);
  }
}

/* Con lugar, el índice queda fijo a la izquierda; si no, va arriba y plegado. */
@media (min-width: 1100px) {
  .hoja {
    grid-template-columns: var(--indice) minmax(0, var(--ancho));
    gap: 48px;
    max-width: calc(var(--indice) + var(--ancho) + 80px);
  }

  /* Alineado con el informe, que empieza después del índice. */
  .aviso-muestra {
    max-width: calc(var(--indice) + var(--ancho) + 80px);
    padding-left: calc(var(--indice) + 48px + 16px);
  }

  .indice {
    position: sticky;
    top: 60px;
    align-self: start;
    max-height: calc(100vh - 80px);
    padding-top: 40px;
    overflow-y: auto;
  }

  .indice summary {
    pointer-events: none;
    list-style: none;
  }

  .indice summary::-webkit-details-marker {
    display: none;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 16px;
  }

  h1 {
    font-size: 1.55rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  /* KaTeX no corta las fórmulas en línea: las largas se salían de la pantalla. Como bloque en línea
     con scroll, la base queda abajo; por eso se centran con el texto. */
  .formula:not(.destacada) {
    display: inline-block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    vertical-align: middle;
  }

  .herramientas {
    padding: 8px 12px;
  }

  .boton {
    padding: 0 10px;
  }
}

@media print {
  /* En papel, siempre claro. */
  :root[data-tema="oscuro"] {
    --fondo: #ffffff;
    --fondo-suave: #f5f6f8;
    --texto: #1d2127;
    --texto-suave: #5b6472;
    --borde: #dfe3e8;
    --acento: #0b5cad;
    --acento-fondo: #e7f0fa;
    color-scheme: light;
  }

  :root[data-tema="oscuro"] .tema-claro {
    display: block;
  }

  :root[data-tema="oscuro"] .tema-oscuro {
    display: none;
  }

  .herramientas,
  .aviso-muestra,
  .indice,
  .vista-cita,
  .conexion,
  .solo-pagina {
    display: none !important;
  }

  .hoja {
    display: block;
    max-width: none;
    padding: 0;
  }

  body {
    font-size: 11pt;
  }

  h2 {
    break-after: avoid;
  }

  .tabla {
    overflow: visible;
    break-inside: avoid;
  }
}
