/* ==========================================================================
   Site-wide Animations & Transitions
   Smooth, polished animations for better UX
   ========================================================================== */

/* ============================================
   Keyframe Animations
   ============================================ */

/* Fade in from bottom (for new messages, activity items) */
@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Fade in from top (for loading older messages) */
@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Simple fade in */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Scale and fade in (for modals, popups) */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Shimmer loading effect */
@keyframes shimmer {
  0% {
    background-position: -468px 0;
  }
  100% {
    background-position: 468px 0;
  }
}

/* Pulse (for notifications, live indicators) */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.05);
  }
}

/* Bounce (for new message indicators) */
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px);
  }
  60% {
    transform: translateY(-4px);
  }
}

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

/* Glow effect */
@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 5px rgba(var(--primary-rgb, 139, 92, 246), 0.3);
  }
  50% {
    box-shadow: 0 0 20px rgba(var(--primary-rgb, 139, 92, 246), 0.6);
  }
}

/* Spin (for loading spinners) */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   Utility Classes
   ============================================ */

/* New item animation */
.animate-new {
  animation: slideInUp 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Loading older items animation */
.animate-old {
  animation: slideInDown 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Simple fade in */
.animate-fade-in {
  animation: fadeIn 200ms ease-out;
}

/* Scale in animation */
.animate-scale-in {
  animation: scaleIn 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Pulse animation */
.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Bounce animation */
.animate-bounce {
  animation: bounce 1s ease infinite;
}

/* Shake animation */
.animate-shake {
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

/* Glow animation */
.animate-glow {
  animation: glow 2s ease-in-out infinite;
}

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

/* ============================================
   Smooth Transitions
   ============================================ */

/* Default smooth transition for interactive elements */
.transition-smooth {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Transform transitions (hover effects) */
.transition-transform {
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Color transitions */
.transition-colors {
  transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

/* Opacity transitions */
.transition-opacity {
  transition: opacity 0.2s ease;
}

/* ============================================
   Hover Effects
   ============================================ */

/* Lift on hover */
.hover-lift {
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease;
}

.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Scale on hover */
.hover-scale {
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Glow on hover */
.hover-glow {
  transition: box-shadow 0.3s ease;
}

.hover-glow:hover {
  box-shadow: 0 0 20px rgba(var(--primary-rgb, 139, 92, 246), 0.5);
}

/* Brighten on hover */
.hover-brighten {
  transition: filter 0.2s ease;
}

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

/* Slide right on hover */
.hover-slide-right {
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.hover-slide-right:hover {
  transform: translateX(4px);
}

/* ============================================
   Loading States
   ============================================ */

/* Loading skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0px,
    rgba(255, 255, 255, 0.1) 40px,
    rgba(255, 255, 255, 0.05) 80px
  );
  background-size: 468px 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  border-radius: 0;
}

/* Loading spinner */
.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary, #8b5cf6);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Loading dots */
.loading-dots {
  display: inline-flex;
  gap: 4px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  background: var(--text, #fff);
  border-radius: 50%;
  animation: pulse 1.4s ease-in-out infinite;
}

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

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

/* Loading bar (for top of page) */
.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary, #8b5cf6), var(--accent, #ec4899));
  transform-origin: left;
  animation: loadingBar 2s ease-in-out infinite;
  z-index: 99999;
}

@keyframes loadingBar {
  0% {
    transform: scaleX(0);
  }
  50% {
    transform: scaleX(0.7);
  }
  100% {
    transform: scaleX(1);
    opacity: 0;
  }
}

/* ============================================
   Stagger Animations (for lists)
   ============================================ */

.stagger-children > * {
  animation: slideInUp 300ms cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

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

/* ============================================
   Message-Specific Animations
   ============================================ */

/* Highlight new message briefly */
@keyframes highlightNew {
  0% {
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.2);
  }
  100% {
    background: transparent;
  }
}

.message-highlight-new {
  animation: highlightNew 1.5s ease-out;
}

/* ============================================
   Scroll Indicators
   ============================================ */

/* Scroll to bottom button animation */
.scroll-indicator {
  position: absolute;
  bottom: 80px;
  right: 16px;
  padding: 10px 16px;
  background: var(--primary, #8b5cf6);
  color: white;
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: bounce 2s ease infinite;
  transition: transform 0.2s ease, opacity 0.2s ease;
  z-index: 100;
}

.scroll-indicator:hover {
  transform: translateY(-2px);
  animation: none;
}

.scroll-indicator.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ============================================
   Reduced Motion Support
   ============================================ */

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .animate-pulse,
  .animate-bounce,
  .animate-glow,
  .animate-spin {
    animation: none !important;
  }
}

/* ============================================
   Performance Optimizations
   ============================================ */

/* Use GPU acceleration for transforms */
.gpu-accelerate {
  transform: translateZ(0);
  will-change: transform;
}

/* Smooth scrolling */
.smooth-scroll {
  scroll-behavior: smooth;
}

/* ============================================
   Custom Easing Functions
   ============================================ */

.ease-out-expo {
  transition-timing-function: cubic-bezier(0.19, 1, 0.22, 1);
}

.ease-in-out-back {
  transition-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.ease-spring {
  transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
