/* ============================
   GALLERY (MOSAIC + LIGHTBOX)
   ============================ */

/* ====== Gallery Wrapper ====== */
.gallery {
  width: 100%;
}

/* ====== Mosaic Grid (ORDENADO como referencia) ====== */
.gallery__grid {
  list-style: none;
  margin: 0;
  padding: 14px;                 /* borde interno blanco */
  background: #fff;

  display: grid;
  grid-template-columns: repeat(24, 1fr); /* 24 columnas para controlar spans */
  grid-auto-rows: 250px;         /* alto consistente por fila */
  gap: 14px;

  /* CLAVE: evita reordenamientos “raros” */
  grid-auto-flow: row;
  padding-top: 8%;
}

/* Items */
.gallery__item {
  margin: 0;
  min-width: 0;
}

/* Botón clickable */
.gallery__btn {
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  display: block;
}

/* Imagen (look limpio, recto, tipo referencia) */
.gallery__img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 0;
  background: #f3f3f3;
}

/* ========= PATRÓN 5 / 4 POR FILA (se repite cada 9 imágenes) =========
   Fila 1: 5 items -> 3 | 8 | 3 | 7 | 3  (suma 24)
   Fila 2: 4 items -> 7 | 7 | 7 | 3      (suma 24)
*/
.gallery__item:nth-child(9n + 1) { grid-column: span 3; }
.gallery__item:nth-child(9n + 2) { grid-column: span 8; }
.gallery__item:nth-child(9n + 3) { grid-column: span 3; }
.gallery__item:nth-child(9n + 4) { grid-column: span 7; }
.gallery__item:nth-child(9n + 5) { grid-column: span 3; }

.gallery__item:nth-child(9n + 6) { grid-column: span 7; }
.gallery__item:nth-child(9n + 7) { grid-column: span 7; }
.gallery__item:nth-child(9n + 8) { grid-column: span 7; }
.gallery__item:nth-child(9n + 9) { grid-column: span 3; }

/* ====== Responsive (Tablet/Small Desktop) ====== */
@media (max-width: 1023px) {
  .gallery__grid {
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 190px;
    gap: 10px;
    padding: 10px;
    padding-top: 8%;
  }

  /* 2 por fila por defecto */
  .gallery__item {
    grid-column: span 6;
  }

  /* algunos “featured” full ancho para look editorial */
  .gallery__item:nth-child(5n + 2) {
    grid-column: span 6;
  }
  .gallery__item:nth-child(9n + 1) {
    grid-column: span 12;
}
.gallery__item:nth-child(9n + 3) {
    grid-column: span 6;
}
.gallery__item:nth-child(9n + 4) {
    grid-column: span 12;
}
.gallery__item:nth-child(9n + 5) {
    grid-column: span 6;
}
.gallery__item:nth-child(9n + 6) {
    grid-column: span 6;
}
}

/* ====== Responsive (≤ 640px) - patrón: full, 2 small, full, 2 small... ====== */
@media (max-width: 640px) {
  .gallery__grid {
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 200px; /* ajusta si quieres más alto o más bajo */
    gap: 10px;
    padding: 10px;
    padding-top: 8%;
  }

  /* Reset claro para no heredar spans anteriores */
  .gallery__item {
    grid-column: span 6;   /* por defecto: 2 imágenes por fila */
    grid-row: span 1;
  }

  /* 1ra de cada 3: imagen full-width */
  .gallery__item:nth-child(3n + 1) {
    grid-column: span 12;  /* full de lado a lado */
  }

  /* (opcional) si quieres que las FULL sean un poquito más altas */
  .gallery__item:nth-child(3n + 1) {
    grid-row: span 1;
  }
}

/* ====== Extra small (≤ 420px) - un poco más alto para que se vea mejor ====== */
@media (max-width: 420px) {
  .gallery__grid {
    grid-auto-rows: 220px;
  }
}

/* ============================
   LIGHTBOX
   ============================ */

.gallery__lightbox[hidden] {
  display: none;
}

.gallery__lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
}

.gallery__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

/* Modal layout */
.gallery__modal {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  padding: 24px;
}

/* Imagen central */
.gallery__figure {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
}

.gallery__viewer {
  max-width: min(1100px, 92vw);
  max-height: 86vh;
  width: auto;
  height: auto;
  border-radius: 14px;
  background: #111;
}

/* Botones */
.gallery__nav,
.gallery__close {
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  border-radius: 12px;
}

.gallery__nav {
  width: 52px;
  height: 52px;
  font-size: 34px;
  line-height: 52px;
}

.gallery__close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  font-size: 28px;
  line-height: 44px;
}

/* Ajustes lightbox en mobile */
@media (max-width: 640px) {
  .gallery__modal {
    grid-template-columns: 52px 1fr 52px;
    padding: 14px;
  }

  .gallery__nav {
    width: 44px;
    height: 44px;
    font-size: 28px;
    line-height: 44px;
  }

  .gallery__close {
    top: 12px;
    right: 12px;
  }
  .gallery__item:nth-child(9n + 2) {
    grid-column: span 12;
}
}
