/* ===========================================================================
   PAGE TRANSITIONS
   ===========================================================================

   Every navigation on this site was a hard cut. The browser tore down one
   document and painted the next, so the masthead - byte-identical on all of
   them - was rebuilt from scratch on each hop, and the page arrived through a
   white frame.

   `navigation: auto` is the entire opt-in. There is no router and no script
   involved: the browser captures the outgoing page, waits for the incoming one,
   and cross-fades the two snapshots itself. Only same-origin navigations where
   BOTH documents opt in are captured, and form submissions never are, so /quote
   and /contact-us POST through untouched. A browser without it (Firefox, as of
   writing) gets exactly the cut it gets today - nothing below is load-bearing.
   =========================================================================== */
@view-transition {
    navigation: auto;
}

/* The incoming page fades in ON TOP of the outgoing one. It is not a
   cross-fade, and the difference matters here.

   The UA default is a symmetric 250ms cross: old ramps 1->0 while new ramps
   0->1. Two copies of the same pixel at complementary opacity do not compose
   back to that pixel - halfway through it is ~75% content over 25% ground - and
   most of this viewport IS the same pixel on both sides, because the masthead,
   the search box and the phone number are identical on every page. So the
   default dips the whole chrome on every click to animate the small part of the
   page that actually changed.

   Instead the new snapshot comes up fast (110ms, ease-out) while the old one
   holds its opacity underneath and only falls away late (180ms, ease-in). By
   the time the outgoing page is meaningfully transparent it is completely
   covered, so the composite stays at ~97% content throughout and the chrome
   simply does not move.

   There is deliberately no translate. An 8px rise on the incoming page is the
   gesture .appear-bottom makes in the hero and it looks right on content that
   differs - but it offsets the identical chrome against itself for the length
   of the fade, which renders as doubled, embossed-looking nav labels and a
   doubled search placeholder. Direction is not worth ghosting every word in the
   masthead. */
@keyframes vt-page-out {
    to {
        opacity: 0;
    }
}

@keyframes vt-page-in {
    from {
        opacity: 0;
    }
}

::view-transition-old(root) {
    animation: vt-page-out 180ms ease-in both;
}

::view-transition-new(root) {
    animation: vt-page-in 110ms ease-out both;
}

/* NOTHING is given a view-transition-name for the cross-document case, and the
   masthead least of all.

   A named element that matches on both sides is carried across rather than
   faded, which is what you want for a bar that holds still. The bar does hold
   still now (the <header> itself is sticky), but the utility strip above it
   scrolls away, so on a scrolled page the outgoing bar sits at the top of the
   viewport and the incoming one below the strip. Naming it would animate it
   from the one position to the other on every click. A masthead that flies in from off-screen on every click is the
   one thing this section is trying not to do. The footer is off-screen for the
   same reason and would do the same in the other direction.

   Unnamed, both simply travel with root, and because they are identical on both
   sides the cross-fade over them resolves to no visible change.
   =========================================================================== */

/* --- Same-document swaps -------------------------------------------------
   The catalog grid and the homepage strip are replaced over AJAX, and both
   replaced instantly: the results of a filter appeared in the same frame the
   old ones vanished, with a spinner doing the work the transition should.

   These names are applied by swapWithTransition() in partials/cards.js for the
   length of the swap and taken off after. A permanent name would also enter the
   cross-document transition above, where a grid that exists on /catalog and not
   on a product page would animate out on its own while the rest faded. */
.js-vt-grid {
    view-transition-name: catalog-grid;
}

.js-vt-strip {
    view-transition-name: homepage-strip;
}

::view-transition-old(catalog-grid),
::view-transition-new(catalog-grid),
::view-transition-group(catalog-grid),
::view-transition-old(homepage-strip),
::view-transition-new(homepage-strip),
::view-transition-group(homepage-strip) {
    animation-duration: 140ms;
}

/* root is captured on every transition, including these, so a filter change
   would cross-fade the whole viewport on top of the grid it is already
   cross-fading. Two identical snapshots at complementary opacity do not
   compose back to the original - the midpoint is ~75% content over 25% ground -
   so the header and the filter rail would dip on every tick of a checkbox.
   swapWithTransition() sets this class on <html> for the duration, which zeroes
   root's animations and leaves only the named region moving.

   The group goes with the two snapshots. A transition runs until its longest
   animation finishes, and root's group carries a 250ms one whether or not
   anything about root changed - which it cannot here, since its box is the
   viewport on both sides. Left in, it held the whole page under a static
   overlay for 110ms after the grid had finished arriving, unscrollable and
   unclickable, to animate nothing. */
html.vt-region-swap::view-transition-group(root),
html.vt-region-swap::view-transition-old(root),
html.vt-region-swap::view-transition-new(root) {
    animation: none;
}

/* Nothing in public/css, resources/views or public/js honoured this, on a site
   whose hero animates its h1, its lead and its CTA on every load.

   Everything here is decorative - a fade-in, a slide, a zoom - so these finish
   instantly rather than merely faster: `forwards` fill means each animation
   still lands on its final frame, so the hero simply renders. The two scripted
   scrolls (back-to-top, and the jump to the sent-confirmation) are outside the
   reach of CSS and check the same query themselves. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .transform-zoom:hover,
    .moving-right:hover,
    .hover-card-effect:hover img,
    .brand-rail__cell:hover .logo-brands,
    .brand-rail__cell:focus-visible .logo-brands {
        transform: none;
    }

    /* The universal selector above does not reach these. ::view-transition-old
       and friends are not descendants of any element that `*` matches - they
       hang off the document root in a tree of their own - so the page
       transitions would have been the one piece of motion on the site that
       ignored the setting. Zeroed here, the browser still runs the transition
       and it still lands on the new page; it just does it in one frame.

       The same query is checked in swapWithTransition() before a transition is
       started at all, so the AJAX swaps do not pay for an overlay they are not
       going to animate. */
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }
}
