/**
 * ActivGate Animation Library
 * ===========================
 * Page transitions, scroll animations, and micro-interactions.
 *
 * All animations respect prefers-reduced-motion.
 */

/* ========================================
 * KEYFRAME ANIMATIONS
 * ======================================== */

/* Fade animations */
@keyframes ag-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ag-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Slide animations */
@keyframes ag-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ag-slide-down {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ag-slide-left {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes ag-slide-right {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Scale animations */
@keyframes ag-scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

@keyframes ag-pop {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Bounce animations */
@keyframes ag-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes ag-bounce-subtle {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

/* Pulse animations */
@keyframes ag-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes ag-pulse-scale {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Shake animation (for errors) */
@keyframes ag-shake {
  0%, 100% {
    transform: translateX(0);
  }
  10%, 30%, 50%, 70%, 90% {
    transform: translateX(-4px);
  }
  20%, 40%, 60%, 80% {
    transform: translateX(4px);
  }
}

/* Spin animation */
@keyframes ag-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Ping animation (notification dot) */
@keyframes ag-ping {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* Shimmer animation (loading) */
@keyframes ag-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Progress bar animation */
@keyframes ag-progress {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

/* Stagger rise animation */
@keyframes ag-stagger-rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
 * ANIMATION UTILITY CLASSES
 * ======================================== */

/* Apply animations */
.ag-animate-fade-in { animation: ag-fade-in var(--ag-duration-normal) var(--ag-ease-out) both; }
.ag-animate-fade-out { animation: ag-fade-out var(--ag-duration-normal) var(--ag-ease-out) both; }
.ag-animate-slide-up { animation: ag-slide-up var(--ag-duration-slow) var(--ag-ease-out) both; }
.ag-animate-slide-down { animation: ag-slide-down var(--ag-duration-slow) var(--ag-ease-out) both; }
.ag-animate-slide-left { animation: ag-slide-left var(--ag-duration-slow) var(--ag-ease-out) both; }
.ag-animate-slide-right { animation: ag-slide-right var(--ag-duration-slow) var(--ag-ease-out) both; }
.ag-animate-scale-in { animation: ag-scale-in var(--ag-duration-slow) var(--ag-ease-out) both; }
.ag-animate-pop { animation: ag-pop var(--ag-duration-slower) var(--ag-ease-out) both; }
.ag-animate-bounce { animation: ag-bounce 1s var(--ag-ease-in-out) infinite; }
.ag-animate-pulse { animation: ag-pulse 2s var(--ag-ease-in-out) infinite; }
.ag-animate-shake { animation: ag-shake 0.5s var(--ag-ease-default); }
.ag-animate-spin { animation: ag-spin 1s linear infinite; }
.ag-animate-ping { animation: ag-ping 1s var(--ag-ease-out) infinite; }

/* Animation delays */
.ag-delay-100 { animation-delay: 100ms; }
.ag-delay-200 { animation-delay: 200ms; }
.ag-delay-300 { animation-delay: 300ms; }
.ag-delay-400 { animation-delay: 400ms; }
.ag-delay-500 { animation-delay: 500ms; }
.ag-delay-700 { animation-delay: 700ms; }
.ag-delay-1000 { animation-delay: 1000ms; }

/* Animation durations */
.ag-duration-fast { animation-duration: var(--ag-duration-fast); }
.ag-duration-normal { animation-duration: var(--ag-duration-normal); }
.ag-duration-slow { animation-duration: var(--ag-duration-slow); }
.ag-duration-slower { animation-duration: var(--ag-duration-slower); }

/* ========================================
 * PAGE TRANSITIONS
 * ======================================== */

/**
 * Page transition wrapper
 * Add to <main> or page content container
 */
.ag-page-transition {
  animation: ag-page-enter var(--ag-duration-slow) var(--ag-ease-out) both;
}

@keyframes ag-page-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Page exit (for JS-triggered transitions) */
.ag-page-transition--exit {
  animation: ag-page-exit var(--ag-duration-fast) var(--ag-ease-in) both;
}

@keyframes ag-page-exit {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ========================================
 * STAGGERED ANIMATIONS
 * ======================================== */

/**
 * Staggered list animation
 * Apply .ag-stagger to parent, children will animate in sequence
 */
.ag-stagger > * {
  animation: ag-stagger-rise var(--ag-duration-slow) var(--ag-ease-out) both;
}

.ag-stagger > *:nth-child(1) { animation-delay: 0ms; }
.ag-stagger > *:nth-child(2) { animation-delay: 50ms; }
.ag-stagger > *:nth-child(3) { animation-delay: 100ms; }
.ag-stagger > *:nth-child(4) { animation-delay: 150ms; }
.ag-stagger > *:nth-child(5) { animation-delay: 200ms; }
.ag-stagger > *:nth-child(6) { animation-delay: 250ms; }
.ag-stagger > *:nth-child(7) { animation-delay: 300ms; }
.ag-stagger > *:nth-child(8) { animation-delay: 350ms; }
.ag-stagger > *:nth-child(9) { animation-delay: 400ms; }
.ag-stagger > *:nth-child(10) { animation-delay: 450ms; }
.ag-stagger > *:nth-child(11) { animation-delay: 500ms; }
.ag-stagger > *:nth-child(12) { animation-delay: 550ms; }

/* Faster stagger */
.ag-stagger--fast > *:nth-child(1) { animation-delay: 0ms; }
.ag-stagger--fast > *:nth-child(2) { animation-delay: 30ms; }
.ag-stagger--fast > *:nth-child(3) { animation-delay: 60ms; }
.ag-stagger--fast > *:nth-child(4) { animation-delay: 90ms; }
.ag-stagger--fast > *:nth-child(5) { animation-delay: 120ms; }
.ag-stagger--fast > *:nth-child(6) { animation-delay: 150ms; }

/* ========================================
 * SCROLL-TRIGGERED ANIMATIONS
 * ======================================== */

/**
 * Elements with .ag-reveal will animate when they enter viewport
 * Requires JavaScript intersection observer (see below)
 */
.ag-reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--ag-duration-slow) var(--ag-ease-out),
              transform var(--ag-duration-slow) var(--ag-ease-out);
}

.ag-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Reveal variants */
.ag-reveal--fade {
  transform: none;
}

.ag-reveal--slide-left {
  transform: translateX(20px);
}

.ag-reveal--slide-left.is-visible {
  transform: translateX(0);
}

.ag-reveal--slide-right {
  transform: translateX(-20px);
}

.ag-reveal--slide-right.is-visible {
  transform: translateX(0);
}

.ag-reveal--scale {
  transform: scale(0.95);
}

.ag-reveal--scale.is-visible {
  transform: scale(1);
}

/* Reveal with delay */
.ag-reveal--delay-1 { transition-delay: 100ms; }
.ag-reveal--delay-2 { transition-delay: 200ms; }
.ag-reveal--delay-3 { transition-delay: 300ms; }
.ag-reveal--delay-4 { transition-delay: 400ms; }

/* ========================================
 * HOVER EFFECTS
 * ======================================== */

/* Lift on hover */
.ag-hover-lift {
  transition: transform var(--ag-transition-slow), box-shadow var(--ag-transition-slow);
}

.ag-hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--ag-shadow-lg);
}

/* Scale on hover */
.ag-hover-scale {
  transition: transform var(--ag-transition-slow);
}

.ag-hover-scale:hover {
  transform: scale(1.02);
}

/* Brightness on hover (for images) */
.ag-hover-bright {
  transition: filter var(--ag-transition-slow);
}

.ag-hover-bright:hover {
  filter: brightness(1.1);
}

/* Darken on hover */
.ag-hover-darken {
  transition: filter var(--ag-transition-slow);
}

.ag-hover-darken:hover {
  filter: brightness(0.9);
}

/* Glow on hover */
.ag-hover-glow {
  transition: box-shadow var(--ag-transition-slow);
}

.ag-hover-glow:hover {
  box-shadow: 0 0 20px rgba(46, 116, 184, 0.4);
}

/* Underline on hover */
.ag-hover-underline {
  position: relative;
}

.ag-hover-underline::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: currentColor;
  transition: width var(--ag-transition-slow);
}

.ag-hover-underline:hover::after {
  width: 100%;
}

/* ========================================
 * INTERACTIVE FEEDBACK
 * ======================================== */

/* Button press effect */
.ag-press {
  transition: transform var(--ag-transition-fast);
}

.ag-press:active {
  transform: scale(0.97);
}

/* Ripple effect container */
.ag-ripple {
  position: relative;
  overflow: hidden;
}

.ag-ripple::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.3s, height 0.3s, opacity 0.3s;
  opacity: 0;
}

.ag-ripple:active::after {
  width: 200%;
  height: 200%;
  opacity: 1;
  transition: none;
}

/* Focus ring animation */
.ag-focus-ring {
  transition: box-shadow var(--ag-transition-fast);
}

.ag-focus-ring:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ag-color-brand-primary-softer),
              0 0 0 5px var(--ag-color-brand-primary);
}

/* ========================================
 * LOADING STATES
 * ======================================== */

/* Skeleton shimmer */
.ag-shimmer {
  background: linear-gradient(
    90deg,
    var(--ag-color-bg-page) 0%,
    var(--ag-color-bg-surface) 50%,
    var(--ag-color-bg-page) 100%
  );
  background-size: 200% 100%;
  animation: ag-shimmer 1.5s infinite;
}

/* Progress bar */
.ag-progress-bar {
  height: 4px;
  background: var(--ag-color-bg-page-alt);
  border-radius: var(--ag-radius-full);
  overflow: hidden;
}

.ag-progress-bar__fill {
  height: 100%;
  background: var(--ag-color-brand-primary);
  border-radius: var(--ag-radius-full);
  transition: width var(--ag-transition-slow);
}

.ag-progress-bar--animated .ag-progress-bar__fill {
  animation: ag-progress 2s var(--ag-ease-out);
}

/* Indeterminate progress */
.ag-progress-bar--indeterminate .ag-progress-bar__fill {
  width: 30%;
  animation: ag-progress-indeterminate 1.5s infinite;
}

@keyframes ag-progress-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(400%);
  }
}

/* ========================================
 * NOTIFICATION DOT
 * ======================================== */

.ag-notification-dot {
  position: relative;
}

.ag-notification-dot::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: var(--ag-color-error);
  border-radius: 50%;
  border: 2px solid var(--ag-color-bg-surface);
}

.ag-notification-dot--ping::after {
  animation: ag-ping 1.5s infinite;
}

/* ========================================
 * REDUCED MOTION
 * ======================================== */

/* ========================================
 * DOUBLE-TAP HEART
 * ======================================== */
@keyframes ag-dbl-heart {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  30%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
}

.ag-dbl-heart {
  position: absolute;
  top: 50%; left: 50%;
  font-size: 72px;
  pointer-events: none;
  z-index: 10;
  animation: ag-dbl-heart 0.9s ease-out forwards;
}

@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;
  }

  .ag-reveal {
    opacity: 1;
    transform: none;
  }

  .ag-stagger > * {
    animation: none;
    opacity: 1;
  }

  .ag-page-transition {
    animation: none;
    opacity: 1;
  }

  .ag-dbl-heart {
    animation: none;
  }
}
