/* ===== IMAGE GALLERY MODE STYLES ===== */
/* Only loaded on image gallery pages (/images/ endpoints) for performance optimization */

/* ===== FULL-WIDTH LAYOUT FOR IMAGE GALLERY PAGES ===== */

body.category #secondary,
body.tag #secondary,
body.home #secondary,
body.search #secondary {
    display: none;
}

body.category #primary,
body.tag #primary,
body.home #primary,
body.search #primary {
    width: 100%;
    max-width: 100%;
    float: none;
}

/* ===== IMAGE GALLERY LAYOUT ===== */

/* Image Gallery - Pinterest Style Masonry Layout */
/* Base layout uses CSS columns as a fallback; JS converts to fixed columns to avoid reshuffling */
.image-gallery {
    column-count: 4;
    column-gap: 1rem;
    margin: 2rem 0;
}

/* When JS initializes masonry, we replace CSS columns with flex containers for stable appends */
.image-gallery.masonry {
    column-count: initial;
    column-gap: 0;
    display: flex;
    gap: .5rem;
}

.image-gallery.masonry .gallery-col {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.image-gallery.masonry .gallery-item {
    margin-bottom: 0;
}

/* ===== GALLERY ITEMS ===== */

.gallery-item {
    position: relative;
    display: block;
    width: 100%;
    margin-bottom: 1rem;
    break-inside: avoid;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.gallery-image {
    width: 100%;
    height: auto;
    display: block;
}

.gallery-item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

.source-post-link {
    color: white;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.source-post-link:hover {
    color: #fff;
    text-decoration: none;
}

/* ===== GALLERY NAVIGATION ===== */

/* Full-card link for gallery items */
.gallery-link {
    display: block;
    position: relative;
    text-decoration: none;
    color: inherit;
}

/* Ensure overlay doesn't block click */
.gallery-item-overlay { pointer-events: none; }

/* Keyboard accessibility: show overlay when focused */
.gallery-link:focus-visible .gallery-item-overlay { opacity: 1; }

/* Stronger focus outline encompassing entire card */
.gallery-link:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 12px;
}

/* ===== GALLERY HEADER ===== */

.image-gallery-header {
    margin-bottom: 2rem;
    padding: 1rem 0;
    border-bottom: 1px solid #eee;
}

.gallery-stats p {
    margin: 0.5rem 0;
    color: #666;
}

.back-to-posts a {
    color: #0073aa;
    text-decoration: none;
}

.back-to-posts a:hover {
    text-decoration: underline;
}

/* ===== GALLERY STATES ===== */

.no-images-found {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.no-images-found a {
    color: #0073aa;
    text-decoration: none;
    font-weight: 500;
}

.no-images-found a:hover {
    text-decoration: underline;
}

.load-more-gallery {
    text-align: center;
    margin: 2rem 0;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 6px;
    color: #666;
    column-span: all;
}

/* ===== LOAD MORE CONTROLS ===== */

/* Align the async load more trigger with the centered masonry output */
.load-more-container {
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    width: 100%;
    clear: both;
    margin: 2rem auto 0;
    column-span: all;
}

.load-more-container #load-more {
    margin-left: auto;
    margin-right: auto;
}

/* ===== ARCHIVE IMAGE MODE ===== */

/* Archive image mode card width constraint */
.archive-image-mode {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

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

/* Image Gallery Responsive Design */
@media (max-width: 1200px) {
    .image-gallery:not(.masonry) {
        column-count: 3;
    }
}

@media (max-width: 768px) {
    .image-gallery:not(.masonry) {
        column-gap: 0.75rem;
    }

    .gallery-item {
        margin-bottom: 1rem;
        border-radius: 8px;
    }

    .gallery-item-overlay {
        padding: 0.75rem;
    }

    .source-post-link {
        font-size: 0.8rem;
    }
}

@media (max-width: 450px) {
    .image-gallery:not(.masonry) {
        column-count: 1;
        column-gap: 0;
    }

    .gallery-item {
        margin-bottom: 1rem;
    }
}

/* ===== NO IMAGES FOUND STATE ===== */

.back-to-posts a {
    color: #0073aa;
    text-decoration: none;
}

.back-to-posts a:hover {
    text-decoration: underline;
}

.no-images-found {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.no-images-found a {
    color: #0073aa;
    text-decoration: none;
    font-weight: 500;
}

.no-images-found a:hover {
    text-decoration: underline;
}