/* Tema claro / oscuro: transición del cambio, selector de apariencia y lo que no es solo color
   (logos). Los valores de cada tema viven en core/tokens.css; la lógica, en assets/lib/tema.js. */

/* ── Transición del cambio ───────────────────────────────────────────
   Con origen (la persona tocó el selector): la vista nueva entra como un círculo que crece desde el
   botón, animado por tema.js; aquí se apagan el fundido y la mezcla por defecto para que no se cruce.
   Sin origen (cambió el sistema u otra pestaña): el fundido por defecto, algo más lento. */
:root.is-theme-reveal::view-transition-old(root),
:root.is-theme-reveal::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

:root.is-theme-transition:not(.is-theme-reveal)::view-transition-group(root) {
  animation-duration: 0.32s;
}

/* Navegadores sin View Transitions: fundido de colores breve (tema.js quita la clase al terminar). */
:root.is-theme-fading,
:root.is-theme-fading *,
:root.is-theme-fading *::before,
:root.is-theme-fading *::after {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    outline-color 0.3s ease,
    fill 0.3s ease,
    stroke 0.3s ease,
    box-shadow 0.3s ease !important;
}

/* ── Logos con versión por tema ──────────────────────────────────────
   Donde el logo va sobre fondo claro se pintan las dos versiones y se muestra la del esquema vigente.
   Al imprimir manda siempre la versión para fondo claro. */
@media screen {
  :root[data-scheme='dark'] .logo-tema--claro,
  :root:not([data-scheme='dark']) .logo-tema--oscuro {
    display: none !important;
  }
}

@media print {
  .logo-tema--oscuro {
    display: none !important;
  }
}

/* La versión para fondo oscuro es la misma marca con menos margen: toma la proporción de la clara
   (928 × 307) para ocupar la misma caja y que el encabezado no salte al cambiar de tema. */
.logo-tema--oscuro {
  aspect-ratio: 928 / 307;
  object-fit: contain;
  padding-inline: 2px;
}

/* ── Selector de apariencia (_partials/theme_switch.html.twig) ────── */
.theme-switch {
  display: inline-flex;
  flex: none;
}

.theme-switch--menu .theme-switch__trigger {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

/* Botón suelto sobre un panel oscuro: igual que el de cerrar sesión del sidebar. */
.theme-switch--menu.theme-switch--oscuro .theme-switch__trigger {
  color: color-mix(in srgb, var(--fg-on-dark) 40%, transparent);
}

.theme-switch--oscuro .theme-switch__trigger:hover,
.theme-switch--oscuro .theme-switch__trigger[aria-expanded='true'] {
  background: color-mix(in srgb, var(--fg-on-dark) 10%, transparent);
  color: var(--fg-on-dark);
}

.theme-switch--oscuro .theme-switch__trigger:focus-visible {
  outline: 2px solid var(--fg-on-dark);
  outline-offset: 2px;
}

/* En el encabezado del portal: botón redondo como el resto de las acciones del encabezado. */
.theme-switch--menu.theme-switch--claro .theme-switch__trigger {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--fg);
}

.theme-switch--claro .theme-switch__trigger:hover,
.theme-switch--claro .theme-switch__trigger[aria-expanded='true'] {
  border-color: var(--fg);
  box-shadow: var(--shadow-sm);
}

.theme-switch--claro .theme-switch__trigger:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

/* Los tres íconos ocupan la misma celda; el de la preferencia vigente entra girando. */
.theme-switch__icons {
  display: inline-grid;
  flex: none;
}

.theme-switch__trigger-icon {
  grid-area: 1 / 1;
  display: grid;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
  transition: opacity 0.2s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

:root[data-theme='system'] .theme-switch__trigger-icon--system,
:root[data-theme='light'] .theme-switch__trigger-icon--light,
:root[data-theme='dark'] .theme-switch__trigger-icon--dark {
  opacity: 1;
  transform: none;
}

/* Panel: popover nativo (capa superior); tema.js lo deja junto al botón. Entra con un leve desliz. */
.theme-switch__panel {
  position: fixed;
  inset: auto;
  width: 248px;
  margin: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  opacity: 1;
  transform: none;
  transition:
    opacity 0.16s ease,
    transform 0.16s ease,
    overlay 0.16s ease allow-discrete,
    display 0.16s ease allow-discrete;
}

.theme-switch__panel:not(:popover-open) {
  opacity: 0;
  transform: translateY(4px) scale(0.98);
}

@starting-style {
  .theme-switch__panel:popover-open {
    opacity: 0;
    transform: translateY(4px) scale(0.98);
  }
}

.theme-switch__fieldset,
.theme-switch--integrado {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.theme-switch__legend {
  padding: 6px 10px 8px;
  color: var(--fg-soft);
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.theme-switch__options {
  display: grid;
  gap: 2px;
}

.theme-switch__option {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 10px 6px 6px;
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.theme-switch__option:hover {
  background: color-mix(in srgb, var(--fg) 6%, transparent);
  color: var(--fg);
}

/* El radio queda accesible (teclado, lector de pantalla) pero lo dibuja la fila entera. */
.theme-switch__radio {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.theme-switch__option:has(.theme-switch__radio:focus-visible) {
  outline: 2px solid var(--fg);
  outline-offset: -2px;
}

.theme-switch__option-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  color: var(--fg-muted);
  transition: background 0.15s, color 0.15s;
}

.theme-switch__option-text {
  display: grid;
  gap: 1px;
  line-height: 1.25;
}

.theme-switch__option-text small {
  color: var(--fg-soft);
  font-size: 12px;
}

.theme-switch__check {
  display: grid;
  color: var(--fg);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s ease, transform 0.2s ease;
}

.theme-switch__option:has(.theme-switch__radio:checked) {
  color: var(--fg);
  font-weight: 600;
}

.theme-switch__option:has(.theme-switch__radio:checked) .theme-switch__option-icon {
  background: var(--fill-ink);
  color: var(--fg-on-ink);
}

.theme-switch__option:has(.theme-switch__radio:checked) .theme-switch__check {
  opacity: 1;
  transform: none;
}

/* Integrado (menú móvil del portal): las tres opciones como botones en fila, al estilo del idioma. */
.theme-switch--integrado {
  display: grid;
  gap: 8px;
}

.theme-switch--integrado .theme-switch__legend {
  padding: 0;
}

.theme-switch--integrado .theme-switch__options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.theme-switch--integrado .theme-switch__option {
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 4px;
  min-height: 62px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  text-align: center;
}

.theme-switch--integrado .theme-switch__option-icon {
  width: 26px;
  height: 26px;
}

.theme-switch--integrado .theme-switch__option-text small,
.theme-switch--integrado .theme-switch__check {
  display: none;
}

.theme-switch--integrado .theme-switch__option:has(.theme-switch__radio:checked) {
  border-color: var(--fg);
  background: color-mix(in srgb, var(--line) 35%, var(--surface));
}

@media (prefers-reduced-motion: reduce) {
  .theme-switch__trigger-icon,
  .theme-switch__panel,
  .theme-switch__check,
  .theme-switch__option,
  .theme-switch__option-icon {
    transition: none;
  }
}
