/* ══════════════════════════════════════════════════════════════════
   ADFLIKER — "How It Works" scroll storytelling
   Scoped entirely to #how-it-works so nothing else on the page moves.
   Only transform / opacity are animated (GPU composited).
   ══════════════════════════════════════════════════════════════════ */

#how-it-works {
  /* Brand tokens pulled from the compiled Tailwind palette */
  --hiw-green: #22c55e;
  --hiw-green-600: #16a34a;
  --hiw-emerald: #10b981;
  --hiw-teal: #14b8a6;
  --hiw-cyan: #06b6d4;
  --hiw-line: #e2e8f0;
  /* slate-200 */
  --hiw-ink: #0f172a;
  --hiw-muted: #64748b;
  --hiw-nav: 72px;
  /* sticky navbar height */
}

/* ──────────────────────────────────────────────────────────────
   1. PINNED STAGE (desktop only)
   The section becomes a full-height stage while it is pinned.
   Spacing is clamped so it never overflows short laptop screens.
   ────────────────────────────────────────────────────────────── */
@media (min-width: 1024px) {

  .hiw-on #how-it-works {
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    align-items: center;
    padding-top: clamp(4.5rem, calc(var(--hiw-nav) + 2vh), 7rem);
    padding-bottom: clamp(2rem, 6vh, 6rem);
  }

  .hiw-on #how-it-works > .relative.z-10 {
    width: 100%;
  }

  /* Header margin collapses on short viewports instead of pushing cards off-screen */
  .hiw-on #how-it-works .hiw-header {
    margin-bottom: clamp(2rem, 6vh, 5rem);
  }
}

/* Keep the pin spacer from inheriting the page gradient overlay */
#how-it-works .hiw-veil {
  will-change: opacity;
}

/* ──────────────────────────────────────────────────────────────
   2. CONNECTION LINE  (gray base + green progress + lead particle)
   ────────────────────────────────────────────────────────────── */
.hiw-track {
  pointer-events: none;
}

.hiw-track-base,
.hiw-track-fill {
  position: absolute;
  inset: 0;
  border-radius: 999px;
}

.hiw-track-base {
  background: var(--hiw-line);
}

.hiw-track-fill {
  background: linear-gradient(90deg,
      var(--hiw-green) 0%,
      var(--hiw-emerald) 40%,
      var(--hiw-teal) 70%,
      var(--hiw-cyan) 100%);
  transform: scaleX(0);
  transform-origin: left center;
  box-shadow: 0 0 12px rgba(34, 197, 94, .45);
}

/* The glowing lead that travels along the line */
.hiw-particle {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #86efac 35%, var(--hiw-green) 70%);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, .18), 0 0 18px 4px rgba(34, 197, 94, .55);
  opacity: 0;
  z-index: 2;
  will-change: transform, opacity;
}

/* Soft comet trail behind the particle */
.hiw-particle::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  width: 46px;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(270deg, rgba(34, 197, 94, .55), rgba(34, 197, 94, 0));
}

/* Static arrows stay in the DOM (they hold the layout) but recede visually */
.hiw-arrow {
  transition: none;
}

/* ── Vertical connector (tablet / mobile) ── */
.hiw-vline {
  position: relative;
  background: var(--hiw-line);
  border-radius: 999px;
  overflow: hidden;
}

.hiw-vline-fill {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--hiw-green), var(--hiw-teal));
  transform: scaleY(0);
  transform-origin: top center;
}

/* ──────────────────────────────────────────────────────────────
   3. STEP / CARD STATES
   ────────────────────────────────────────────────────────────── */
.hiw-step {
  will-change: transform;
}

/* Ambient glow behind an active card — blurred once, only opacity animates */
.hiw-glow {
  position: absolute;
  top: 12px;
  left: 4%;
  width: 92%;
  height: calc(100% - 12px);
  border-radius: 28px;
  background: radial-gradient(60% 55% at 50% 40%, rgba(34, 197, 94, .38) 0%, rgba(34, 197, 94, .12) 45%, rgba(34, 197, 94, 0) 75%);
  filter: blur(14px);
  opacity: 0;
  z-index: 0;
  pointer-events: none;
}

.hiw-card {
  z-index: 1;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

/* Border highlight ring — a real element so GSAP can drive its opacity */
.hiw-ring {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  border: 1.5px solid var(--hiw-green);
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, .12);
  opacity: 0;
  pointer-events: none;
}

/* Progress bar across the top edge of each card */
.hiw-bar {
  transform: scaleX(0);
  transform-origin: left center;
}

.hiw-icon {
  will-change: transform;
  backface-visibility: hidden;
}

/* Gentle floating motion while a step is the hero of the story.
   Applied to the wrapper so it never fights GSAP's transforms on the card. */
.hiw-step.is-active {
  animation: hiw-float 3.4s ease-in-out infinite;
}

@keyframes hiw-float {

  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  50% {
    transform: translate3d(0, -5px, 0);
  }
}

/* ──────────────────────────────────────────────────────────────
   4. ICON MICRO-ANIMATIONS
   Applied to the inner <svg> so the wrapper stays free for GSAP.
   ────────────────────────────────────────────────────────────── */
.hiw-step.is-active .hiw-icon svg {
  transform-origin: 50% 50%;
}

.hiw-step[data-step="1"].is-active .hiw-icon svg {
  animation: hiw-pulse 1.9s ease-in-out infinite;
}

.hiw-step[data-step="2"].is-active .hiw-icon svg {
  animation: hiw-pop .7s cubic-bezier(.34, 1.56, .64, 1) both;
}

.hiw-step[data-step="3"].is-active .hiw-icon svg {
  animation: hiw-bounce 1.8s ease-in-out infinite;
}

.hiw-step[data-step="4"].is-active .hiw-icon svg {
  animation: hiw-fill 2.2s ease-in-out infinite;
}

.hiw-step[data-step="5"].is-active .hiw-icon svg {
  animation: hiw-spin 2.6s cubic-bezier(.65, 0, .35, 1) infinite;
}

@keyframes hiw-pulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.12);
    opacity: .85;
  }
}

@keyframes hiw-pop {
  0% {
    transform: scale(.6);
  }

  60% {
    transform: scale(1.18);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes hiw-bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-4px);
  }

  55% {
    transform: translateY(1px);
  }
}

@keyframes hiw-fill {

  0%,
  100% {
    transform: scaleY(.92);
    opacity: .9;
  }

  50% {
    transform: scaleY(1.06);
    opacity: 1;
  }
}

@keyframes hiw-spin {
  0% {
    transform: rotate(0deg);
  }

  70%,
  100% {
    transform: rotate(180deg);
  }
}

/* Halo ring that expands out of the active icon */
.hiw-halo {
  position: absolute;
  inset: -6px;
  border-radius: 22px;
  border: 2px solid rgba(34, 197, 94, .55);
  opacity: 0;
  pointer-events: none;
}

/* ──────────────────────────────────────────────────────────────
   5. STORY DETAIL PANELS (inside each card)
   Fixed min-height so the pinned stage never reflows between steps.
   ────────────────────────────────────────────────────────────── */
.hiw-detail {
  position: relative;
  margin-top: 12px;
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hiw-detail>* {
  width: 100%;
}

@media (min-width: 1024px) {

  /* Equal detail height keeps the five cards perfectly aligned while pinned */
  #how-it-works .hiw-detail {
    min-height: 100px;
  }
}

/* Before GSAP boots, keep the story panels invisible to avoid a flash of the
   "finished" state. Removed automatically if the GSAP CDN never answers. */
.hiw-js #how-it-works .hiw-signal,
.hiw-js #how-it-works .hiw-field,
.hiw-js #how-it-works .hiw-chat,
.hiw-js #how-it-works .hiw-chain-item,
.hiw-js #how-it-works .hiw-chain-arrow {
  opacity: 0;
}

/* — Step 1: live signal — */
.hiw-signal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--hiw-green-600);
  background: #f0fdf4;
  border: 1px solid #dcfce7;
  border-radius: 999px;
  padding: 6px 12px;
}

.hiw-signal-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hiw-green);
  flex-shrink: 0;
}

.hiw-signal-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid rgba(34, 197, 94, .5);
  animation: hiw-ping 1.8s ease-out infinite;
}

@keyframes hiw-ping {
  0% {
    transform: scale(.6);
    opacity: .9;
  }

  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* — Step 2: lead fields dropping into the CRM — */
.hiw-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.hiw-field {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #d1fae5;
  border-radius: 8px;
  padding: 5px 9px;
  white-space: nowrap;
}

.hiw-field svg {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}

/* — Step 3: WhatsApp chat bubble — */
.hiw-chat {
  position: relative;
  background: #dcf8c6;
  border: 1px solid #bbf7d0;
  border-radius: 12px 12px 12px 3px;
  padding: 8px 10px;
  min-height: 62px;
  text-align: left;
  font-size: 11px;
  line-height: 1.45;
  color: #14532d;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .06);
}

/* Absolute so the typing dots never reflow the bubble when the message lands */
.hiw-chat-typing {
  position: absolute;
  top: 12px;
  left: 10px;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 12px;
}

.hiw-chat-typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #34d399;
  display: block;
  animation: hiw-typing 1.2s ease-in-out infinite;
}

.hiw-chat-typing i:nth-child(2) {
  animation-delay: .16s;
}

.hiw-chat-typing i:nth-child(3) {
  animation-delay: .32s;
}

@keyframes hiw-typing {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: .45;
  }

  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.hiw-chat-msg {
  display: block;
}

.hiw-word {
  display: inline-block;
  white-space: pre;
}

.hiw-tick {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  font-size: 9px;
  font-weight: 700;
  color: #0ea5e9;
}

.hiw-tick svg {
  width: 13px;
  height: 13px;
}

/* — Step 4: pipeline stages — */
.hiw-stages {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hiw-stage {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: #94a3b8;
  background: #f8fafc;
  border: 1px solid #eef2f6;
  border-radius: 7px;
  padding: 3px 8px;
}

.hiw-stage-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(20, 184, 166, .16), rgba(34, 197, 94, .16));
  transform: scaleX(0);
  transform-origin: left center;
}

.hiw-stage-label,
.hiw-stage-check {
  position: relative;
  z-index: 1;
}

.hiw-stage-check {
  opacity: 0;
  color: var(--hiw-green-600);
  font-size: 11px;
  line-height: 1;
}

/* — Step 5: conversion chain — */
.hiw-chain {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hiw-chain-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 700;
  color: #0369a1;
  background: #f0f9ff;
  border: 1px solid #e0f2fe;
  border-radius: 7px;
  padding: 4px 8px;
}

.hiw-chain-arrow {
  display: block;
  text-align: center;
  font-size: 9px;
  line-height: 1;
  color: #94a3b8;
}

.hiw-success {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(120deg, var(--hiw-green-600), var(--hiw-teal));
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(22, 163, 74, .35);
  opacity: 0;
}

.hiw-success svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Finish ripple */
.hiw-burst {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 2px solid rgba(34, 197, 94, .5);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

/* ──────────────────────────────────────────────────────────────
   6. SCROLL HINT
   ────────────────────────────────────────────────────────────── */
.hiw-hint {
  display: none;
}

@media (min-width: 1024px) {
  .hiw-on #how-it-works .hiw-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: clamp(1rem, 3vh, 2.25rem);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: #94a3b8;
  }

  .hiw-hint-rail {
    position: relative;
    width: 120px;
    height: 3px;
    border-radius: 999px;
    background: var(--hiw-line);
    overflow: hidden;
  }

  .hiw-hint-rail i {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--hiw-green), var(--hiw-teal));
    transform: scaleX(0);
    transform-origin: left center;
  }
}

/* ──────────────────────────────────────────────────────────────
   7. TABLET — slightly compressed spacing on the stacked layout
   ────────────────────────────────────────────────────────────── */
@media (min-width: 640px) and (max-width: 1023px) {
  #how-it-works .hiw-mobile-flow {
    max-width: 42rem;
    margin-inline: auto;
  }

  #how-it-works .hiw-mobile-flow .hiw-step-m {
    max-width: 100%;
  }

  #how-it-works .hiw-detail {
    min-height: 0;
  }
}

@media (max-width: 1023px) {
  #how-it-works .hiw-detail {
    min-height: 0;
    margin-top: 10px;
  }

  #how-it-works .hiw-glow {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 20px;
  }

  #how-it-works .hiw-ring {
    border-radius: 16px;
  }

  /* No floating on touch devices — it competes with momentum scrolling */
  .hiw-step.is-active {
    animation: none;
  }
}

/* ──────────────────────────────────────────────────────────────
   8. ACCESSIBILITY — reduced motion & no-JS
   Everything resolves to the finished, fully readable state.
   ────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

  .hiw-on #how-it-works,
  #how-it-works {
    min-height: 0 !important;
    display: block !important;
  }

  #how-it-works *,
  #how-it-works *::before,
  #how-it-works *::after {
    animation: none !important;
    transition: none !important;
  }

  #how-it-works .hiw-signal,
  #how-it-works .hiw-field,
  #how-it-works .hiw-chat,
  #how-it-works .hiw-chain-item,
  #how-it-works .hiw-chain-arrow,
  #how-it-works .hiw-tick,
  #how-it-works .hiw-word,
  #how-it-works .hiw-ring,
  #how-it-works .hiw-success {
    opacity: 1 !important;
  }

  /* The success badge covers the chain when motion is off — stack them instead */
  #how-it-works .hiw-detail {
    flex-direction: column;
  }

  #how-it-works .hiw-success {
    position: static;
    margin-top: 6px;
    padding: 6px 10px;
  }

  #how-it-works .hiw-glow {
    opacity: .35 !important;
  }

  #how-it-works .hiw-particle,
  #how-it-works .hiw-burst,
  #how-it-works .hiw-halo,
  #how-it-works .hiw-chat-typing {
    display: none !important;
  }

  #how-it-works .hiw-track-fill,
  #how-it-works .hiw-vline-fill,
  #how-it-works .hiw-stage-fill,
  #how-it-works .hiw-bar,
  #how-it-works .hiw-hint-rail i {
    transform: none !important;
  }

  #how-it-works .hiw-stage-check {
    opacity: 1 !important;
  }

  #how-it-works .hiw-chat-typing {
    display: none !important;
  }
}

/* Low-power mode: drop the expensive blurs, keep the choreography */
.hiw-lite #how-it-works .hiw-glow {
  filter: none;
  opacity: 0;
}

.hiw-lite #how-it-works .hiw-particle::after {
  display: none;
}

.hiw-lite #how-it-works .hiw-step.is-active {
  animation: none;
}
