/* Movimiento y fluidez del panel, compartido por todas las páginas.

   Un archivo aparte, y no tocando redesign.css, para que el diseño base y
   la capa de movimiento se puedan razonar por separado. Todo lo que anima
   vive bajo `prefers-reduced-motion: no-preference`: quien pidió menos
   movimiento recibe un panel quieto y completo, no uno roto. Va después de
   redesign.css a propósito: las transiciones se suman a lo que ya hay. */

/* --- lo que siempre aplica (no es animación: es respuesta al toque) ----- */

:root { --mv-fast: .16s; --mv-base: .22s; --mv-slow: .42s; }

.btn-primary, .link-extracto, .chip, .sidebar-link, .item, .input,
.p2p-ficha, .p2p-fila, .p2p-btn-rechazar, .status-chip, .stat, .card,
.action, a.p2p-fila {
    transition:
        transform var(--mv-fast) var(--al-ease),
        box-shadow var(--mv-base) var(--al-ease),
        background-color var(--mv-base) var(--al-ease),
        border-color var(--mv-base) var(--al-ease),
        color var(--mv-base) var(--al-ease),
        opacity var(--mv-base) var(--al-ease);
}

/* Presionar se siente: un poco más pequeño, y vuelve. */
.btn-primary:active, .link-extracto:active, .chip:active,
.p2p-btn-rechazar:active, .sidebar-link:active { transform: scale(.985); }

/* El foco por teclado se ve igual en todo el panel. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--al-accent);
    outline-offset: 3px;
    border-radius: 6px;
}

/* La barra superior acompaña el scroll sin tapar: cristal, no muro. */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--al-bg) 78%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.sidebar-link:hover { transform: translateX(2px); }
.p2p-ficha:hover, .p2p-fila:hover { border-color: color-mix(in srgb, var(--al-accent) 45%, var(--al-line)); }
.p2p-ficha:hover { box-shadow: 0 22px 56px rgba(23, 24, 27, .12); }

/* Contenido que se está reemplazando en vivo: se atenúa, no parpadea. */
.is-actualizando { opacity: .55; pointer-events: none; }

/* Barra de tiempo restante de una orden: se ve de un vistazo cuánto queda. */
.p2p-tiempo {
    height: 4px;
    margin-top: 12px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--al-line) 70%, transparent);
    overflow: hidden;
}
.p2p-tiempo > i {
    display: block;
    height: 100%;
    width: var(--restante, 0%);
    border-radius: inherit;
    background: var(--al-green);
    transition: width var(--mv-slow) var(--al-ease), background-color var(--mv-base);
}
.p2p-tiempo.es-apurado > i { background: var(--al-warning); }

/* Indicador de «en vivo» junto al título de la cola. */
.en-vivo {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: var(--al-muted);
}
.en-vivo::before {
    content: ""; width: 7px; height: 7px; border-radius: 50%;
    background: var(--al-green);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--al-green) 45%, transparent);
}
.en-vivo.is-parado::before { background: var(--al-muted); box-shadow: none; }

/* --- lo que se mueve (solo si la persona no pidió lo contrario) --------- */

@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }

    /* Entre páginas: un fundido en vez de un parpadeo blanco. Es progresivo:
       donde el navegador no lo soporta, simplemente navega como siempre. */
    @view-transition { navigation: auto; }
    ::view-transition-old(root) { animation: mv-fuera .18s ease-out both; }
    ::view-transition-new(root) { animation: mv-dentro .26s var(--al-ease) both; }
    @keyframes mv-fuera { to { opacity: 0; } }
    @keyframes mv-dentro { from { opacity: 0; transform: translateY(6px); } }

    /* Al entrar, cada bloque aparece en orden. redesign.css lo hacía solo
       en el tablero; ahora lo hacen todas las páginas. */
    .app-content main > * { animation: al-reveal .46s var(--al-ease) both; }
    .app-content main > *:nth-child(2) { animation-delay: 55ms; }
    .app-content main > *:nth-child(3) { animation-delay: 100ms; }
    .app-content main > *:nth-child(4) { animation-delay: 145ms; }
    .app-content main > *:nth-child(n+5) { animation-delay: 190ms; }
    .p2p-grupo { animation: al-reveal .4s var(--al-ease) both; }
    .p2p-grupo:nth-of-type(2) { animation-delay: 60ms; }
    .p2p-grupo:nth-of-type(3) { animation-delay: 120ms; }
    .p2p-grupo:nth-of-type(4) { animation-delay: 180ms; }

    /* Lo que llega o se va en un refresco en vivo. */
    .p2p-entra { animation: mv-dentro .32s var(--al-ease) both; }

    /* Cuando hay algo esperando tu decisión, el contador respira. */
    .p2p-grupo-cuenta.es-pendiente { animation: mv-latido 2.2s ease-in-out infinite; }
    @keyframes mv-latido { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

    .en-vivo::before { animation: mv-pulso 2.4s ease-out infinite; }
    @keyframes mv-pulso {
        0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--al-green) 45%, transparent); }
        70% { box-shadow: 0 0 0 8px transparent; }
        100% { box-shadow: 0 0 0 0 transparent; }
    }
}

/* Con menos movimiento, la barra superior deja de ser cristal (el blur
   también es movimiento para algunas personas) y nada respira. */
@media (prefers-reduced-motion: reduce) {
    .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--al-bg); }
}
