/**
 * Mosaïque Photographique — Frontend CSS
 * Tous les effets visuels, modes couleur et animations
 *
 * @author  Olivier RIMMEL
 * @version 1.0.0
 */

/* ══════════════════════════════════════════════════════════════
   1. Wrapper & Grid container
══════════════════════════════════════════════════════════════ */

.mosaic-photo-wrapper {
  width: 100%;
  display: block;
  background-color: var(--mp-bg, #0d0d0d);
  overflow: hidden;
  box-sizing: border-box;
  /* Reset des marges héritées des thèmes WordPress */
  margin-top: 0 !important;
  margin-bottom: 3rem !important; /* espace sous la mosaïque */
}

/* Pleine largeur dans les thèmes FSE (Twenty Twenty-Five, etc.) */
.wp-site-blocks > .mosaic-photo-wrapper,
#page > .mosaic-photo-wrapper,
body > .mosaic-photo-wrapper {
  width: 100vw !important;
  max-width: 100vw !important;
  margin-left: calc(50% - 50vw) !important;
  margin-right: calc(50% - 50vw) !important;
  margin-top: 0 !important;
  margin-bottom: 3rem !important;
}

/* Espace entre mosaïque et contenu suivant (thème FSE) */
.mosaic-photo-wrapper + main,
.mosaic-photo-wrapper + .wp-block-group,
.mosaic-photo-wrapper + #primary {
  padding-top: 2rem !important;
  margin-top:  0 !important;
}

.mosaic-photo-grid {
  width: 100%;
  box-sizing: border-box;
  min-height: 100px;
}

.mp-no-images {
  color: #888;
  padding: 2rem;
  text-align: center;
  font-size: 1rem;
}

/* ══════════════════════════════════════════════════════════════
   2. Individual grid item
══════════════════════════════════════════════════════════════ */

.mp-item {
  position: relative;
  display: block;
  overflow: hidden;
  text-decoration: none;
  cursor: pointer;
  background-color: #1e1e1e;
  border-radius: var(--mp-radius, 3px);
  /* Base font-size en px pour que les em des titres se calculent correctement */
  font-size: 14px;
  /* Stacking context for pseudo-element */
  isolation: isolate;
}

.mp-item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition:
    transform    var(--mp-transition, 380ms) cubic-bezier(.4,0,.2,1),
    filter       var(--mp-transition, 380ms) ease,
    opacity      var(--mp-transition, 380ms) ease;
  will-change: transform, filter, opacity;
}

/* Hover overlay pseudo-element */
.mp-item::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--mp-transition, 380ms) ease;
  z-index: 1;
}

/* ══════════════════════════════════════════════════════════════
   3. Hover effects (controlled by wrapper class)
══════════════════════════════════════════════════════════════ */

/* ── Zoom ── */
.mosaic-hover-zoom .mp-item:hover img,
.mosaic-hover-lift  .mp-item:hover img {
  transform: scale(var(--mp-zoom, 1.07));
}

/* ── Brightness ── */
.mosaic-hover-brightness .mp-item:hover img {
  filter: brightness(1.18) saturate(1.1);
}

/* ── Overlay ── */
.mosaic-hover-overlay .mp-item::after {
  background-color: var(--mp-overlay-color, #000);
}
.mosaic-hover-overlay .mp-item:hover::after {
  opacity: var(--mp-overlay-alpha, 0.2);
}

/* ── Lift (zoom + shadow) ── */
.mosaic-hover-lift .mp-item {
  transition: box-shadow var(--mp-transition, 380ms) ease,
              transform  var(--mp-transition, 380ms) cubic-bezier(.4,0,.2,1);
}
.mosaic-hover-lift .mp-item:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  z-index: 2;
}
.mosaic-hover-lift .mp-item:hover img {
  transform: scale(var(--mp-zoom, 1.07));
}

/* ── None ── (nothing to add) */

/* ══════════════════════════════════════════════════════════════
   4. Color modes (wrapper classes)
══════════════════════════════════════════════════════════════ */

/* ── Black & White ── */
.mosaic-mode-bw .mp-item img {
  filter: grayscale(100%);
}
.mosaic-mode-bw .mp-item:hover img {
  filter: grayscale(0%) brightness(1.05);
}

/* ── Sepia ── */
.mosaic-mode-sepia .mp-item img {
  filter: sepia(85%) contrast(1.05);
}
.mosaic-mode-sepia .mp-item:hover img {
  filter: sepia(0%) contrast(1);
}

/* ── Vintage ── */
.mosaic-mode-vintage .mp-item img {
  filter: sepia(35%) contrast(1.12) brightness(0.9) saturate(0.75) hue-rotate(-5deg);
}
.mosaic-mode-vintage .mp-item:hover img {
  filter: sepia(0%) contrast(1) brightness(1) saturate(1);
}

/* ── Combine BW with Hover effects ── */
.mosaic-mode-bw.mosaic-hover-brightness .mp-item:hover img {
  filter: grayscale(0%) brightness(1.15) saturate(1.1);
}
.mosaic-mode-bw.mosaic-hover-zoom .mp-item:hover img {
  filter: grayscale(0%);
  transform: scale(var(--mp-zoom, 1.07));
}

/* ══════════════════════════════════════════════════════════════
   5. Title overlays
══════════════════════════════════════════════════════════════ */

.mp-title {
  position: absolute;
  left: 0;
  right: 0;
  padding: 0.5em 0.7em 0.45em;
  color: var(--mp-title-color, #fff);
  font-family: var(--mp-title-font, inherit); /* hérite de la police du thème */
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 4px rgba(0,0,0,.55);
  z-index: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  transition: opacity var(--mp-transition, 380ms) ease,
              transform var(--mp-transition, 380ms) ease;
}

/* ── Bottom position (default) ── */
.mp-title--bottom {
  bottom: 0;
  top: auto;
  background: linear-gradient(
    to top,
    rgba(0,0,0,calc(var(--mp-title-overlay, 0.72) * 1.0)) 0%,
    rgba(0,0,0,calc(var(--mp-title-overlay, 0.72) * 0.6)) 50%,
    transparent 100%
  );
  padding-top: 1.8em;
  transform: translateY(2px);
}
.mp-item:hover .mp-title--bottom {
  transform: translateY(0);
}

/* ── Top position ── */
.mp-title--top {
  top: 0;
  bottom: auto;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,calc(var(--mp-title-overlay, 0.72) * 1.0)) 0%,
    rgba(0,0,0,calc(var(--mp-title-overlay, 0.72) * 0.6)) 50%,
    transparent 100%
  );
  padding-bottom: 1.8em;
  transform: translateY(-2px);
}
.mp-item:hover .mp-title--top {
  transform: translateY(0);
}

/* ── Hover-only visibility ── */
.mosaic-titles-hover .mp-title,
.mp-title--hover-only {
  opacity: 0;
}
.mosaic-titles-hover .mp-item:hover .mp-title,
.mp-item:hover .mp-title--hover-only {
  opacity: 1;
}

/* ── Never ── */
.mosaic-titles-never .mp-title {
  display: none;
}

/* Line clamp via CSS variable */
.mp-title {
  -webkit-line-clamp: var(--mp-title-lines, 2);
}

/* ══════════════════════════════════════════════════════════════
   6. Entry animations
══════════════════════════════════════════════════════════════ */

/* Fade in */
@keyframes mpFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.mp-anim--fadein {
  animation: mpFadeIn 0.55s ease both;
}

/* Slide in from bottom */
@keyframes mpSlideIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.mp-anim--slidein {
  animation: mpSlideIn 0.5s cubic-bezier(.4,0,.2,1) both;
}

/* Scale in */
@keyframes mpScaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}
.mp-anim--scalein {
  animation: mpScaleIn 0.45s cubic-bezier(.4,0,.2,1) both;
}

/* ══════════════════════════════════════════════════════════════
   7. Loading shimmer (shown before images load)
══════════════════════════════════════════════════════════════ */

.mp-item::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    rgba(255,255,255,0)     35%,
    rgba(255,255,255,0.07)  50%,
    rgba(255,255,255,0)     65%
  );
  background-size: 300% 100%;
  animation: mpShimmer 1.8s infinite ease-in-out;
  pointer-events: none;
  z-index: 0;
  border-radius: inherit;
}
@keyframes mpShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ══════════════════════════════════════════════════════════════
   8. Accessibility: focus styles
══════════════════════════════════════════════════════════════ */

.mp-item:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  z-index: 10;
}

/* ══════════════════════════════════════════════════════════════
   9. Reduced motion
══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .mp-item img,
  .mp-title,
  .mp-item,
  .mp-item::after {
    transition: none !important;
    animation: none !important;
  }
  .mp-item::before {
    animation: none !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   11. Date overlay (position opposée au titre)
══════════════════════════════════════════════════════════════ */

.mp-date {
  position: absolute;
  left: 0;
  right: 0;
  padding: 0.4em 0.6em;
  color: var(--mp-title-color, #fff);
  font-family: var(--mp-title-font, inherit); /* hérite de la police du thème */
  font-size: 0.62em;
  font-weight: 500;
  letter-spacing: 0.04em;
  opacity: 0.75;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
  z-index: 2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transition: opacity var(--mp-transition, 380ms) ease;
}

/* ── Position haute ── */
.mp-date--top {
  top: 0;
  bottom: auto;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,calc(var(--mp-title-overlay, 0.72) * 0.55)) 0%,
    transparent 100%
  );
  padding-bottom: 1.2em;
}

/* ── Position basse ── */
.mp-date--bottom {
  bottom: 0;
  top: auto;
  background: linear-gradient(
    to top,
    rgba(0,0,0,calc(var(--mp-title-overlay, 0.72) * 0.55)) 0%,
    transparent 100%
  );
  padding-top: 1.2em;
}

/* ── Hover-only (suit la visibilité du titre) ── */
.mosaic-titles-hover .mp-date,
.mp-date--hover-only {
  opacity: 0;
}
.mosaic-titles-hover .mp-item:hover .mp-date,
.mp-item:hover .mp-date--hover-only {
  opacity: 0.75;
}
