/**
 * MG Gallery Masonry CSS
 * Version: 1.0.0
 */

/* Main gallery container */
.mg-gallery-masonry {
    position: relative;
    width: 100%;
    padding: 0;
    margin: 20px 0;
}

/* Loading state */
.mg-gallery-masonry.loading {
    opacity: 0;
    min-height: 200px; /* Prevent layout shift during loading */
}

/* Individual gallery items */
.mg-gallery-item {
    position: absolute; /* Will be positioned by JavaScript */
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    background: #fff;
    box-sizing: border-box;
}

.mg-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Images */
.mg-gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

.mg-gallery-item:hover img {
    transform: scale(1.05);
}

/* Links */
.mg-gallery-item a {
    display: block;
    text-decoration: none;
    color: inherit;
}

.mg-gallery-item a:hover {
    text-decoration: none;
}

/* Captions */
.mg-gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: white;
    padding: 20px 15px 15px;
    font-size: 14px;
    line-height: 1.4;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.mg-gallery-item:hover .mg-gallery-caption {
    transform: translateY(0);
}

/* Responsive behavior is handled by JavaScript */

/* Animation effects */
.mg-gallery-item {
    opacity: 0;
    animation: mgFadeIn 0.6s ease forwards;
}

.mg-gallery-item:nth-child(1) { animation-delay: 0.1s; }
.mg-gallery-item:nth-child(2) { animation-delay: 0.2s; }
.mg-gallery-item:nth-child(3) { animation-delay: 0.3s; }
.mg-gallery-item:nth-child(4) { animation-delay: 0.4s; }
.mg-gallery-item:nth-child(5) { animation-delay: 0.5s; }
.mg-gallery-item:nth-child(6) { animation-delay: 0.6s; }
.mg-gallery-item:nth-child(n+7) { animation-delay: 0.7s; }

@keyframes mgFadeIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading state */
.mg-gallery-masonry.loading .mg-gallery-item {
    opacity: 0.5;
}

.mg-gallery-masonry.loaded .mg-gallery-item {
    opacity: 1;
}

/* Gap sizes are now handled by JavaScript positioning */

/* Accessibility improvements */
.mg-gallery-item:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.mg-gallery-item a:focus {
    outline: none;
}

/* Print styles */
@media print {
    .mg-gallery-masonry {
        display: block;
    }

    .mg-gallery-item {
        display: inline-block;
        width: 48%;
        margin: 1%;
        break-inside: avoid;
    }

    .mg-gallery-caption {
        position: static;
        background: #f5f5f5;
        color: #333;
        transform: none;
    }
}