/* ============================================
   IMATICA LIGHTBOX v2 — CSS
   ============================================ */

/* ---- Grid ---- */
.emlb-gallery-grid {
    display: grid;
    gap: 12px;
}

.emlb-item {
    cursor: pointer;
    overflow: hidden;
    border-radius: 8px;
    position: relative;
    min-width: 0; /* prevent grid blowout */
    display: flex;
    justify-content: flex-start; /* default left — Elementor alignment control overrides this */
}

.emlb-img-ratio {
    position: relative;
    width: 100%;
    overflow: hidden;
    /* Default equal-height thumbnails: all cells share the same 4:3 ratio.
       Overridden below when the user sets an explicit ratio via the Elementor
       "Proporció d'imatge" control (--emlb-ratio). When gallery_row_height is
       also set, flex-stretch on .emlb-item overrides this ratio so images fill
       the explicit row height — aspect-ratio is secondary to definite sizing. */
    aspect-ratio: 4 / 3;
}

/* Base image style */
.emlb-img-ratio img {
    display: block;
    width: 100%;
    height: 100%;   /* fills the aspect-ratio container — was: auto */
    object-fit: cover;
    transition: transform 0.4s ease, filter 0.3s ease, opacity 0.4s ease;
}

/* Explicit ratio via Elementor control (--emlb-ratio on the element) —
   override the container's aspect-ratio with the user-chosen value.
   The img keeps height:100% + object-fit:cover from the base rule.
   When gallery_row_height is also active, CSS flex-stretch on .emlb-item
   gives this container a definite height which takes priority over aspect-ratio,
   so increasing row height physically enlarges the thumbnails as expected. */
.emlb-img-ratio[style*="--emlb-ratio"] {
    aspect-ratio: calc(100 / var(--emlb-ratio));
}

/* ---- Link mode ---- */
/* Wraps the image when On Click = "Media File" or "Custom link". */
.emlb-img-link {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
    color: inherit;
}

/* ---- Hover effects ---- */

/* Zoom hover */
.emlb-hover-zoom .emlb-item:hover img {
    transform: scale(1.06);
}

/* Darken / Icon hover overlay */
.emlb-hover-darken .emlb-hover-overlay,
.emlb-hover-icon   .emlb-hover-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0);
    transition: background 0.3s ease;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.emlb-hover-darken .emlb-item:hover .emlb-hover-overlay {
    background: rgba(0,0,0,0.35);
}

.emlb-hover-icon .emlb-item:hover img {
    transform: scale(1.04);
}

.emlb-hover-icon .emlb-item:hover .emlb-hover-overlay {
    background: rgba(0,0,0,0.4);
}

.emlb-zoom-icon {
    font-size: 32px;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.25s ease, transform 0.3s ease;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    filter: drop-shadow(0 0 8px rgba(255,255,255,0.3));
}

.emlb-hover-icon .emlb-item:hover .emlb-zoom-icon {
    opacity: 1;
    transform: scale(1);
}

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

#emlb-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#emlb-overlay.emlb-active {
    opacity: 1;
    pointer-events: all;
}

#emlb-backdrop {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.3s ease;
    cursor: pointer;
}

#emlb-overlay.emlb-active #emlb-backdrop {
    opacity: var(--emlb-opacity, 0.92);
}

/* ---- Main container ---- */
#emlb-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 90vw;
    max-height: 90vh;
}

#emlb-img-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.75);
    max-width: 88vw;
    max-height: 78vh;
    will-change: transform, opacity;
}

#emlb-img-wrapper img {
    display: block;
    max-width: 88vw;
    max-height: 78vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
    user-select: none;
}

/* ---- Transition effects ---- */

/* SLIDE */
.emlb-effect-slide #emlb-img-wrapper {
    transition: transform 0.38s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.28s ease;
}
.emlb-slide-out-left  { transform: translateX(-115%) !important; opacity: 0 !important; }
.emlb-slide-out-right { transform: translateX(115%)  !important; opacity: 0 !important; }
.emlb-slide-in-left   { transform: translateX(115%);  opacity: 0; }
.emlb-slide-in-right  { transform: translateX(-115%); opacity: 0; }

/* FADE */
.emlb-effect-fade #emlb-img-wrapper {
    transition: opacity 0.38s ease;
}
.emlb-fade-out { opacity: 0 !important; }
.emlb-fade-in  { opacity: 0; }

/* ZOOM */
.emlb-effect-zoom #emlb-img-wrapper {
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}
.emlb-zoom-out { transform: scale(0.25) !important; opacity: 0 !important; }
.emlb-zoom-in  { transform: scale(0.25); opacity: 0; }

/* FLIP */
.emlb-effect-flip #emlb-img-wrapper {
    perspective: 1200px;
    transform-style: preserve-3d;
    transition: transform 0.45s ease, opacity 0.25s ease;
}
.emlb-flip-out { transform: rotateY(90deg)  !important; opacity: 0 !important; }
.emlb-flip-in  { transform: rotateY(-90deg); opacity: 0; }

/* ---- Buttons ---- */
#emlb-close,
#emlb-prev,
#emlb-next {
    position: fixed;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.18);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    z-index: 2;
    line-height: 1;
    font-weight: 300;
}

#emlb-close:hover, #emlb-prev:hover, #emlb-next:hover {
    background: rgba(255,255,255,0.22);
}

#emlb-close {
    top: 18px; right: 18px;
    width: 42px; height: 42px;
    font-size: 20px;
}
#emlb-close:hover { transform: rotate(90deg); }

#emlb-prev, #emlb-next {
    top: 50%; transform: translateY(-50%);
    width: 50px; height: 50px;
    font-size: 28px;
}
#emlb-prev:hover { transform: translateY(-50%) translateX(-3px); }
#emlb-next:hover { transform: translateY(-50%) translateX(3px); }
#emlb-prev { left: 16px; }
#emlb-next { right: 16px; }

/* ---- Counter & Caption ---- */
#emlb-counter {
    color: rgba(255,255,255,0.6);
    font-size: 12px;
    font-family: -apple-system, sans-serif;
    letter-spacing: 0.1em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}

#emlb-caption {
    color: rgba(255,255,255,0.9);
    font-size: 14px;
    font-family: -apple-system, sans-serif;
    text-align: center;
    max-width: 600px;
    text-shadow: 0 1px 6px rgba(0,0,0,0.8);
    padding: 0 20px;
    min-height: 18px;
}

/* ---- Thumbnails ---- */
#emlb-thumbs {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    max-width: 88vw;
    padding: 4px 4px 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.25) transparent;
}

#emlb-thumbs img {
    width: 54px; height: 40px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.5;
    border: 2px solid transparent;
    transition: opacity 0.2s, border-color 0.2s, transform 0.15s;
    flex-shrink: 0;
}
#emlb-thumbs img:hover   { opacity: 0.8; transform: scale(1.07); }
#emlb-thumbs img.emlb-thumb-active { opacity: 1; border-color: #fff; }

/* ---- Swipe hint (mobile) ---- */
#emlb-swipe-hint {
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.35);
    font-size: 11px;
    font-family: sans-serif;
    pointer-events: none;
    display: none;
    white-space: nowrap;
}

@media (max-width: 767px) {
    #emlb-prev, #emlb-next { display: none; }
    #emlb-swipe-hint { display: block; }
    #emlb-thumbs img { width: 44px; height: 32px; }
}

/* ---- Cover mode ---- */
.emlb-mode-cover {
    display: block; /* no !important — allows Elementor alignment control to override with flex */
}
.emlb-mode-cover .emlb-item {
    display: none;
}
.emlb-mode-cover .emlb-item.emlb-cover {
    display: block;
}
