/**
 * Gallery Component - Blue Apulia Child
 * Ispirato a PAF / Airbnb
 */

/* --- GRIGLIA PRINCIPALE (BENTO) --- */
.ba-gallery-grid-container {
    position: relative;
    width: 100%;
    margin-bottom: 2rem;
    margin-top: 2rem;
}

.ba-gallery-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    height: 480px; /* Altezza desktop */
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.ba-gallery-item {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #f0f0f0;
}

.ba-gallery-item a {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.ba-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.ba-gallery-item:hover img {
    transform: scale(1.03);
}

/* Hero Image (Prima foto): occupa 2 righe nella prima colonna (metà larghezza tot) */
.ba-gallery-hero {
    grid-row: 1 / 3;
    grid-column: 1 / 2;
}

/* Bottone "Mostra tutte" */
.ba-show-all-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: #fff;
    color: #222;
    border: 1px solid rgba(0,0,0,0.08);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s, background 0.2s;
    z-index: 2;
}

.ba-show-all-btn:hover {
    transform: scale(1.02);
    background: #f9f9f9;
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 1024px) {
    .ba-gallery-grid {
        height: 300px; /* Tablet */
        gap: 6px;
    }
}

@media (max-width: 768px) {
    .ba-gallery-grid {
        /* MANTENIAMO LA GRIGLIA, NIENTE SLIDER */
        display: grid; 
        grid-template-columns: 2fr 1fr 1fr; /* Mantiene la struttura 3 colonne */
        grid-template-rows: 1fr 1fr;
        height: 220px; /* Altezza compatta come PAF */
        gap: 4px;
        border-radius: 10px;
        overflow: hidden;
        margin: 0; /* Reset margini negativi */
        width: 100%;
        scroll-snap-type: none;
    }

    .ba-gallery-item {
        min-width: 0; /* Reset flex */
        width: 100%;
        height: 100%;
    }
    
    /* La Hero deve continuare ad occupare la prima colonna intera (2 righe) */
    .ba-gallery-hero {
        grid-row: 1 / 3;
        grid-column: 1 / 2;
    }

    .ba-show-all-btn {
        bottom: 10px;
        right: 10px;
        padding: 4px 10px;
        font-size: 11px;
        border-radius: 4px;
    }
}

/* --- MODALE INTERMEDIO (FULL SCREEN) --- */
.ba-full-gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 99999; /* Sopra tutto (wp admin bar etc) */
    overflow-y: auto;
    display: none; /* Nascosto di default */
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ba-full-gallery-modal.is-active {
    display: block;
    opacity: 1;
}

.ba-gallery-header {
    position: sticky;
    top: 0;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    border-bottom: 1px solid #eee;
}

.ba-close-gallery {
    background: transparent;
    color: #222;
    border: none;
    padding: 8px 0;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ba-gallery-title {
    font-size: 16px;
    font-weight: 600;
    color: #222;
    max-width: 60%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ba-gallery-spacer {
    width: 80px; /* Spacer per bilanciare il bottone back */
}

/* Griglia verticale Modale (Logica 1-2-1 PAF) */
.ba-gallery-modal-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 20px;
    max-width: 1000px;
    margin: 0 auto;
}

.ba-modal-item {
    display: block;
    width: 100%;
    cursor: zoom-in;
    overflow: hidden;
    position: relative;
}

.ba-modal-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.ba-modal-item:hover img {
    transform: scale(1.02);
}

/* Pattern: 
   1° item: Grande (span 2 cols)
   2° e 3°: Piccoli (1 col)
   Ripeti...
*/
.ba-modal-item:nth-child(3n+1) {
    grid-column: span 2;
    height: 500px;
}

.ba-modal-item:nth-child(3n+2),
.ba-modal-item:nth-child(3n+3) {
    grid-column: span 1;
    height: 300px;
}

@media (max-width: 768px) {
    .ba-gallery-modal-grid {
        padding: 10px;
        gap: 6px;
    }
    
    /* Altezza ridotta su mobile */
    .ba-modal-item:nth-child(3n+1) { height: 300px; }
    .ba-modal-item:nth-child(3n+2),
    .ba-modal-item:nth-child(3n+3) { height: 200px; }
}