/* Movimiento de la tienda (js/tienda-motion.js): entrada de las cards y bloques al aparecer en pantalla,
   fundido de las imágenes al terminar de cargar, esqueletos del scroll infinito, barra de navegación
   y transición entre páginas.
   - Lo que se oculta para animar depende de html.tm-js, que agrega un script del <head> solo si el
     navegador puede animar y la persona no pidió menos movimiento. Sin esa clase todo se ve normal.
   - Si el script no llega a iniciar (html.tm-listo), a los 2,5 s todo aparece igual: nada queda oculto.
   - Solo se animan transform y opacity. La entrada usa fill "backwards" para no pisar el hover de la card. */
:root {
    --tm-salida: cubic-bezier(.16, 1, .3, 1);
    --tm-resorte: cubic-bezier(.34, 1.56, .64, 1);
    --tm-entrada: 520ms;
    --tm-corta: 180ms;
}

/* ---------- Entrada al aparecer en pantalla ---------- */
.tm-js .tm-r:not(.tm-in) {
    opacity: 0;
}

.tm-js:not(.tm-listo) .tm-r:not(.tm-in) {
    animation: tm-seguro 0s linear 2.5s forwards;
}

.tm-js .tm-r.tm-in {
    animation: tm-entrar var(--tm-entrada) var(--tm-salida) var(--tm-retraso, 0ms) backwards;
}

.tm-js .tm-r.tm-in.tm-suave {
    animation-name: tm-entrar-suave;
}

@keyframes tm-entrar {
    from {
        opacity: 0;
        transform: translateY(18px) scale(.97);
    }
}

@keyframes tm-entrar-suave {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
}

@keyframes tm-seguro {
    to { opacity: 1; }
}

/* ---------- Imagen de la card: brillo de espera y fundido al cargar ---------- */
.tm-js .product.pc .pc-media::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: linear-gradient(100deg, transparent 30%, rgb(255 255 255 / .75) 50%, transparent 70%) #F1F5F3;
    background-size: 200% 100%;
    animation: tm-brillo 1.3s ease-in-out infinite;
    transition: opacity .35s ease;
}

.tm-js .product.pc .pc-media.tm-img-lista::before {
    opacity: 0;
    animation: none;
}

.tm-js .product.pc .pc-media img {
    position: relative;
    z-index: 1;
    opacity: 0;
    transition: opacity .45s ease, transform .4s var(--tm-salida);
}

.tm-js .product.pc .pc-media.tm-img-lista img {
    opacity: 1;
}

.tm-js .product.pc .pc-media .pc-sin-imagen {
    position: relative;
    z-index: 1;
}

@keyframes tm-brillo {
    from { background-position: 150% 0; }
    to { background-position: -50% 0; }
}

/* ---------- Esqueletos del scroll infinito (productos/indexSinFiltro) ---------- */
.tm-esqueleto {
    display: flex;
    flex-direction: column;
    border: 1px solid #DEE7E3;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
    animation: tm-entrar-suave .3s var(--tm-salida) backwards;
}

.tm-esqueleto-media,
.tm-esqueleto-linea {
    background: linear-gradient(100deg, transparent 30%, rgb(255 255 255 / .75) 50%, transparent 70%) #EEF3F1;
    background-size: 200% 100%;
    animation: tm-brillo 1.3s ease-in-out infinite;
}

.tm-esqueleto-media {
    aspect-ratio: 1 / 1;
}

.tm-esqueleto-cuerpo {
    display: grid;
    gap: 9px;
    padding: 14px 16px 18px;
    border-top: 1px solid #F0F4F2;
}

.tm-esqueleto-linea {
    height: 11px;
    border-radius: 6px;
}

.tm-esqueleto-linea:nth-child(1) { width: 38%; }
.tm-esqueleto-linea:nth-child(2) { width: 88%; }
.tm-esqueleto-linea:nth-child(3) { width: 58%; height: 20px; margin-top: 8px; }

.tm-esqueleto-linea:nth-child(2) { animation-delay: .08s; }
.tm-esqueleto-linea:nth-child(3) { animation-delay: .16s; }

/* Con esqueletos el spinner sobra a la vista; queda para los lectores de pantalla */
.tu-scroll-infinito .spinner-border.tm-solo-lector {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    border: 0;
}

/* ---------- Toques: botón y favorito ---------- */
.product.pc .pc-btn {
    transition: background-color .15s, color .15s, transform var(--tm-corta) var(--tm-salida);
}

.product.pc .pc-btn:active:not(:disabled) {
    transform: scale(.96);
}

.product.pc .pc-fav {
    transition: opacity .2s, transform var(--tm-corta) var(--tm-salida);
}

.product.pc .pc-fav:active {
    transform: scale(.88);
}

.product.pc .pc-fav.tm-latido i {
    animation: tm-latido .5s var(--tm-resorte);
}

@keyframes tm-latido {
    0% { transform: scale(1); }
    35% { transform: scale(1.35); }
    65% { transform: scale(.92); }
    100% { transform: scale(1); }
}

/* ---------- Barra de navegación (arriba de todo al ir a otra página) ---------- */
.tm-barra {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2000;
    width: 100%;
    height: 3px;
    background: var(--tu-acento);
    box-shadow: 0 0 10px var(--tu-acento);
    transform: scaleX(0);
    transform-origin: 0 50%;
    opacity: 0;
    pointer-events: none;
}

.tm-barra.tm-activa {
    opacity: 1;
    transform: scaleX(.85);
    transition: transform 6s cubic-bezier(.1, .7, .2, 1), opacity .15s;
}

/* ---------- Transición entre páginas de la tienda (Chrome, Edge y Safari 18.2+) ---------- */
@media (prefers-reduced-motion: no-preference) {
    @view-transition {
        navigation: auto;
    }

    /* El header queda quieto; cambia el resto de la página */
    #app {
        view-transition-name: tienda-header;
    }

    ::view-transition-old(root) {
        animation: tm-vt-sale 160ms ease-in both;
    }

    ::view-transition-new(root) {
        animation: tm-vt-entra 300ms var(--tm-salida) both;
    }
}

@keyframes tm-vt-sale {
    to { opacity: 0; }
}

@keyframes tm-vt-entra {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .tm-esqueleto,
    .tm-esqueleto-media,
    .tm-esqueleto-linea,
    .product.pc .pc-fav.tm-latido i {
        animation: none;
    }

    .product.pc .pc-btn:active:not(:disabled),
    .product.pc .pc-fav:active {
        transform: none;
    }

    .tm-barra.tm-activa {
        transition: opacity .15s;
    }
}
