/* ===== Grid Styles ===== */

/* Base grid styles */
.blog-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    width: 100%;
    justify-content: center;
    max-width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Standalone grids use container queries */
.blog-grid.standalone {
    container-name: imagegroup;
    container-type: inline-size;
    max-width: 1800px;
}

/* Content-image-group should also be a container */
.content-image-group {
    container-name: imagegroup;
    container-type: inline-size;
}

/* Grid figure styles */
.blog-grid,
.blog-grid figure {
    box-sizing: border-box;
    overflow: visible;
}

.blog-grid figure {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    height: 100%;
}

/* Grid image styles */
.blog-grid img {
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

/* Grid link styles */
.blog-grid a {
    display: block;
    width: 100%;
}

/* Figcaption styles */
.blog-grid figcaption {
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.5rem;
    container-type: inline-size;
    container-name: caption;
}

@container caption (max-width: 500px) {
    .caption-text {
        width: 100% !important;
        min-width: 100%;
        padding: 1rem !important;
        margin-left: 0rem !important;
        margin-right: 0rem !important;
        background-color: var(--light-2);
    }
}

/* Column classes */
.blog-grid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.blog-grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* Grid item variations */
.grid-img,
.grid-img-tall {
    width: 100%;
    height: auto;
    max-width: 100%;
    /* object-fit: cover; */
    display: block;
    border-radius: 8px;
}

.grid-img img {
    aspect-ratio: 3 / 2;
    object-fit: cover;
}

.grid-img-tall {
    grid-row: span 2;
    aspect-ratio: 2 / 3;
}

/* Fix for tall images in single column */
@container imagegroup (max-width: 600px) {
    .grid-img-tall {
        grid-row: span 1; /* Don't span multiple rows in single column */
    }
}

/* Also add for media query fallback */
@media (max-width: 768px) {
    .blog-grid .grid-img-tall {
        grid-row: span 1 !important;
    }
}

.grid-img-wide {
    grid-column: 1 / -1;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.grid-img-wide img {
    width: 100%;
    height: auto;
    max-width: none;
}

.figure-group {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 1800px;
    /* Add container properties */
    container-name: imagegroup;
    container-type: inline-size;
}

.figure-group .image-grid,
.figure-group .blog-grid {
    margin-bottom: 0; /* Remove bottom margin when inside figure */
}

.figure-group .shared-caption {
    background-color: white;
    padding: 1.5rem;
    margin-top: 1rem;
    text-align: center;
}

.figure-group .image-item {
    position: relative;
}

/* Ensure proper spacing */
.figure-group + * {
    margin-top: 2rem;
}

.grid-img-wide,
.grid-img-wide figure {
    overflow: visible;
}

/* When inside flex-pair-wrapper */
.flex-pair-wrapper .blog-grid {
    flex-grow: 1;
    flex-shrink: 1;
    margin-left: 0;
    transition: margin-left 0.3s ease;
    padding: 0;
    box-sizing: border-box;
}

/* ===== Container Queries for Responsive Columns ===== */

/* 3 → 2 columns transition */
@container imagegroup (max-width: 1200px) {
    .blog-grid.cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 2 → 1 column transition */
@container imagegroup (max-width: 600px) {
    .blog-grid,
    .blog-grid.cols-2,
    .blog-grid.cols-3 {
        grid-template-columns: 1fr;
    }
    
    /* Make wide images span single column when in single column mode */
    .blog-grid .grid-img-wide {
        grid-column: span 1;
    }
}

/* ===== Media Query Overrides for Special Cases ===== */

/* Force single column for grids inside right-image-group at narrow widths */
@media (max-width: 1040px) {
    .right-image-group .blog-grid.cols-3,
    .right-image-group .blog-grid.cols-2 {
        grid-template-columns: 1fr;
    }
}

/* Mobile adjustments */
@media (max-width: 768px) {
    /* Ensure images span full width */
    .blog-grid .grid-img,
    .blog-grid .grid-img-wide {
        grid-column: 1 / -1;
    }
    
    /* Make sure images use full available width */
    .blog-grid img {
        width: 100%;
        max-width: 100%;
    }
    
    /* Ensure proper gap on mobile */
    .blog-grid {
        gap: 1rem;
    }
}

@media (max-width: 650px) {
    .grid-img-wide {
        grid-column: span 1;
    }

    .flex-pair-wrapper .blog-grid {
        margin-left: 0;
    }
}







/* Force single column for tall images on small screens */
@container imagegroup (max-width: 600px) {
    .blog-grid.standalone {
        grid-template-columns: 1fr !important;
    }
    
    .blog-grid .grid-img-tall {
        grid-row: span 1 !important;
        width: 100%;
        max-width: 100%;
    }
    
    .blog-grid .grid-img-tall img {
        width: 100%;
        height: auto;
        aspect-ratio: auto; /* Override the 2/3 aspect ratio */
    }
}

/* Media query fallback for browsers without container query support */
@media (max-width: 768px) {
    .blog-grid.standalone.cols-3 {
        grid-template-columns: 1fr !important;
        gap: 2rem; /* More space between tall images */
    }
    
    .blog-grid .grid-img-tall {
        grid-row: span 1 !important;
        aspect-ratio: auto !important;
    }
    
    .blog-grid .grid-img-tall img {
        width: 100%;
        height: auto;
        max-height: 80vh; /* Prevent images from being too tall on mobile */
        object-fit: contain;
    }
}