/* ==========================================================
   LOMISA · PROJECT GALLERY
   Galería interactiva reutilizable para Gutenberg

   Bloque: .lm-project-gallery
   JS: project-gallery.js

   Diseño:
   - Imagen principal a la izquierda
   - Miniaturas a la derecha
   - 4 miniaturas: 2 columnas x 2 filas
   - Misma altura total en ambas zonas
   ========================================================== */

/* ----------------------------------------------------------
   01. VARIABLES
   ---------------------------------------------------------- */

.lm-project-gallery {
    --lm-gallery-gap: 12px;
    --lm-gallery-accent: var(--lm-color-accent);
    --lm-gallery-background: #f2f4f6;

    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box;
}

/* ----------------------------------------------------------
   02. GALERÍA ORIGINAL DE GUTENBERG
   Se conserva hasta que JavaScript la transforme
   ---------------------------------------------------------- */

.wp-block-gallery.lm-project-gallery:not(.is-enhanced) {
    display: flex !important;
}

/* ----------------------------------------------------------
   03. ESTRUCTURA PRINCIPAL
   ---------------------------------------------------------- */

.wp-block-gallery.lm-project-gallery.is-enhanced {
    display: grid !important;

    grid-template-columns:
        minmax(0, 1.1fr)
        minmax(0, 1fr) !important;

    grid-template-rows: minmax(0, 1fr) !important;

    gap: var(--lm-gallery-gap) !important;

    align-items: stretch !important;

    aspect-ratio: 3 / 1;

    overflow: hidden;
}

/* ----------------------------------------------------------
   04. VISOR PRINCIPAL
   ---------------------------------------------------------- */

.lm-project-gallery.is-enhanced .lm-project-gallery__main {
    position: relative;

    width: 100%;
    height: 100%;

    min-width: 0;
    min-height: 0;

    overflow: hidden;

    background: var(--lm-gallery-background);
}

.lm-project-gallery.is-enhanced .lm-project-gallery__main-image {
    position: absolute;

    inset: 0;

    display: block;

    width: 100% !important;
    height: 100% !important;

    max-width: none !important;

    object-fit: cover;
    object-position: center;
}

/* ----------------------------------------------------------
   05. CONTENEDOR DE MINIATURAS
   ---------------------------------------------------------- */

.lm-project-gallery.is-enhanced .lm-project-gallery__thumbs {
    display: grid !important;

    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));

    gap: var(--lm-gallery-gap) !important;

    width: 100%;
    height: 100%;

    min-width: 0;
    min-height: 0;

    overflow: hidden;
}

/* ----------------------------------------------------------
   06. FIGURAS DE GUTENBERG
   Neutralizamos sus tamaños y proporciones
   ---------------------------------------------------------- */

.lm-project-gallery.is-enhanced
.lm-project-gallery__thumbs > figure.wp-block-image {
    position: relative !important;

    display: block !important;

    flex: none !important;

    grid-column: auto !important;
    grid-row: auto !important;

    width: 100% !important;
    height: 100% !important;

    max-width: none !important;

    min-width: 0 !important;
    min-height: 0 !important;

    aspect-ratio: auto !important;

    margin: 0 !important;
    padding: 0 !important;

    overflow: hidden !important;

    box-sizing: border-box;

    cursor: pointer;
}

/* ----------------------------------------------------------
   07. IMÁGENES DE LAS MINIATURAS
   ---------------------------------------------------------- */

.lm-project-gallery.is-enhanced
.lm-project-gallery__thumbs > figure.wp-block-image img {
    position: absolute !important;

    inset: 0;

    display: block !important;

    width: 100% !important;
    height: 100% !important;

    max-width: none !important;

    object-fit: cover !important;
    object-position: center !important;

    transition: transform 0.35s ease;
}

.lm-project-gallery.is-enhanced
.lm-project-gallery__thumbs > figure.wp-block-image:hover img {
    transform: scale(1.035);
}

/* ----------------------------------------------------------
   08. MINIATURA ACTIVA
   ---------------------------------------------------------- */

.lm-project-gallery.is-enhanced
.lm-project-gallery__thumbs > figure.is-active {
    outline: 3px solid var(--lm-gallery-accent);
    outline-offset: -3px;
}

/* ----------------------------------------------------------
   09. DISTRIBUCIÓN SEGÚN CANTIDAD DE IMÁGENES
   ---------------------------------------------------------- */

/* 1 imagen */

.lm-project-gallery.is-enhanced[data-count="1"]
.lm-project-gallery__thumbs {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

/* 2 imágenes */

.lm-project-gallery.is-enhanced[data-count="2"]
.lm-project-gallery__thumbs {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, minmax(0, 1fr));
}

/* 3 imágenes */

.lm-project-gallery.is-enhanced[data-count="3"]
.lm-project-gallery__thumbs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
}

.lm-project-gallery.is-enhanced[data-count="3"]
.lm-project-gallery__thumbs > figure:first-child {
    grid-column: 1 / -1 !important;
}

/* 4 imágenes: 2 columnas y 2 filas */

.lm-project-gallery.is-enhanced[data-count="4"]
.lm-project-gallery__thumbs {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
}

/* 5 o 6 imágenes */

.lm-project-gallery.is-enhanced[data-count="5"]
.lm-project-gallery__thumbs,
.lm-project-gallery.is-enhanced[data-count="6"]
.lm-project-gallery__thumbs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
}

/* ----------------------------------------------------------
   10. TABLET
   ---------------------------------------------------------- */

@media (min-width: 768px) and (max-width: 1024px) {

    .wp-block-gallery.lm-project-gallery.is-enhanced {
        aspect-ratio: 2.6 / 1;
        gap: 8px !important;
    }

    .lm-project-gallery.is-enhanced
    .lm-project-gallery__thumbs {
        gap: 8px !important;
    }
}

/* ----------------------------------------------------------
   11. MÓVIL
   ---------------------------------------------------------- */

@media (max-width: 767px) {

    .wp-block-gallery.lm-project-gallery.is-enhanced {
        display: flex !important;
        flex-direction: column !important;

        aspect-ratio: auto !important;

        gap: 8px !important;

        overflow: visible;
    }

    .lm-project-gallery.is-enhanced
    .lm-project-gallery__main {
        height: auto !important;

        aspect-ratio: 16 / 10;
    }

    .lm-project-gallery.is-enhanced
    .lm-project-gallery__thumbs {
        height: auto !important;

        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        grid-template-rows: auto !important;

        gap: 8px !important;

        overflow: visible;
    }

    .lm-project-gallery.is-enhanced
    .lm-project-gallery__thumbs > figure.wp-block-image {
        grid-column: auto !important;
        grid-row: auto !important;

        height: auto !important;
        aspect-ratio: 16 / 10 !important;
    }
}