/* ═══════════════════════════════════════════════════════════════════════════
   Optimisations Performance Images — Galerie Assa
   • Responsive images avec srcset
   • Constraints strictes sur la taille
   • Lazy loading avec background colors
   • Improved video performance
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Image & Video Optimization ────────────────────────────────────────────── */

/* Toutes les images dans les cards */
.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Prévient le débordement */
  max-width: 100%;
  /* Background pendant le chargement */
  background-color: #f9a8d4;
  background-image: linear-gradient(135deg, #fce7f3 25%, #fbcfe8 50%, #fce7f3 75%);
  background-size: 200% 100%;
  animation: imgLoadingShimmer 2s ease-in-out infinite;
}

.card-img[src],
.card-img[srcset] {
  animation: none;
  background-image: none;
}

@keyframes imgLoadingShimmer {
  0%, 100% { background-position: 200% center; }
  50% { background-position: -200% center; }
}

/* Toutes les vidéos */
video {
  max-width: 100%;
  display: block;
  /* Empêche les débordements */
  width: 100%;
  height: auto;
}

/* Video dans les cards */
.card-img[is="video"],
.scroll-card video,
.grid-card video,
video.media-main {
  background: #f9a8d4;
}

/* Image principale dans les pages œuvre */
.media-main {
  width: 100%;
  /* Force le max pour éviter les débordements */
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  /* Responsive */
  display: block;
}

.media-main.single {
  max-height: 70vh;
}

/* Carrousel images */
.carousel-slide img,
.carousel-slide video {
  width: 100%;
  height: 100%;
  /* Important: contain au lieu de cover pour les carrousels */
  object-fit: contain;
  /* Empêche le débordement */
  max-width: 100%;
  display: block;
}

/* Vignettes du carrousel */
.thumb-strip {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.thumb-btn img,
.thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Important pour éviter les débordements */
  max-width: 100%;
}

/* ── Responsive Containers ─────────────────────────────────────────────────── */

/* Limiter la largeur du layout principal */
.oeuvre-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 32px;
  align-items: start;
  /* Important: max-width pour éviter les images trop larges */
  max-width: 100%;
  width: 100%;
}

.oeuvre-media {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.carousel {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg2);
  aspect-ratio: 4/3;
  width: 100%;
  max-width: 100%;
}

/* ── Works Grid Responsive ─────────────────────────────────────────────────── */

.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  width: 100%;
}

.grid-card {
  height: 260px;
  width: 100%;
  /* Important: overflow pour capturer les images qui débordent */
  overflow: hidden;
}

/* ── Hero Grid Optimization ────────────────────────────────────────────────── */

.hero-grid {
  display: grid;
  grid-template-columns: 1.8fr 1fr 1fr;
  grid-template-rows: 260px 260px;
  gap: 12px;
  width: 100%;
}

.hero-main,
.hero-side {
  overflow: hidden;
}

/* ── Mobile Optimization ──────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .oeuvre-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .oeuvre-info {
    position: static !important;
  }

  .hero-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .hero-main,
  .hero-side {
    grid-column: auto !important;
    grid-row: auto !important;
  }

  .works-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }

  .grid-card {
    height: 220px;
  }
}

@media (max-width: 640px) {
  .oeuvre-layout {
    gap: 16px;
  }

  .media-main {
    max-height: 50vh;
  }

  .media-main.single {
    max-height: 50vh;
  }

  .scroll-row {
    gap: 10px;
  }

  .scroll-card {
    min-width: 160px;
    max-width: 160px;
    height: 200px;
  }

  .works-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }

  .grid-card {
    height: 180px;
  }

  .hero-grid {
    grid-template-columns: 1fr;
  }

  .thumb-btn {
    min-width: 50px;
    max-width: 50px;
    height: 40px;
  }
}

/* ── Content wrapper constraints ───────────────────────────────────────────── */

.g-main {
  flex: 1;
  padding: 32px 28px 60px;
  max-width: 1200px;
  width: 100%;
  /* Important: box-sizing et overflow pour éviter les débordements */
  box-sizing: border-box;
  overflow-x: hidden;
}

/* ── Prévention des débordements horizontaux ──────────────────────────────── */

body {
  overflow-x: hidden;
  box-sizing: border-box;
}

* {
  box-sizing: border-box;
}

/* ── Lazy Loading Placeholder ──────────────────────────────────────────────── */

img[loading="lazy"],
img[data-src] {
  background-color: #f9a8d4;
  background-image: linear-gradient(
    90deg,
    #fce7f3 0%,
    #fbcfe8 50%,
    #fce7f3 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Video Optimization ────────────────────────────────────────────────────── */

video {
  /* Prévient le redimensionnement aléatoire */
  aspect-ratio: auto;
}

.carousel-slide video {
  /* Contient la vidéo sans déborder */
  object-fit: contain;
  background: #f9a8d4;
}

.media-main[preload="metadata"] {
  /* Le preload metadata suffit */
}

/* ── Focus Performance ─────────────────────────────────────────────────────── */

/* Désactive les animations pendant le scroll pour améliorer les perfs */
.scroll-row::-webkit-scrollbar-thumb {
  background: var(--pink-200);
  border-radius: 2px;
}

.thumb-strip::-webkit-scrollbar {
  height: 3px;
}

.thumb-strip::-webkit-scrollbar-thumb {
  background: var(--pink-300);
  border-radius: 2px;
}

/* Désactive les animations lourdes sur les appareils lents */
@media (prefers-reduced-motion: reduce) {
  .card-img,
  img[loading="lazy"],
  .carousel-track,
  .work-card {
    animation: none !important;
    transition: none !important;
  }
}

/* ── Aspect Ratio preservation ─────────────────────────────────────────────── */

.card-img,
.scroll-card,
.grid-card,
.hero-card {
  aspect-ratio: auto / auto;
}

/* ── Print optimization ────────────────────────────────────────────────────── */

@media print {
  .carousel-btn,
  .carousel-dots,
  .thumb-strip,
  .oeuvre-nav {
    display: none !important;
  }

  .media-main {
    max-height: none;
  }
}
