/*
 * precurs-ux.css — experiència comuna a totes les pàgines de Precurs
 *
 *  - Transicions suaus entre pàgines (View Transitions entre documents:
 *    Chrome/Edge 126+, Safari 18.2+; la resta de navegadors canvien de pàgina com sempre).
 *  - Animació en prémer qualsevol botó (es fa servir la propietat `scale`, que se suma
 *    a les transformacions que ja tingui cada botó i no les trepitja).
 *  - Barra de progrés fina mentre es carrega la pàgina següent.
 *  - Contorn visible en navegar amb el teclat.
 *
 * Es carrega ABANS dels estils de cada pàgina i fa servir :where() (especificitat 0),
 * de manera que qualsevol estil propi de la pàgina sempre mana.
 */

/* ---------- 0. Base estable ---------- */
/* El text no es fa gran sol en girar el mòbil; lletra més neta; la pàgina no «salta» quan s'obre un modal */
:where(html) { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scrollbar-gutter: stable; }
:where(body) { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
@media (prefers-reduced-motion: no-preference) { :where(html) { scroll-behavior: smooth; } }
:where(img) { max-width: 100%; }

/* ---------- 1. Transicions entre pàgines ---------- */
@view-transition {
    navigation: auto;
}

::view-transition-old(root) {
    animation: pux-sortir 220ms cubic-bezier(0.4, 0, 1, 1) both;
}
::view-transition-new(root) {
    animation: pux-entrar 380ms cubic-bezier(0.2, 0.8, 0.2, 1) 40ms both;
}

/* La barra inferior del mòbil queda quieta entre pàgines */
.mobile-bottom-bar {
    view-transition-name: pux-barra-inferior;
}
::view-transition-group(pux-barra-inferior) {
    animation-duration: 0s;
    z-index: 100;
}
::view-transition-old(pux-barra-inferior),
::view-transition-new(pux-barra-inferior) {
    animation-duration: 180ms;
}

@keyframes pux-sortir {
    to { opacity: 0; }
}
@keyframes pux-entrar {
    from { opacity: 0; transform: translateY(24px) scale(0.985); }
}

/* ---------- 2. Botons ---------- */
:where(button, a[class*="btn"], input[type="submit"], input[type="button"], [role="button"], .mobile-bottom-bar a) {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: scale 0.16s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.2s ease, color 0.2s ease,
                border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

:is(button, a[class*="btn"], input[type="submit"], input[type="button"], .mobile-bottom-bar a):not(:disabled):not([aria-disabled="true"]):not([class*="container"]):not(.btn-group):not(.btn-send):not(.btn-clean):not(.nav):active {
    scale: 0.96;
}

/* Les targetes d'anuncis (són enllaços fets amb JavaScript) també responen al toc */
:is(.product-card, [role="link"][data-href]):active {
    scale: 0.985;
}
:where(.product-card, [role="link"][data-href]) {
    transition: scale 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.25s ease, box-shadow 0.25s ease;
}

/* Contorn per a qui navega amb el teclat (no apareix en fer clic) */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid #15803d;
    outline-offset: 2px;
}

/* ---------- 3. Imatges que apareixen suaument en carregar-se ---------- */
/* Només s'amaguen si precurs-ux.js s'ha carregat; i si una foto triga massa, apareix igualment */
img.pux-img {
    transition: opacity 0.35s ease;
}
html.pux-js img.pux-img:not(.pux-carregada) {
    opacity: 0;
    animation: pux-mostra 0.3s ease 4s forwards;
}
@keyframes pux-mostra {
    to { opacity: 1; }
}

/* ---------- 4. Barra de progrés en canviar de pàgina ---------- */
#pux-barra {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 100%;
    z-index: 2147483646;
    pointer-events: none;
    background: linear-gradient(90deg, #22c55e, #15803d);
    box-shadow: 0 0 8px rgba(21, 128, 61, 0.45);
    transform-origin: 0 50%;
    transform: scaleX(0);
    opacity: 0;
}
#pux-barra.pux-actiu {
    opacity: 1;
    animation: pux-progres 2.4s cubic-bezier(0.1, 0.6, 0.2, 1) forwards;
}
@keyframes pux-progres {
    0%   { transform: scaleX(0.05); }
    40%  { transform: scaleX(0.55); }
    100% { transform: scaleX(0.88); }
}

/* Navegadors sense transicions entre pàgines: la pàgina actual s'esvaeix una mica */
html.pux-sortint body {
    transition: opacity 0.18s ease;
    opacity: 0.55;
}

/* ---------- 5. Transicions amb direcció (endavant / enrere) ---------- */
/* precurs-ux.js marca el tipus de navegació: endavant = la pàgina nova entra per la dreta; enrere = per l'esquerra */
html:active-view-transition-type(endavant)::view-transition-old(root) { animation: pux-surt-esq 260ms cubic-bezier(0.4, 0, 1, 1) both; }
html:active-view-transition-type(endavant)::view-transition-new(root) { animation: pux-entra-dreta 420ms cubic-bezier(0.2, 0.8, 0.2, 1) 40ms both; }
html:active-view-transition-type(enrere)::view-transition-old(root) { animation: pux-surt-dreta 260ms cubic-bezier(0.4, 0, 1, 1) both; }
html:active-view-transition-type(enrere)::view-transition-new(root) { animation: pux-entra-esq 420ms cubic-bezier(0.2, 0.8, 0.2, 1) 40ms both; }
@keyframes pux-surt-esq { to { opacity: 0; transform: translateX(-44px) scale(0.97); } }
@keyframes pux-entra-dreta { from { opacity: 0; transform: translateX(64px) scale(0.985); } }
@keyframes pux-surt-dreta { to { opacity: 0; transform: translateX(44px) scale(0.97); } }
@keyframes pux-entra-esq { from { opacity: 0; transform: translateX(-64px) scale(0.985); } }

/* La foto de l'anunci «vola» de la targeta a la pàgina del producte */
::view-transition-group(pux-foto) {
    animation-duration: 420ms;
    animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 50;
}
::view-transition-old(pux-foto),
::view-transition-new(pux-foto) {
    height: 100%;
    object-fit: cover;
    overflow: clip;
}

/* Amb transicions natives, la capa antiga amb el logo girant ja no cal (tapava l'animació) */
html.pux-vt .page-transition { display: none !important; }

/* ---------- 6. Aparicions en fer scroll ---------- */
html.pux-js .pux-revela {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
    transition: opacity 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition-delay: var(--pux-retard, 0ms);
}
html.pux-js .pux-revela.pux-vist {
    opacity: 1;
    transform: none;
}

/* Targetes d'anunci: la foto s'apropa una mica en passar-hi per sobre (ordinador) */
@media (hover: hover) and (pointer: fine) {
    :where(.card, .product-card) img {
        transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.35s ease;
    }
    :where(.card, .product-card):hover img {
        transform: scale(1.06);
    }
}

/* ---------- 7. Ona en tocar un botó ---------- */
.pux-ona-capa {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: inherit;
    pointer-events: none;
}
.pux-ona {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    background: currentColor;
    opacity: 0.22;
    transform: scale(0);
    animation: pux-ona 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
@keyframes pux-ona {
    to { transform: scale(1); opacity: 0; }
}

/* ---------- 8. Esquelet mentre es carrega (llampec suau) ---------- */
.pux-esquelet {
    color: transparent !important;
    border-radius: 8px;
    background: linear-gradient(90deg, #eef2f0 25%, #f8faf9 45%, #eef2f0 65%) 0 0 / 300% 100%;
    animation: pux-llampec 1.3s ease-in-out infinite;
    user-select: none;
}
.pux-esquelet * { visibility: hidden; }
.pux-esquelet:empty { display: block; min-height: 3.2em; }
@keyframes pux-llampec {
    from { background-position: 100% 0; }
    to { background-position: 0 0; }
}

/* Contingut que entra en ordre (p. ex. la fitxa del producte un cop carregada) */
.pux-entra > * {
    animation: pux-puja 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.pux-entra > *:nth-child(2) { animation-delay: 60ms; }
.pux-entra > *:nth-child(3) { animation-delay: 120ms; }
.pux-entra > *:nth-child(4) { animation-delay: 180ms; }
.pux-entra > *:nth-child(5) { animation-delay: 240ms; }
.pux-entra > *:nth-child(n+6) { animation-delay: 300ms; }
@keyframes pux-puja {
    from { opacity: 0; transform: translateY(14px); }
}

/* Petit «bot» per a icones que canvien d'estat (favorit, notificacions…) */
.pux-bot { animation: pux-bot 0.45s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes pux-bot {
    0% { transform: scale(1); }
    35% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* ---------- 9. Moviment reduït ---------- */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }
    :is(button, a[class*="btn"], input[type="submit"], input[type="button"], .mobile-bottom-bar a, .product-card):active {
        scale: none;
    }
    img.pux-img { transition: none; }
    #pux-barra.pux-actiu { animation: none; transform: scaleX(0.7); }
    html.pux-js .pux-revela { opacity: 1; transform: none; transition: none; }
    .pux-ona, .pux-entra > *, .pux-bot { animation: none !important; }
    .pux-esquelet { animation: none; }
    :where(.card, .product-card):hover img { transform: none; }
}
