/*
 * Fix per dispositivi iOS - gestione sfondo e viewport
 * Risolve problemi di background-attachment: fixed e rotazione schermo
 */

/* Detecta se è un dispositivo iOS */
@supports (-webkit-touch-callout: none) {
  /* Fix per background-attachment: fixed su iOS */
  .page-cover .cover-bg {
    background-attachment: scroll !important;
    position: fixed !important;
    will-change: transform;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  
  /* Forza il ricalcolo delle dimensioni durante la rotazione */
  .page-cover {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }
  
  /* Fix per il viewport su iOS durante la rotazione */
  .fullpage-container {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  
  /* Assicura che lo sfondo copra sempre tutto lo schermo */
  .page-cover .cover-bg {
    min-width: 100vw;
    min-height: 100vh;
    width: 100vw;
    height: 100vh;
    /* Fix specifico per il problema di scaling in altezza invece che in larghezza */
    background-size: cover !important;
    background-position: center center !important;
    object-fit: cover;
    object-position: center center;
  }
  
  /* Fix per le sezioni con sfondo */
  .section-cover,
  .section-cover-full {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }
  
  /* Fix per gli sfondi delle sezioni */
  .section-cover .bg-img,
  .section-cover-full .bg-img {
    background-attachment: scroll !important;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}

/* Fix generale per tutti i dispositivi iOS */
@supports (-webkit-touch-callout: none) {
  /* Fix aggiuntivi per tutti gli sfondi su iOS */
  .page-cover .cover-bg {
    background-size: cover !important;
    background-position: center center !important;
    object-fit: cover;
    width: 100vw !important;
    height: 100vh !important;
    min-width: 100vw !important;
    min-height: 100vh !important;
  }
  
  /* Fix per le sezioni con sfondo */
  .section-cover,
  .section-cover-full {
    background-size: cover !important;
    background-position: center center !important;
    width: 100% !important;
    height: 100% !important;
  }
  
  /* Fix per tutti gli elementi con bg-img */
  .bg-img {
    background-size: cover !important;
    background-position: center center !important;
    background-attachment: scroll !important;
  }
}

/* Fix generale per tutti i dispositivi iOS con problemi di viewport */
@media screen and (-webkit-min-device-pixel-ratio: 1) {
  /* Previene il bounce scroll su iOS */
  body {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
  }
  
  /* Fix per il fullpage container */
  .fullpage-container {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
  }
  
  /* Migliora le performance di rendering */
  .section {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }
}

/* Fix per la rotazione del dispositivo - applicato a tutti i dispositivi iOS */
@supports (-webkit-touch-callout: none) {
  @media screen and (orientation: landscape),
         screen and (orientation: portrait) {
    .page-cover .cover-bg,
    .section-cover,
    .section-cover-full,
    .bg-img {
      width: 100vw !important;
      height: 100vh !important;
      background-size: cover !important;
      background-position: center center !important;
      background-attachment: scroll !important;
      -webkit-transform: translateZ(0);
      transform: translateZ(0);
    }
    
    /* Forza il ricalcolo durante la rotazione */
    .fullpage-container {
      width: 100vw !important;
      height: 100vh !important;
    }
  }
}