/* Video flotante: PiP + fullscreen (namespaced .cambiate-fv-) */
/* z-index máximo práctico: por encima del chrome HubSpot (admin) */
.cambiate-fv-root {
  position: fixed;
  z-index: 2147483647;
  left: max(16px, env(safe-area-inset-left, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  width: min(280px, calc(100vw - 32px));
  /* Relación de aspecto real del vídeo (JS: --cambiate-fv-vw / --cambiate-fv-vh); fallback 16:9 */
  aspect-ratio: var(--cambiate-fv-vw, 16) / var(--cambiate-fv-vh, 9);
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 8px 24px rgba(0, 42, 109, 0.14),
    0 2px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cambiate-fv-root:hover {
  transform: translateY(-2px);
  box-shadow:
    0 14px 36px rgba(0, 42, 109, 0.18),
    0 4px 12px rgba(0, 0, 0, 0.1);
}

.cambiate-fv-root:focus-visible {
  outline: 2px solid #002a6d;
  outline-offset: 3px;
}

.cambiate-fv-root.cambiate-fv-preview-hidden {
  display: none !important;
}

.cambiate-fv-backdrop {
  display: none;
}

/*
 * Desktop overlay: blur sobre la página (insertado en body por module.js).
 * z-index justo bajo el root del vídeo para que el marco quede encima.
 */
#cambiateFvBackdropLayer.cambiate-fv-backdrop-layer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  margin: 0;
  padding: 0;
  border: 0;
  cursor: pointer;
  pointer-events: none;
  background: rgba(6, 10, 22, 0.42);
  -webkit-backdrop-filter: blur(40px) saturate(1.22);
  backdrop-filter: blur(40px) saturate(1.22);
}

#cambiateFvBackdropLayer.cambiate-fv-backdrop-layer.is-active {
  display: block;
  pointer-events: auto;
}

.cambiate-fv-expanded-stack {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;
  z-index: 1;
}

.cambiate-fv-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cambiate-fv-frame {
  position: relative;
  width: 100%;
  height: 100%;
  background: #0a1628;
}

.cambiate-fv-video {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  vertical-align: middle;
  background: transparent;
}

/* Capa poster hasta que el vídeo esté listo (o preview en baja calidad) */
.cambiate-fv-poster-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
  transition: opacity 0.45s ease, visibility 0.45s ease;
  pointer-events: none;
}

.cambiate-fv-root.cambiate-fv-poster-done .cambiate-fv-poster-img {
  opacity: 0;
  visibility: hidden;
}

.cambiate-fv-dim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.2s ease;
}

.cambiate-fv-play-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 3;
}

.cambiate-fv-play-icon.font-awesome-icon-default[data-icon] {
  width: 48px;
  height: 48px;
  min-width: 48px;
  max-width: 48px;
  flex: 0 0 48px;
  color: #fff;
}

.cambiate-fv-play-icon.font-awesome-icon-default[data-icon]::before {
  font-size: 40px;
  color: #fff;
}

/* Cerrar solo la vista previa (vuelve al recargar la página) */
.cambiate-fv-dismiss-preview {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s ease, transform 0.15s ease;
}

.cambiate-fv-dismiss-preview:hover,
.cambiate-fv-dismiss-preview:focus-visible {
  background: rgba(0, 0, 0, 0.65);
}

.cambiate-fv-dismiss-preview:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.cambiate-fv-dismiss-preview .font-awesome-icon-default[data-icon] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  max-width: 18px;
  flex: 0 0 18px;
  color: #fff;
}

.cambiate-fv-dismiss-preview .font-awesome-icon-default[data-icon]::before {
  font-size: 16px;
  color: #fff;
}

/* Salir de pantalla completa (solo visible en fullscreen; fuera del marco del vídeo en desktop) */
.cambiate-fv-close-full {
  display: none;
  position: relative;
  /* Por encima del propio overlay y del UI HubSpot */
  z-index: 2147483647;
  flex-shrink: 0;
  align-self: flex-end;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s ease, transform 0.15s ease;
}

.cambiate-fv-close-full:hover,
.cambiate-fv-close-full:focus-visible {
  background: rgba(0, 0, 0, 0.65);
}

.cambiate-fv-close-full:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.cambiate-fv-close-full .font-awesome-icon-default[data-icon] {
  width: 22px;
  height: 22px;
  min-width: 22px;
  max-width: 22px;
  flex: 0 0 22px;
  color: #fff;
}

.cambiate-fv-close-full .font-awesome-icon-default[data-icon]::before {
  font-size: 18px;
  color: #fff;
}

/* Entrada overlay desktop: sin scale (evita recorte por subpíxeles / overflow) */
@keyframes cambiate-fv-frame-in-overlay {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) translateY(6px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

/* Solo ≥992px: overlay con margen generoso, oscurecido + blur (JS no usa fullscreen nativo aquí) */
@media (min-width: 992px) {
  .cambiate-fv-root.cambiate-fv-expanded {
    --fv-edge: 56px;
    /* Colchón mínimo para no recortar (mucho menor que antes: el marco ya va dentro del área inset) */
    --fv-shrink: 16px;
    --fv-pad-l: max(var(--fv-edge), env(safe-area-inset-left, 0px));
    --fv-pad-r: max(var(--fv-edge), env(safe-area-inset-right, 0px));
    --fv-pad-t: max(var(--fv-edge), env(safe-area-inset-top, 0px));
    --fv-pad-b: max(var(--fv-edge), env(safe-area-inset-bottom, 0px));
    /* Fallback si el navegador no soporta unidades sv* */
    --fv-max-w: calc(100vw - var(--fv-pad-l) - var(--fv-pad-r) - var(--fv-shrink));
    --fv-max-h: calc(100vh - var(--fv-pad-t) - var(--fv-pad-b) - var(--fv-shrink));

    position: fixed !important;
    /* Clic fuera del marco → atraviesa hacia #cambiateFvBackdropLayer (body) */
    pointer-events: none;
    z-index: 2147483647;
    inset: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    margin: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    min-width: 0;
    aspect-ratio: auto;
    border-radius: 0;
    cursor: default;
    transform: none;
    box-shadow: none;
    overflow: visible !important;
    /* Sin relleno opaco: el backdrop puede muestrear la página detrás */
    background: transparent;
    transition: none;
  }

  .cambiate-fv-root.cambiate-fv-expanded:hover {
    transform: none;
    box-shadow: none;
  }

  /* El blur real va en #cambiateFvBackdropLayer (body); el div del módulo no muestrea bien la página */
  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-backdrop {
    display: none !important;
  }

  /*
   * Sin flex ni height:100% del base: si no, height:100% + top/bottom desplaza el bloque y el vídeo
   * queda bajo el centro (más aire arriba que abajo). Solo insets + width/height auto.
   */
  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-expanded-stack {
    display: block;
    position: absolute;
    z-index: 1;
    left: var(--fv-pad-l);
    right: var(--fv-pad-r);
    top: var(--fv-pad-t);
    bottom: var(--fv-pad-b);
    width: auto;
    height: auto;
    min-height: 0;
    pointer-events: none;
    box-sizing: border-box;
  }

  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-close-full {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 3;
    display: flex;
    pointer-events: auto;
  }

  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-stage {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
    overflow: visible;
    pointer-events: none;
  }

  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-frame {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 1;
    margin: 0;
    pointer-events: auto;
    box-sizing: border-box;
    width: min(
      var(--fv-max-w),
      calc(var(--fv-max-h) * var(--cambiate-fv-vw, 16) / var(--cambiate-fv-vh, 9))
    );
    height: min(
      var(--fv-max-h),
      calc(var(--fv-max-w) * var(--cambiate-fv-vh, 9) / var(--cambiate-fv-vw, 16))
    );
    transform: translate(-50%, -50%);
    transform-origin: center center;
    border-radius: 16px;
    overflow: hidden;
    box-shadow:
      0 24px 64px rgba(0, 0, 0, 0.35),
      0 8px 24px rgba(0, 42, 109, 0.12);
    animation: cambiate-fv-frame-in-overlay 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    cursor: default;
    pointer-events: auto;
  }

  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-video {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center center;
    background: transparent;
  }

  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-poster-img {
    opacity: 0;
    visibility: hidden;
  }

  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-dim,
  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-play-wrap {
    opacity: 0;
    pointer-events: none;
  }

  .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-dismiss-preview {
    display: none;
  }
}

@supports (height: 100svh) {
  @media (min-width: 992px) {
    .cambiate-fv-root.cambiate-fv-expanded {
      --fv-max-w: calc(100svw - var(--fv-pad-l) - var(--fv-pad-r) - var(--fv-shrink));
      --fv-max-h: calc(100svh - var(--fv-pad-t) - var(--fv-pad-b) - var(--fv-shrink));
    }
  }
}

/* Fullscreen nativo (≤991px desde JS): 100% + mismo overlay con blur que desktop */
.cambiate-fv-root:fullscreen,
.cambiate-fv-root:-webkit-full-screen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  cursor: default;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  transform: none;
  box-shadow: none;
  pointer-events: none;
}

.cambiate-fv-root:fullscreen .cambiate-fv-backdrop,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-backdrop {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 0;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  pointer-events: auto;
  background: rgba(6, 10, 22, 0.4);
  -webkit-backdrop-filter: blur(32px) saturate(1.2);
  backdrop-filter: blur(32px) saturate(1.2);
}

.cambiate-fv-root:fullscreen:hover,
.cambiate-fv-root:-webkit-full-screen:hover {
  transform: none;
  box-shadow: none;
}

.cambiate-fv-root:fullscreen .cambiate-fv-expanded-stack,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-expanded-stack {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
  pointer-events: none;
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
}

.cambiate-fv-root:fullscreen .cambiate-fv-close-full,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-close-full {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  display: flex;
  pointer-events: auto;
}

.cambiate-fv-root:fullscreen .cambiate-fv-stage,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cambiate-fv-root:fullscreen .cambiate-fv-frame,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-frame {
  --fv-fs-pad-x: calc(
    max(24px, env(safe-area-inset-left, 0px)) + max(24px, env(safe-area-inset-right, 0px))
  );
  --fv-fs-pad-y: calc(
    max(24px, env(safe-area-inset-top, 0px)) + max(24px, env(safe-area-inset-bottom, 0px))
  );
  position: absolute;
  left: 50%;
  top: 50%;
  right: auto;
  bottom: auto;
  width: min(
    calc(100vw - var(--fv-fs-pad-x)),
    calc((100dvh - var(--fv-fs-pad-y)) * var(--cambiate-fv-vw, 16) / var(--cambiate-fv-vh, 9))
  );
  height: min(
    calc(100dvh - var(--fv-fs-pad-y)),
    calc((100vw - var(--fv-fs-pad-x)) * var(--cambiate-fv-vh, 9) / var(--cambiate-fv-vw, 16))
  );
  transform: translate(-50%, -50%);
  transform-origin: center center;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  animation: none;
  pointer-events: auto;
}

.cambiate-fv-root:fullscreen .cambiate-fv-video,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-video {
  object-fit: contain;
  background: transparent;
}

.cambiate-fv-root:fullscreen .cambiate-fv-poster-img,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-poster-img {
  opacity: 0;
  visibility: hidden;
}

.cambiate-fv-root:fullscreen .cambiate-fv-dim,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-dim,
.cambiate-fv-root:fullscreen .cambiate-fv-play-wrap,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-play-wrap {
  opacity: 0;
  pointer-events: none;
}

.cambiate-fv-root:fullscreen .cambiate-fv-dismiss-preview,
.cambiate-fv-root:-webkit-full-screen .cambiate-fv-dismiss-preview {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .cambiate-fv-root {
    transition: none;
  }

  .cambiate-fv-root:hover {
    transform: none;
  }

  .cambiate-fv-dim {
    transition: none;
  }

  @media (min-width: 992px) {
    .cambiate-fv-root.cambiate-fv-expanded .cambiate-fv-frame {
      animation: none;
      transform: translate(-50%, -50%);
      opacity: 1;
    }
  }
}

/* Móvil y tablet estrecha: ancho completo con márgenes (sigue “flotando” sobre el contenido) */
@media screen and (max-width: 767px) {
  .cambiate-fv-root {
    left: max(16px, env(safe-area-inset-left, 0px));
    right: max(16px, env(safe-area-inset-right, 0px));
    width: auto;
    max-width: none;
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    aspect-ratio: var(--cambiate-fv-vw, 16) / var(--cambiate-fv-vh, 9);
    border-radius: 14px;
  }

  .cambiate-fv-dismiss-preview {
    width: 44px;
    height: 44px;
    top: 10px;
    right: 10px;
  }

  .cambiate-fv-dismiss-preview .font-awesome-icon-default[data-icon] {
    width: 20px;
    height: 20px;
    min-width: 20px;
    max-width: 20px;
    flex: 0 0 20px;
  }

  .cambiate-fv-dismiss-preview .font-awesome-icon-default[data-icon]::before {
    font-size: 18px;
  }
}

@media screen and (max-width: 479px) {
  .cambiate-fv-root {
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    border-radius: 12px;
  }
}
