/* Image Gallery */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

/* No images message */
.no-images-message {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--md-default-fg-color--light);
    background: var(--md-default-fg-color--lightest);
    border: 1px solid var(--md-default-fg-color--lighter);
    border-radius: 8px;
    margin: 1rem 0;
}

.no-images-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.no-images-message p {
    margin: 0;
    font-size: 1rem;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1/1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background: var(--md-default-bg-color--light, hsla(210, 17%, 98%, 1));
    box-shadow: 0 2px 8px hsla(0, 0%, 0%, 0.1);
}

/* Image source badge */
.image-source {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    z-index: 2;
    backdrop-filter: blur(4px);
}

/* Different colors for different image types */
.gallery-item[data-type="local"] .image-source {
    background: rgba(76, 175, 80, 0.8); /* Green for local */
}

.gallery-item[data-type="linked"] .image-source {
    background: rgba(33, 150, 243, 0.8); /* Blue for linked */
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px hsla(0, 0%, 0%, 0.2);
}

/* Placeholder Styles */
.gallery-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, hsla(0, 0%, 94%, 1) 25%, hsla(0, 0%, 88%, 1) 25%, hsla(0, 0%, 88%, 1) 50%, hsla(0, 0%, 94%, 1) 50%, hsla(0, 0%, 94%, 1) 75%, hsla(0, 0%, 88%, 1) 75%);
    background-size: 16px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--md-default-fg-color--lighter, hsla(0, 0%, 60%, 1));
    font-size: 0.9rem;
}

.placeholder-shimmer {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, hsla(0, 0%, 100%, 0.6), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Gallery Image Styles */
.gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: opacity 0.3s ease;
    opacity: 1;
    display: block;
}

/* Lightbox Modal Styles */
.lightbox-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: hsla(0, 0%, 0%, 0.9);
    cursor: pointer;
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 24px hsla(0, 0%, 0%, 0.5);
}

/* Lightbox Controls */
.lightbox-close {
    position: absolute;
    top: -40px;
    right: -40px;
    width: 40px;
    height: 40px;
    border: none;
    background: hsla(0, 0%, 100%, 0.2);
    color: hsla(0, 0%, 100%, 1);
    font-size: 24px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.lightbox-close:hover {
    background: hsla(0, 0%, 100%, 0.3);
}

.lightbox-prev,
.lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border: none;
    background: hsla(0, 0%, 100%, 0.2);
    color: hsla(0, 0%, 100%, 1);
    font-size: 24px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

.lightbox-prev {
    left: -70px;
}

.lightbox-next {
    right: -70px;
}

.lightbox-prev:hover,
.lightbox-next:hover {
    background: hsla(0, 0%, 100%, 0.3);
}

.lightbox-prev:disabled,
.lightbox-next:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.lightbox-counter {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    color: hsla(0, 0%, 100%, 1);
    background: hsla(0, 0%, 0%, 0.5);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 14px;
}

/* Dark mode support */
[data-md-color-scheme="slate"] .gallery-placeholder {
    background: linear-gradient(45deg, hsla(215, 25%, 27%, 1) 25%, hsla(221, 39%, 11%, 1) 25%, hsla(221, 39%, 11%, 1) 50%, hsla(215, 25%, 27%, 1) 50%, hsla(215, 25%, 27%, 1) 75%, hsla(221, 39%, 11%, 1) 75%);
}

[data-md-color-scheme="slate"] .gallery-item {
    background: var(--md-code-bg-color, hsla(215, 25%, 27%, 1));
}

[data-md-color-scheme="slate"] .no-images-message {
    background: var(--md-code-bg-color);
    border-color: var(--md-default-fg-color--lightest);
    color: var(--md-default-fg-color--light);
}

/* Responsive Design */
@media (max-width: 768px) {
    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }
    
    .lightbox-prev,
    .lightbox-next {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .lightbox-prev {
        left: -50px;
    }
    
    .lightbox-next {
        right: -50px;
    }
    
    .lightbox-close {
        top: -35px;
        right: -35px;
        width: 35px;
        height: 35px;
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 0.5rem;
    }
    
    .lightbox-content {
        max-width: 95%;
        max-height: 85%;
    }
    
    .lightbox-prev,
    .lightbox-next {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }
    
    .lightbox-prev {
        left: -45px;
    }
    
    .lightbox-next {
        right: -45px;
    }
    
    .lightbox-close {
        top: -30px;
        right: -30px;
        width: 30px;
        height: 30px;
        font-size: 18px;
    }
    
    .lightbox-counter {
        bottom: -35px;
        font-size: 12px;
        padding: 2px 8px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .gallery-item:hover {
        transform: none;
        box-shadow: 0 2px 8px hsla(0, 0%, 0%, 0.1);
    }
    
    .lightbox-prev,
    .lightbox-next,
    .lightbox-close {
        width: 44px;
        height: 44px;
    }
}