/**
 * Optimized Animations Library
 * 
 * Transform-based, hardware-accelerated animations
 * with accessibility support (prefers-reduced-motion)
 * 
 * @package TeamPortal
 * @subpackage Animations
 * @since 2.3.0
 * @version 2.3.0
 */

/**
 * ==========================================
 * ANIMATION VARIABLES (reusable)
 * ==========================================
 */
:root {
  /* Animation Durations */
  --anim-instant: 100ms;
  --anim-fast: 200ms;
  --anim-normal: 300ms;
  --anim-slow: 500ms;
  --anim-slower: 800ms;

  /* Timing Functions (optimized cubic-bezier) */
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1); /* Material Design standard */
  --ease-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275); /* Bounce effect */
  --ease-elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55); /* Elastic effect */
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.6, 1);

  /* Transform Origins */
  --origin-center: center center;
  --origin-top: center top;
  --origin-bottom: center bottom;
  --origin-left: left center;
  --origin-right: right center;
}

/**
 * ==========================================
 * HARDWARE ACCELERATION UTILITIES
 * ==========================================
 */

/* Force GPU acceleration for animations */
.will-animate {
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

.will-animate-color {
  will-change: color, background-color;
}

.will-animate-scale {
  will-change: transform;
  transform: translateZ(0) scale(1);
}

/* Remove will-change after animation */
@media (hover: hover) {
  .will-animate:not(:hover):not(:active) {
    will-change: auto;
  }
}

/**
 * ==========================================
 * FADE ANIMATIONS (Optimized)
 * ==========================================
 */

/* Fade In */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.anim-fade-in {
  animation: fadeIn var(--anim-normal) var(--ease-smooth);
}

/* Fade Out */
@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.anim-fade-out {
  animation: fadeOut var(--anim-normal) var(--ease-smooth);
}

/* Fade In Up (Transform-based) */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate3d(0, 20px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.anim-fade-in-up {
  animation: fadeInUp var(--anim-normal) var(--ease-smooth);
}

/* Fade In Down */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translate3d(0, -20px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.anim-fade-in-down {
  animation: fadeInDown var(--anim-normal) var(--ease-smooth);
}

/**
 * ==========================================
 * SLIDE ANIMATIONS (Transform-based)
 * ==========================================
 */

/* Slide In Right */
@keyframes slideInRight {
  from {
    transform: translate3d(100%, 0, 0);
    opacity: 0;
  }
  to {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

.anim-slide-in-right {
  animation: slideInRight var(--anim-normal) var(--ease-smooth);
}

/* Slide In Left */
@keyframes slideInLeft {
  from {
    transform: translate3d(-100%, 0, 0);
    opacity: 0;
  }
  to {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

.anim-slide-in-left {
  animation: slideInLeft var(--anim-normal) var(--ease-smooth);
}

/* Slide Up */
@keyframes slideUp {
  from {
    transform: translate3d(0, 100%, 0);
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

.anim-slide-up {
  animation: slideUp var(--anim-slow) var(--ease-smooth);
}

/**
 * ==========================================
 * SCALE ANIMATIONS (GPU-accelerated)
 * ==========================================
 */

/* Scale Up */
@keyframes scaleUp {
  from {
    transform: scale3d(0.8, 0.8, 1);
    opacity: 0;
  }
  to {
    transform: scale3d(1, 1, 1);
    opacity: 1;
  }
}

.anim-scale-up {
  animation: scaleUp var(--anim-normal) var(--ease-smooth);
  transform-origin: var(--origin-center);
}

/* Scale Down */
@keyframes scaleDown {
  from {
    transform: scale3d(1.2, 1.2, 1);
    opacity: 0;
  }
  to {
    transform: scale3d(1, 1, 1);
    opacity: 1;
  }
}

.anim-scale-down {
  animation: scaleDown var(--anim-normal) var(--ease-smooth);
  transform-origin: var(--origin-center);
}

/* Pulse (Scale + Opacity) */
@keyframes pulse {
  0%, 100% {
    transform: scale3d(1, 1, 1);
    opacity: 1;
  }
  50% {
    transform: scale3d(1.05, 1.05, 1);
    opacity: 0.8;
  }
}

.anim-pulse {
  animation: pulse 2s var(--ease-smooth) infinite;
}

/* Pulse Gentle */
@keyframes pulseGentle {
  0%, 100% {
    transform: scale3d(1, 1, 1);
  }
  50% {
    transform: scale3d(1.02, 1.02, 1);
  }
}

.anim-pulse-gentle {
  animation: pulseGentle 3s var(--ease-smooth) infinite;
}

/**
 * ==========================================
 * ROTATION ANIMATIONS (Transform-based)
 * ==========================================
 */

/* Spin */
@keyframes spin {
  from {
    transform: rotate3d(0, 0, 1, 0deg);
  }
  to {
    transform: rotate3d(0, 0, 1, 360deg);
  }
}

.anim-spin {
  animation: spin 1s linear infinite;
}

.anim-spin-slow {
  animation: spin 2s linear infinite;
}

/* Rotate In */
@keyframes rotateIn {
  from {
    transform: rotate3d(0, 0, 1, -180deg);
    opacity: 0;
  }
  to {
    transform: rotate3d(0, 0, 1, 0deg);
    opacity: 1;
  }
}

.anim-rotate-in {
  animation: rotateIn var(--anim-slow) var(--ease-smooth);
}

/**
 * ==========================================
 * BOUNCE ANIMATIONS
 * ==========================================
 */

/* Bounce */
@keyframes bounce {
  0%, 100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, -10px, 0);
  }
}

.anim-bounce {
  animation: bounce 2s var(--ease-smooth) infinite;
}

/* Bounce In */
@keyframes bounceIn {
  0% {
    transform: scale3d(0.3, 0.3, 1);
    opacity: 0;
  }
  50% {
    transform: scale3d(1.05, 1.05, 1);
    opacity: 1;
  }
  70% {
    transform: scale3d(0.95, 0.95, 1);
  }
  100% {
    transform: scale3d(1, 1, 1);
  }
}

.anim-bounce-in {
  animation: bounceIn var(--anim-slow) var(--ease-bounce);
}

/**
 * ==========================================
 * SHIMMER/GLOW ANIMATIONS
 * ==========================================
 */

/* Shimmer (Gradient movement) */
@keyframes shimmer {
  0% {
    background-position: -200% center;
  }
  100% {
    background-position: 200% center;
  }
}

.anim-shimmer {
  animation: shimmer 3s linear infinite;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
}

/* Glow */
@keyframes glow {
  from {
    filter: drop-shadow(0 0 0 transparent);
  }
  to {
    filter: drop-shadow(0 0 8px currentColor);
  }
}

.anim-glow {
  animation: glow 2s var(--ease-smooth) infinite alternate;
}

/**
 * ==========================================
 * SPECIAL EFFECTS
 * ==========================================
 */

/* Float */
@keyframes float {
  0%, 100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, -10px, 0);
  }
}

.anim-float {
  animation: float 6s var(--ease-smooth) infinite;
}

/* Shake */
@keyframes shake {
  0%, 100% {
    transform: translate3d(0, 0, 0);
  }
  10%, 30%, 50%, 70%, 90% {
    transform: translate3d(-5px, 0, 0);
  }
  20%, 40%, 60%, 80% {
    transform: translate3d(5px, 0, 0);
  }
}

.anim-shake {
  animation: shake 0.5s var(--ease-smooth);
}

/* Wiggle */
@keyframes wiggle {
  0%, 100% {
    transform: rotate3d(0, 0, 1, 0deg);
  }
  25% {
    transform: rotate3d(0, 0, 1, -5deg);
  }
  75% {
    transform: rotate3d(0, 0, 1, 5deg);
  }
}

.anim-wiggle {
  animation: wiggle 0.5s var(--ease-smooth);
}

/* Ripple Effect (for buttons) */
@keyframes ripple {
  from {
    transform: scale3d(0, 0, 1);
    opacity: 0.5;
  }
  to {
    transform: scale3d(2, 2, 1);
    opacity: 0;
  }
}

.anim-ripple {
  animation: ripple 0.6s linear;
}

/**
 * ==========================================
 * LOADING ANIMATIONS
 * ==========================================
 */

/* Loading Dots */
@keyframes loadingDots {
  0%, 20% {
    opacity: 0.3;
    transform: scale3d(0.8, 0.8, 1);
  }
  50% {
    opacity: 1;
    transform: scale3d(1.2, 1.2, 1);
  }
  100% {
    opacity: 0.3;
    transform: scale3d(0.8, 0.8, 1);
  }
}

.loading-dot {
  animation: loadingDots 1.4s infinite;
}

.loading-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* Progress Bar Shimmer */
@keyframes progressShimmer {
  0% {
    transform: translate3d(-100%, 0, 0);
  }
  100% {
    transform: translate3d(100%, 0, 0);
  }
}

.anim-progress-shimmer {
  animation: progressShimmer 2s linear infinite;
}

/**
 * ==========================================
 * ATTENTION SEEKERS
 * ==========================================
 */

/* Heartbeat */
@keyframes heartbeat {
  0%, 100% {
    transform: scale3d(1, 1, 1);
  }
  14%, 42% {
    transform: scale3d(1.3, 1.3, 1);
  }
  28%, 70% {
    transform: scale3d(1, 1, 1);
  }
}

.anim-heartbeat {
  animation: heartbeat 1.5s var(--ease-smooth) infinite;
}

/* Flash */
@keyframes flash {
  0%, 50%, 100% {
    opacity: 1;
  }
  25%, 75% {
    opacity: 0.3;
  }
}

.anim-flash {
  animation: flash 2s var(--ease-smooth) infinite;
}

/* Swing */
@keyframes swing {
  20% {
    transform: rotate3d(0, 0, 1, 15deg);
  }
  40% {
    transform: rotate3d(0, 0, 1, -10deg);
  }
  60% {
    transform: rotate3d(0, 0, 1, 5deg);
  }
  80% {
    transform: rotate3d(0, 0, 1, -5deg);
  }
  100% {
    transform: rotate3d(0, 0, 1, 0deg);
  }
}

.anim-swing {
  animation: swing 1s var(--ease-smooth);
  transform-origin: top center;
}

/**
 * ==========================================
 * UTILITY CLASSES
 * ==========================================
 */

/* Animation Delays */
.anim-delay-1 { animation-delay: 0.1s; }
.anim-delay-2 { animation-delay: 0.2s; }
.anim-delay-3 { animation-delay: 0.3s; }
.anim-delay-4 { animation-delay: 0.4s; }
.anim-delay-5 { animation-delay: 0.5s; }

/* Animation Durations */
.anim-duration-fast { animation-duration: var(--anim-fast); }
.anim-duration-normal { animation-duration: var(--anim-normal); }
.anim-duration-slow { animation-duration: var(--anim-slow); }
.anim-duration-slower { animation-duration: var(--anim-slower); }

/* Animation Iteration */
.anim-infinite { animation-iteration-count: infinite; }
.anim-once { animation-iteration-count: 1; }
.anim-twice { animation-iteration-count: 2; }

/* Animation Direction */
.anim-alternate { animation-direction: alternate; }
.anim-reverse { animation-direction: reverse; }

/* Animation Fill Mode */
.anim-fill-forwards { animation-fill-mode: forwards; }
.anim-fill-backwards { animation-fill-mode: backwards; }
.anim-fill-both { animation-fill-mode: both; }

/**
 * ==========================================
 * HOVER TRANSITIONS (Optimized)
 * ==========================================
 */

/* Smooth Hover - Transform only */
.hover-lift {
  transition: transform var(--anim-fast) var(--ease-smooth);
}

.hover-lift:hover {
  transform: translate3d(0, -2px, 0);
}

/* Scale on hover */
.hover-scale {
  transition: transform var(--anim-fast) var(--ease-smooth);
}

.hover-scale:hover {
  transform: scale3d(1.05, 1.05, 1);
}

/* Rotate on hover */
.hover-rotate {
  transition: transform var(--anim-normal) var(--ease-smooth);
}

.hover-rotate:hover {
  transform: rotate3d(0, 0, 1, 5deg);
}

/* Glow on hover */
.hover-glow {
  transition: filter var(--anim-fast) var(--ease-smooth);
}

.hover-glow:hover {
  filter: drop-shadow(0 0 8px currentColor);
}

/**
 * ==========================================
 * ACCESSIBILITY: PREFERS-REDUCED-MOTION
 * ==========================================
 */

@media (prefers-reduced-motion: reduce) {
  /* Disable all animations */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Keep essential transforms but make instant */
  .will-animate,
  .hover-lift,
  .hover-scale,
  .hover-rotate {
    transition-duration: 0.01ms !important;
  }

  /* Disable infinite animations completely */
  [class*="anim-pulse"],
  [class*="anim-spin"],
  [class*="anim-bounce"],
  [class*="anim-float"],
  [class*="anim-shimmer"],
  [class*="anim-glow"],
  [class*="anim-heartbeat"],
  [class*="anim-flash"] {
    animation: none !important;
  }
}

/**
 * ==========================================
 * DARK MODE OPTIMIZATIONS
 * ==========================================
 */

[data-theme="dark"] {
  /* Slightly slower animations in dark mode (easier on eyes) */
  --anim-fast: 250ms;
  --anim-normal: 350ms;
  --anim-slow: 550ms;
}

/**
 * ==========================================
 * PERFORMANCE TIPS
 * ==========================================
 * 
 * ✅ DO:
 * - Use transform and opacity (GPU-accelerated)
 * - Add will-change before animation
 * - Remove will-change after animation
 * - Use translate3d() instead of translate()
 * - Use scale3d() instead of scale()
 * - Use rotate3d() instead of rotate()
 * 
 * ❌ DON'T:
 * - Animate width, height, margin, padding
 * - Animate top, left, right, bottom
 * - Animate box-shadow (use drop-shadow filter instead)
 * - Keep will-change permanently
 * - Use too many concurrent animations
 * 
 * 🎯 BEST PRACTICES:
 * - Limit to 2-3 properties per animation
 * - Use shorter durations for micro-interactions
 * - Test on low-end devices
 * - Always support prefers-reduced-motion
 * - Use transforms over position changes
 * 
 * ==========================================
 */
