/* State transitions. src/components/motion.js names what moves or fades, and only
   while a transition runs, so nothing here changes a screen at rest. */
:root {
  --motion-ease: cubic-bezier(.32, .72, 0, 1);
  --motion-page: 340ms;
  --motion-step: 300ms;
  --motion-tab: 280ms;
  --motion-rows: 150ms;
  --motion-pop: 220ms;
  --motion-panel: 320ms;
  --motion-close: 200ms;
  --motion-menu: 170ms;
  --motion-drawer: 280ms;
}
/* Phones move further and slower; desktop takes two thirds of that. */
@media (pointer: coarse), (max-width: 760px) {
  :root {
    --motion-page: 500ms;
    --motion-step: 450ms;
    --motion-tab: 420ms;
    --motion-pop: 320ms;
    --motion-panel: 460ms;
    --motion-close: 280ms;
    --motion-menu: 230ms;
    --motion-drawer: 400ms;
  }
}
html[data-motion-input="key"] {
  --motion-page: 240ms;
  --motion-step: 240ms;
  --motion-tab: 220ms;
}

@keyframes motion-fade-out { to { opacity: 0; } }
@keyframes motion-fade-in { from { opacity: 0; } }
@keyframes motion-pop-in { from { opacity: 0; transform: scale(.96); } }
@keyframes motion-pop-out { to { opacity: 0; transform: scale(.96); } }
@keyframes motion-panel-in { from { opacity: 0; transform: translateY(-10px) scale(.97); } }
@keyframes motion-panel-out { to { opacity: 0; transform: translateY(-10px) scale(.97); } }
@keyframes motion-drawer-in { from { transform: translateX(-100%); } }
@keyframes motion-drawer-out { to { transform: translateX(-100%); } }
@keyframes motion-menu-in { from { opacity: 0; transform: scale(.96); } }
@keyframes motion-menu-out { to { opacity: 0; transform: scale(.96); } }
@keyframes motion-slide-out { to { opacity: 0; transform: translateX(calc(var(--motion-dir, 1) * -18px)); } }
/* A carried title changes font size on its way, and hands over mid-flight. */
@keyframes motion-title-out {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(var(--title-dx, 0px), var(--title-dy, 0px)) scale(var(--title-scale, 1)); }
}
@keyframes motion-title-hide { 0%, 35% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes motion-title-show { 0%, 45% { opacity: 0; } 60%, 100% { opacity: 1; } }

/* Dialogs grow out of the control that opened them; the shade follows. These
   come before the component styles in the page, hence the html prefix. */
html [data-slot=dialog-content][data-state=open] { animation: motion-pop-in var(--motion-pop) var(--motion-ease); }
html [data-slot=dialog-overlay][data-state=open] { animation: motion-fade-in var(--motion-pop) linear; }

/* The assistant panel drops down from its button in the top bar. */
html [data-slot=sheet-content].visa-assistant[data-state=open] {
  animation: motion-panel-in var(--motion-panel) var(--motion-ease);
}

/* The phone menu slides in from the left edge. It is a sheet that calls its
   content "sidebar", so the sheet rules above do not reach it. */
html [data-slot=sidebar][data-mobile=true] { transition: none; }
html [data-slot=sidebar][data-mobile=true][data-state=open] {
  animation: motion-drawer-in var(--motion-drawer) var(--motion-ease);
}
html [data-slot=sidebar][data-mobile=true][data-state=closed] {
  animation: motion-drawer-out var(--motion-drawer) var(--motion-ease);
}
html [data-slot=sheet-overlay][data-state=open] { animation: motion-fade-in var(--motion-drawer) linear; }
html [data-slot=sheet-overlay][data-state=closed] { animation: motion-fade-out var(--motion-drawer) linear; }

/* Menus unfold from the corner of the control they belong to. */
html [data-slot=select-content][data-state=open] { animation: motion-menu-in var(--motion-menu) var(--motion-ease); }
html [data-slot=select-content][data-state=closed] { animation: motion-menu-out var(--motion-menu) var(--motion-ease); }

@media (prefers-reduced-motion: reduce) {
  html [data-slot=dialog-content][data-state=open],
  html [data-slot=dialog-overlay][data-state=open],
  html [data-slot=sheet-content][data-state=open],
  html [data-slot=sidebar][data-state=open],
  html [data-slot=sheet-overlay][data-state=open],
  html [data-slot=select-content][data-state=open] { animation: motion-fade-in 150ms linear !important; }
  html [data-slot=sheet-content][data-state=closed],
  html [data-slot=sidebar][data-state=closed],
  html [data-slot=sheet-overlay][data-state=closed],
  html [data-slot=select-content][data-state=closed] { animation: motion-fade-out 150ms linear !important; }
}

/* View transitions. While one runs, the viewport itself is not captured: Chrome
   then paints the page live and lets clicks through, and a named element
   becomes a snapshot that stops taking clicks. Only the outgoing page is named,
   so the incoming one is on screen and clickable from the first frame. The
   theme switch captures the viewport for its circle reveal, hence the scope.
   Engines that read pointer-events on the overlay get the second rule. */
html[data-motion] {
  view-transition-name: none;
}
::view-transition { pointer-events: none; }
/* Where the focusVisible option of focus() is missing, the app marks the element. */
[data-motion-pointer]:focus-visible { outline: none; box-shadow: none; }

/* The underline of a tab row, drawn as a bar so it can slide between tabs. */
.motion-inked { position: relative; }
.motion-inked [role=tab] { border-bottom-color: transparent; }
.motion-ink {
  position: absolute;
  background: var(--focus);
  pointer-events: none;
}
html[data-motion] .motion-ink { view-transition-name: tab-ink; }
@media (min-width: 761px) {
  html[data-motion="page"] .nav-item.active { view-transition-name: nav-active; }
}

/* 1. A whole page changes. The outgoing copy fades away on top of the incoming
      page, which is live underneath, so the frame around it stays still and
      nothing blinks. */
html[data-motion]::view-transition-group(page-out) { z-index: 2; }
html[data-motion="page"]::view-transition-old(page-out) {
  animation: motion-fade-out calc(var(--motion-page) * .5) var(--motion-ease) both;
}
html[data-motion="step"]::view-transition-old(page-out) {
  animation: motion-fade-out calc(var(--motion-step) * .5) var(--motion-ease) both;
}

/* 2. A case is carried between a table row and its page header: one avatar
      travels, and the name changes size on its way to the title. */
html[data-motion]::view-transition-group(case-avatar),
html[data-motion]::view-transition-group(case-title-in),
html[data-motion]::view-transition-group(case-title-out) { z-index: 3; }
html[data-motion]::view-transition-group(case-avatar) {
  animation-duration: var(--motion-page);
  animation-timing-function: var(--motion-ease);
}
html[data-motion]::view-transition-old(case-avatar),
html[data-motion]::view-transition-new(case-avatar) {
  animation-duration: var(--motion-page);
  animation-timing-function: linear;
}
html[data-motion]::view-transition-old(case-title-out) {
  transform-origin: left top;
  animation:
    motion-title-out var(--motion-page) var(--motion-ease) both,
    motion-title-hide var(--motion-page) linear both;
}
html[data-motion]::view-transition-new(case-title-in) {
  animation: motion-title-show var(--motion-page) linear both;
}

/* 3. The highlight of the side navigation glides to the section just opened. */
html[data-motion="page"]::view-transition-group(nav-active) {
  z-index: 3;
  animation-duration: var(--motion-page);
  animation-timing-function: var(--motion-ease);
}
html[data-motion="page"]::view-transition-old(nav-active),
html[data-motion="page"]::view-transition-new(nav-active) {
  animation-duration: var(--motion-page);
  animation-timing-function: linear;
}

/* 4. A summary tile or chart panel fades away above the interactive filtered list.
      Returning to the summary brings the original tile back. */
html[data-motion]::view-transition-group(card-source),
html[data-motion]::view-transition-group(card-out-child-0),
html[data-motion]::view-transition-group(card-out-child-1),
html[data-motion]::view-transition-group(card-out-child-2),
html[data-motion]::view-transition-group(card-out-child-3),
html[data-motion]::view-transition-group(card-in-child-0),
html[data-motion]::view-transition-group(card-in-child-1),
html[data-motion]::view-transition-group(card-in-child-2),
html[data-motion]::view-transition-group(card-in-child-3) { z-index: 3; }
html[data-motion="card"]::view-transition-group(card-source),
html[data-motion="card-back"]::view-transition-group(card-source) {
  overflow: clip;
  animation-duration: var(--motion-page);
  animation-timing-function: var(--motion-ease);
}
html[data-motion]::view-transition-image-pair(card-source) { overflow: clip; }
html[data-motion="card"]::view-transition-old(card-source) {
  animation: motion-fade-out calc(var(--motion-page) * .5) var(--motion-ease) both;
  animation-delay: calc(var(--motion-page) * .5);
}
html[data-motion="card-back"]::view-transition-old(card-source) {
  animation: motion-fade-out calc(var(--motion-page) * .4) var(--motion-ease) both;
}
html[data-motion="card-back"]::view-transition-new(card-source),
html[data-motion]::view-transition-new(card-in-child-0),
html[data-motion]::view-transition-new(card-in-child-1),
html[data-motion]::view-transition-new(card-in-child-2),
html[data-motion]::view-transition-new(card-in-child-3) {
  animation: motion-fade-in calc(var(--motion-page) * .55) linear both;
  animation-delay: calc(var(--motion-page) * .45);
}
html[data-motion]::view-transition-old(card-out-child-0),
html[data-motion]::view-transition-old(card-out-child-1),
html[data-motion]::view-transition-old(card-out-child-2),
html[data-motion]::view-transition-old(card-out-child-3) {
  animation: motion-fade-out calc(var(--motion-page) * .3) var(--motion-ease) both;
}

/* 5. Switching tabs slides the underline, then the outgoing section steps aside
      in the direction opposite to the tab that was picked; the new section is
      already live underneath. */
html[data-motion]::view-transition-group(tab-ink) { z-index: 4; }
html[data-motion="tab"]::view-transition-group(tab-ink) {
  animation-duration: var(--motion-tab);
  animation-timing-function: var(--motion-ease);
}
html[data-motion="step"]::view-transition-group(tab-ink) {
  animation-duration: var(--motion-step);
  animation-timing-function: var(--motion-ease);
}
html[data-motion]::view-transition-old(tab-ink),
html[data-motion]::view-transition-new(tab-ink) { animation: none; }
html[data-motion="tab"]::view-transition-group(tab-body-out) { z-index: 2; }
html[data-motion="tab"]::view-transition-old(tab-body-out) {
  animation: motion-slide-out calc(var(--motion-tab) * .5) linear both;
}

/* 6. Advancing a case moves the current step dot to the next step. */
html[data-motion="step"]::view-transition-group(step-dot) {
  z-index: 4;
  animation-duration: var(--motion-step);
  animation-timing-function: var(--motion-ease);
}
html[data-motion="step"]::view-transition-old(step-dot),
html[data-motion="step"]::view-transition-new(step-dot) {
  animation-duration: var(--motion-step);
  animation-timing-function: linear;
}

/* 7. Closing a dialog or the assistant: the page underneath is already live,
      so only the outgoing picture shrinks back to where it came from. */
html[data-motion="modal-out"]::view-transition-group(veil-out) { z-index: 2; }
html[data-motion="modal-out"]::view-transition-group(modal-out),
html[data-motion="assistant-out"]::view-transition-group(assistant-out) { z-index: 3; }
html[data-motion="modal-out"]::view-transition-old(veil-out) {
  animation: motion-fade-out var(--motion-close) linear both;
}
html[data-motion="modal-out"]::view-transition-old(modal-out) {
  transform-origin: var(--motion-origin, 50% 50%);
  animation: motion-pop-out var(--motion-close) var(--motion-ease) both;
}
html[data-motion="assistant-out"]::view-transition-old(assistant-out) {
  transform-origin: var(--motion-origin, 100% 0);
  animation: motion-panel-out var(--motion-close) var(--motion-ease) both;
}
