.cr-hero-galerie {
    width: 100%;
    position: relative;
    z-index: 20; /* Ensure it stays above subsequent overlapping sections */
    overflow: hidden;
}

/* Hero Section */
.cr-hero-galerie__hero {
    height: 550px;
    width: 100%;
    transition: height 0.6s cubic-bezier(0.25, 1, 0.5, 1);
    overflow: hidden;
}

.cr-hero-galerie__grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: minmax(0, 1fr); /* Prevent expansion */
    gap: 20px;
    height: 100%;
    width: 100%;
}

/* Column Wrappers */
.cr-hero-col-1 {
    grid-column: span 2;
    height: 100%;
    /* Flex container for content (image) */
    display: flex;
    flex-direction: column;
    min-height: 0; /* Prevent Grid blowout */
    overflow: hidden;
}

.cr-hero-col-2, .cr-hero-col-3 {
    grid-column: span 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Default split variable */
    --split-ratio: 50%;
    min-height: 0; /* Prevent Grid blowout */
    overflow: hidden;
}

.cr-hero-col-1 .cr-hero-galerie__item {
    height: 100%;
    width: 100%;
}

/* Split Logic for Col 2 & 3 */
.cr-hero-col-2 .cr-hero-galerie__item:first-child,
.cr-hero-col-3 .cr-hero-galerie__item:first-child {
    height: var(--split-ratio);
}

.cr-hero-col-2 .cr-hero-galerie__item:last-child,
.cr-hero-col-3 .cr-hero-galerie__item:last-child,
.cr-hero-col-3 .cr-hero-galerie__trigger-container {
    flex: 1; /* Fills remaining space */
}

.cr-hero-galerie__item {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    cursor: pointer; /* Clickable */
}

.cr-hero-galerie__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
}

.cr-hero-galerie__item:hover img {
    transform: scale(1.05);
}

/* Item Positioning for Hero - REMOVED (Handled by Flex Layout) */

.cr-hero-galerie__trigger-container {
    /* Grid placement removed */
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    cursor: pointer;
    transition: background-color 0.3s ease;
    border-radius: 10px;
    text-align: center;
    padding: 20px;
    border: none;
    outline: none;
    font-family: inherit;
}

.cr-hero-galerie__trigger-container:hover {
    background-color: #e0e0e0;
}

.cr-hero-galerie__trigger-text {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    pointer-events: none;
}

/* Expanded View */
.cr-hero-galerie__expanded {
    display: none; /* Hidden initially */
    margin-top: 20px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.cr-hero-galerie.is-open .cr-hero-galerie__expanded {
    display: block; /* Block for Masonry */
    opacity: 1;
    transform: translateY(0);
}

/* Masonry Grid */
.cr-masonry-grid {
    column-count: 3; /* Default, overridden by Elementor control */
    column-gap: 20px; /* Default */
    width: 100%;
}

.cr-masonry-item {
    break-inside: avoid;
    margin-bottom: 20px; /* Default */
    border-radius: 10px; /* Consistent with other items */
    overflow: hidden;
    cursor: pointer;
    position: relative;
    display: inline-block; /* Helps with break-inside in some browsers */
    width: 100%;
}

.cr-masonry-item img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.5s ease;
}

.cr-masonry-item:hover img {
    transform: scale(1.05);
}

/* Lightbox / Expanded Item (Bento Style) */
.cr-hero-galerie-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    -webkit-backdrop-filter: blur(0px);
    backdrop-filter: blur(0px);
    z-index: 99990;
    opacity: 0;
    pointer-events: none;
    transition: all 0.6s ease;
}

.cr-hero-galerie-backdrop.is-active {
    opacity: 1;
    pointer-events: auto;
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
}

.cr-hero-galerie-clone {
    position: fixed;
    z-index: 99999;
    transition: all 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.cr-hero-galerie-clone.is-expanded {
    border-radius: 20px;
}

.cr-hero-galerie-clone img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Responsive */
@media (max-width: 1024px) {
    .cr-hero-galerie__grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        /* Proportional rows: Top larger, others equal */
        grid-template-rows: 1.5fr 1fr 1fr;
        height: 100%; /* Respect container height */
        /* Gap is handled by Elementor control */
    }

    .cr-hero-col {
        display: contents; /* Unwrap columns so items participate in grid */
    }
    
    /* Reset layout specific styles */
    .cr-hero-galerie__item, 
    .cr-hero-galerie__trigger-container {
        height: 100%;
        width: 100%;
        flex: none;
    }

    /* Item 1: Full width top */
    .cr-hero-galerie__item--1 {
        grid-column: 1 / -1;
        grid-row: 1;
    }
    
    /* Row 2 */
    .cr-hero-galerie__item--2 {
        grid-column: 1;
        grid-row: 2;
    }
    .cr-hero-galerie__item--3 {
        grid-column: 2;
        grid-row: 2;
    }

    /* Row 3 */
    .cr-hero-galerie__item--4 {
        grid-column: 1;
        grid-row: 3;
    }
    .cr-hero-galerie__trigger-container {
        grid-column: 2;
        grid-row: 3;
    }

    /* Remove height auto override so Elementor control works */
    .cr-hero-galerie__hero {
        /* Height controlled by Elementor setting */
    }
    
    /* Bento Responsive - Tablet */
    .cr-masonry-grid {
        /* Handled by Elementor control tablet_default */
    }
}

@media (max-width: 767px) {
    /* Mobile: Simplified Layout - Image 1 + Column 3 (Item 4 & Button) */
    .cr-hero-galerie__grid {
        display: flex;
        flex-direction: column;
        height: 100%;
        width: 100% !important; /* Force full width */
        align-items: stretch; /* Ensure items stretch to full width */
        margin: 0 !important; /* Reset any margins */
        padding: 0 !important; /* Reset any padding */
        
        /* FIX: Reset column-gap to prevent any horizontal spacing issues */
        column-gap: 0 !important; 
        
        /* FIX: Ensure gap setting works vertically but doesn't affect width */
        box-sizing: border-box;
    }
    
    /* Revert display: contents to manage columns directly */
    .cr-hero-col {
        display: flex;
        width: 100% !important; /* Force full width */
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box;
    }

    /* Col 1: Hero Image - Takes all available space minus button */
    .cr-hero-col-1 {
        display: flex;
        flex: 1; 
        height: auto;
        min-height: 0;
    }

    /* Col 2: Hidden on mobile */
    .cr-hero-col-2 {
        display: none;
    }

    /* Col 3: Button Column - Only shows button, auto height */
    .cr-hero-col-3 {
        display: flex;
        flex: 0 0 auto; /* Shrink to fit content (button) */
        height: auto;
        min-height: 0;
        gap: 0; 
    }

    /* Hide Image 4 (first child of col 3) on mobile */
    .cr-hero-col-3 .cr-hero-galerie__item {
        display: none;
    }

    /* Reset manual placements */
    .cr-hero-galerie__item, 
    .cr-hero-galerie__trigger-container {
        width: 100% !important; /* Force full width */
        max-width: 100% !important;
        height: auto; /* Allow flex to control height */
        flex: auto; /* Reset flex-grow behavior */
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* Button container styling for mobile */
    .cr-hero-col-3 .cr-hero-galerie__trigger-container {
        height: auto;
        min-height: 60px; /* Ensure touch target size */
        flex: 1;
    }

    /* Remove height auto override */
    .cr-hero-galerie__hero {
        /* Height controlled by Elementor setting */
    }

    /* Bento Responsive - Mobile */
    .cr-masonry-grid {
        /* Handled by Elementor control mobile_default */
    }
}
