/**
 * Advanced Animation System
 * Performance-optimized animations with reduced motion support
 * @version 3.0.0
 */

/* Base animation settings */
:root {
  --animation-duration-fast: 0.2s;
  --animation-duration-normal: 0.3s;
  --animation-duration-slow: 0.5s;
  --animation-easing: cubic-bezier(0.4, 0.0, 0.2, 1);
  --animation-easing-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Reduced motion support */
@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;
  }
}

/* Fade animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate3d(0, 30px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translate3d(0, -30px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translate3d(-30px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translate3d(30px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

/* Scale animations */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale3d(0.8, 0.8, 1);
  }
  to {
    opacity: 1;
    transform: scale3d(1, 1, 1);
  }
}

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

/* Bounce animation */
@keyframes bounce {
  0%, 20%, 53%, 80%, 100% {
    animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    transform: translate3d(0, 0, 0);
  }
  40%, 43% {
    animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
    transform: translate3d(0, -8px, 0);
  }
  70% {
    animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
    transform: translate3d(0, -4px, 0);
  }
  90% {
    transform: translate3d(0, -2px, 0);
  }
}

/* Slide animations */
@keyframes slideInUp {
  from {
    transform: translate3d(0, 100%, 0);
    visibility: visible;
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes slideInDown {
  from {
    transform: translate3d(0, -100%, 0);
    visibility: visible;
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

/* Rotation animations */
@keyframes rotateIn {
  from {
    transform-origin: center;
    transform: rotate3d(0, 0, 1, -200deg);
    opacity: 0;
  }
  to {
    transform-origin: center;
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

/* Loading spinner */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Utility classes */
.animate-fade-in {
  animation: fadeIn var(--animation-duration-normal) var(--animation-easing) forwards;
}

.animate-fade-in-up {
  animation: fadeInUp var(--animation-duration-normal) var(--animation-easing) forwards;
}

.animate-fade-in-down {
  animation: fadeInDown var(--animation-duration-normal) var(--animation-easing) forwards;
}

.animate-fade-in-left {
  animation: fadeInLeft var(--animation-duration-normal) var(--animation-easing) forwards;
}

.animate-fade-in-right {
  animation: fadeInRight var(--animation-duration-normal) var(--animation-easing) forwards;
}

.animate-scale-in {
  animation: scaleIn var(--animation-duration-normal) var(--animation-easing) forwards;
}

.animate-bounce {
  animation: bounce var(--animation-duration-slow) var(--animation-easing-bounce);
}

.animate-pulse {
  animation: pulse 2s infinite;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Hover animations */
.hover-lift {
  transition: transform var(--animation-duration-fast) var(--animation-easing);
}

.hover-lift:hover {
  transform: translateY(-2px);
}

.hover-scale {
  transition: transform var(--animation-duration-fast) var(--animation-easing);
}

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

/* Intersection Observer animations */
.animate-on-scroll {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity var(--animation-duration-slow) var(--animation-easing),
              transform var(--animation-duration-slow) var(--animation-easing);
}

.animate-on-scroll.animate-in {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered animations */
.animate-stagger > * {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--animation-duration-normal) var(--animation-easing),
              transform var(--animation-duration-normal) var(--animation-easing);
}

.animate-stagger.animate-in > *:nth-child(1) { transition-delay: 0.1s; }
.animate-stagger.animate-in > *:nth-child(2) { transition-delay: 0.2s; }
.animate-stagger.animate-in > *:nth-child(3) { transition-delay: 0.3s; }
.animate-stagger.animate-in > *:nth-child(4) { transition-delay: 0.4s; }
.animate-stagger.animate-in > *:nth-child(5) { transition-delay: 0.5s; }
.animate-stagger.animate-in > *:nth-child(6) { transition-delay: 0.6s; }

.animate-stagger.animate-in > * {
  opacity: 1;
  transform: translateY(0);
}

/* Button animations */
.btn-animated {
  position: relative;
  overflow: hidden;
  transition: all var(--animation-duration-fast) var(--animation-easing);
}

.btn-animated::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left var(--animation-duration-slow) var(--animation-easing);
}

.btn-animated:hover::before {
  left: 100%;
}

/* Card animations */
.card-animated {
  transition: transform var(--animation-duration-fast) var(--animation-easing),
              box-shadow var(--animation-duration-fast) var(--animation-easing);
}

.card-animated:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

/* Loading states */
.loading-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Progress animations */
.progress-animated .progress-bar {
  transition: width var(--animation-duration-slow) var(--animation-easing);
}

/* Counter animations */
.counter-animated {
  font-variant-numeric: tabular-nums;
}

/* Parallax effect */
.parallax-element {
  will-change: transform;
}

/* Performance optimizations */
.animate-gpu {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Focus animations */
.focus-animated:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-200);
  transition: box-shadow var(--animation-duration-fast) var(--animation-easing);
}

/* Medical-specific animations */
.heartbeat {
  animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
  0% { transform: scale(1); }
  14% { transform: scale(1.1); }
  28% { transform: scale(1); }
  42% { transform: scale(1.1); }
  70% { transform: scale(1); }
}

/* Success/Error state animations */
.success-animation {
  animation: successPulse 0.6s var(--animation-easing);
}

@keyframes successPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); background-color: var(--color-success-100); }
  100% { transform: scale(1); }
}

.error-animation {
  animation: errorShake 0.6s var(--animation-easing);
}

@keyframes errorShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
  20%, 40%, 60%, 80% { transform: translateX(2px); }
}
