/* ═══════════════════════════════════════════════════════════════
   View Transitions — desktop SPA route changes
   Browser-native crossfade between pages, GPU-accelerated.
   Mobile keeps its custom slide-in (handled in spa-router.js, the
   helper bails out below the 768px breakpoint).
   ═══════════════════════════════════════════════════════════════ */

/* Respect user's motion preference. */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root),
    ::view-transition-old(spa-main),
    ::view-transition-new(spa-main) {
        animation: none !important;
    }
}

/* Mobile: SPA router already runs a slide-in animation on .main-content.
   Letting the browser also snapshot a root transition over the top causes
   a double-paint and a brief overlay artifact on Android Chrome. */
@media (max-width: 768px) {
    .main-content { view-transition-name: none; }
    ::view-transition-old(root),
    ::view-transition-new(root) { animation: none; }
}

/* The whole main-content is the swap target — give it a name so the
   browser can morph the BEFORE/AFTER snapshots in place rather than
   crossfading the entire root (sidebar/header would flicker). */
@media (min-width: 769px) {
    .main-content {
        view-transition-name: spa-main;
        contain: layout style;
    }

    ::view-transition-old(spa-main) {
        animation: spa-main-out 180ms cubic-bezier(0.4, 0, 0.6, 1) forwards;
    }
    ::view-transition-new(spa-main) {
        animation: spa-main-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1) 20ms backwards;
    }

    /* Root-level transition kept short and subtle — handles cases where
       a route loader mutates persistent UI (theme/realm switch, etc.). */
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 160ms;
        animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
    }
}

@keyframes spa-main-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-6px); }
}
@keyframes spa-main-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
