/* ============================================================
   SELECTOR DE TEMA Y TAMAÑO DE TEXTO
   Menú desplegable compartido por landing, legal y visor.
============================================================ */

.tema-menu {
  position: relative;
  flex-shrink: 0;
}

.tema-menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.tema-menu > summary::-webkit-details-marker {
  display: none;
}

.tema-menu > summary::marker {
  content: "";
}

.tema-menu > summary:focus-visible {
  outline: 3px solid var(--naranja, #f49f1e);
  outline-offset: 3px;
}

/* El disparador de la landing es texto; en el visor y legal es circular. */
.tema-menu > .boton-contraste {
  border-radius: 8px;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.tema-menu > .boton-contraste:hover,
.tema-menu[open] > .boton-contraste {
  background: #eef3f6;
  color: var(--azul-900, #004b6f);
}

.tema-menu > .boton-contraste:hover svg,
.tema-menu[open] > .boton-contraste svg {
  color: var(--naranja-500, #d9842b);
}

.tema-menu[open] > .btn-contraste-nav {
  background: var(--azul-900, #004b6f);
  border-color: var(--azul-900, #004b6f);
  color: #ffffff;
}

/* ------------------------------------------------------------
   Panel
------------------------------------------------------------ */
.tema-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 12px);
  z-index: 1200;
  width: 304px;
  padding: 18px;
  background: #ffffff;
  color: var(--azul-900, #004b6f);
  border: 1px solid #dce7ee;
  border-radius: 14px;
  box-shadow:
    0 22px 50px -20px rgba(11, 31, 42, 0.35),
    0 2px 8px rgba(11, 31, 42, 0.06);
  font-family: "Source Sans 3", system-ui, sans-serif;
  animation: tema-panel-in 0.16s ease-out both;
}

.tema-panel::before {
  content: "";
  display: block;
  width: 34px;
  height: 3px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: var(--naranja, #f49f1e);
}

@keyframes tema-panel-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tema-panel {
    animation: none;
  }
}

.tema-panel-titulo {
  margin: 0 0 8px;
  color: #5b6b75;
  font-family: "Source Sans 3", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.tema-panel-titulo--texto {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #e5edf2;
}

.tema-opcion {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 14px;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease;
}

.tema-opcion + .tema-opcion {
  margin-top: 2px;
}

/* Muestra visual del tema, sin depender solo del texto. */
.tema-opcion::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #c7d6df;
  background: #ffffff;
  box-shadow:
    inset 0 0 0 3px #ffffff,
    inset 0 0 0 4px rgba(11, 31, 42, 0.05);
}

.tema-opcion[data-tema-opcion="oscuro"]::before {
  background: #0b1a24;
  border-color: #2a4654;
  box-shadow: none;
}

.tema-opcion[data-tema-opcion="contraste"]::before {
  background: #000000;
  border: 2px solid #ffd400;
  box-shadow: none;
}

/* Check dibujado, no un glifo tipográfico. */
.tema-opcion::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg) translateY(-1px);
  opacity: 0;
}

.tema-opcion:hover {
  background: #f2f7fa;
  color: #004b6f;
}

.tema-opcion:hover::before {
  border-color: #8fb0c2;
}

.tema-opcion.is-active,
.tema-opcion[aria-pressed="true"] {
  background: #edf4f8;
  border-color: #d7e6ee;
  color: #004b6f;
  font-weight: 600;
}

.tema-opcion.is-active::after,
.tema-opcion[aria-pressed="true"]::after {
  opacity: 1;
}

.tema-texto {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #f4f8fb;
  border: 1px solid #e1ebf1;
  border-radius: 10px;
}

.tema-texto button {
  flex: 1;
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #4d606b;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 0.16s ease,
    color 0.16s ease;
}

.tema-texto button:hover {
  background: #e6eef4;
  color: #004b6f;
}

.tema-texto button.is-active,
.tema-texto button[aria-pressed="true"] {
  background: #004b6f;
  color: #ffffff;
}

/* ------------------------------------------------------------
   Tema oscuro
------------------------------------------------------------ */
html[data-tema="oscuro"] .tema-panel {
  background: #0f2633;
  color: #eef5f8;
  border-color: #2a4654;
  box-shadow:
    0 24px 55px -20px rgba(0, 0, 0, 0.8),
    0 2px 8px rgba(0, 0, 0, 0.3);
}

html[data-tema="oscuro"] .tema-panel::before {
  background: var(--naranja);
}

html[data-tema="oscuro"] .tema-panel-titulo {
  color: #b7c6cf;
}

html[data-tema="oscuro"] .tema-panel-titulo--texto {
  border-top-color: #2a4654;
}

html[data-tema="oscuro"] .tema-opcion {
  color: #eef5f8;
}

html[data-tema="oscuro"] .tema-opcion:hover {
  background: rgba(147, 210, 255, 0.1);
  color: #ffffff;
}

html[data-tema="oscuro"] .tema-opcion:hover::before {
  border-color: #93d2ff;
}

html[data-tema="oscuro"] .tema-opcion.is-active,
html[data-tema="oscuro"] .tema-opcion[aria-pressed="true"] {
  background: rgba(244, 159, 30, 0.14);
  border-color: rgba(244, 159, 30, 0.4);
  color: #ffb43a;
}

html[data-tema="oscuro"] .tema-opcion::before {
  border-color: #3b5663;
}

html[data-tema="oscuro"] .tema-opcion[data-tema-opcion="oscuro"]::before {
  border-color: #93d2ff;
}

html[data-tema="oscuro"] .tema-texto {
  background: #0b1a24;
  border-color: #2a4654;
}

html[data-tema="oscuro"] .tema-texto button {
  color: #b7c6cf;
}

html[data-tema="oscuro"] .tema-texto button:hover {
  background: rgba(147, 210, 255, 0.12);
  color: #ffffff;
}

html[data-tema="oscuro"] .tema-texto button.is-active,
html[data-tema="oscuro"] .tema-texto button[aria-pressed="true"] {
  background: var(--naranja);
  color: #081820;
}

html[data-tema="oscuro"] .tema-menu > .boton-contraste:hover,
html[data-tema="oscuro"] .tema-menu[open] > .boton-contraste {
  background: rgba(147, 210, 255, 0.12);
  color: #ffffff;
}

html[data-tema="oscuro"] .tema-menu > .boton-contraste:hover svg,
html[data-tema="oscuro"] .tema-menu[open] > .boton-contraste svg {
  color: #ffb43a;
}

html[data-tema="oscuro"] .tema-menu[open] > .btn-contraste-nav {
  background: var(--azul-700);
  border-color: var(--azul-700);
  color: #081820;
}

/* ------------------------------------------------------------
   Alto contraste
------------------------------------------------------------ */
html[data-contraste="1"] .tema-panel {
  background: #000000;
  color: #ffffff;
  border: 2px solid #ffffff;
  border-radius: 0;
  box-shadow: none;
  animation: none;
}

html[data-contraste="1"] .tema-panel::before {
  background: #ffd400;
}

html[data-contraste="1"] .tema-panel-titulo {
  color: #ffd400;
}

html[data-contraste="1"] .tema-panel-titulo--texto {
  border-top: 2px solid #ffffff;
}

html[data-contraste="1"] .tema-opcion {
  color: #ffffff;
  border-radius: 0;
}

html[data-contraste="1"] .tema-opcion + .tema-opcion {
  margin-top: 0;
}

html[data-contraste="1"] .tema-opcion:hover,
html[data-contraste="1"] .tema-opcion:focus-visible {
  background: #000000;
  color: #ffd400;
  outline: 2px solid #ffd400;
  outline-offset: -2px;
}

html[data-contraste="1"] .tema-opcion.is-active,
html[data-contraste="1"] .tema-opcion[aria-pressed="true"] {
  background: #ffd400;
  border-color: #ffd400;
  color: #000000;
  outline: 0;
}

html[data-contraste="1"] .tema-opcion::before {
  background: #000000;
  border: 2px solid #ffffff;
  box-shadow: none;
}

html[data-contraste="1"] .tema-opcion[data-tema-opcion="claro"]::before {
  background: #ffffff;
}

html[data-contraste="1"] .tema-opcion[data-tema-opcion="contraste"]::before {
  background: #ffd400;
  border-color: #ffffff;
}

html[data-contraste="1"] .tema-panel .tema-opcion.is-active::before,
html[data-contraste="1"] .tema-panel .tema-opcion[aria-pressed="true"]::before {
  border-color: #000000;
}

html[data-contraste="1"] .tema-texto {
  background: #000000;
  border: 2px solid #ffffff;
  border-radius: 0;
}

html[data-contraste="1"] .tema-texto button {
  color: #ffffff;
  border-radius: 0;
}

html[data-contraste="1"] .tema-texto button:hover,
html[data-contraste="1"] .tema-texto button:focus-visible {
  background: #000000;
  color: #ffd400;
  outline: 2px solid #ffd400;
  outline-offset: -2px;
}

html[data-contraste="1"] .tema-texto button.is-active,
html[data-contraste="1"] .tema-texto button[aria-pressed="true"] {
  background: #ffd400;
  color: #000000;
  outline: 0;
}

html[data-contraste="1"] .tema-menu[open] > .btn-contraste-nav {
  background: #ffd400;
  border-color: #ffd400;
  color: #000000;
}

/* ------------------------------------------------------------
   Adaptación a menús colapsados
------------------------------------------------------------ */
@media (max-width: 1199.98px) {
  .nav-menu .tema-menu {
    width: 100%;
  }

  .nav-menu .tema-panel {
    position: static;
    width: 100%;
    margin-top: 10px;
    border-radius: 12px;
    box-shadow: none;
  }
}

@media (max-width: 1399.98px) {
  #mainNav .navbar-collapse .tema-panel {
    position: static;
    width: 100%;
    margin-top: 10px;
    border-radius: 12px;
    box-shadow: none;
  }
}

/* En la página legal el encabezado no tiene menú colapsable: en pantallas
   estrechas el panel se ancla al encabezado y no al botón para no salirse. */
@media (max-width: 575.98px) {
  .legal-header {
    position: relative;
  }

  .legal-header .tema-menu {
    position: static;
  }

  .legal-header .tema-panel {
    left: 16px;
    right: 16px;
    top: calc(100% + 8px);
    width: auto;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
  }
}

/* ------------------------------------------------------------
   TAMAÑO DE TEXTO
   A / A+ / A++ amplían la interfaz para mejorar la lectura.
------------------------------------------------------------ */
html[data-texto="grande"] body {
  zoom: 1.08;
}

html[data-texto="muy-grande"] body {
  zoom: 1.16;
}

/* En las barras Bootstrap clásicas el menú de tema se integra al
   desplegable para que no se salga del viewport en móvil. */
@media (max-width: 1199.98px) {
  .navbar-collapse .tema-menu {
    width: 100%;
  }

  .navbar-collapse .tema-panel {
    position: static;
    width: 100%;
    margin-top: 10px;
    border-radius: 12px;
    box-shadow: none;
  }
}
