/**
 * Itala Vimeo Hero Banner — Frontend CSS
 * Version: 1.0.0
 *
 * STRUTTURA DELLE VARIABILI CSS
 * ─────────────────────────────
 * Le variabili --ivh-* vengono iniettate inline sul <section>
 * dal PHP (class-ivh-shortcode.php) così ogni istanza
 * può avere valori indipendenti nella stessa pagina.
 *
 * NOTA TECNICA: SIMULARE background-size: cover PER IL VIDEO
 * ────────────────────────────────────────────────────────────
 * Il video Vimeo è tecnicamente 1920×1080 (ratio 16:9 = 1.7778)
 * ma contiene bande nere incorporate in alto/basso.
 * Il contenuto visibile effettivo è 1920×800 (ratio = 2.4).
 *
 * Il JavaScript in frontend.js calcola le dimensioni dell'iframe
 * usando il rapporto 2.4 per il cover, poi scala l'iframe
 * tenendo conto che Vimeo lo renderizza come 16:9:
 *
 *   altezza_iframe_reale = altezza_calcolata * (2.4 / 1.7778)
 *
 * Questo "zoom" verticale fa uscire le bande nere dal contenitore
 * e mostra solo il contenuto centrale 1920×800.
 * overflow: hidden sul wrapper taglia le bande in eccesso.
 */

/* ─── Reset scoped ──────────────────────────────────────────── */
.ivh-hero *,
.ivh-hero *::before,
.ivh-hero *::after {
  box-sizing: border-box;
}

/* ─── Sezione principale ────────────────────────────────────── */
.ivh-hero {
  /* Fallback prima del JS e per i CSS-only */
  --ivh-height:          100svh;
  --ivh-height-tablet:   100svh;
  --ivh-height-mobile:   100svh;
  --ivh-min-height:      400px;
  --ivh-align-h:         center;
  --ivh-align-v:         center;
  --ivh-max-width:       1100px;
  --ivh-overlay-opacity: 0.35;
  --ivh-overlay-color:   #000000;
  --ivh-text-color:      #ffffff;
  --ivh-gap:             24px;
  --ivh-padding-desktop: 40px;
  --ivh-padding-tablet:  30px;
  --ivh-padding-mobile:  20px;
  --ivh-content-ratio:   2.4;
  --ivh-source-ratio:    1.777778;
  --ivh-logo-w-desktop:  260px;
  --ivh-logo-w-tablet:   200px;
  --ivh-logo-w-mobile:   160px;
  --ivh-sec-w-desktop:   220px;
  --ivh-sec-w-tablet:    180px;
  --ivh-sec-w-mobile:    140px;

  position: relative;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: var(--ivh-align-v);
  justify-content: var(--ivh-align-h);

  /* Altezza con fallback progressivo */
  height: var(--ivh-height);
  min-height: var(--ivh-min-height);
  color: var(--ivh-text-color);
}

/* Fallback per browser che non supportano svh */
@supports not (height: 1svh) {
  .ivh-hero {
    height: var(--ivh-height, 100vh);
  }
}

/* ─── Strato media (wrapper video) ─────────────────────────── */
.ivh-hero__media {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
  /* Impedisce che il media intercetti gli eventi utente */
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/*
 * NEUTRALIZZA FLUIDVIDS E QUALSIASI WRAPPER INIETTATO
 * ─────────────────────────────────────────────────────
 * FluidVids (e plugin simili) wrappano gli iframe in un <div>
 * con padding-bottom, height e dimensioni fisse che rompono
 * il nostro algoritmo di cover.
 * Questi selettori azzerano qualsiasi elemento intermedio
 * inserito dentro .ivh-hero__media, ripristinando il
 * posizionamento assoluto del nostro iframe.
 */
.ivh-hero__media > *:not(.ivh-hero__iframe):not(.ivh-hero__poster) {
  /* Wrapper iniettati (es: .fluidvids) diventano trasparenti */
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: visible !important;
  pointer-events: none !important;
}

/* Azzera tutti i div annidati dentro wrapper iniettati */
.ivh-hero__media > *:not(.ivh-hero__iframe):not(.ivh-hero__poster) > div {
  position: static !important;
  width: auto !important;
  height: auto !important;
  padding: 0 !important;
}

/* ─── Poster image ──────────────────────────────────────────── */
.ivh-hero__poster {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  z-index: 1;
  transition: opacity 0.6s ease;
}

/* Quando il video è caricato, nascondi il poster */
.ivh-hero.ivh-video-ready .ivh-hero__poster {
  opacity: 0;
  pointer-events: none;
}

/* ─── Iframe Vimeo ──────────────────────────────────────────── */
/*
 * Usiamo !important su position/top/left/transform per battere
 * qualsiasi override di FluidVids o altri script che forzano
 * position:relative / padding-bottom / dimensioni inline.
 *
 * Il JS sovrascrive width e height via style inline (priorità massima),
 * quindi !important sulle dimensioni NON serve (e sarebbe controproducente).
 */
.ivh-hero__iframe {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  border: 0 !important;
  pointer-events: none !important;
  z-index: 2;
  display: block !important;

  /*
   * Dimensioni di fallback CSS (senza JS).
   * Il JS le sovrascrive con style inline al resize.
   * Logica: cover con ratio effettivo 2.4 + compensazione bande nere.
   * scaleFactor = 2.4 / 1.7778 ≈ 1.35
   *
   * Se il viewport è più wide di 2.4:
   *   w = 100vw,  h = (100vw / 2.4) * 1.35
   * Altrimenti:
   *   h = 100svh * 1.35,  w = 100svh * 2.4
   *
   * min-width e min-height garantiscono la copertura in entrambe le direzioni.
   */
  width: 100vw;
  height: calc(100vw / 1.777778);      /* Altezza frame 16:9 */
  min-width: calc(100svh * 2.4);       /* Copertura quando il viewport è alto */
  min-height: calc(100svh * 1.35);     /* +35% per espellere le bande nere */
}

/* Fallback per browser senza svh */
@supports not (height: 1svh) {
  .ivh-hero__iframe {
    min-width: calc(100vh * 2.4);
    min-height: calc(100vh * 1.35);
  }
}

/* ─── Overlay ───────────────────────────────────────────────── */
.ivh-hero__overlay {
  position: absolute;
  inset: 0;
  background-color: var(--ivh-overlay-color);
  opacity: var(--ivh-overlay-opacity);
  pointer-events: none;
  z-index: 3;
}

/* ─── Contenuto sovrapposto ─────────────────────────────────── */
.ivh-hero__content {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: var(--ivh-align-h);
  gap: var(--ivh-gap);
  width: 100%;
  max-width: var(--ivh-max-width);
  padding-left: var(--ivh-padding-desktop);
  padding-right: var(--ivh-padding-desktop);
  /* Safe area per dispositivi con notch */
  padding-left: max(var(--ivh-padding-desktop), env(safe-area-inset-left));
  padding-right: max(var(--ivh-padding-desktop), env(safe-area-inset-right));
  padding-bottom: max(var(--ivh-padding-desktop), env(safe-area-inset-bottom));
  text-align: var(--ivh-align-h);
}

/* ─── Logo principale ───────────────────────────────────────── */
.ivh-hero__logo-wrap {
  display: block;
  width: 100%;
  max-width: var(--ivh-logo-w-desktop);
}

.ivh-hero__logo {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

/* ─── Immagine secondaria ───────────────────────────────────── */
.ivh-hero__secondary-wrap {
  display: block;
  width: 100%;
  max-width: var(--ivh-sec-w-desktop);
}

.ivh-hero__secondary-image {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

/* ─── Azioni / Pulsanti ─────────────────────────────────────── */
.ivh-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: var(--ivh-align-h);
}

/* ─── Pulsanti ──────────────────────────────────────────────── */
.ivh-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.03em;
  text-decoration: none;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition:
    background-color 0.22s ease,
    color            0.22s ease,
    border-color     0.22s ease,
    box-shadow       0.22s ease,
    transform        0.12s ease;
  white-space: nowrap;
  /* Overridate gli stili del tema */
  font-family: inherit;
  text-transform: none;
}

.ivh-button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.5);
}

/* Primary */
.ivh-button--primary {
  background-color: #ffffff;
  color: #1a1a1a;
  border-color: #ffffff;
}

.ivh-button--primary:hover,
.ivh-button--primary:focus-visible {
  background-color: transparent;
  color: #ffffff;
  border-color: #ffffff;
  box-shadow: inset 0 0 0 2px #fff;
}

/* Secondary */
.ivh-button--secondary {
  background-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.ivh-button--secondary:hover,
.ivh-button--secondary:focus-visible {
  background-color: rgba(255, 255, 255, 0.25);
  border-color: #ffffff;
}

/* Outlined */
.ivh-button--outlined {
  background-color: transparent;
  color: #ffffff;
  border-color: #ffffff;
}

.ivh-button--outlined:hover,
.ivh-button--outlined:focus-visible {
  background-color: #ffffff;
  color: #1a1a1a;
}

/* ─── Allineamenti ──────────────────────────────────────────── */
.ivh-align-h--left  .ivh-hero__content { align-items: flex-start; text-align: left; }
.ivh-align-h--right .ivh-hero__content { align-items: flex-end;   text-align: right; }
.ivh-align-h--center .ivh-hero__content { align-items: center;    text-align: center; }

.ivh-align-h--left  .ivh-hero__actions { justify-content: flex-start; }
.ivh-align-h--right .ivh-hero__actions { justify-content: flex-end;   }
.ivh-align-h--center .ivh-hero__actions { justify-content: center;    }

/* ─── Responsive: Tablet ────────────────────────────────────── */
@media (max-width: 1024px) {
  .ivh-hero {
    height: var(--ivh-height-tablet);
  }

  .ivh-hero__content {
    padding-left: max(var(--ivh-padding-tablet), env(safe-area-inset-left));
    padding-right: max(var(--ivh-padding-tablet), env(safe-area-inset-right));
  }

  .ivh-hero__logo-wrap {
    max-width: var(--ivh-logo-w-tablet);
  }

  .ivh-hero__secondary-wrap {
    max-width: var(--ivh-sec-w-tablet);
  }
}

/* ─── Responsive: Mobile ────────────────────────────────────── */
@media (max-width: 767px) {
  .ivh-hero {
    height: var(--ivh-height-mobile);
  }

  .ivh-hero__content {
    padding-left: max(var(--ivh-padding-mobile), env(safe-area-inset-left));
    padding-right: max(var(--ivh-padding-mobile), env(safe-area-inset-right));
    padding-bottom: max(var(--ivh-padding-mobile), env(safe-area-inset-bottom));
  }

  .ivh-hero__logo-wrap {
    max-width: var(--ivh-logo-w-mobile);
  }

  .ivh-hero__secondary-wrap {
    max-width: var(--ivh-sec-w-mobile);
  }

  /* Pulsanti a tutta larghezza su mobile stretto */
  @media (max-width: 400px) {
    .ivh-hero__actions {
      flex-direction: column;
      width: 100%;
    }

    .ivh-button {
      width: 100%;
      text-align: center;
    }
  }
}

/* ─── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  /* Mostra il poster image (se presente) e nascondi il video */
  .ivh-hero.ivh-has-poster .ivh-hero__iframe {
    display: none;
  }

  .ivh-hero.ivh-has-poster .ivh-hero__poster {
    opacity: 1;
  }

  /* Disabilita la transizione del poster */
  .ivh-hero__poster,
  .ivh-button {
    transition: none;
  }
}
