/* Page transitions.
   - Blazor's enhanced navigation (most clicks): transitions.js fades the new content in once it is in place.
   - Full page loads (sign-in redirects, the language switch, the sign-in tabs): the browser's cross-document view
     transition below. It keeps the browser's own cross-fade, where the old and new page blend at the same time so the page never
     dips to the background colour, only shorter. The header and the admin menu stay put.
   Nothing moves for visitors who prefer reduced motion, and browsers without the API simply change pages. */

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  .store-header { view-transition-name: site-header; }
  .auth-header { view-transition-name: auth-header; }
  .admin-nav { view-transition-name: admin-nav; }

  ::view-transition-group(site-header),
  ::view-transition-group(auth-header),
  ::view-transition-group(admin-nav) {
    animation-duration: 0s;
  }

  /* The old and new page images inherit this duration and keep the browser's blending. */
  ::view-transition-group(root) {
    animation-duration: 200ms;
  }

  /* Sign in and Create account (two full page loads, AuthShell): only the form slides, towards the tab that was
     picked; the illustration stays put and the tabs cross-fade with the page. js/view-transition-types.js names the
     direction. The Create account tab is on the end side, so in Arabic the slide is mirrored. */
  .auth-body { view-transition-name: auth-form; }
  .auth-side { view-transition-name: auth-side; }

  ::view-transition-group(auth-side) {
    animation-duration: 0s;
  }

  :root { --auth-slide: 32px; }
  :root[dir="rtl"] { --auth-slide: -32px; }
  :root:active-view-transition-type(auth-back) { --auth-slide: -32px; }
  :root[dir="rtl"]:active-view-transition-type(auth-back) { --auth-slide: 32px; }

  :root:active-view-transition-type(auth-forward, auth-back)::view-transition-group(auth-form) {
    animation-duration: 300ms;
  }

  :root:active-view-transition-type(auth-forward, auth-back)::view-transition-old(auth-form) {
    animation: auth-slide-out 140ms cubic-bezier(0.4, 0, 1, 1) both;
  }

  :root:active-view-transition-type(auth-forward, auth-back)::view-transition-new(auth-form) {
    animation: auth-slide-in 240ms cubic-bezier(0, 0, 0.2, 1) 60ms both;
  }

  @keyframes auth-slide-out {
    to { opacity: 0; transform: translateX(calc(-1 * var(--auth-slide))); }
  }

  @keyframes auth-slide-in {
    from { opacity: 0; transform: translateX(var(--auth-slide)); }
  }
}
