/* ============================================
   Animations - ReceiptIQ
   Micro-interactions and scroll animations
   ============================================ */

/* ----------------------------------------
   Scroll-triggered Animations
   ---------------------------------------- */

/* Fade up animation */
.animate-on-scroll {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

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

/* Fade in (no movement) */
.animate-fade {
  opacity: 0;
  transition: opacity 0.6s ease-out;
}

.animate-fade.visible {
  opacity: 1;
}

/* Scale up */
.animate-scale {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.animate-scale.visible {
  opacity: 1;
  transform: scale(1);
}

/* Slide from left */
.animate-slide-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.animate-slide-left.visible {
  opacity: 1;
  transform: translateX(0);
}

/* Slide from right */
.animate-slide-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.animate-slide-right.visible {
  opacity: 1;
  transform: translateX(0);
}

/* ----------------------------------------
   Stagger Children Animation
   ---------------------------------------- */

.stagger-children > * {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.stagger-children.visible > *:nth-child(1) { transition-delay: 0ms; }
.stagger-children.visible > *:nth-child(2) { transition-delay: 100ms; }
.stagger-children.visible > *:nth-child(3) { transition-delay: 200ms; }
.stagger-children.visible > *:nth-child(4) { transition-delay: 300ms; }
.stagger-children.visible > *:nth-child(5) { transition-delay: 400ms; }
.stagger-children.visible > *:nth-child(6) { transition-delay: 500ms; }
.stagger-children.visible > *:nth-child(7) { transition-delay: 600ms; }
.stagger-children.visible > *:nth-child(8) { transition-delay: 700ms; }
.stagger-children.visible > *:nth-child(9) { transition-delay: 800ms; }
.stagger-children.visible > *:nth-child(10) { transition-delay: 900ms; }

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

/* ----------------------------------------
   Hover Animations
   ---------------------------------------- */

/* Lift effect */
.hover-lift {
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

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

/* Scale effect */
.hover-scale {
  transition: transform var(--transition-base);
}

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

/* Glow effect */
.hover-glow {
  transition: box-shadow var(--transition-base);
}

.hover-glow:hover {
  box-shadow: var(--shadow-glow);
}

/* ----------------------------------------
   Button Press Effect
   ---------------------------------------- */

.btn:active,
.press-effect:active {
  transform: scale(0.98);
}

/* ----------------------------------------
   Carousel / Slider Animations
   ---------------------------------------- */

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

.carousel-slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.5s ease, transform 0.5s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-slide.active {
  position: relative;
  opacity: 1;
  transform: scale(1);
}

.carousel-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ----------------------------------------
   Loading / Skeleton Animation
   ---------------------------------------- */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-tertiary) 25%,
    var(--color-bg-elevated) 50%,
    var(--color-bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

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

/* ----------------------------------------
   Pulse Animation
   ---------------------------------------- */

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

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

/* ----------------------------------------
   Spin Animation
   ---------------------------------------- */

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

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

/* ----------------------------------------
   Bounce Animation
   ---------------------------------------- */

.bounce {
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(-5%);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

/* ----------------------------------------
   Float Animation (subtle)
   ---------------------------------------- */

.float {
  animation: float 6s ease-in-out infinite;
}

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

/* ----------------------------------------
   Gradient Shift Animation
   ---------------------------------------- */

.gradient-shift {
  background-size: 200% 200%;
  animation: gradient-shift 3s ease infinite;
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* ----------------------------------------
   Glow Pulse Animation
   ---------------------------------------- */

.glow-pulse {
  animation: glow-pulse 2s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(99, 102, 241, 0.3); }
  50% { box-shadow: 0 0 40px rgba(99, 102, 241, 0.5); }
}

/* ----------------------------------------
   Shake Animation (for errors)
   ---------------------------------------- */

.shake {
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

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

/* ----------------------------------------
   Typing Animation
   ---------------------------------------- */

.typing::after {
  content: '|';
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ----------------------------------------
   Page Transition
   ---------------------------------------- */

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

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

/* ----------------------------------------
   Mobile: Reduce Motion
   ---------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .animate-on-scroll,
  .animate-fade,
  .animate-scale,
  .animate-slide-left,
  .animate-slide-right,
  .stagger-children > * {
    opacity: 1;
    transform: none;
  }
}

/* ----------------------------------------
   Touch Devices: Simplify Hover
   ---------------------------------------- */

@media (hover: none) {
  .hover-lift:hover,
  .hover-scale:hover {
    transform: none;
  }

  .card:hover {
    transform: none;
    box-shadow: var(--shadow-lg);
  }

  .card:hover::before {
    opacity: 0;
  }
}

/* ----------------------------------------
   Hero Glow Effect
   ---------------------------------------- */

.hero-glow {
  position: absolute;
  top: -200px;
  left: 50%;
  transform: translateX(-50%);
  width: 800px;
  height: 600px;
  background: var(--gradient-hero-glow);
  pointer-events: none;
  z-index: 0;
}

/* ----------------------------------------
   Floating Element Animation
   ---------------------------------------- */

.float-element {
  position: relative;
  animation: float-element 6s ease-in-out infinite;
}

@keyframes float-element {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-5px) rotate(1deg);
  }
  75% {
    transform: translateY(5px) rotate(-1deg);
  }
}

/* ----------------------------------------
   Counter Animation (for stats)
   ---------------------------------------- */

.count-up {
  display: inline-block;
}

/* ----------------------------------------
   Underline Animation for Links
   ---------------------------------------- */

.link-underline {
  position: relative;
  text-decoration: none;
}

.link-underline::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--gradient-primary);
  transition: width var(--transition-base);
}

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

/* ----------------------------------------
   Menu Toggle Animation
   ---------------------------------------- */

.hamburger {
  display: flex;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  padding: var(--space-2);
}

.hamburger-line {
  width: 24px;
  height: 2px;
  background: var(--color-text-primary);
  transition: all var(--transition-base);
  transform-origin: center;
}

.hamburger.active .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active .hamburger-line:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}

.hamburger.active .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ----------------------------------------
   Ripple Effect
   ---------------------------------------- */

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

.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%);
  opacity: 0;
}

.ripple:active::after {
  width: 200%;
  height: 200%;
  opacity: 1;
  transition: width 0.3s ease-out, height 0.3s ease-out, opacity 0.3s ease-out;
}
