/* Flexible Gallery Block Styles */
.flexible-gallery {
    width: 100%;
    margin: 0 auto;
    padding: 20px 0;
}

/* Gallery Grid Base */
.gallery-grid {
    display: grid;
    width: 100%;
}

/* Grid Layout */
.layout-grid .gallery-grid {
    grid-template-columns: repeat(var(--desktop-cols), 1fr);
}

/* Masonry Layout */
.layout-masonry .gallery-grid {
    grid-template-columns: repeat(var(--desktop-cols), 1fr);
    grid-auto-rows: auto;
}

.layout-masonry .gallery-item {
    break-inside: avoid;
}

/* Creative Split Layout */
.layout-creative-split .gallery-grid.creative-split-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    width: 100%;
}

.creative-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.creative-row {
    display: grid;
    gap: 20px;
}

/* Left Column Styles */
.creative-column-left .creative-row-large {
    grid-template-columns: 1fr;
    min-height: 300px;
}

.creative-column-left .creative-row-small {
    grid-template-columns: 1fr 1fr;
    min-height: 150px;
}

/* Right Column Styles */
.creative-column-right .creative-row-square {
    grid-template-columns: 1fr;
    min-height: 150px;
}

.creative-column-right .creative-row-wide {
    grid-template-columns: 1fr;
    min-height: 300px;
}

/* Creative Item Sizes */
.creative-item.creative-size-large .image-container {
    aspect-ratio: 4/3;
    height: 100%;
}

.creative-item.creative-size-small .image-container {
    aspect-ratio: 1/1;
    height: 100%;
}

.creative-item.creative-size-square .image-container {
    aspect-ratio: 1/1;
    height: 100%;
}

.creative-item.creative-size-wide .image-container {
    aspect-ratio: 4/3;
    height: 100%;
}

/* Gallery Item */
.gallery-item {
    position: relative;
    overflow: hidden;
}

/* Image Container */
.image-container {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

/* Aspect Ratios */
.aspect-square .image-container {
    aspect-ratio: 1 / 1;
}

.aspect-portrait .image-container {
    aspect-ratio: 3 / 4;
}

.aspect-landscape .image-container {
    aspect-ratio: 4 / 3;
}

.aspect-auto .image-container {
    aspect-ratio: auto;
    height: auto;
}

.aspect-auto .image-container img {
    height: auto;
}

/* Images */
.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.link-none .gallery-item:hover img,
.link-image .gallery-item:hover img {
    transform: scale(1.05);
}

/* Captions */
.image-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 15px 20px;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.caption-hover .image-caption {
    transform: translateY(100%);
}

.caption-hover .gallery-item:hover .image-caption {
    transform: translateY(0);
}

.caption-always .image-caption {
    transform: translateY(0);
    position: relative;
    background: #f8f8f8;
    color: #333;
    margin-top: -1px;
}

/* Gallery Gaps */
.gap-none .gallery-grid {
    gap: 0;
}

.gap-small .gallery-grid {
    gap: 5px;
}

.gap-medium .gallery-grid {
    gap: 10px;
}

.gap-large .gallery-grid {
    gap: 20px;
}

/* Link Styles */
.gallery-link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.3s ease;
}

.gallery-link:hover {
    opacity: 0.9;
}

.link-image .gallery-item:hover {
    cursor: pointer;
}

/* Column Settings */
.flexible-gallery {
    --desktop-cols: 4;
    --tablet-cols: 3;
    --mobile-cols: 2;
}

.cols-desktop-2 { --desktop-cols: 2; }
.cols-desktop-3 { --desktop-cols: 3; }
.cols-desktop-4 { --desktop-cols: 4; }
.cols-desktop-5 { --desktop-cols: 5; }
.cols-desktop-6 { --desktop-cols: 6; }

.cols-tablet-2 { --tablet-cols: 2; }
.cols-tablet-3 { --tablet-cols: 3; }
.cols-tablet-4 { --tablet-cols: 4; }

.cols-mobile-1 { --mobile-cols: 1; }
.cols-mobile-2 { --mobile-cols: 2; }

/* Responsive Design */
@media (max-width: 1024px) {
    .layout-grid .gallery-grid,
    .layout-masonry .gallery-grid {
        grid-template-columns: repeat(var(--tablet-cols), 1fr);
    }
    
    .layout-creative-split .gallery-grid.creative-split-grid {
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }
    
    .creative-column {
        gap: 15px;
    }
    
    .creative-row {
        gap: 15px;
    }
    
    .creative-column-left .creative-row-large {
        min-height: 250px;
    }
    
    .creative-column-left .creative-row-small {
        min-height: 120px;
    }
    
    .creative-column-right .creative-row-square {
        min-height: 120px;
    }
    
    .creative-column-right .creative-row-wide {
        min-height: 250px;
    }
}

@media (max-width: 768px) {
    .layout-grid .gallery-grid,
    .layout-masonry .gallery-grid {
        grid-template-columns: repeat(var(--mobile-cols), 1fr);
    }
    
    .layout-creative-split .gallery-grid.creative-split-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .creative-column {
        gap: 10px;
    }
    
    .creative-column-left .creative-row-small {
        grid-template-columns: 1fr;
    }
    
    .creative-column-left .creative-row-large {
        min-height: 200px;
    }
    
    .creative-column-left .creative-row-small {
        min-height: 150px;
    }
    
    .creative-column-right .creative-row-square {
        min-height: 150px;
    }
    
    .creative-column-right .creative-row-wide {
        min-height: 200px;
    }
    
    .image-caption {
        padding: 10px 15px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .flexible-gallery {
        padding: 10px 0;
    }
    
    .layout-grid .gallery-grid,
    .layout-masonry .gallery-grid {
        grid-template-columns: 1fr;
    }
    
    .layout-creative-split .gallery-grid.creative-split-grid {
        gap: 8px;
    }
    
    .creative-column {
        gap: 8px;
    }
    
    .creative-row {
        gap: 8px;
    }
    
    .gap-large .gallery-grid {
        gap: 10px;
    }
}

/* Justified Grid Layout */
.layout-justified .gallery-grid {
    display: flex;
    flex-wrap: wrap;
}

.layout-justified .gallery-item {
    flex: 1 0 auto;
    margin: 5px;
}

.layout-justified .image-container {
    height: 200px; /* Base height for justified grid */
}

/* Ensure proper loading */
.gallery-item img {
    transition: opacity 0.3s ease;
}

/* Simple focus styles for accessibility */
.gallery-link:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .flexible-gallery {
        break-inside: avoid;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Empty slot styling for creative layout */
.empty-slot {
    background: #f5f5f5;
    border: 2px dashed #ddd;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-slot::after {
    content: "No Image";
    color: #999;
    font-style: italic;
}

/* Force creative layout to display properly */
.layout-creative-split .gallery-grid.creative-split-grid {
    display: grid !important;
}

.creative-column {
    display: flex !important;
}

.creative-row {
    display: grid !important;
}