/* ============================================================
   Mosaic Gallery for Divi  –  mosaic-gallery.css
   ============================================================ */

/* ── Custom properties (defaults; overridden per-instance inline) ── */
:root {
    --mgd-gap:    12px;
    --mgd-cols:   3;
    --mgd-radius: 0;
    --mgd-overlay: rgba(0, 0, 0, 0.50);
    --mgd-caption-color: #ffffff;
    --mgd-accent: #c8a97e;
    --mgd-duration: 0.38s;
    --mgd-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Placeholder (VB / empty state) ── */
.mgd-placeholder {
    padding: 2rem;
    text-align: center;
    color: #666;
    font-style: italic;
    border: 6px solid #ffffff;
    border-radius: 0px;
}

/* ================================================================
   MASONRY layout  (JS-driven column positioning)
   ================================================================ */

.mgd-gallery.mgd-style-masonry {
    position: relative;
    width: 100%;
}

/* Sizer element tells Masonry each column width */
.mgd-gallery.mgd-style-masonry .mgd-sizer,
.mgd-gallery.mgd-style-masonry .mgd-item {
    width: calc((100% - (var(--mgd-cols) - 1) * var(--mgd-gap)) / var(--mgd-cols));
}

.mgd-gallery.mgd-style-masonry .mgd-item {
    /* No margin-bottom here — the JS engine adds gap to colHeights directly,
       so adding it in CSS too was doubling the vertical space vs horizontal. */
    float: left; /* fallback before Masonry init */
}

/* ================================================================
   UNIFORM GRID layout  (CSS Grid, fixed aspect-ratio squares)
   ================================================================ */

.mgd-gallery.mgd-style-grid {
    display: grid;
    grid-template-columns: repeat(var(--mgd-cols), 1fr);
    gap: var(--mgd-gap);
}

.mgd-gallery.mgd-style-grid .mgd-sizer { display: none; }

.mgd-gallery.mgd-style-grid .mgd-item {
    aspect-ratio: 1 / 1;
    overflow: hidden;
}

.mgd-gallery.mgd-style-grid .mgd-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ================================================================
   METRO layout  (CSS Grid with alternating large/small spans)
   ================================================================ */

.mgd-gallery.mgd-style-metro {
    display: grid;
    grid-template-columns: repeat(var(--mgd-cols), 1fr);
    grid-auto-rows: 220px;
    gap: var(--mgd-gap);
}

.mgd-gallery.mgd-style-metro .mgd-sizer { display: none; }

.mgd-gallery.mgd-style-metro .mgd-item {
    overflow: hidden;
}

.mgd-gallery.mgd-style-metro .mgd-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Every 5th item spans 2 cols + 2 rows */
.mgd-gallery.mgd-style-metro .mgd-item:nth-child(5n + 1) {
    grid-column: span 2;
    grid-row: span 2;
}

/* ================================================================
   SHARED item styles
   ================================================================ */

.mgd-item {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border-radius: 0 !important;              /* no rounded corners */
    border: 6px solid #ffffff;     /* 4pt white border on every image block */
    box-sizing: border-box;        /* border is inside the JS-computed column width */
    -moz-box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
    transition: transform var(--mgd-duration) var(--mgd-ease);
}

.mgd-item a {
    display: block;
    color: inherit;
    text-decoration: none;
}

.mgd-item img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 0;
    transition: transform var(--mgd-duration) var(--mgd-ease),
                filter var(--mgd-duration) var(--mgd-ease);
    will-change: transform;
}

/* ── Overlay ── */
.mgd-item-overlay {
    position: absolute;
    inset: 0;
    background: var(--mgd-overlay);
    border-radius: 0;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    transition: opacity var(--mgd-duration) var(--mgd-ease);
}

.mgd-item-overlay-inner {
    width: 100%;
    padding: 1rem 1rem 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.mgd-caption {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--mgd-caption-color, #fff);
    font-weight: 400;
    letter-spacing: 0.01em;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
    flex: 1;
}

.mgd-zoom-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1.5px solid rgba(255,255,255,0.6);
    border-radius: 50%;
    padding: 5px;
    color: #fff;
    transition: border-color 0.2s, background 0.2s;
}

.mgd-zoom-icon svg {
    width: 100%;
    height: 100%;
}

.mgd-item:hover .mgd-zoom-icon {
    background: rgba(255,255,255,0.15);
    border-color: #fff;
}

/* ================================================================
   HOVER EFFECTS
   ================================================================ */

/* zoom */
.mgd-hover-zoom .mgd-item:hover img {
    transform: scale(1.07);
}
.mgd-hover-zoom .mgd-item:hover .mgd-item-overlay {
    opacity: 1;
}
.mgd-hover-zoom .mgd-item:hover {
    box-shadow: 0 8px 28px rgba(0,0,0,0.22);
}

/* fade */
.mgd-hover-fade .mgd-item:hover .mgd-item-overlay {
    opacity: 1;
}
.mgd-hover-fade .mgd-item:hover img {
    filter: brightness(0.85);
}

/* slide-up */
.mgd-hover-slide-up .mgd-item-overlay {
    opacity: 1;
    transform: translateY(100%);
    transition: transform var(--mgd-duration) var(--mgd-ease);
}
.mgd-hover-slide-up .mgd-item:hover .mgd-item-overlay {
    transform: translateY(0);
}
.mgd-hover-slide-up .mgd-item:hover img {
    transform: scale(1.04);
}

/* none */
.mgd-hover-none .mgd-item-overlay { display: none; }

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

.mgd-lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.93);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.mgd-lightbox-overlay.is-open {
    opacity: 1;
    pointer-events: all;
}

.mgd-lightbox-inner {
    position: relative;
    max-width: 92vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mgd-lightbox-img-wrap {
    position: relative;
    max-width: 100%;
    max-height: 80vh;
    overflow: hidden;
    border-radius: 4px;
}

.mgd-lightbox-img-wrap img {
    display: block;
    max-width: 92vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    border-radius: 0px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.7);
    /* entry animation */
    transform: scale(0.94);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mgd-lightbox-overlay.is-open .mgd-lightbox-img-wrap img {
    transform: scale(1);
}

.mgd-lightbox-caption {
    margin-top: 0.9rem;
    color: rgba(255,255,255,0.72);
    font-size: 0.84rem;
    letter-spacing: 0.02em;
    text-align: center;
    max-width: 60ch;
    line-height: 1.5;
}

/* Prev / Next arrows */
.mgd-lightbox-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.18);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    z-index: 1000000;
}

.mgd-lightbox-btn:hover {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.4);
}

.mgd-lightbox-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mgd-lightbox-prev { left: max(1rem, 2vw); }
.mgd-lightbox-next { right: max(1rem, 2vw); }

/* Close button */
.mgd-lightbox-close {
    position: fixed;
    top: 1.2rem;
    right: 1.4rem;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.18);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    z-index: 1000000;
}

.mgd-lightbox-close:hover {
    background: rgba(255,255,255,0.18);
    transform: rotate(90deg);
}

.mgd-lightbox-close svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
}

/* Counter pill */
.mgd-lightbox-counter {
    position: fixed;
    bottom: 1.4rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.7);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    z-index: 1000000;
    user-select: none;
}

/* ================================================================
   ENTRY animation for gallery items
   ================================================================ */

.mgd-item {
    animation: mgd-item-enter 0.5s var(--mgd-ease) both;
}

@keyframes mgd-item-enter {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Stagger up to 12 items */
.mgd-item:nth-child(1)  { animation-delay: 0.04s; }
.mgd-item:nth-child(2)  { animation-delay: 0.08s; }
.mgd-item:nth-child(3)  { animation-delay: 0.12s; }
.mgd-item:nth-child(4)  { animation-delay: 0.16s; }
.mgd-item:nth-child(5)  { animation-delay: 0.20s; }
.mgd-item:nth-child(6)  { animation-delay: 0.24s; }
.mgd-item:nth-child(7)  { animation-delay: 0.28s; }
.mgd-item:nth-child(8)  { animation-delay: 0.32s; }
.mgd-item:nth-child(9)  { animation-delay: 0.36s; }
.mgd-item:nth-child(10) { animation-delay: 0.40s; }
.mgd-item:nth-child(11) { animation-delay: 0.44s; }
.mgd-item:nth-child(12) { animation-delay: 0.48s; }

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 980px) {
    .mgd-gallery {
        --mgd-cols: 2;
    }
    .mgd-gallery.mgd-style-masonry .mgd-sizer,
    .mgd-gallery.mgd-style-masonry .mgd-item {
        width: calc((100% - var(--mgd-gap)) / 2);
    }
    .mgd-gallery.mgd-style-metro .mgd-item:nth-child(5n + 1) {
        grid-column: span 2;
        grid-row: span 1;
    }
}

@media (max-width: 600px) {
    .mgd-gallery {
        --mgd-cols: 1;
        --mgd-gap: 8px;
    }
    .mgd-gallery.mgd-style-masonry .mgd-sizer,
    .mgd-gallery.mgd-style-masonry .mgd-item {
        width: 100%;
    }
    .mgd-gallery.mgd-style-metro {
        grid-auto-rows: 180px;
    }
    .mgd-lightbox-btn { display: none; }
}

/* ================================================================
   ACCESSIBILITY – reduce motion
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
    .mgd-item,
    .mgd-item img,
    .mgd-item-overlay,
    .mgd-lightbox-overlay,
    .mgd-lightbox-img-wrap img {
        animation: none !important;
        transition: none !important;
    }
}
