/* ─────────────────────────────────────────────────────────────────
   SERVICIOS — HERO "RECORRIDO" ligado al scroll
   240 fotogramas (frames-servicios/d 1440×810 · m 720×960) de dos videos:
     0–119   el dron llega a la planta
     120–239 portería → laboratorio → letrero de IMMAC
   La escena queda fija (sticky) mientras se baja 400svh; js/servicios-hero.js dibuja
   el fotograma en el canvas y escribe el estado de los textos.
   Capítulos: intro (título) → 01 Planta → paso entre videos → 02 Laboratorio → letrero.
───────────────────────────────────────────────────────────────── */
.sv-hero {
  --sv-ease: cubic-bezier(0.19, 1, 0.22, 1);
  display: block;
  height: calc(100svh + 400svh);
  min-height: 0;
  padding: 0;
  overflow: clip;                  /* clip (no hidden): deja funcionar el sticky */
  /* el último borde ya es el gris de la página: sin línea en la unión */
  background: linear-gradient(180deg, #0B1724 calc(100% - 4px), #F4F6F8 calc(100% - 4px));
}

.sv-sticky {
  position: sticky;
  top: 0;
  height: 100svh;
  min-height: 560px;
  overflow: hidden;
  isolation: isolate;
  color: #fff;
}

/* Primer fotograma como imagen (carga inmediata) y canvas encima cuando está listo */
.sv-poster,
.sv-poster img,
.sv-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.sv-poster { z-index: -3; }
.sv-poster img { object-fit: cover; }
.sv-canvas { z-index: -2; opacity: 0; transition: opacity 0.5s ease; }
.sv-hero.is-ready .sv-canvas { opacity: 1; }

/* Velo: arriba para el menú y abajo para los textos (las escenas del laboratorio son muy claras) */
.sv-shade {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 12, 21, 0.58) 0%, rgba(5, 12, 21, 0.18) 13%, rgba(5, 12, 21, 0) 22%),
    linear-gradient(0deg, rgba(5, 12, 21, 0.9) 0%, rgba(5, 12, 21, 0.76) 20%, rgba(5, 12, 21, 0.42) 38%, rgba(5, 12, 21, 0) 58%);
}

/* Legibilidad de la intro sobre fotos cargadas (árboles, planta): una sombra amplia y suave
   detrás del bloque, que se va con él al bajar; texto y accesos más firmes */
.sv-intro::before {
  content: '';
  position: absolute;
  z-index: -1;
  left: -12vw;
  right: -12vw;
  top: -22vh;
  bottom: -16vh;
  background: radial-gradient(60% 80% at 38% 72%, rgba(5, 12, 21, 0.62) 0%, rgba(5, 12, 21, 0.32) 45%, rgba(5, 12, 21, 0) 75%);
  pointer-events: none;
}
.sv-intro .pg-hero__title,
.sv-intro .pg-hero__lead,
.sv-intro .pg-eyebrow { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 22px rgba(0, 0, 0, 0.3); }
.sv-intro .pg-hero__lead { color: rgba(255, 255, 255, 0.94); }
.sv-intro .pg-chip {
  background: rgba(10, 16, 24, 0.52);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  backdrop-filter: blur(16px) saturate(1.3);
}
@media (hover: hover) and (pointer: fine) {
  .sv-intro .pg-chip:hover { background: rgba(10, 16, 24, 0.72); }
}

/* ── Intro: el título de la página, abajo; se despide al empezar a bajar ── */
.sv-intro {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(92px, 13vh, 132px);
  margin: 0 auto;
  will-change: opacity, transform, filter;
}
@media (min-width: 1024px) {
  .sv-intro {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "eyebrow ." "title lead" "title chips";
    align-items: end;
    column-gap: clamp(40px, 6vw, 120px);
  }
  .sv-intro .pg-eyebrow { grid-area: eyebrow; }
  .sv-intro .pg-hero__title { grid-area: title; font-size: clamp(34px, 3.4vw, 56px); text-wrap: balance; }
  .sv-intro .pg-hero__lead { grid-area: lead; margin-top: 0; max-width: 520px; }
  .sv-intro .pg-chips { grid-area: chips; margin-top: 22px; flex-wrap: nowrap; }
}

/* ── Capítulos: aparecen y se van con el recorrido (js escribe --v de 0 a 1) ── */
.sv-chapters {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(92px, 13vh, 132px);
  margin: 0 auto;
  pointer-events: none;
}
.sv-chapter {
  --v: 0;
  position: absolute;          /* left automático: arranca en el margen del contenedor */
  bottom: 0;
  max-width: 560px;
  opacity: var(--v);
  transform: translate3d(0, calc((1 - var(--v)) * 22px), 0);
  filter: blur(calc((1 - var(--v)) * 8px));
  visibility: hidden;
}
.sv-chapter.is-on { visibility: visible; }
.sv-chapter__n {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #3FB4E6;
}
.sv-chapter__n::after {
  content: '';
  width: 56px;
  height: 1px;
  background: linear-gradient(90deg, #3FB4E6, rgba(63, 180, 230, 0));
}
.sv-chapter__t {
  font-size: clamp(40px, 5.2vw, 84px);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.035em;
  color: #fff;
  text-wrap: balance;
}
.sv-chapter__p {
  max-width: 44ch;
  margin-top: 18px;
  font-size: clamp(16px, 1.25vw, 19px);
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.86);
}

/* ── Avance: dos tramos, Planta y Laboratorio ── */
.sv-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(32px, 5vh, 52px);
  margin: 0 auto;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);   /* tantos tramos como tenga la barra */
  gap: 16px;
}
.sv-progress__seg span {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  transition: color 0.4s ease;
}
.sv-progress__seg.is-on span { color: #fff; }
.sv-progress__seg i {
  display: block;
  height: 2px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}
.sv-progress__seg b {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #B6CD20, #3FB4E6);
  transform: scaleX(var(--f, 0));
  transform-origin: left center;
}

/* Indicador para bajar: solo al inicio */
.sv-cue {
  position: absolute;
  /* a la izquierda, entre el texto y la barra de avance (a la derecha lo tapaba el asistente) */
  left: clamp(24px, 4vw, 64px);
  bottom: calc(clamp(32px, 5vh, 52px) + 36px);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
  opacity: calc(1 - var(--cue, 0));
}
.sv-cue i {
  position: relative;
  width: 1px;
  height: 22px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}
.sv-cue i::after {
  content: '';
  position: absolute;
  left: 0;
  top: -40%;
  width: 1px;
  height: 40%;
  background: #fff;
  animation: sv-cue 1.8s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes sv-cue { to { top: 100%; } }

/* La intro entra después de que aparece la escena */
.js .sv-hero .sv-intro > * { animation-delay: calc(0.25s + var(--c, 0) * 0.08s); }
.sv-intro > :nth-child(2) { --c: 1; }
.sv-intro > :nth-child(3) { --c: 2; }
.sv-intro > :nth-child(4) { --c: 3; }

/* ── Variante de un solo video (I+D+I): recorrido más corto y tres tramos en la barra.
   El video trae su propio texto al centro: la intro se despide antes de que aparezca ── */
.sv-hero--one { height: calc(100svh + 300svh); }
.sv-hero--one .sv-progress { grid-template-columns: repeat(3, 1fr); }
.sv-hero--one .sv-shade {
  background:
    linear-gradient(180deg, rgba(5, 8, 30, 0.45) 0%, rgba(5, 8, 30, 0) 18%),
    linear-gradient(0deg, rgba(5, 8, 30, 0.75) 0%, rgba(5, 8, 30, 0.35) 22%, rgba(5, 8, 30, 0) 40%);
}

/* ── Celular: mismos capítulos, textos más compactos ── */
@media (max-width: 760px) {
  .sv-hero { height: calc(100svh + 340svh); }
  .sv-hero--one { height: calc(100svh + 260svh); }
  .sv-hero--one .sv-progress__seg span { font-size: 10.5px; letter-spacing: 0.06em; }
  .sv-intro,
  .sv-chapters { bottom: 104px; }
  .sv-chapter { right: 16px; }
  .sv-chapter__t { font-size: 40px; }
  .sv-progress { bottom: 28px; gap: 10px; }
  .sv-hero .sv-progress { padding-right: 84px; } /* deja libre el botón del asistente */
  .sv-cue { display: none; }
  .sv-shade {
    background:
      linear-gradient(180deg, rgba(5, 12, 21, 0.58) 0%, rgba(5, 12, 21, 0) 18%),
      linear-gradient(0deg, rgba(5, 12, 21, 0.9) 0%, rgba(5, 12, 21, 0.7) 26%, rgba(5, 12, 21, 0.25) 46%, rgba(5, 12, 21, 0) 60%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sv-chapter { transform: none; filter: none; }
  .sv-cue i::after { animation: none; }
}
