/**
 * Mosaic Image - Frontend Styles (Masonry Version)
 * Author: reZeta Sites
 */

/* Mosaic Gallery Container - Masonry Layout */
.mosaic-image-gallery {
    --mosaic-columns: 4;
    --mosaic-gap: 10px;

    column-count: var(--mosaic-columns);
    column-gap: var(--mosaic-gap);
    width: 100%;
    margin: 20px 0;
}

/* ================================================
   JUSTIFIED / MOSAICO INTELIGENTE LAYOUT
   ================================================ */
.mosaic-image-gallery[data-layout="justified"] {
    column-count: unset;
    display: block;
    position: relative;
    overflow: hidden;
}

.mosaic-image-gallery[data-layout="justified"] .mosaic-item {
    position: absolute;
    overflow: hidden;
    margin: 0;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.4s ease;
    animation: none;
}

.mosaic-image-gallery[data-layout="justified"].justified-ready .mosaic-item {
    opacity: 1;
}

.mosaic-image-gallery[data-layout="justified"] .mosaic-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .mosaic-image-gallery {
        column-count: 3 !important;
    }
}

@media (max-width: 768px) {
    .mosaic-image-gallery {
        column-count: 2 !important;
    }
}

@media (max-width: 480px) {
    .mosaic-image-gallery {
        column-count: 1 !important;
    }
}

/* Mosaic Item - Masonry behavior */
.mosaic-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: #f0f0f0;
    margin-bottom: var(--mosaic-gap);
    break-inside: avoid;
    page-break-inside: avoid;
    -webkit-column-break-inside: avoid;
}

/* Size classes not needed - masonry handles sizing automatically */

/* Mosaic Link */
.mosaic-link {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
    cursor: zoom-in;
}

/* Mosaic Image - Natural proportions for masonry */
.mosaic-img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.4s ease, filter 0.4s ease;
}

.mosaic-item:hover .mosaic-img {
    transform: scale(1.05);
}

/* Overlay */
.mosaic-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom,
            transparent 0%,
            transparent 50%,
            rgba(0, 0, 0, 0.5) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

/* Zoom Icon */
.mosaic-zoom {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mosaic-item:hover .mosaic-zoom {
    transform: scale(1);
}

.mosaic-zoom svg {
    width: 24px;
    height: 24px;
    color: #333;
}

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

.mosaic-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mosaic-lightbox.active {
    opacity: 1;
    visibility: visible;
}

/* Lightbox Content */
.mosaic-lightbox-content {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mosaic-lightbox-img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.mosaic-lightbox.active .mosaic-lightbox-img {
    transform: scale(1);
    opacity: 1;
}

/* Lightbox Buttons */
.mosaic-lightbox-close,
.mosaic-lightbox-prev,
.mosaic-lightbox-next {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    padding: 15px;
    border-radius: 50%;
    transition: background 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mosaic-lightbox-close:hover,
.mosaic-lightbox-prev:hover,
.mosaic-lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.mosaic-lightbox-close {
    top: 20px;
    right: 20px;
}

.mosaic-lightbox-prev {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.mosaic-lightbox-prev:hover {
    transform: translateY(-50%) scale(1.1);
}

.mosaic-lightbox-next {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.mosaic-lightbox-next:hover {
    transform: translateY(-50%) scale(1.1);
}

.mosaic-lightbox-close svg,
.mosaic-lightbox-prev svg,
.mosaic-lightbox-next svg {
    width: 24px;
    height: 24px;
}

/* Counter */
.mosaic-lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Mobile adjustments */
@media (max-width: 768px) {

    .mosaic-lightbox-prev,
    .mosaic-lightbox-next {
        top: auto;
        bottom: 70px;
        transform: none;
    }

    .mosaic-lightbox-prev {
        left: 30%;
        transform: translateX(-50%);
    }

    .mosaic-lightbox-prev:hover {
        transform: translateX(-50%) scale(1.1);
    }

    .mosaic-lightbox-next {
        right: auto;
        left: 70%;
        transform: translateX(-50%);
    }

    .mosaic-lightbox-next:hover {
        transform: translateX(-50%) scale(1.1);
    }
}

/* Loading animation */
@keyframes mosaicFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mosaic-item {
    animation: mosaicFadeIn 0.5s ease forwards;
}

.mosaic-item:nth-child(1) {
    animation-delay: 0.05s;
}

.mosaic-item:nth-child(2) {
    animation-delay: 0.1s;
}

.mosaic-item:nth-child(3) {
    animation-delay: 0.15s;
}

.mosaic-item:nth-child(4) {
    animation-delay: 0.2s;
}

.mosaic-item:nth-child(5) {
    animation-delay: 0.25s;
}

.mosaic-item:nth-child(6) {
    animation-delay: 0.3s;
}

.mosaic-item:nth-child(7) {
    animation-delay: 0.35s;
}

.mosaic-item:nth-child(8) {
    animation-delay: 0.4s;
}

.mosaic-item:nth-child(n+9) {
    animation-delay: 0.45s;
}

/* Loading placeholder while images load */
.mosaic-item.loading {
    min-height: 150px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

    100% {
        background-position: -200% 0;
    }
}

/* ================================================
   MOSAIC VIDEO STYLES (MASONRY AND JUSTIFIED)
   ================================================ */
.mosaic-video-gallery {
    --mosaic-video-columns: 3;
    --mosaic-video-gap: 10px;
    width: 100%;
    margin: 20px 0;
}

/* --- Classic Masonry --- */
.mosaic-video-gallery-masonry {
    column-count: var(--mosaic-video-columns);
    column-gap: var(--mosaic-video-gap);
}

.mosaic-video-gallery-masonry .mosaic-video-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    margin-bottom: var(--mosaic-video-gap);
    break-inside: avoid;
    page-break-inside: avoid;
    -webkit-column-break-inside: avoid;
    display: block;
}

/* --- Smart Justified (Grid Dense) --- */
.mosaic-video-gallery-justified {
    display: grid;
    grid-template-columns: repeat(var(--mosaic-video-columns), 1fr);
    grid-auto-rows: minmax(150px, auto);
    /* Flexible row height */
    grid-auto-flow: dense;
    /* Crucial for smart packing */
    gap: var(--mosaic-video-gap);
}

.mosaic-video-gallery-justified .mosaic-video-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mosaic-vid {
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
}

/* -- Classic Masonry (Force Horizontal) -- */
.mosaic-video-gallery-masonry .mosaic-vid {
    aspect-ratio: 16/9;
}

/* -- Smart Justified Orientations -- */
.mosaic-video-gallery-justified .mosaic-video-item-vertical {
    grid-column: span 1;
    grid-row: span 2;
}

.mosaic-video-gallery-justified .mosaic-video-item-vertical .mosaic-vid {
    aspect-ratio: 9/16;
}

.mosaic-video-gallery-justified .mosaic-video-item-horizontal {
    grid-column: span 2;
    grid-row: span 1;
}

.mosaic-video-gallery-justified .mosaic-video-item-horizontal .mosaic-vid {
    aspect-ratio: 16/9;
}

.mosaic-video-gallery-justified .mosaic-video-item-auto {
    grid-column: span 1;
    grid-row: span 1;
}

.mosaic-video-gallery-justified .mosaic-video-item-auto .mosaic-vid {
    aspect-ratio: 1/1;
}

/* Responsive Grid Adjustments for Video */
@media (max-width: 992px) {
    .mosaic-video-gallery-masonry {
        column-count: 2 !important;
    }

    .mosaic-video-gallery-justified {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 768px) {
    .mosaic-video-gallery-justified {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 576px) {
    .mosaic-video-gallery-masonry {
        column-count: 1 !important;
    }

    .mosaic-video-gallery-justified {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 600px) {
    .mosaic-video-gallery-justified {
        grid-template-columns: repeat(1, 1fr) !important;
    }

    .mosaic-video-gallery-justified .mosaic-video-item-horizontal,
    .mosaic-video-gallery-justified .mosaic-video-item-vertical {
        grid-column: span 1 !important;
        grid-row: span 1 !important;
    }
}

.mosaic-video-item {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease;
    margin-bottom: var(--mosaic-video-gap);
    /* Compatibility for masonry */
}

.mosaic-video-item:hover {
    transform: translateY(-4px);
}

.mosaic-video-content {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    overflow: hidden;
}

/* For Justified, we override the aspect ratio based on orientation */
.mosaic-video-gallery-justified .mosaic-video-item-vertical .mosaic-video-content {
    aspect-ratio: 9 / 16;
}

.mosaic-video-gallery-justified .mosaic-video-item-horizontal .mosaic-video-content {
    aspect-ratio: 16 / 9;
}

.mosaic-video-caption {
    padding: 15px;
    background: #fff;
    color: #3e4d5c;
    font-size: 15px;
    line-height: 1.4;
    text-align: center;
    font-weight: 500;
    border-top: 1px solid #f0f0f0;
}

/* --- Custom YouTube Preview & Play Button --- */
.mosaic-youtube-preview {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.mosaic-youtube-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.mosaic-youtube-preview:hover img {
    transform: scale(1.05);
}

.mosaic-video-play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    z-index: 2;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.mosaic-youtube-preview:hover .mosaic-video-play-button {
    transform: translate(-50%, -50%) scale(1.15);
}

.mosaic-video-play-button svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.3));
}

.mosaic-video-play-button svg circle {
    transition: fill 0.3s ease;
}

.mosaic-youtube-preview:hover .mosaic-video-play-button svg circle {
    fill: rgba(255, 255, 255, 0.2);
}