/* ==========================================================
   SIGAE — LOADER INSTITUCIONAL
   Compatible con:
     .loader-body
     .loader
     .loader-body.done

   Mantiene el mecanismo de cierre existente.
   ========================================================== */

.loader-body {
  /* Colores de marca con respaldo para la carga inicial */
  --ld-primary: rgb(var(--sb-theme-rgb, 16, 185, 129));
  --ld-secondary: rgb(
    var(--brand-secondary-rgb, var(--sb-theme-rgb, 16, 185, 129))
  );

  /* Oscuro por defecto */
  --ld-bg: #11161c;
  --ld-text: #dbe4ef;
  --ld-muted: #93a3b6;
  --ld-grid: rgba(255, 255, 255, 0.025);
  --ld-track: rgba(255, 255, 255, 0.09);

  position: fixed;
  inset: 0;
  z-index: 10000;

  width: 100%;
  height: 100vh;
  height: 100dvh;

  margin: 0;
  overflow: hidden;
  isolation: isolate;

  color: var(--ld-text);
  text-align: center;
  font-family: "Inter", system-ui, -apple-system, sans-serif;

  /*
    Dos halos suaves y una retícula casi imperceptible.
    No se utiliza un fondo negro puro.
  */
  background-color: var(--ld-bg);
  background-image:
    radial-gradient(
      ellipse at 42% 42%,
      rgba(var(--sb-theme-rgb, 16, 185, 129), 0.075),
      transparent 48%
    ),
    radial-gradient(
      ellipse at 65% 58%,
      rgba(
        var(--brand-secondary-rgb, var(--sb-theme-rgb, 16, 185, 129)),
        0.045
      ),
      transparent 42%
    ),
    linear-gradient(var(--ld-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--ld-grid) 1px, transparent 1px);

  background-size:
    auto,
    auto,
    56px 56px,
    56px 56px;

  background-position: center;
  background-repeat: no-repeat, no-repeat, repeat, repeat;
  background-attachment: scroll;

  opacity: 1;
  visibility: visible;
  pointer-events: auto;

  transition:
    opacity 320ms ease,
    visibility 0s linear 0s;
}

/* ==========================================================
   LOGOTIPO
   Más pequeño, centrado y separado del indicador.
   ========================================================== */

.loader-body::before {
  content: "";
  position: absolute;

  top: calc(50% - 62px);
  left: 50%;

  width: min(340px, 78vw);
  height: 170px;

  background:
    url("../images/ICONO_SOFT.png")
    center / contain no-repeat;

  transform: translate(-50%, -50%);
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.12));

  animation: sigae-loader-reveal 450ms ease-out both;
}

/* Texto discreto: no simula un progreso inexistente */
.loader-body::after {
  content: "Cargando plataforma";
  position: absolute;

  top: calc(50% + 112px);
  left: 50%;

  width: calc(100% - 40px);

  color: var(--ld-muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.12em;

  transform: translateX(-50%);
}

/* ==========================================================
   INDICADOR ORBITAL
   Aro exterior principal + aro interior secundario.
   ========================================================== */

.loader-body .loader {
  position: absolute;

  top: calc(50% + 67px);
  left: 50%;

  width: 42px;
  height: 42px;
  box-sizing: border-box;
  margin: 0;

  border: 2px solid var(--ld-track);
  border-top-color: var(--ld-primary);
  border-right-color: color-mix(
    in srgb,
    var(--ld-primary) 30%,
    transparent
  );
  border-radius: 50%;

  background: transparent;
  box-shadow: none;

  transform: translate(-50%, -50%);

  animation: sigae-loader-orbit 1050ms linear infinite;
}

.loader-body .loader::before {
  content: "";
  position: absolute;
  inset: 7px;

  box-sizing: border-box;
  border: 1px solid transparent;
  border-bottom-color: var(--ld-secondary);
  border-left-color: color-mix(
    in srgb,
    var(--ld-secondary) 25%,
    transparent
  );
  border-radius: 50%;

  animation: sigae-loader-counter-orbit 1500ms linear infinite;
}

/* ==========================================================
   SALIDA
   Conservar la clase .done que ya añade tu JavaScript.
   ========================================================== */

.loader-body.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  transition:
    opacity 320ms ease,
    visibility 0s linear 320ms;
}

.loader-body.done .loader,
.loader-body.done .loader::before {
  animation-play-state: paused;
}

/* ==========================================================
   MODO CLARO
   Se utiliza el modo del sistema, no el del sidebar.
   ========================================================== */

html.light-style:not(.dark-style) .loader-body {
  --ld-bg: #f4f7fa;
  --ld-text: #233247;
  --ld-muted: #63758b;
  --ld-grid: rgba(35, 50, 71, 0.025);
  --ld-track: rgba(35, 50, 71, 0.10);
}

/* ==========================================================
   ANIMACIONES
   Nombres propios para evitar conflictos con otros spinners.
   ========================================================== */

@keyframes sigae-loader-orbit {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

@keyframes sigae-loader-counter-orbit {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(-360deg);
  }
}

@keyframes sigae-loader-reveal {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 8px));
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

/* ==========================================================
   PANTALLAS PEQUEÑAS
   ========================================================== */

@media (max-width: 480px) {
  .loader-body::before {
    width: min(290px, 82vw);
    height: 150px;
  }

  .loader-body::after {
    font-size: 11px;
    letter-spacing: 0.08em;
  }
}

@media (max-height: 420px) {
  .loader-body::before {
    top: calc(50% - 42px);
    height: 110px;
  }

  .loader-body .loader {
    top: calc(50% + 45px);
    width: 34px;
    height: 34px;
  }

  .loader-body::after {
    top: calc(50% + 78px);
  }
}

/* ==========================================================
   ACCESIBILIDAD
   Indicador estático si se solicita movimiento reducido.
   ========================================================== */

@media (prefers-reduced-motion: reduce) {
  .loader-body,
  .loader-body.done {
    transition: none;
  }

  .loader-body::before,
  .loader-body .loader,
  .loader-body .loader::before {
    animation: none;
  }
}


/* ==========================================================
   AJUSTE: LOGO MÁS GRANDE + FONDO GRAFITO PERMANENTE
   ========================================================== */

/* Sobrescribe también la variante clara del loader */
.loader-body,
html.light-style:not(.dark-style) .loader-body {
  --ld-bg: #16181c;
  --ld-text: #e5e7eb;
  --ld-muted: #a1a8b3;
  --ld-grid: rgba(255, 255, 255, 0.018);
  --ld-track: rgba(255, 255, 255, 0.10);

  color-scheme: dark;
}

/* Logo más grande, manteniendo su proporción */
.loader-body::before {
  width: min(440px, 84vw);
  height: 220px;
  top: calc(50% - 70px);

  filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.20));
}

/* Separación equilibrada respecto al logo */
.loader-body .loader {
  top: calc(50% + 88px);
}

.loader-body::after {
  top: calc(50% + 132px);
  color: var(--ld-muted);
}

/* Móviles */
@media (max-width: 480px) {
  .loader-body::before {
    width: min(350px, 88vw);
    height: 175px;
    top: calc(50% - 55px);
  }

  .loader-body .loader {
    top: calc(50% + 68px);
  }

  .loader-body::after {
    top: calc(50% + 112px);
  }
}

/* Pantallas bajas o móvil horizontal */
@media (max-height: 420px) {
  .loader-body::before {
    width: min(360px, 70vw);
    height: 145px;
    top: calc(50% - 45px);
  }

  .loader-body .loader {
    top: calc(50% + 57px);
  }

  .loader-body::after {
    top: calc(50% + 90px);
  }
}
