/*
  Advanced Animations CSS - Performance Optimized & Visually Upgraded
  Controls scroll animations, loading states, and dynamic effects.

  --- ENHANCEMENTS ---
  - Refined easing curves for smoother scroll animations.
  - Added .animate-blur-in scroll effect.
  - Added .hover-tilt 3D card hover effect.
  - Added .modal-sheet-enter/exit for mobile bottom-sheets.
  - Updated .loading-spinner-glow to use CSS theme variables.
  - Improved 'prefers-reduced-motion' for skeleton loaders.
*/

/* ========================================
   SCROLL ANIMATIONS
======================================== */

.animate-on-scroll {
  opacity: 0;
  transform: translateY(20px);
  /* REFINED: Using a smoother easing curve */
  transition: opacity 0.7s cubic-bezier(0.215, 0.61, 0.355, 1), 
              transform 0.7s cubic-bezier(0.215, 0.61, 0.355, 1);
  will-change: opacity, transform;
}

.animate-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0);
  will-change: auto;
}

/* Staggered animation delays for sequential elements */
.animate-on-scroll:nth-child(1) { transition-delay: 0s; }
.animate-on-scroll:nth-child(2) { transition-delay: 0.1s; }
.animate-on-scroll:nth-child(3) { transition-delay: 0.2s; }
.animate-on-scroll:nth-child(4) { transition-delay: 0.3s; }
.animate-on-scroll:nth-child(5) { transition-delay: 0.4s; }
.animate-on-scroll:nth-child(n+6) { transition-delay: 0.5s; }

/* Alternative animation directions */
.animate-from-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity 0.7s cubic-bezier(0.215, 0.61, 0.355, 1), 
              transform 0.7s cubic-bezier(0.215, 0.61, 0.355, 1);
  will-change: opacity, transform;
}

.animate-from-left.is-visible {
  opacity: 1;
  transform: translateX(0);
  will-change: auto;
}

.animate-from-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.7s cubic-bezier(0.215, 0.61, 0.355, 1), 
              transform 0.7s cubic-bezier(0.215, 0.61, 0.355, 1);
  will-change: opacity, transform;
}

.animate-from-right.is-visible {
  opacity: 1;
  transform: translateX(0);
  will-change: auto;
}

.animate-scale {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.7s cubic-bezier(0.215, 0.61, 0.355, 1), 
              transform 0.7s cubic-bezier(0.215, 0.61, 0.355, 1);
  will-change: opacity, transform;
}

.animate-scale.is-visible {
  opacity: 1;
  transform: scale(1);
  will-change: auto;
}

.animate-fade {
  opacity: 0;
  transition: opacity 0.7s ease-out;
  will-change: opacity;
}

.animate-fade.is-visible {
  opacity: 1;
  will-change: auto;
}

/* NEW: Blur-in animation */
.animate-blur-in {
  opacity: 0;
  filter: blur(8px);
  transform: scale(0.98);
  transition: opacity 0.7s ease-out, filter 0.7s ease-out, transform 0.7s ease-out;
  will-change: opacity, filter, transform;
}

.animate-blur-in.is-visible {
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
  will-change: auto;
}

/* ========================================
   LOADING SPINNERS
======================================== */

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: var(--space-xl) auto;
  will-change: transform;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Enhanced spinner with glow effect */
.loading-spinner-glow {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite, pulse-glow 2s ease-in-out infinite;
  margin: var(--space-xl) auto;
  will-change: transform, box-shadow;
}

@keyframes pulse-glow {
  0%, 100% {
    box-shadow: 0 0 0 0 transparent;
  }
  50% {
    /* REFINED: Uses --accent color with an alpha */
    box-shadow: 0 0 20px 5px color-mix(in srgb, var(--accent) 30%, transparent);
  }
}

/* Dual ring spinner */
.loading-spinner-dual {
  display: inline-block;
  width: 40px;
  height: 40px;
  margin: var(--space-xl) auto;
  position: relative;
}

.loading-spinner-dual::after {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 4px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  border-color: var(--accent) transparent var(--accent) transparent;
  animation: spin 1.2s linear infinite;
  will-change: transform;
}

/* Dots spinner */
.loading-dots {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  align-items: center;
  margin: var(--space-xl) auto;
}

.loading-dots span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce-dot 1.4s infinite ease-in-out both;
  will-change: transform;
}

.loading-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce-dot {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Pulse loader */
.loading-pulse {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  margin: var(--space-xl) auto;
  animation: pulse-scale 1.5s ease-in-out infinite;
  will-change: transform, opacity;
}

@keyframes pulse-scale {
  0%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
}

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

.loading-skeleton {
  width: 100%;
  contain: layout style paint;
}

.skeleton-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-secondary) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  animation: skeleton-shimmer 1.5s infinite;
  will-change: background-position;
}

.skeleton-text {
  width: 100%;
  height: 1rem;
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-secondary) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  animation: skeleton-shimmer 1.5s infinite;
  will-change: background-position;
}

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-text.short {
  width: 40%;
}

.skeleton-text.medium {
  width: 70%;
}

.skeleton-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  overflow: hidden;
  contain: layout style paint;
}

/* Enhanced shimmer animation */
@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Pulse alternative for skeleton */
.skeleton-pulse {
  animation: skeleton-pulse-anim 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  background-color: var(--bg-tertiary);
  will-change: opacity;
}

@keyframes skeleton-pulse-anim {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ========================================
   PROGRESS INDICATORS
======================================== */

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 0.3s ease-out;
  position: relative;
  overflow: hidden;
}

/* Animated progress indicator */
.progress-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: progress-shine 1.5s infinite;
}

@keyframes progress-shine {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* Indeterminate progress */
.progress-bar-indeterminate {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-indeterminate::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 30%;
  background: var(--accent);
  border-radius: var(--radius-full);
  animation: indeterminate-progress 1.5s infinite;
  will-change: transform;
}

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

/* ========================================
   NOTIFICATION ANIMATIONS
======================================== */

/* NEW KEYFRAMES */
@keyframes slideInRight {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}
/* END NEW KEYFRAMES */

.notification-enter {
  animation: slideInRight 0.3s ease-out;
}

.notification-exit {
  animation: slideOutRight 0.3s ease-out;
}


/* Modal animations */
.modal-backdrop-enter {
  animation: fadeIn 0.3s ease-out;
}

.modal-backdrop-exit {
  animation: fadeOut 0.3s ease-in;
}

.modal-content-enter {
  animation: scaleIn 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.modal-content-exit {
  animation: scaleOut 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

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

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

/* NEW: Animations for mobile bottom-sheets */
@keyframes slideInUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes slideOutDown {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

.modal-sheet-enter {
  animation: slideInUp 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.modal-sheet-exit {
  animation: slideOutDown 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
}

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

.hover-lift {
  transition: transform var(--transition-base);
  will-change: transform;
}

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

.hover-grow {
  transition: transform var(--transition-base);
  will-change: transform;
}

.hover-grow:hover {
  transform: scale(1.05);
}

.hover-glow {
  transition: box-shadow var(--transition-base);
  will-change: box-shadow;
}

.hover-glow:hover {
  /* REFINED: Uses theme-aware color */
  box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* NEW: 3D Tilt effect for cards */
.hover-tilt {
  transition: transform 0.3s ease-out;
  will-change: transform;
}
.hover-tilt:hover {
  transform: perspective(1000px) rotateX(2deg) rotateY(-2deg) scale(1.02);
}


/* ========================================
   FLOATING ANIMATION
======================================== */

.float {
  animation: float 3s ease-in-out infinite;
  will-change: transform;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

.float-slow {
  animation: float 6s ease-in-out infinite;
  will-change: transform;
}

/* ========================================
   TYPEWRITER EFFECT
======================================== */

.typewriter {
  overflow: hidden;
  border-right: 2px solid var(--text-primary);
  white-space: nowrap;
  animation: typing 3.5s steps(40) 1s forwards, blink 0.75s step-end infinite;
}

@keyframes typing {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

@keyframes blink {
  50% {
    border-color: transparent;
  }
}

/* ========================================
   RIPPLE EFFECT
======================================== */

.ripple {
  position: relative;
  overflow: hidden;
}

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

.ripple:active::after {
  width: 300px;
  height: 300px;
}

/* ========================================
   COUNTER ANIMATION
======================================== */

@keyframes countUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.counter-animate {
  animation: countUp 0.5s ease-out;
}

/* ========================================
   PARALLAX SCROLL
======================================== */

.parallax-slow {
  will-change: transform;
  transition: transform 0.1s ease-out;
}

.parallax-medium {
  will-change: transform;
  transition: transform 0.15s ease-out;
}

.parallax-fast {
  will-change: transform;
  transition: transform 0.2s ease-out;
}

/* ========================================
   ACCESSIBILITY - REDUCED MOTION
======================================== */

@media (prefers-reduced-motion: reduce) {
  .animate-on-scroll,
  .animate-from-left,
  .animate-from-right,
  .animate-scale,
  .animate-fade,
  .hover-tilt {
    animation: none;
    transition: none;
    opacity: 1;
    transform: none;
  }
  
  .loading-spinner,
  .loading-spinner-glow,
  .loading-spinner-dual::after,
  .loading-dots span,
  .loading-pulse {
    animation: none;
  }
  
  .skeleton-image,
  .skeleton-text {
    /* REFINED: Keep the shimmer but make it very slow */
    animation: skeleton-shimmer 4s infinite;
  }
  
  .float,
  .float-slow,
  .typewriter {
    animation: none;
  }
  
  .progress-bar-fill::after,
  .progress-bar-indeterminate::after {
    animation: none;
  }
  
  * {
    will-change: auto !important;
  }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
======================================== */

/* Use GPU acceleration for animated elements */
.animate-on-scroll,
.animate-from-left,
.animate-from-right,
.animate-scale,
.loading-spinner,
.loading-spinner-glow,
.skeleton-image,
.skeleton-text {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Contain layout for better performance */
.skeleton-card,
.loading-skeleton {
  contain: layout style paint;
}