/* ==========================================================================
   Pantalla de carga — el recorrido de origen a destino
   --------------------------------------------------------------------------
   El paquete sale del hito de origen y recorre la carretera hasta el destino.
   Al llegar se detiene, el humo se disipa y el destino marca la llegada; recien
   entonces se descubre el sistema.

   El viaje dura --pm-viaje (1.4s). El tope duro de 2s y la coordinacion con la
   carga real del sistema estan en index.html y en Main.hide_preloader: si el
   sistema tarda mas que el viaje, el paquete espera en el destino y no se
   agrega ni un milisegundo de espera artificial.

   Contrato: el contenedor es #loader y se oculta con la clase "done".
   ========================================================================== */

:root {
    --pm-viaje: 1.4s;   /* duracion del recorrido */
    --pm-pista: 340px;  /* ancho de la carretera  */
    --pm-movil: 150px;  /* ancho del paquete      */
}

.loader-body {
    width: 100%;
    height: 100vh;
    background: #ffffff;
    position: fixed;
    z-index: 10000;
    visibility: visible;
    opacity: 1;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .4s ease, visibility .4s ease;
}

.loader-body.done {
    visibility: hidden;
    opacity: 0;
}

.pm-vuelo {
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateY(-4%);
}

/* ── Pista: el area por donde avanza ──────────────────────────────────── */

.pm-pista {
    position: relative;
    width: var(--pm-pista);
    height: 150px;
}

/* ── El viajero: se desplaza de origen a destino, una sola vez ────────── */

.pm-viajero {
    position: absolute;
    bottom: 22px;
    left: 0;
    width: var(--pm-movil);
    animation: pm-recorrido var(--pm-viaje) cubic-bezier(.45, .05, .35, 1) forwards;
}

@keyframes pm-recorrido {
    from { transform: translateX(0); }
    to   { transform: translateX(calc(var(--pm-pista) - var(--pm-movil))); }
}

.pm-paloma {
    width: 100%;
    height: auto;
    display: block;
    position: relative;
    z-index: 2;
    transform-origin: 50% 60%;
    animation: pm-cabeceo 1.15s ease-in-out infinite;
}

/* Cabeceo: sigue aunque el paquete ya haya llegado */
@keyframes pm-cabeceo {
    0%, 100% { transform: translateY(0)    rotate(-1.8deg); }
    50%      { transform: translateY(-9px) rotate(1.8deg);  }
}

/* Al llegar, el cabeceo se vuelve mas calmo */
.loader-body.llego .pm-paloma { animation-duration: 2.2s; }

.pm-sombra {
    position: absolute;
    bottom: -12px;
    left: 50%;
    width: 100px;
    height: 11px;
    margin-left: -50px;
    border-radius: 50%;
    background: rgba(26, 31, 43, .16);
    filter: blur(5px);
    z-index: 1;
    animation: pm-sombra 1.15s ease-in-out infinite;
}

@keyframes pm-sombra {
    0%, 100% { transform: scale(1);   opacity: .5;  }
    50%      { transform: scale(.8);  opacity: .3;  }
}

.loader-body.llego .pm-sombra { animation-duration: 2.2s; }

/* ── Estela de humo: solo mientras viaja ──────────────────────────────── */

.pm-humo {
    position: absolute;
    left: 14px;
    top: 52%;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: rgba(146, 152, 166, .40);
    filter: blur(2px);
    opacity: 0;
    z-index: 0;
    animation: pm-humo .95s linear infinite;
}

.pm-humo:nth-child(1) { animation-delay: 0s;    margin-top: -3px;  }
.pm-humo:nth-child(2) { animation-delay: .19s;  margin-top: -12px; }
.pm-humo:nth-child(3) { animation-delay: .38s;  margin-top: 3px;   }
.pm-humo:nth-child(4) { animation-delay: .57s;  margin-top: -16px; }
.pm-humo:nth-child(5) { animation-delay: .76s;  margin-top: 6px;   }

@keyframes pm-humo {
    0%   { opacity: 0;   transform: translate(0, 0)          scale(.35); }
    12%  { opacity: .55; }
    60%  { opacity: .28; }
    100% { opacity: 0;   transform: translate(-105px, -20px) scale(2.6); }
}

/* Llegada: el humo se disipa y deja de emitir */
.loader-body.llego .pm-humo {
    animation: none;
    opacity: 0;
    transition: opacity .5s ease;
}

/* ── La carretera, con origen y destino ───────────────────────────────── */

.pm-ruta {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    border-radius: 3px;
    background: #eceef2;
    overflow: visible;
}

/* Marcas viales corriendo hacia atras mientras avanza */
.pm-ruta-marcas {
    position: absolute;
    inset: 0;
    border-radius: 3px;
    overflow: hidden;
}
.pm-ruta-marcas::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: calc(100% + 44px);
    background: repeating-linear-gradient(
        90deg,
        #ccd1da 0, #ccd1da 20px,
        transparent 20px, transparent 44px
    );
    animation: pm-marcas .5s linear infinite;
}

@keyframes pm-marcas {
    from { transform: translateX(0);     }
    to   { transform: translateX(-44px); }
}

/* Al llegar, la carretera se detiene */
.loader-body.llego .pm-ruta-marcas::before { animation-play-state: paused; }

/* ── Hitos de origen y destino ────────────────────────────────────────── */

.pm-hito {
    position: absolute;
    bottom: -7px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.pm-hito--inicio { left: 0;  }
.pm-hito--fin    { right: 0; }

.pm-hito i {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid #ccd1da;
    display: block;
}

.pm-hito b {
    margin-top: 9px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
                 Roboto, Helvetica, Arial, sans-serif;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #aeb5c2;
    white-space: nowrap;
}

/* El destino se enciende cuando el paquete llega */
.loader-body.llego .pm-hito--fin i {
    border-color: #2fa36a;
    background: #2fa36a;
    animation: pm-llegada .55s ease-out;
}
.loader-body.llego .pm-hito--fin b { color: #2fa36a; }

@keyframes pm-llegada {
    0%   { transform: scale(1);   box-shadow: 0 0 0 0   rgba(47, 163, 106, .5); }
    100% { transform: scale(1);   box-shadow: 0 0 0 14px rgba(47, 163, 106, 0); }
}

/* ── Texto ────────────────────────────────────────────────────────────── */

.pm-cargando {
    margin: 26px 0 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
                 Roboto, Helvetica, Arial, sans-serif;
    font-size: 12.5px;
    font-weight: 500;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: #98a0b0;
    animation: pm-latido 1.5s ease-in-out infinite;
}

@keyframes pm-latido {
    0%, 100% { opacity: .5; }
    50%      { opacity: 1;  }
}

/* ── Pantallas angostas ───────────────────────────────────────────────── */

@media (max-width: 560px) {
    :root { --pm-pista: 260px; --pm-movil: 118px; }
    .pm-pista    { height: 124px; }
    .pm-sombra   { width: 80px; margin-left: -40px; }
    .pm-hito b   { font-size: 9px; }
}

/* ── Respeto por quien pide menos movimiento ──────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .pm-viajero {
        animation: none;
        transform: translateX(calc(var(--pm-pista) - var(--pm-movil)));
    }
    .pm-paloma,
    .pm-sombra,
    .pm-humo,
    .pm-ruta-marcas::before,
    .pm-cargando {
        animation: none;
    }
    .pm-humo { opacity: 0; }
}
