/* Lazy Gallery Styles */
.lazy-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    grid-gap: 20px;
    padding: 20px 0;
    max-width: 100%;
}

/* Responsive grid based on data-columns attribute */
.lazy-gallery[data-columns="1"] {
    grid-template-columns: 1fr;
    max-width: 800px;
    margin: 0 auto;
}

.lazy-gallery[data-columns="2"] {
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}

.lazy-gallery[data-columns="3"] {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.lazy-gallery[data-columns="4"] {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.lazy-gallery[data-columns="5"] {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* Gallery item container */
.lazy-gallery-item {
    position: relative;
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.lazy-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* === Styles for Clickable Gallery Items === */

/* Add a pointer cursor to the entire item if it contains a link */
.lazy-gallery-item:has(.gallery-item-link) {
    cursor: pointer;
}

/* Style for the anchor tag itself */
.lazy-gallery-item .gallery-item-link {
    display: block;
    text-decoration: none;
    color: inherit;
    position: relative;
    /* Needed for the icon positioning */
}

/* Link icon that appears on hover */
.lazy-gallery-item .gallery-item-link::after {
    content: '🔗';
    /* You can change this to any icon or text */
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 24px;
    color: white;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    /* Ensure the icon doesn't interfere with the click */
}

/* Show the icon when the parent item is hovered */
.lazy-gallery-item:hover .gallery-item-link::after {
    opacity: 1;
    transform: scale(1);
}

/* Lazy image styles */
.lazy-image {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 0.3s ease;
    opacity: 1;
    min-height: 200px;
    background: #f0f0f0;
}

/* Image not yet loaded */
.lazy-image:not(.loaded) {
    opacity: 0.3;
}

/* Image loaded state */
.lazy-image.loaded {
    opacity: 1;
}

/* Loading spinner */
.lazy-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Hide spinner when image is loaded */
.lazy-gallery-item .lazy-image.loaded+.lazy-loading-spinner {
    opacity: 0;
    pointer-events: none;
}

/* Spinner animation */
@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .lazy-gallery {
        grid-template-columns: 1fr;
        grid-gap: 15px;
        padding: 15px 0;
    }

    .lazy-gallery[data-columns="2"] {
        grid-template-columns: repeat(2, 1fr);
    }

    .lazy-gallery[data-columns="3"],
    .lazy-gallery[data-columns="4"],
    .lazy-gallery[data-columns="5"] {
        grid-template-columns: repeat(2, 1fr);
    }

    .lazy-gallery-item {
        border-radius: 6px;
    }
}

@media (max-width: 480px) {
    .lazy-gallery {
        grid-gap: 10px;
        padding: 10px 0;
    }

    .lazy-gallery[data-columns="2"],
    .lazy-gallery[data-columns="3"],
    .lazy-gallery[data-columns="4"],
    .lazy-gallery[data-columns="5"] {
        grid-template-columns: 1fr;
    }
}

/* Error state for images that fail to load */
.lazy-image.error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #721c24;
    font-size: 14px;
    min-height: 200px;
}

.lazy-image.error::after {
    content: "Image failed to load";
}

/* Fade-in animation for loaded images */
.lazy-gallery-item {
    animation: fadeInUp 0.6s ease forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

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