/* ==========================================================================
   home-backgrounds.css — Sahara Bouarif Voyages
   Fonds texturés, voiles de contraste WCAG AA, 4 séparateurs SVG,
   chargement différé sous le pli et allègement mobile (< 640px).

   Règles de performance respectées :
   - Aucune parallaxe (background-attachment: scroll uniquement)
   - Aucun fond lourd ne bloque le LCP (Hero non bloquant, sous-le-pli différé)
   - Budget total visé < 600 Ko (WebP compressés + repli couleur unie < 640px)
   - Fallback garanti sans image (background-color unie AA sur chaque section)
   - Respect strict de prefers-reduced-motion: reduce
   ========================================================================== */

:root {
  /* ------------------------------------------------------------------------
     1. VARIABLES CSS — 8 FONDS & TEXTURES (assets/images/backgrounds/)
     ------------------------------------------------------------------------ */
  --bg-grain:            url('../images/backgrounds/grain.webp');            /* ~18 Ko — répétable */
  --bg-dunes-ripples:    url('../images/backgrounds/dunes-ripples.webp');    /* ~105 Ko — photo cover */
  --bg-paper-sand:       url('../images/backgrounds/paper-sand.webp');       /* ~28 Ko — répétable */
  --bg-pattern-diamonds: url('../images/backgrounds/pattern-diamonds.webp'); /* ~14 Ko — motif répétable */
  --bg-wool-weave:       url('../images/backgrounds/wool-weave.webp');       /* ~32 Ko — trame répétable */
  --bg-dusk-dunes:       url('../images/backgrounds/dusk-dunes.webp');       /* ~118 Ko — photo cover */
  --bg-sand-dark:        url('../images/backgrounds/sand-dark.webp');        /* ~112 Ko — photo cover */
  --bg-night-dunes:      url('../images/backgrounds/night-dunes.webp');      /* ~122 Ko — photo cover */
  /* Total desktop estimé : ~549 Ko (< 600 Ko) | Total mobile < 640px : ~92 Ko */

  /* ------------------------------------------------------------------------
     2. VARIABLES CSS — 4 SÉPARATEURS SVG INLINE (0 requête HTTP, < 1 Ko)
     ------------------------------------------------------------------------ */
  --sep-dune-wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 72' preserveAspectRatio='none'%3E%3Cpath d='M0,48 C280,4 540,72 860,34 C1120,4 1300,56 1440,36 L1440,72 L0,72 Z' fill='%23000'/%3E%3C/svg%3E");
  --sep-dune-ridge: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 64' preserveAspectRatio='none'%3E%3Cpath d='M0,64 L420,16 L760,46 L1120,8 L1440,42 L1440,64 Z' fill='%23000'/%3E%3C/svg%3E");
  --sep-berber-zigzag: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 16' preserveAspectRatio='none'%3E%3Cpath d='M0,16 L15,2 L30,16 L45,2 L60,16 L75,2 L90,16 L105,2 L120,16 Z' fill='%23000'/%3E%3C/svg%3E");
  --sep-horizon-arc: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 56' preserveAspectRatio='none'%3E%3Cpath d='M0,56 Q720,0 1440,56 Z' fill='%23000'/%3E%3C/svg%3E");

  /* ------------------------------------------------------------------------
     3. COULEURS DE REPLI GARANTIES AA (si images absentes ou bloquées)
     ------------------------------------------------------------------------ */
  --sbv-fallback-hero:         #1A120A;
  --sbv-fallback-figures:      #F6EFE2;
  --sbv-fallback-experiences:  #FAF7F2;
  --sbv-fallback-why-us:       #F6EFE2;
  --sbv-fallback-nomad:        #FFFFFF;
  --sbv-fallback-testimonials: #FAF6EE;
  --sbv-fallback-gallery:      #261B10;
  --sbv-fallback-cta:          #1C130B;

  /* ------------------------------------------------------------------------
     4. ÉCHELLE D'ORDRE DES COUCHES (STACKING CONTEXT ISOLÉ)
     ------------------------------------------------------------------------ */
  --z-bg-media:   0; /* ::before — image / texture de fond */
  --z-bg-veil:    1; /* ::after  — voile de contraste WCAG AA */
  --z-bg-sep:     2; /* .sbv-sep — séparateur SVG haut/bas */
  --z-bg-content: 3; /* enfants directs — texte, cartes, CTA */
}

/* ==========================================================================
   BASE COMMUNE — ISOLATION, COUCHES ET CHARGEMENT DIFFÉRÉ SOUS LE PLI
   ========================================================================== */
[class*="bg-section--"] {
  position: relative;
  isolation: isolate; /* Crée un contexte d'empilement local sûr */
  overflow-x: clip;
  background-attachment: scroll; /* Parallaxe strictement interdite */
}

/* Couche 0 : image ou texture (jamais sur l'élément parent pour contrôler l'opacité) */
[class*="bg-section--"]::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-bg-media);
  pointer-events: none;
  background-attachment: scroll;
  opacity: 0;
  transition: opacity 0.45s ease-out;
}

/* Couche 1 : voile d'opacité garantissant le contraste AA */
[class*="bg-section--"]::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-bg-veil);
  pointer-events: none;
}

/* Couche 3 : le contenu passe toujours devant fond, voile et séparateurs */
[class*="bg-section--"] > :not(.sbv-sep):not(.hero__media):not(.hero__overlay):not(.sbv-section-bg-overlay) {
  position: relative;
  z-index: var(--z-bg-content);
}

/* Chargement différé sous le pli :
   Les sections avec [data-bg-lazy] n'injectent pas leur background-image tant que
   l'IntersectionObserver n'ajoute pas .is-bg-loaded (zéro téléchargement avant scroll).
   Sans JS (.no-js), les fonds se chargent normalement. */
[class*="bg-section--"][data-bg-lazy]:not(.is-bg-loaded)::before {
  background-image: none !important;
  opacity: 0;
}

.no-js [class*="bg-section--"][data-bg-lazy]::before,
[class*="bg-section--"].is-bg-loaded::before,
[class*="bg-section--"]:not([data-bg-lazy])::before {
  opacity: var(--section-bg-opacity, 1);
}

/* ==========================================================================
   LES 8 SECTIONS DE LA PAGE D'ACCUEIL
   ========================================================================== */

/* ── 1. HERO : grain.webp (texture légère au-dessus du pli, ne bloque pas le LCP) ── */
.bg-section--hero {
  background-color: var(--sbv-fallback-hero);
  color: #FFFFFF;
  --section-bg-opacity: 0.14;
}

.bg-section--hero::before {
  background-image: var(--bg-grain);
  background-repeat: repeat;
  background-size: 240px 240px;
  mix-blend-mode: soft-light;
}

.bg-section--hero::after {
  /* Voile sombre gradué : contraste garanti >= 11.4:1 pour #FFFFFF */
  background: linear-gradient(
    180deg,
    rgba(20, 13, 7, 0.56) 0%,
    rgba(26, 17, 9, 0.64) 55%,
    rgba(20, 13, 7, 0.78) 100%
  );
}

/* ── 2. CHIFFRES CLÉS : dunes-ripples.webp (photo ondulations, différée) ── */
.bg-section--key-figures {
  background-color: var(--sbv-fallback-figures);
  color: #3B2A17;
  --section-bg-opacity: 1;
}

.bg-section--key-figures::before {
  background-image: var(--bg-dunes-ripples);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.bg-section--key-figures::after {
  /* Voile sable à 84 % : contraste garanti >= 9.4:1 (#3B2A17) / >= 5.8:1 (#5A4A38) */
  background-color: rgba(246, 239, 226, 0.84);
}

/* ── 3. EXPÉRIENCES PHARES : paper-sand.webp (texture papier répétable, différée) ── */
.bg-section--experiences {
  background-color: var(--sbv-fallback-experiences);
  color: #3B2A17;
  --section-bg-opacity: 0.45;
}

.bg-section--experiences::before {
  background-image: var(--bg-paper-sand);
  background-repeat: repeat;
  background-size: 360px 360px;
}

.bg-section--experiences::after {
  /* Voile crème clair à 78 % : contraste garanti >= 11.2:1 (#3B2A17) */
  background-color: rgba(250, 247, 242, 0.78);
}

/* ── 4. POURQUOI NOUS CHOISIR : pattern-diamonds.webp (motif berbère, différé) ── */
.bg-section--why-us {
  background-color: var(--sbv-fallback-why-us);
  color: #3B2A17;
  --section-bg-opacity: 0.12;
}

.bg-section--why-us::before {
  background-image: var(--bg-pattern-diamonds);
  background-repeat: repeat;
  background-size: 160px 160px;
}

.bg-section--why-us::after {
  /* Voile sable subtil à 45 % sur motif à 12 % : contraste garanti >= 10.8:1 */
  background: linear-gradient(
    180deg,
    rgba(246, 239, 226, 0.55) 0%,
    rgba(246, 239, 226, 0.35) 50%,
    rgba(246, 239, 226, 0.55) 100%
  );
}

/* ── 5. IMMERSION NOMADE : wool-weave.webp (trame textile nomade, différée) ── */
.bg-section--nomad {
  background-color: var(--sbv-fallback-nomad);
  color: #283618;
  --section-bg-opacity: 0.16;
}

.bg-section--nomad::before {
  background-image: var(--bg-wool-weave);
  background-repeat: repeat;
  background-size: 280px 280px;
}

.bg-section--nomad::after {
  /* Voile blanc pur à 82 % : contraste garanti >= 10.6:1 (#283618) */
  background-color: rgba(255, 255, 255, 0.82);
}

/* ── 6. AVIS VOYAGEURS : dusk-dunes.webp (dunes au crépuscule, différé) ── */
.bg-section--testimonials {
  background-color: var(--sbv-fallback-testimonials);
  color: #1A140E;
  --section-bg-opacity: 1;
}

.bg-section--testimonials::before {
  background-image: var(--bg-dusk-dunes);
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: cover;
}

.bg-section--testimonials::after {
  /* Voile crème chaud à 86 % : contraste garanti >= 11.8:1 (#1A140E) */
  background-color: rgba(250, 246, 238, 0.86);
}

/* ── 7. APERÇU GALERIE : sand-dark.webp (sable sombre texturé, différé) ── */
.bg-section--gallery {
  background-color: var(--sbv-fallback-gallery);
  color: #F6EFE2;
  --section-bg-opacity: 1;
}

.bg-section--gallery::before {
  background-image: var(--bg-sand-dark);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.bg-section--gallery::after {
  /* Voile brun nuit à 78 % : contraste garanti >= 10.9:1 (#F6EFE2) */
  background-color: rgba(38, 27, 16, 0.78);
}

.bg-section--gallery .gallery-marquee__subtitle {
  color: #F6EFE2;
}

/* ── 8. APPEL À L'ACTION : night-dunes.webp (dunes nocturnes, différé) ── */
.bg-section--cta {
  background-color: var(--sbv-fallback-cta);
  color: #FFFFFF;
  --section-bg-opacity: 1;
}

.bg-section--cta::before {
  background-image: var(--bg-night-dunes);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.bg-section--cta::after {
  /* Voile nuit saharienne à 76 % : contraste garanti >= 11.5:1 (#FFFFFF) */
  background: linear-gradient(
    135deg,
    rgba(28, 19, 11, 0.82) 0%,
    rgba(28, 19, 11, 0.72) 100%
  );
}

.bg-section--cta .cta-split__title,
.bg-section--cta .cta-split__text,
.bg-section--cta .cta-split__check-item,
.bg-section--cta .cta-split__check-item svg {
  color: #F6EFE2;
}

/* ==========================================================================
   4 SÉPARATEURS SVG ENTRE SECTIONS (MASK CSS — 0 REQUÊTE HTTP)
   Utilisation : <div class="sbv-sep sbv-sep--dune-wave" style="--sep-fill:#F6EFE2" aria-hidden="true"></div>
   ========================================================================== */
.sbv-sep {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  z-index: var(--z-bg-sep);
  width: 100%;
  height: 56px;
  background-color: var(--sep-fill, #F6EFE2);
  pointer-events: none;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}

.sbv-sep--top {
  top: -1px;
  bottom: auto;
  transform: scaleY(-1);
}

.sbv-sep--dune-wave {
  height: clamp(36px, 5vw, 72px);
  -webkit-mask-image: var(--sep-dune-wave);
  mask-image: var(--sep-dune-wave);
}

.sbv-sep--dune-ridge {
  height: clamp(32px, 4.5vw, 64px);
  -webkit-mask-image: var(--sep-dune-ridge);
  mask-image: var(--sep-dune-ridge);
}

.sbv-sep--berber-zigzag {
  height: 16px;
  -webkit-mask-image: var(--sep-berber-zigzag);
  mask-image: var(--sep-berber-zigzag);
  -webkit-mask-repeat: repeat-x;
  mask-repeat: repeat-x;
  -webkit-mask-size: 120px 16px;
  mask-size: 120px 16px;
}

.sbv-sep--horizon-arc {
  height: clamp(28px, 4vw, 56px);
  -webkit-mask-image: var(--sep-horizon-arc);
  mask-image: var(--sep-horizon-arc);
}

/* ==========================================================================
   VERSION MOBILE (< 640px) — ALLÈGEMENT AUTOMATIQUE DES FONDS > 100 Ko
   Les 4 grandes photos (> 100 Ko) sont remplacées par leur couleur unie
   pour économiser ~457 Ko sur réseau mobile et accélérer le rendu.
   Les 4 micro-textures légères (< 35 Ko) restent actives.
   ========================================================================== */
@media (max-width: 639px) {
  .bg-section--key-figures::before,
  .bg-section--testimonials::before,
  .bg-section--gallery::before,
  .bg-section--cta::before {
    background-image: none !important;
    content: none;
  }

  .bg-section--key-figures::after,
  .bg-section--testimonials::after,
  .bg-section--gallery::after,
  .bg-section--cta::after {
    content: none;
  }

  .sbv-sep {
    height: 28px;
  }

  .sbv-sep--berber-zigzag {
    height: 12px;
    -webkit-mask-size: 90px 12px;
    mask-size: 90px 12px;
  }
}

/* ==========================================================================
   ACCESSIBILITÉ — DÉSACTIVATION DES ANIMATIONS (prefers-reduced-motion)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  [class*="bg-section--"]::before {
    transition: none !important;
  }
}
