/* ========================================
   BS CUSTOM - MOBILE PERFORMANCE 2026
   Optimisations Core Web Vitals
   LCP, CLS, INP optimizations
   ======================================== */

/* ==================== CRITICAL: PREVENT LAYOUT SHIFTS (CLS) ==================== */

/* Reserve space for images to prevent CLS */
@media (max-width: 980px) {
  /* Hero images - fixed aspect ratio */
  .hero {
    aspect-ratio: auto;
    contain: layout style;
  }

  .hero-slide,
  .hero-bg {
    position: absolute;
    inset: 0;
  }

  /* Gallery images */
  .gallery-item {
    aspect-ratio: 1/1;
    position: relative;
    contain: layout;
  }

  .gallery-item img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* Service cards : plus de ratio forcé, il coupait le texte des cartes (audit 25.09.2026) */
  .svc-card {
    min-height: auto;
  }

  /* Instagram feed items */
  .instagram-item {
    aspect-ratio: 1/1;
    contain: layout;
  }

  /* Brand logo */
  .brand-mark {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
  }

  .brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

/* ==================== OPTIMIZE LCP (Largest Contentful Paint) ==================== */

@media (max-width: 980px) {
  /* Hero background - optimize rendering */
  .hero-slide {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    /* Hint browser to prioritize */
    content-visibility: visible;
  }

  /* First hero slide is LCP - prioritize */
  .hero-slide.is-active {
    z-index: 1;
  }

  /* Defer non-critical hero slides */
  .hero-slide:not(.is-active) {
    content-visibility: auto;
  }

  /* Optimize text rendering for LCP text */
  .hero-title,
  .hero-word,
  .hero-tagline {
    text-rendering: optimizeSpeed;
  }
}

/* ==================== OPTIMIZE INP (Interaction to Next Paint) ==================== */

@media (max-width: 980px) {
  /* Ensure fast touch response */
  .btn,
  .filter-btn,
  .mobile-nav-item,
  .vehicle-card,
  .shop-card,
  a,
  button {
    /* Fast tap response */
    touch-action: manipulation;

    /* Prevent 300ms tap delay */
    -webkit-tap-highlight-color: transparent;

    /* NB (Phase 3.6 / P1-P4) : plus de will-change/translateZ global ici.
       Promouvoir chaque a/button/carte en couche GPU multipliait les layers
       et dégradait l'INP sur mobile bas de gamme. On garde touch-action seul. */
  }

  /* Optimize transitions for 60fps */
  .btn,
  .filter-btn,
  .vehicle-card,
  .shop-card,
  .svc-card {
    transition-property: transform, opacity, background-color, border-color, box-shadow;
    transition-duration: 0.15s;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Use GPU-accelerated properties only */
  .mobile-nav-item:active,
  .btn:active,
  .filter-btn:active,
  .vehicle-card:active,
  .shop-card:active {
    transform: scale(0.97) translateZ(0);
  }
}

/* ==================== CONTAIN FOR PERFORMANCE ==================== */

@media (max-width: 980px) {
  /* Contain layout for major sections */
  .section {
    contain: layout style;
  }

  .footer {
    contain: layout style;
  }

  .svc-card {
    contain: layout style;
  }

  /* Mobile nav containment */
  .mobile-bottom-nav {
    contain: layout style;
    isolation: isolate;
  }
}

/* ==================== CONTENT VISIBILITY (Auto-load) ==================== */

@media (max-width: 980px) {
  /* Defer rendering of below-fold content */
  .section:not(:first-of-type) {
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
  }

  .footer {
    content-visibility: auto;
    contain-intrinsic-size: auto 400px;
  }

  /* Gallery and Instagram - defer */
  .gallery-grid,
  .instagram-feed {
    content-visibility: auto;
    contain-intrinsic-size: auto 300px;
  }
}

/* ==================== FONT OPTIMIZATION ==================== */

@media (max-width: 980px) {
  /* Optimize font rendering */
  body {
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

}

/* ==================== IMAGE OPTIMIZATION ==================== */

@media (max-width: 980px) {
  /* Lazy load images by default */
  img[loading="lazy"] {
    /* Fade in when loaded */
    opacity: 1;
    transition: opacity 0.3s ease;
  }

  img[loading="lazy"]:not([src]) {
    opacity: 0;
  }

  /* Anti layout-shift images (Phase 3.6 / P1-P5) : image-rendering:crisp-edges
     retiré — il pixellisait les photos redimensionnées. On garde le fit fluide. */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Background images optimization */
  [style*="background-image"] {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
  }
}

/* ==================== SCROLL OPTIMIZATION ==================== */

@media (max-width: 980px) {
  /* Défilement lissé : géré par Lenis (JS), jamais en CSS (conflit) */
}

/* ==================== ANIMATION PERFORMANCE ==================== */

@media (max-width: 980px) {
  /* Use transform and opacity only for animations */
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes slideIn {
    from {
      transform: translateX(-100%);
    }
    to {
      transform: translateX(0);
    }
  }

  /* Ensure animations use GPU */
  .hero-slide {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
  }

  /* Mouvement réduit : règle globale dans theme.css */
}

/* ==================== PAINT OPTIMIZATION ==================== */

@media (max-width: 980px) {
  /* Isolate elements that change frequently */
  .mobile-bottom-nav,
  .nav,
  .hero-dots,
  .hero-slide {
    isolation: isolate;
  }

  /* Optimize layers */
  .hero {
    transform: translateZ(0);
  }

  /* Prevent unnecessary repaints */
  .btn:hover,
  .filter-btn:hover,
  .vehicle-card:hover,
  .shop-card:hover {
    will-change: transform;
  }

  .btn:not(:hover),
  .filter-btn:not(:hover),
  .vehicle-card:not(:hover),
  .shop-card:not(:hover) {
    will-change: auto;
  }
}

/* ==================== FORM OPTIMIZATION ==================== */

@media (max-width: 980px) {
  /* Optimize form inputs.
     appearance:none efface le rendu natif : sur une case a cocher ou un bouton
     radio, il ne reste plus rien a l'ecran. On les exclut donc ici ; le garde-fou
     anti-zoom iOS ne concerne que les champs de saisie. Les composants qui
     dessinent leur propre case (.auth-remember, .radio-pill) redeclarent
     appearance:none de leur cote et ne sont pas touches. */
  input:not([type="checkbox"]):not([type="radio"]),
  textarea,
  select {
    /* Prevent zoom on iOS */
    font-size: 16px !important;

    -webkit-appearance: none;
    appearance: none;
  }

}

