/* ==========================================================================
   Casa Scotia - Animations & Transitions
   Scroll-reveal, keyframes, stagger delays, entrance animations

   TABLE OF CONTENTS:
   1. Scroll Reveal
   2. Stagger Children
   3. Hero Entrance
   4. Keyframes
   5. Loading States
   6. Focus-Visible
   ========================================================================== */

/* ==========================================================================
   1. Scroll Reveal
   ========================================================================== */

/* New system (Helio-style) */
.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.5s var(--ease-expo-out),
    transform 0.5s var(--ease-expo-out);
}

.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Legacy system (backwards-compatible) */
.animate-on-scroll {
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.6s var(--ease-expo-out),
    transform 0.6s var(--ease-expo-out);
}

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

/* ==========================================================================
   2. Stagger Children
   ========================================================================== */

/* New system: reveal-stagger (children animate in sequence) */
.reveal-stagger > * {
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.4s var(--ease-expo-out),
    transform 0.4s var(--ease-expo-out);
}

.reveal-stagger.is-visible > *:nth-child(1) { transition-delay: 0ms; }
.reveal-stagger.is-visible > *:nth-child(2) { transition-delay: 60ms; }
.reveal-stagger.is-visible > *:nth-child(3) { transition-delay: 120ms; }
.reveal-stagger.is-visible > *:nth-child(4) { transition-delay: 180ms; }
.reveal-stagger.is-visible > *:nth-child(5) { transition-delay: 240ms; }
.reveal-stagger.is-visible > *:nth-child(6) { transition-delay: 300ms; }
.reveal-stagger.is-visible > *:nth-child(7) { transition-delay: 360ms; }

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

/* Legacy stagger: data-delay attributes */
[data-delay="0"] { transition-delay: 0ms; }
[data-delay="1"] { transition-delay: 60ms; }
[data-delay="2"] { transition-delay: 120ms; }
[data-delay="3"] { transition-delay: 180ms; }
[data-delay="4"] { transition-delay: 240ms; }
[data-delay="5"] { transition-delay: 300ms; }

/* ==========================================================================
   3. Hero Entrance (cascading badge → title → subtitle → CTA)
   ========================================================================== */

.hero__badge {
  animation: badgeEnter 0.6s var(--ease-expo-out) 0.2s both;
}

.hero__title {
  animation: badgeEnter 0.6s var(--ease-expo-out) 0.3s both;
}

.hero__subtitle {
  animation: badgeEnter 0.6s var(--ease-expo-out) 0.45s both;
}

.hero__cta {
  animation: badgeEnter 0.5s var(--ease-expo-out) 0.6s both;
}

/* Page header entrance (for inner pages) */
.page-header .badge {
  animation: badgeEnter 0.6s var(--ease-expo-out) 0.15s both;
}

.page-header .page-header__title,
.hero--compact h1 {
  animation: badgeEnter 0.6s var(--ease-expo-out) 0.25s both;
}

.page-header .page-header__subtitle,
.hero--compact .hero__subtitle {
  animation: badgeEnter 0.6s var(--ease-expo-out) 0.4s both;
}

.page-header .btn {
  animation: badgeEnter 0.5s var(--ease-expo-out) 0.55s both;
}

/* ==========================================================================
   4. Keyframes
   ========================================================================== */

/* Badge / Hero entrance — fade in + slide down from -8px */
@keyframes badgeEnter {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Legacy alias */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Number count-up */
@keyframes countUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-count {
  animation: countUp var(--duration-slow) var(--ease-out) forwards;
}

/* Step number pop-in */
@keyframes numberPop {
  from {
    transform: scale(0.5);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

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

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

/* Spin (loaders) */
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Button spin */
@keyframes buttonSpin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   5. Loading States
   ========================================================================== */

.btn.is-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-right-color: transparent;
  animation: buttonSpin 0.6s linear infinite;
}

/* ==========================================================================
   6. Focus-Visible (supplement to base)
   ========================================================================== */

.btn:focus-visible {
  outline: 3px solid var(--gold-500);
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}

.input:focus-visible {
  border-color: var(--green-500);
  box-shadow: var(--shadow-focus-green);
  outline: none;
}

/* ==========================================================================
   7. Micro-interactions (Batch 5)
   ========================================================================== */

/* Quick estimate result bounce entrance */
@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: translateY(16px);
  }
  60% {
    opacity: 1;
    transform: translateY(-4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.quick-estimate__result.is-visible {
  animation: bounceIn 0.5s var(--ease-expo-out) forwards;
}

/* Guarantee pillar hover animation */
.guarantee-pillar {
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.guarantee-pillar:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(93, 118, 82, 0.15);
}

.guarantee-pillar__icon {
  transition: transform var(--transition-fast);
}

.guarantee-pillar:hover .guarantee-pillar__icon {
  transform: translateY(-2px);
}

/* Chatbot attention pulse — 3 gentle pulses after 10s delay */
@keyframes chatPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.chatbot-toggle {
  animation: chatPulse 0.6s ease-in-out 10s 3;
}

/* FAQ smooth open/close via grid technique */
.faq-item__answer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}

.faq-item[open] .faq-item__answer {
  grid-template-rows: 1fr;
}

.faq-item__answer > * {
  overflow: hidden;
}

/* Assessment progress bar shimmer */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.form__progress-bar {
  position: relative;
  overflow: hidden;
}

.form__progress-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 2s ease-in-out infinite;
}

/* ==========================================================================
   8. Reduced Motion Override
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .quick-estimate__result.is-visible {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .guarantee-pillar:hover {
    transform: none;
  }

  .guarantee-pillar:hover .guarantee-pillar__icon {
    transform: none;
  }

  .chatbot-toggle {
    animation: none;
  }

  .faq-item__answer {
    transition: none;
  }

  .form__progress-bar::after {
    animation: none;
  }

  .form-success-routed:not([hidden]) {
    animation: none;
  }
}
