/* Global motion utilities and shared animations */

/* Stagger entrance for list/grid children */
@keyframes list-item-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slide-up-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 260ms variant for carousel labels */
.slide-up-in-260 {
  animation: slide-up-in 260ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Popover / panel entrance utilities */
.panel-enter {
  animation: scale-in 150ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both,
             slide-up-in 150ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.backdrop-enter {
  animation: backdrop-in 140ms ease both;
}

/* Heart toggle spring animation */
@keyframes heart-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

.heart-animate {
  animation: heart-pop 420ms var(--ease-spring, cubic-bezier(0.34, 1.2, 0.64, 1)) both;
}

/* Result reveal stagger for generation output grids */
.result-reveal > * {
  opacity: 0;
  animation: slide-up-in 320ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.result-reveal > *:nth-child(1) { animation-delay: 0ms; }
.result-reveal > *:nth-child(2) { animation-delay: 80ms; }
.result-reveal > *:nth-child(3) { animation-delay: 160ms; }
.result-reveal > *:nth-child(4) { animation-delay: 240ms; }
.result-reveal > *:nth-child(5) { animation-delay: 320ms; }
.result-reveal > *:nth-child(n+6) { animation-delay: 400ms; }

/* Scroll-triggered entrance: hidden until revealed by IntersectionObserver */
.scroll-entrance {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 480ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)),
              transform 480ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
}

.scroll-entrance.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.scroll-entrance.is-visible > * {
  animation: slide-up-in 380ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.scroll-entrance.is-visible > *:nth-child(1) { animation-delay: 60ms; }
.scroll-entrance.is-visible > *:nth-child(2) { animation-delay: 140ms; }
.scroll-entrance.is-visible > *:nth-child(3) { animation-delay: 220ms; }

/* Chat message entrance animation */
@keyframes chat-message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message-enter {
  animation: chat-message-in 220ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* AnimatedPanel: CSS transition-based enter/exit for popovers */
.animated-panel {
  opacity: 0;
  transform: scale(0.95) translateY(8px);
  transition:
    opacity 140ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)),
    transform 140ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
  pointer-events: none;
}

.animated-panel.is-visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* Ecommerce tool panel crossfade on tool switch */
@keyframes tool-panel-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.tool-panel-enter {
  animation: tool-panel-fade-in 180ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* Stagger utility: apply to parent, children get delayed entrance */
.motion-stagger > * {
  animation: list-item-in 280ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.motion-stagger > *:nth-child(1) { animation-delay: 0ms; }
.motion-stagger > *:nth-child(2) { animation-delay: 40ms; }
.motion-stagger > *:nth-child(3) { animation-delay: 80ms; }
.motion-stagger > *:nth-child(4) { animation-delay: 120ms; }
.motion-stagger > *:nth-child(5) { animation-delay: 160ms; }
.motion-stagger > *:nth-child(6) { animation-delay: 200ms; }
.motion-stagger > *:nth-child(7) { animation-delay: 240ms; }
.motion-stagger > *:nth-child(8) { animation-delay: 280ms; }
.motion-stagger > *:nth-child(9) { animation-delay: 320ms; }
.motion-stagger > *:nth-child(10) { animation-delay: 360ms; }
.motion-stagger > *:nth-child(n+11) { animation-delay: 400ms; }

/* Global reduced-motion override */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
