/*
 * Flashbit Gioria Galleria — fbg-frontend.css
 * Version: 3.1.0
 *
 * MODIFICHE rispetto alla v3.0:
 *  - Modal panel quasi a schermo intero: max-width 96vw, max-height 94vh
 *  - Griglia foto più fitta (minmax 200px) per sfruttare lo spazio
 *  - Padding ridotto su schermi grandi per massimizzare le foto visibili
 */

/* ==========================================================================
   1. BODY LOCK
   ========================================================================== */
body.fbg-modal-open {
    overflow: hidden;
}

/* ==========================================================================
   2. WRAPPER PRINCIPALE
   ========================================================================== */
.fbg-gallery-wrapper {
    --fbg-radius:      10px;
    --fbg-gap:         20px;
    --fbg-shadow-card: 0 2px 16px rgba(0, 0, 0, .1);
    --fbg-overlay-bg:  rgba(0, 0, 0, .38);
    --fbg-transition:  .26s ease;
    --fbg-white:       rgba(255, 255, 255, .97);
    --fbg-backdrop:    rgba(20, 20, 30, .6);

    box-sizing: border-box;
    width: 100%;
    font-family: inherit;
    position: relative;
    margin-left: auto;
    margin-right: auto;
}

.fbg-gallery-wrapper *,
.fbg-gallery-wrapper *::before,
.fbg-gallery-wrapper *::after {
    box-sizing: inherit;
}

/* ==========================================================================
   3. HEADER
   ========================================================================== */
.fbg-gallery-wrapper .fbg-header {
    text-align: center;
    margin-bottom: 40px;
}

.fbg-gallery-wrapper .fbg-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 10px;
    line-height: 1.2;
    color: inherit;
}

.fbg-gallery-wrapper .fbg-subtitle {
    font-size: 1.05rem;
    color: #666;
    margin: 0;
}

/* ==========================================================================
   4. GRIGLIA CATEGORIE
   ========================================================================== */
.fbg-gallery-wrapper .fbg-grid {
    display: grid;
    gap: var(--fbg-gap);
    grid-template-columns: repeat(4, 1fr);
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 1024px) {
    .fbg-gallery-wrapper .fbg-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

@media (max-width: 640px) {
    .fbg-gallery-wrapper .fbg-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

/* ==========================================================================
   5. CARD CATEGORIA
   ========================================================================== */
.fbg-gallery-wrapper .fbg-cat-card {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    outline: none;
    border-radius: var(--fbg-radius);
    overflow: hidden;
    background: #fff;
    box-shadow: var(--fbg-shadow-card);
    transition: transform var(--fbg-transition), box-shadow var(--fbg-transition);
}

.fbg-gallery-wrapper .fbg-cat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, .15);
}

.fbg-gallery-wrapper .fbg-cat-card:focus-visible {
    outline: 3px solid #0073aa;
    outline-offset: 3px;
}

.fbg-gallery-wrapper .fbg-cat-cover {
    position: relative;
    width: 100%;
    padding-bottom: 65%;
    background-color: #ececec;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
}

.fbg-gallery-wrapper .fbg-cat-cover.fbg-no-cover {
    background-color: #f4f4f4;
}

.fbg-gallery-wrapper .fbg-cat-cover.fbg-no-cover::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='40' height='40' fill='none' stroke='%23cccccc' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z'/%3E%3Ccircle cx='12' cy='13' r='4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center 42%;
    background-size: 40px 40px;
}

.fbg-gallery-wrapper .fbg-cat-hover-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--fbg-transition);
}

.fbg-gallery-wrapper .fbg-cat-card:hover .fbg-cat-hover-overlay,
.fbg-gallery-wrapper .fbg-cat-card:focus-visible .fbg-cat-hover-overlay {
    background: rgba(0, 0, 0, .32);
}

.fbg-gallery-wrapper .fbg-open-icon {
    font-size: 1.8rem;
    opacity: 0;
    transform: scale(.5);
    transition: opacity var(--fbg-transition), transform var(--fbg-transition);
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, .3);
    pointer-events: none;
}

.fbg-gallery-wrapper .fbg-cat-card:hover .fbg-open-icon,
.fbg-gallery-wrapper .fbg-cat-card:focus-visible .fbg-open-icon {
    opacity: 1;
    transform: scale(1);
}

.fbg-gallery-wrapper .fbg-cat-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: #fff;
}

.fbg-gallery-wrapper .fbg-cat-name {
    font-weight: 600;
    font-size: .95rem;
    line-height: 1.3;
    color: #222;
}

.fbg-gallery-wrapper .fbg-cat-count {
    font-size: .78rem;
    color: #999;
    white-space: nowrap;
    flex-shrink: 0;
    background: #f4f4f4;
    padding: 2px 8px;
    border-radius: 10px;
}

.fbg-gallery-wrapper .fbg-cat-desc {
    font-size: .82rem;
    color: #777;
    margin: 0;
    padding: 0 14px 12px;
    line-height: 1.4;
}

/* ==========================================================================
   6. EMPTY STATE (admin)
   ========================================================================== */
.fbg-gallery-wrapper.fbg-empty-admin {
    padding: 20px;
    background: #f9f9f9;
    border: 1px dashed #ddd;
    border-radius: 8px;
    text-align: center;
    color: #666;
}

/* ==========================================================================
   7. MODAL ROOT — popup griglia foto quasi a schermo intero
   ========================================================================== */
.fbg-modal-root {
    position: fixed;
    inset: 0;
    z-index: 99990;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    visibility: hidden;
    opacity: 0;
    transition: opacity .26s ease, visibility 0s linear .26s;
}

.fbg-modal-root.fbg-modal-active {
    visibility: visible;
    opacity: 1;
    transition: opacity .26s ease;
}

.fbg-modal-root .fbg-modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--fbg-backdrop);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    z-index: 0;
}

/* -----------------------------------------------------------------------
   PANEL — quasi a schermo intero
----------------------------------------------------------------------- */
.fbg-modal-root .fbg-modal-panel {
    position: relative;
    z-index: 1;
    background: var(--fbg-white);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, .8);
    /* FULLSCREEN: occupa quasi tutta la viewport */
    width: 96vw;
    max-width: 96vw;
    height: 94vh;
    max-height: 94vh;
    overflow-y: auto;
    padding: 24px 24px 20px;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, .04),
        0 8px 24px rgba(0, 0, 0, .1),
        0 32px 72px rgba(0, 0, 0, .2);
    cursor: default;
    display: flex;
    flex-direction: column;
    /* Animazione entrata */
    transform: scale(.97) translateY(10px);
    transition: transform .26s ease;
}

.fbg-modal-root.fbg-modal-active .fbg-modal-panel {
    transform: scale(1) translateY(0);
}

/* Header */
.fbg-modal-root .fbg-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(0, 0, 0, .08);
    gap: 16px;
    flex-shrink: 0;
}

.fbg-modal-root .fbg-modal-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
    color: #1a1a1a;
    letter-spacing: -.01em;
}

.fbg-modal-root .fbg-modal-counter {
    position: fixed;
    right: 18px;
    bottom: 18px;
    top: auto;
    left: auto;
    transform: none;
    z-index: 100030;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    line-height: 1;
    color: #222;
    background: rgba(255, 255, 255, .82);
    border: 1px solid rgba(255, 255, 255, .78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 6px 18px rgba(0,0,0,.12);
    white-space: nowrap;
    flex-shrink: 0;
    pointer-events: none;
}

/* Pulsante chiudi */
.fbg-modal-root .fbg-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .1);
    background: rgba(0, 0, 0, .05);
    color: #555;
    font-size: .9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background .18s ease, transform .18s ease, color .18s ease;
    line-height: 1;
    padding: 0;
    margin: 0;
    font-family: inherit;
}

.fbg-modal-root .fbg-modal-close:hover {
    background: rgba(0, 0, 0, .1);
    color: #111;
    transform: rotate(90deg);
}

/* ==========================================================================
   8. GRIGLIA FOTO NEL POPUP — sfrutta lo spazio fullscreen
   ========================================================================== */
.fbg-modal-root .fbg-photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    overflow-y: auto;
    flex: 1;
    align-content: start;
}

.fbg-modal-root .fbg-photo-thumb {
    position: relative;
    cursor: pointer;
    border-radius: 10px;
    overflow: hidden;
    background: #f0f0f0;
    isolation: isolate;
    transition: transform .22s ease, box-shadow .22s ease;
    aspect-ratio: 4 / 3;
}

.fbg-modal-root .fbg-photo-thumb:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}

.fbg-modal-root .fbg-photo-thumb:focus-visible {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
}

.fbg-modal-root .fbg-photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .28s ease;
    margin: 0;
    padding: 0;
    border: none;
    max-width: 100%;
}

.fbg-modal-root .fbg-photo-thumb:hover img {
    transform: scale(1.05);
}

/* Didascalia hover nella griglia */
.fbg-modal-root .fbg-photo-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, .72));
    color: #fff;
    font-size: .72rem;
    padding: 22px 10px 8px;
    transform: translateY(100%);
    transition: transform .22s ease;
    pointer-events: none;
    letter-spacing: .01em;
    line-height: 1.4;
}

.fbg-modal-root .fbg-photo-thumb:hover .fbg-photo-caption {
    transform: translateY(0);
}

/* ==========================================================================
   9. LIGHTBOX — card popup sovrapposta
   ========================================================================== */
.fbg-modal-root .fbg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 80px;
    background: rgba(10, 10, 20, .75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    visibility: hidden;
    opacity: 0;
    transition: opacity .22s ease, visibility 0s linear .22s;
}

.fbg-modal-root .fbg-lightbox.fbg-lb-active {
    visibility: visible;
    opacity: 1;
    transition: opacity .22s ease;
}

/* -----------------------------------------------------------------------
   CARD LIGHTBOX — bianca con immagine + barra didascalia
----------------------------------------------------------------------- */
.fbg-modal-root .fbg-lb-card {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, .08),
        0 16px 48px rgba(0, 0, 0, .28),
        0 48px 96px rgba(0, 0, 0, .22);
    max-width: min(90vw, 1000px);
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    transform: scale(.94) translateY(10px);
    transition: transform .24s ease;
}

.fbg-modal-root .fbg-lightbox.fbg-lb-active .fbg-lb-card {
    transform: scale(1) translateY(0);
}

/* Area immagine */
.fbg-modal-root .fbg-lb-img-area {
    position: relative;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    flex: 1;
    overflow: hidden;
}

.fbg-modal-root .fbg-lb-main-img {
    display: block;
    max-width: min(88vw, 960px);
    max-height: calc(100vh - 170px);
    width: auto;
    height: auto;
    object-fit: contain;
    margin: 0;
    padding: 0;
    border: none;
    transition: opacity .22s ease;
}

/* Spinner */
.fbg-modal-root .fbg-lb-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background: #111;
}

.fbg-modal-root .fbg-lb-spinner::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 2.5px solid rgba(255, 255, 255, .15);
    border-top-color: rgba(255, 255, 255, .65);
    border-radius: 50%;
    animation: fbg-spin .7s linear infinite;
}

@keyframes fbg-spin {
    to { transform: rotate(360deg); }
}

/* Barra info — didascalia sempre visibile */
.fbg-modal-root .fbg-lb-info {
    background: #fff;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    border-top: 1px solid rgba(0, 0, 0, .07);
    flex-shrink: 0;
}

.fbg-modal-root .fbg-lb-caption-text {
    flex: 1;
    font-size: .9rem;
    color: #333;
    line-height: 1.5;
    font-style: italic;
}

.fbg-modal-root .fbg-lb-counter-text {
    font-size: .78rem;
    color: #aaa;
    white-space: nowrap;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    letter-spacing: .04em;
}

/* Pulsante chiudi dentro la card */
.fbg-modal-root .fbg-lb-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    font-size: .85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background .18s ease, transform .18s ease;
    line-height: 1;
    padding: 0;
    margin: 0;
    font-family: inherit;
}

.fbg-modal-root .fbg-lb-close-btn:hover {
    background: rgba(255, 255, 255, .3);
    transform: rotate(90deg);
}

/* Frecce */
.fbg-modal-root .fbg-lb-prev,
.fbg-modal-root .fbg-lb-next {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100001;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .25);
    cursor: pointer;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 300;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    line-height: 1;
    padding: 0;
    margin: 0;
    font-family: inherit;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .2);
    transition: background .18s ease, border-color .18s ease,
                transform .18s ease, box-shadow .18s ease;
    user-select: none;
    -webkit-user-select: none;
}

.fbg-modal-root .fbg-lb-prev { left: 16px; }
.fbg-modal-root .fbg-lb-next { right: 16px; }

.fbg-modal-root .fbg-lb-prev:hover {
    background: rgba(255, 255, 255, .3);
    border-color: rgba(255, 255, 255, .5);
    transform: translateY(-50%) scale(1.1) translateX(2px);
}

.fbg-modal-root .fbg-lb-next:hover {
    background: rgba(255, 255, 255, .3);
    border-color: rgba(255, 255, 255, .5);
    transform: translateY(-50%) scale(1.1) translateX(-2px);
}

.fbg-modal-root .fbg-lb-prev.fbg-lb-hidden,
.fbg-modal-root .fbg-lb-next.fbg-lb-hidden {
    visibility: hidden;
    pointer-events: none;
}

/* ==========================================================================
   10. RESPONSIVE
   ========================================================================== */
@media (max-width: 1024px) {
    .fbg-modal-root .fbg-modal-panel {
        padding: 20px 18px 16px;
        border-radius: 16px;
        width: 98vw;
        max-width: 98vw;
        height: 96vh;
        max-height: 96vh;
    }
    .fbg-modal-root .fbg-photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 8px;
    }
    .fbg-modal-root .fbg-lightbox {
        padding: 16px 70px;
    }
    .fbg-modal-root .fbg-lb-prev { left: 10px; }
    .fbg-modal-root .fbg-lb-next { right: 10px; }
    .fbg-modal-root .fbg-lb-prev,
    .fbg-modal-root .fbg-lb-next { width: 44px; height: 44px; font-size: 1.8rem; }
}

@media (max-width: 640px) {
    .fbg-modal-root {
        padding: 0;
        align-items: flex-end;
    }
    .fbg-modal-root .fbg-modal-panel {
        padding: 16px 12px 12px;
        border-radius: 16px 16px 0 0;
        width: 100vw;
        max-width: 100vw;
        height: 95vh;
        max-height: 95vh;
    }
    .fbg-modal-root .fbg-modal-title {
        font-size: 1.1rem;
    }
    .fbg-modal-root .fbg-photos-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 7px;
    }
    .fbg-modal-root .fbg-lightbox {
        padding: 10px;
        align-items: flex-end;
    }
    .fbg-modal-root .fbg-lb-card {
        border-radius: 14px 14px 8px 8px;
        max-width: 100%;
        max-height: 92vh;
    }
    .fbg-modal-root .fbg-lb-main-img {
        max-height: calc(100vh - 150px);
    }
    .fbg-modal-root .fbg-lb-prev,
    .fbg-modal-root .fbg-lb-next {
        top: auto;
        bottom: 70px;
        transform: none;
        width: 42px;
        height: 42px;
        font-size: 1.6rem;
    }
    .fbg-modal-root .fbg-lb-prev { left: 10px; }
    .fbg-modal-root .fbg-lb-next { right: 10px; }
    .fbg-modal-root .fbg-lb-prev:hover,
    .fbg-modal-root .fbg-lb-next:hover { transform: scale(1.1); }
    .fbg-modal-root .fbg-lb-info { padding: 10px 14px; }
    .fbg-modal-root .fbg-lb-caption-text { font-size: .82rem; }
}

/* ==========================================================================
   11. COMPATIBILITÀ TEMA INSPIRO
   ========================================================================== */
.fbg-modal-root img {
    max-width: 100%;
    height: auto;
}

.fbg-modal-root .fbg-lb-main-img {
    height: auto;
}

/* ==========================================================================
   12. CENTRAMENTO IN LAYOUT STACKABLE
   ========================================================================== */
.stk-row:has(> .fbg-gallery-wrapper),
.stk-inner-blocks:has(> .fbg-gallery-wrapper),
.alignwide:has(> .fbg-gallery-wrapper),
.entry-content:has(> .fbg-gallery-wrapper) {
    justify-content: center;
}

.stk-block-column > .fbg-gallery-wrapper {
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

@media (max-width: 1024px) {
    .fbg-gallery-wrapper {
        padding-left: 16px;
        padding-right: 16px;
    }
}

@media (max-width: 640px) {
    .fbg-gallery-wrapper {
        padding-left: 12px;
        padding-right: 12px;
    }
}


@media (max-width: 1024px) {
    .fbg-modal-root .fbg-modal-counter {
        right: 14px;
        bottom: 14px;
    }
}

@media (max-width: 640px) {
    .fbg-modal-root .fbg-modal-counter {
        right: 12px;
        bottom: 12px;
        min-height: 34px;
        padding: 7px 11px;
        font-size: .74rem;
    }
}


/* ==========================================================================
   13. FIX GALLERIA FOTO - MINIATURE LEGGERE E DISTANZIATE
   ========================================================================== */
.fbg-modal-root .fbg-photos-grid {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
    align-items: start;
    grid-auto-flow: row;
}

.fbg-modal-root .fbg-photos-grid > * {
    min-width: 0;
    min-height: 0;
}

.fbg-modal-root .fbg-photo-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    padding: 4px;
    border: 1px solid rgba(255,255,255,.10);
    background: rgba(255,255,255,.06);
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

.fbg-modal-root .fbg-photo-thumb img {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    object-fit: cover;
    border-radius: 8px;
}

.fbg-modal-root .fbg-photo-thumb:hover {
    transform: translateY(-2px);
}

@media (max-width: 1024px) {
    .fbg-modal-root .fbg-photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
        gap: 10px;
    }
}

@media (max-width: 640px) {
    .fbg-modal-root .fbg-photos-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .fbg-modal-root .fbg-photo-thumb {
        padding: 3px;
        border-radius: 8px;
    }

    .fbg-modal-root .fbg-photo-thumb img {
        border-radius: 6px;
    }
}
