/* ============================================================
   Photo Display – Public Styles  v1.1
   Author: Richard LALIEU / Dub Silence
   Fix: images nettes — on utilise la taille réelle de chaque image
        pour masonry/justified ; object-fit uniquement quand la
        cellule a une taille imposée (grid, mosaic, honeycomb).
   ============================================================ */

/* ---- Variables ---- */
.pd-gallery {
  --pd-cols: 3;
  --pd-gap:  10px;
  width: 100%;
  box-sizing: border-box;
}

/* ---- Base item ---- */
.pd-item { position: relative; overflow: hidden; }
.pd-item a { display: block; }

/* ============================================================
   1. MASONRY  — hauteur naturelle de chaque image (pas de flou)
   ============================================================ */
.pd-layout-masonry {
  column-count: var(--pd-cols);
  column-gap: var(--pd-gap);
}
.pd-layout-masonry .pd-item {
  break-inside: avoid;
  margin-bottom: var(--pd-gap);
  display: block;
}
.pd-layout-masonry .pd-item img {
  width: 100%;
  height: auto;      /* ← prop. naturelle, aucun étirement */
  display: block;
}

/* ============================================================
   2. GRILLE UNIFORME — ratio imposé, object-fit nécessaire
      On affiche en "medium_large" (768px max WordPress) pour la netteté
   ============================================================ */
.pd-layout-grid {
  display: grid;
  grid-template-columns: repeat(var(--pd-cols), 1fr);
  gap: var(--pd-gap);
}
.pd-layout-grid .pd-item {
  aspect-ratio: 4/3;
  overflow: hidden;
}
.pd-layout-grid .pd-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* object-position peut être personnalisé via data-attr en JS */
}

/* ============================================================
   3. MOSAÏQUE LIBRE — cellules fixes, taille suffisante (300px base)
   ============================================================ */
.pd-layout-mosaic {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 240px;
  gap: var(--pd-gap);
}
.pd-layout-mosaic .pd-item:nth-child(7n+1) { grid-column: span 2; grid-row: span 2; }
.pd-layout-mosaic .pd-item:nth-child(7n+4) { grid-column: span 4; grid-row: span 1; }
.pd-layout-mosaic .pd-item:nth-child(7n+7) { grid-column: span 2; grid-row: span 2; }
.pd-layout-mosaic .pd-item { overflow: hidden; }
.pd-layout-mosaic .pd-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================================
   4. JUSTIFIÉE — lignes de hauteur fixe, largeur naturelle
      L'image garde sa proportion via flex-grow calculé en JS
   ============================================================ */
.pd-layout-justified {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pd-gap);
}
.pd-layout-justified .pd-item {
  height: 240px;
  flex-grow: 1;          /* JS ajuste flex-basis selon le ratio natif */
  overflow: hidden;
  min-width: 80px;
}
.pd-layout-justified .pd-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;     /* couvre la cellule sans étirer */
  display: block;
}

/* ============================================================
   5. NIDS D'ABEILLE
   ============================================================ */
.pd-layout-honeycomb {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pd-gap);
  justify-content: center;
}
.pd-layout-honeycomb .pd-item {
  width: calc( (100% - (var(--pd-cols) - 1) * var(--pd-gap)) / var(--pd-cols) );
  aspect-ratio: 1;
  overflow: hidden;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
.pd-layout-honeycomb .pd-item:nth-child(even) {
  margin-top: calc( var(--pd-gap) * 2 );
}
.pd-layout-honeycomb .pd-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================================
   6. FILMSTRIP — hauteur fixe, largeur auto (ratio conservé)
   ============================================================ */
.pd-layout-filmstrip {
  display: flex;
  overflow-x: auto;
  gap: var(--pd-gap);
  padding-bottom: 10px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.pd-layout-filmstrip::-webkit-scrollbar { height: 5px; }
.pd-layout-filmstrip::-webkit-scrollbar-thumb { background: #bbb; border-radius: 3px; }
.pd-layout-filmstrip .pd-item {
  flex: 0 0 auto;
  height: 280px;
  scroll-snap-align: start;
  overflow: hidden;
}
.pd-layout-filmstrip .pd-item img {
  height: 100%;
  width: auto;           /* largeur naturelle = ratio conservé */
  display: block;
  object-fit: cover;     /* sécurité si l'image est trop petite */
  max-width: none;
}

/* ============================================================
   Coins arrondis
   ============================================================ */
.pd-rounded-sm .pd-item { border-radius: 4px; }
.pd-rounded-md .pd-item { border-radius: 8px; }
.pd-rounded-lg .pd-item { border-radius: 16px; }
.pd-rounded-full .pd-item { border-radius: 50%; }

/* ============================================================
   Hover effects
   ============================================================ */
.pd-hover-zoom .pd-item img {
  transition: transform .4s cubic-bezier(.25,.46,.45,.94);
}
.pd-hover-zoom .pd-item:hover img { transform: scale(1.07); }

.pd-hover-fade .pd-item img { transition: opacity .35s ease; }
.pd-hover-fade .pd-item:hover img { opacity: .65; }

.pd-hover-slide .pd-item img {
  transition: transform .4s cubic-bezier(.25,.46,.45,.94);
}
.pd-hover-slide .pd-item:hover img { transform: translateY(-6px) scale(1.03); }

.pd-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.65) 0%, rgba(0,0,0,0) 60%);
  display: flex;
  align-items: flex-end;
  padding: 14px;
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
}
.pd-hover-overlay .pd-item:hover .pd-overlay { opacity: 1; }
.pd-caption {
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}

/* ============================================================
   PICKER DE GROUPE (shortcode [photo_display_picker])
   ============================================================ */
.pd-picker-wrap {
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.pd-picker-label {
  font-weight: 600;
  font-size: 14px;
  color: #333;
  white-space: nowrap;
}
.pd-picker-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 9px 36px 9px 14px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23555' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  cursor: pointer;
  min-width: 200px;
  transition: border-color .2s, box-shadow .2s;
  color: #222;
}
.pd-picker-select:focus {
  outline: none;
  border-color: #e85d26;
  box-shadow: 0 0 0 3px rgba(232,93,38,.12);
}

/* Transitions de galerie */
.pd-picker-gallery-wrap { position: relative; }
.pd-picker-gallery-wrap .pd-gallery {
  transition: opacity .3s ease;
}
.pd-picker-gallery-wrap.pd-loading .pd-gallery {
  opacity: .35;
  pointer-events: none;
}
.pd-picker-empty {
  padding: 40px;
  text-align: center;
  color: #888;
  font-style: italic;
  border: 2px dashed #ddd;
  border-radius: 8px;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.pd-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pd-lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.93);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.pd-lightbox-inner {
  position: relative;
  z-index: 1;
  max-width: 96vw;
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.pd-lb-img-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 120px;
  min-height: 80px;
}
.pd-lb-img {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 3px;
  box-shadow: 0 24px 80px rgba(0,0,0,.7);
  opacity: 0;
  transition: opacity .3s ease;
  display: block;
}
.pd-lb-img.loaded { opacity: 1; }

/* Spinner */
.pd-lb-spinner {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: pd-spin .65s linear infinite;
}
.pd-lb-spinner.hidden { display: none; }
@keyframes pd-spin { to { transform: rotate(360deg); } }

/* Controls — reset complet pour neutraliser les styles bouton du thème */
.pd-lb-close,
.pd-lb-prev,
.pd-lb-next {
  position: fixed;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  backdrop-filter: blur(4px);
  /* Reset anti-thème : sans ça, le padding/line-height du thème décale l'icône */
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  line-height: 0;
  font-size: 0;
  box-shadow: none;
  text-shadow: none;
  min-width: 0;
  min-height: 0;
}
.pd-lb-close svg,
.pd-lb-prev svg,
.pd-lb-next svg {
  display: block;   /* supprime l'espace de baseline sous le SVG inline */
  flex: 0 0 auto;
}
.pd-lb-close:hover,
.pd-lb-prev:hover,
.pd-lb-next:hover { background: rgba(255,255,255,.22); }
.pd-lb-close { top: 18px; right: 18px; }
.pd-lb-prev  { left: 14px;  top: 50%; transform: translateY(-50%); }
.pd-lb-next  { right: 14px; top: 50%; transform: translateY(-50%); }
.pd-lb-caption {
  color: rgba(255,255,255,.8);
  font-size: 14px;
  text-align: center;
  margin: 10px 0 3px;
  max-width: 80vw;
}
.pd-lb-counter {
  color: rgba(255,255,255,.4);
  font-size: 12px;
  text-align: center;
  margin: 0;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .pd-layout-masonry   { column-count: 2 !important; }
  .pd-layout-grid      { grid-template-columns: repeat(2, 1fr) !important; }
  .pd-layout-mosaic    { grid-template-columns: repeat(2, 1fr) !important; grid-auto-rows: 180px !important; }
  .pd-layout-mosaic .pd-item:nth-child(7n+4) { grid-column: span 2 !important; }
  .pd-layout-honeycomb .pd-item { width: calc(50% - var(--pd-gap)) !important; }
}
@media (max-width: 540px) {
  .pd-layout-masonry   { column-count: 1 !important; }
  .pd-layout-grid      { grid-template-columns: repeat(2, 1fr) !important; }
  .pd-layout-mosaic    { grid-template-columns: repeat(2, 1fr) !important; grid-auto-rows: 140px !important; }
  .pd-layout-mosaic .pd-item { grid-column: auto !important; grid-row: auto !important; }
  .pd-layout-honeycomb .pd-item { width: calc(50% - var(--pd-gap)) !important; }
  .pd-layout-justified .pd-item { height: 160px; }
  .pd-layout-filmstrip .pd-item { height: 200px; }
  .pd-lb-prev { left: 4px; }
  .pd-lb-next { right: 4px; }
  .pd-picker-select { min-width: 160px; }
}
