/* Motion. Rules: transform/opacity only, ease-out for anything entering,
   UI motion under 300ms, nothing on keyboard-driven or theme changes. */

/* Page navigation (htmx boost + View Transitions): only the content column
   crossfades; sidebar and top bar are captured separately and stay still. */
.content { view-transition-name: content; }
::view-transition-old(root), ::view-transition-new(root) { animation: none; }
::view-transition-old(content) { animation: vt-out 120ms ease-out both; }
::view-transition-new(content) { animation: vt-in 200ms var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes vt-fade { from { opacity: 0; } }

/* Request progress: appears only if a request outlives 150ms, then eases
   toward 90% until the response lands. */
.progress.htmx-request {
  opacity: 1;
  transition: opacity 120ms ease 150ms;
  animation: progress 2.4s var(--ease-out) 150ms both;
}
@keyframes progress { from { transform: scaleX(0); } to { transform: scaleX(0.9); } }

/* Filter results swap in place with a quick fade. */
#results { transition: opacity 160ms ease; }
#results.htmx-added { opacity: 0; }
.filters.htmx-request + #results { opacity: 0.55; }

/* First full load of the dashboard: tiles rise in once, 40ms apart. */
html:not(.booted) .metric { animation: rise 280ms var(--ease-out) both; }
html:not(.booted) .metric:nth-child(2) { animation-delay: 40ms; }
html:not(.booted) .metric:nth-child(3) { animation-delay: 80ms; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* Login card settles in once. */
.login { animation: rise 320ms var(--ease-out) both; }

/* Confirm dialog: scales up from just below full size, centered (not anchored
   to a trigger). Exit is faster than enter. */
.dialog {
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 140ms ease-in, transform 140ms ease-in, overlay 140ms allow-discrete, display 140ms allow-discrete;
}
.dialog[open] {
  opacity: 1;
  transform: none;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out), overlay 200ms allow-discrete, display 200ms allow-discrete;
}
@starting-style { .dialog[open] { opacity: 0; transform: scale(0.96); } }
.dialog::backdrop { opacity: 0; transition: opacity 200ms ease, overlay 200ms allow-discrete, display 200ms allow-discrete; }
.dialog[open]::backdrop { opacity: 1; }
@starting-style { .dialog[open]::backdrop { opacity: 0; } }

/* Toast: rises from the bottom edge, leaves the same way (faster). */
.toast { transition: opacity 280ms var(--ease-out), transform 280ms var(--ease-out); }
@starting-style { .toast { opacity: 0; transform: translateY(16px); } }
.toast.is-leaving { opacity: 0; transform: translateY(12px); transition-duration: 180ms; transition-timing-function: ease-in; }

/* Reduced motion: keep fades that explain a change, drop every movement. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-new(content) { animation: vt-fade 160ms ease both; }
  html:not(.booted) .metric, .login { animation: none; }
  .progress.htmx-request { animation: none; transform: scaleX(0.9); }
  .sidebar { transition-property: opacity !important; }
  .dialog, .dialog[open] { transform: none; }
  @starting-style { .dialog[open] { transform: none; } }
  .toast, .toast.is-leaving { transform: none; }
  @starting-style { .toast { transform: none; } }
  .button:active, .icon-button:active, .copy:active { transform: none; }
  .copy-label.is-swapping { filter: none; }
}
