/* Motion: page transitions, entrance choreography, HTMX swaps. Everything stops under reduced motion. */

/* Cross-document view transitions: the sidebar and topbar stay put, the active nav pill glides
   to the new item, the page content crossfades. Browsers without support simply navigate. */
@view-transition {
  navigation: auto;
}

@layer components {
  ::view-transition-group(app-sidebar),
  ::view-transition-group(app-topbar) {
    animation: none;
  }
  ::view-transition-old(app-sidebar),
  ::view-transition-old(app-topbar) {
    display: none;
  }
  ::view-transition-new(app-sidebar),
  ::view-transition-new(app-topbar) {
    animation: none;
  }
  ::view-transition-group(nav-active) {
    animation-duration: 380ms;
    animation-timing-function: var(--ease-out);
  }
  ::view-transition-old(root) {
    animation: ui-fade-out 140ms var(--ease) both;
  }
  ::view-transition-new(root) {
    animation: ui-fade-in 200ms var(--ease) both;
  }

  /* ---------- Page entrance: the header, then each block, rise into place ----------
     Fill mode "backwards": once finished, no animation is left holding a transform, which would
     make a containing block for fixed popovers and a stacking context for menus. */
  .page > *,
  .rise > * {
    animation: ui-rise var(--dur-enter) var(--ease-out) backwards;
  }
  .page > :nth-child(2),
  .rise > :nth-child(2) {
    animation-delay: calc(var(--stagger) * 1);
  }
  .page > :nth-child(3),
  .rise > :nth-child(3) {
    animation-delay: calc(var(--stagger) * 2);
  }
  .page > :nth-child(4),
  .rise > :nth-child(4) {
    animation-delay: calc(var(--stagger) * 3);
  }
  .page > :nth-child(5),
  .rise > :nth-child(5) {
    animation-delay: calc(var(--stagger) * 4);
  }
  .page > :nth-child(n + 6),
  .rise > :nth-child(n + 6) {
    animation-delay: calc(var(--stagger) * 5);
  }

  /* Table rows cascade in on first render and after every HTMX swap. */
  .dtable__table tbody tr {
    animation: ui-row-in 360ms var(--ease-out) backwards;
  }
  .dtable__table tbody tr:nth-child(2) {
    animation-delay: 25ms;
  }
  .dtable__table tbody tr:nth-child(3) {
    animation-delay: 50ms;
  }
  .dtable__table tbody tr:nth-child(4) {
    animation-delay: 75ms;
  }
  .dtable__table tbody tr:nth-child(5) {
    animation-delay: 100ms;
  }
  .dtable__table tbody tr:nth-child(6) {
    animation-delay: 125ms;
  }
  .dtable__table tbody tr:nth-child(7) {
    animation-delay: 150ms;
  }
  .dtable__table tbody tr:nth-child(n + 8) {
    animation-delay: 175ms;
  }

  /* Anything HTMX inserts fades in. */
  .htmx-added {
    animation: ui-fade-in var(--dur-slow) var(--ease) backwards;
  }

  /* Cards that lead somewhere lift towards the pointer. */
  .lift {
    transition:
      transform var(--dur-slow) var(--ease-out),
      box-shadow var(--dur-slow) var(--ease-out),
      border-color var(--dur) var(--ease);
  }
  .lift:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-card-hover);
    border-color: var(--cobalt-200);
  }
  .lift:active {
    transform: translateY(-1px);
  }

  @keyframes ui-rise {
    from {
      opacity: 0;
      transform: translateY(14px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
  @keyframes ui-row-in {
    from {
      opacity: 0;
      transform: translateY(6px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
  @keyframes ui-fade-out {
    to {
      opacity: 0;
    }
  }
  @keyframes ui-float {
    0%,
    100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-5px);
    }
  }
  @keyframes ui-grow-x {
    from {
      transform: scaleX(0);
    }
  }
  @keyframes ui-grow-y {
    from {
      transform: scaleY(0);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 1ms !important;
      animation-delay: 0ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 1ms !important;
    }
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
      animation: none !important;
    }
    .lift:hover {
      transform: none;
    }
  }
}
