/**
 * ============================================================
 *  MIXED MASONRY GALLERY — Production CSS
 *  Pinterest / Behance-style masonry with mixed media
 *  + Built-in Premium Lightbox
 *  Compatible with: WordPress + Elementor (Flexbox Containers)
 *  No jQuery · No external libraries · Pure CSS
 * ============================================================
 */

/* -------------------------------------------------------
   1. CSS CUSTOM PROPERTIES
   ------------------------------------------------------- */
.mg-gallery {
    --mg-gap: 20px;
    --mg-columns: 4;
    --mg-radius: 8px;
    --mg-overlay-bg: rgba(255, 255, 255, 0.70);
    --mg-overlay-speed: 400ms;
    --mg-overlay-ease: ease;
    --mg-scale-speed: 600ms;
    --mg-scale-ease: cubic-bezier(.22, .61, .36, 1);
    --mg-heading-size: 24px;
    --mg-heading-weight: 500;
    --mg-heading-color: #1a1a1a;
}

/* Tablet */
@media (max-width: 1024px) {
    .mg-gallery {
        --mg-gap: 16px;
        --mg-columns: 2 !important;
        --mg-heading-size: 18px;
    }
}

/* Mobile */
@media (max-width: 767px) {
    .mg-gallery {
        --mg-gap: 12px;
        --mg-columns: 1 !important;
        --mg-heading-size: 16px;
    }
}

/* -------------------------------------------------------
   2. GALLERY CONTAINER
   ------------------------------------------------------- */
.mg-gallery {
    position: relative;
    width: 100%;
    margin: 0 auto;
    padding: 0;
    box-sizing: border-box;
}

.mg-gallery > .elementor-element {
    max-width: 100% !important;
    width: 100% !important;
}

/* -------------------------------------------------------
   3. GALLERY ITEMS
   ------------------------------------------------------- */
.mg-item {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    border-radius: var(--mg-radius);
    cursor: pointer;
    box-sizing: border-box;
    will-change: transform;
    transition: box-shadow 0.3s ease;
    margin: 0 !important;
    padding: 0 !important;
}

.mg-item:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    z-index: 2;
}

.mg-item.elementor-element {
    --container-widget-width: 100%;
    --container-widget-height: auto;
    --container-widget-flex-grow: 0;
}

/* -------------------------------------------------------
   4. MEDIA (Images & Videos)
   ------------------------------------------------------- */
.mg-item .mg-media {
    position: relative;
    width: 100%;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden;
    border-radius: var(--mg-radius);
    line-height: 0;
}

.mg-item .mg-media img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
    transition: transform var(--mg-scale-speed) var(--mg-scale-ease);
    will-change: transform;
}

.mg-item .mg-media video {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
    transition: transform var(--mg-scale-speed) var(--mg-scale-ease);
    will-change: transform;
}

.mg-item .mg-media .elementor-video-container,
.mg-item .mg-media .elementor-wrapper {
    width: 100% !important;
    height: auto !important;
}

.mg-item:hover .mg-media img,
.mg-item:hover .mg-media video {
    transform: scale(1.03);
}

/* -------------------------------------------------------
   5. OVERLAY
   ------------------------------------------------------- */
.mg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mg-overlay-bg);
    opacity: 0;
    transition: opacity var(--mg-overlay-speed) var(--mg-overlay-ease);
    pointer-events: none;
    z-index: 3;
    padding: 20px;
    box-sizing: border-box;
    border-radius: var(--mg-radius);
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
}

.mg-item:hover .mg-overlay {
    opacity: 1;
}

/* -------------------------------------------------------
   6. HEADING INSIDE OVERLAY
   ------------------------------------------------------- */
.mg-overlay .mg-heading {
    text-align: center;
    opacity: 0;
    transform: translateY(15px);
    transition:
        opacity var(--mg-overlay-speed) var(--mg-overlay-ease),
        transform var(--mg-overlay-speed) var(--mg-overlay-ease);
}

.mg-overlay .mg-heading .elementor-heading-title {
    font-size: var(--mg-heading-size) !important;
    font-weight: var(--mg-heading-weight) !important;
    color: var(--mg-heading-color) !important;
    letter-spacing: 0 !important;
    line-height: 1.4 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.mg-item:hover .mg-overlay .mg-heading {
    opacity: 1;
    transform: translateY(0);
}

/* -------------------------------------------------------
   7. CLICKABLE ITEM
   ------------------------------------------------------- */
.mg-item a.mg-link {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    text-decoration: none;
    outline: none;
}

.mg-item[data-mg-link],
.mg-item[data-mg-lightbox] {
    cursor: pointer;
}

/* -------------------------------------------------------
   8. LOADING STATE
   ------------------------------------------------------- */
.mg-item.mg-loading {
    opacity: 0;
    transition: opacity 0.5s ease;
}

.mg-item.mg-loaded {
    opacity: 1;
}

.mg-item.mg-placeholder .mg-media {
    background: linear-gradient(110deg, #f0f0f0 8%, #e8e8e8 18%, #f0f0f0 33%);
    background-size: 200% 100%;
    animation: mg-shimmer 1.5s linear infinite;
    min-height: 200px;
}

@keyframes mg-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}


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

/* -------------------------------------------------------
   L1. LIGHTBOX BACKDROP & WRAPPER
   ------------------------------------------------------- */
.mg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.35s cubic-bezier(.22, .61, .36, 1),
        visibility 0.35s;
    -webkit-font-smoothing: antialiased;
}

.mg-lightbox.mg-lightbox--open {
    opacity: 1;
    visibility: visible;
}

/* Backdrop */
.mg-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* -------------------------------------------------------
   L2. LIGHTBOX CONTENT AREA
   ------------------------------------------------------- */
.mg-lightbox__stage {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 60px 80px;
    box-sizing: border-box;
}

@media (max-width: 767px) {
    .mg-lightbox__stage {
        padding: 60px 16px 80px;
    }
}

/* -------------------------------------------------------
   L3. MEDIA CONTAINER
   ------------------------------------------------------- */
.mg-lightbox__media-wrap {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0.92);
    opacity: 0;
    transition:
        transform 0.4s cubic-bezier(.22, .61, .36, 1),
        opacity 0.4s ease;
}

.mg-lightbox--open .mg-lightbox__media-wrap {
    transform: scale(1);
    opacity: 1;
}

/* Transitioning between slides */
.mg-lightbox__media-wrap.mg-transitioning {
    opacity: 0;
    transform: scale(0.96);
    transition-duration: 0.2s;
}

.mg-lightbox__media-wrap img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    user-select: none;
    -webkit-user-drag: none;
}

.mg-lightbox__media-wrap video {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    border-radius: 4px;
    outline: none;
    background: #000;
}

@media (max-width: 767px) {
    .mg-lightbox__media-wrap img,
    .mg-lightbox__media-wrap video {
        max-height: calc(100vh - 160px);
    }
}

/* -------------------------------------------------------
   L4. LOADING SPINNER
   ------------------------------------------------------- */
.mg-lightbox__loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.mg-lightbox__loader.mg-visible {
    opacity: 1;
}

.mg-lightbox__loader::after {
    content: '';
    display: block;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    animation: mg-spin 0.8s linear infinite;
}

@keyframes mg-spin {
    to { transform: rotate(360deg); }
}

/* -------------------------------------------------------
   L5. CLOSE BUTTON
   ------------------------------------------------------- */
.mg-lightbox__close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    padding: 0;
    transition:
        background 0.25s ease,
        transform 0.25s ease,
        border-color 0.25s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mg-lightbox__close:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.mg-lightbox__close:active {
    transform: scale(0.95);
}

.mg-lightbox__close svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

/* -------------------------------------------------------
   L6. NAVIGATION ARROWS
   ------------------------------------------------------- */
.mg-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    padding: 0;
    transition:
        background 0.25s ease,
        transform 0.25s ease,
        opacity 0.25s ease,
        border-color 0.25s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mg-lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.25);
}

.mg-lightbox__nav:active {
    transform: translateY(-50%) scale(0.93);
}

.mg-lightbox__nav svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mg-lightbox__prev {
    left: 20px;
}

.mg-lightbox__next {
    right: 20px;
}

/* Hide nav if only 1 item */
.mg-lightbox--single .mg-lightbox__nav {
    display: none;
}

@media (max-width: 767px) {
    .mg-lightbox__nav {
        width: 44px;
        height: 44px;
        top: auto;
        bottom: 20px;
        transform: none;
    }
    .mg-lightbox__nav:active {
        transform: scale(0.93);
    }
    .mg-lightbox__prev {
        left: 20px;
    }
    .mg-lightbox__next {
        right: 20px;
    }
}

/* -------------------------------------------------------
   L7. CAPTION & COUNTER
   ------------------------------------------------------- */
.mg-lightbox__caption {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    color: rgba(255, 255, 255, 0.85);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.01em;
    text-align: center;
    max-width: 60%;
    line-height: 1.5;
    opacity: 0;
    transition: opacity 0.35s ease 0.15s;
    pointer-events: none;
}

.mg-lightbox--open .mg-lightbox__caption {
    opacity: 1;
}

.mg-lightbox__caption:empty {
    display: none;
}

.mg-lightbox__counter {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 10;
    color: rgba(255, 255, 255, 0.5);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.05em;
    user-select: none;
    opacity: 0;
    transition: opacity 0.35s ease 0.1s;
}

.mg-lightbox--open .mg-lightbox__counter {
    opacity: 1;
}

@media (max-width: 767px) {
    .mg-lightbox__caption {
        bottom: 72px;
        max-width: 80%;
        font-size: 13px;
    }
    .mg-lightbox__counter {
        top: 22px;
        left: 16px;
        font-size: 12px;
    }
}

/* -------------------------------------------------------
   L8. BODY SCROLL LOCK
   ------------------------------------------------------- */
body.mg-lightbox-active {
    overflow: hidden !important;
}

/* -------------------------------------------------------
   L9. VIDEO TYPE BADGE
   ------------------------------------------------------- */
.mg-lightbox__badge {
    position: absolute;
    top: 24px;
    right: 80px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255, 255, 255, 0.5);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    user-select: none;
    opacity: 0;
    transition: opacity 0.35s ease 0.15s;
}

.mg-lightbox--open .mg-lightbox__badge {
    opacity: 1;
}

.mg-lightbox__badge svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

@media (max-width: 767px) {
    .mg-lightbox__badge {
        top: 22px;
        right: 68px;
        font-size: 11px;
    }
}


/* -------------------------------------------------------
   9. ACCESSIBILITY
   ------------------------------------------------------- */
.mg-item:focus-within {
    outline: 2px solid #0066ff;
    outline-offset: 2px;
}

.mg-item:focus-within .mg-overlay {
    opacity: 1;
}

.mg-item:focus-within .mg-overlay .mg-heading {
    opacity: 1;
    transform: translateY(0);
}

.mg-lightbox__close:focus-visible,
.mg-lightbox__nav:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

/* -------------------------------------------------------
   10. PRINT STYLES
   ------------------------------------------------------- */
@media print {
    .mg-gallery {
        position: static !important;
        height: auto !important;
    }

    .mg-item {
        position: static !important;
        transform: none !important;
        width: 50% !important;
        display: inline-block;
        vertical-align: top;
        break-inside: avoid;
    }

    .mg-overlay,
    .mg-lightbox {
        display: none !important;
    }
}

/* -------------------------------------------------------
   11. REDUCED MOTION
   ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .mg-item .mg-media img,
    .mg-item .mg-media video,
    .mg-overlay,
    .mg-overlay .mg-heading,
    .mg-lightbox,
    .mg-lightbox__media-wrap {
        transition-duration: 0.01ms !important;
    }

    .mg-item:hover .mg-media img,
    .mg-item:hover .mg-media video {
        transform: none;
    }

    .mg-lightbox__media-wrap {
        transform: none !important;
    }
}
