/* Gallery container */
.rndnanthu-gallery {
    width: 100%;
    margin: 0;
    position: relative;
    max-width: 100%;
    overflow: hidden;
    /* Ensure Elementor widget width/height settings work properly */
    box-sizing: border-box;
    /* Allow height to be set by Elementor controls */
    height: auto;
}

/* Responsive gallery class */
.rndnanthu-gallery.responsive-gallery {
    width: 100%;
    height: auto;
}

/* Elementor gallery container that should respect height settings */
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery {
    height: inherit;
}

/* Gallery grid container - Horizontal layout */
.rndnanthu-gallery-grid {
    display: grid;
    /* Default to auto-fit if no data-columns attribute is provided, but the specific column CSS will override */
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Adaptive grid as fallback */
    gap: 15px;
    width: 100%;
    max-width: 100%;
    /* Ensure the grid respects its container */
    box-sizing: border-box;
}

/* Gallery grid columns based on data-columns attribute - Horizontal layout */
.rndnanthu-gallery-grid[data-columns="1"] { grid-template-columns: repeat(1, 1fr) !important; }
.rndnanthu-gallery-grid[data-columns="2"] { grid-template-columns: repeat(2, 1fr) !important; }
.rndnanthu-gallery-grid[data-columns="3"] { grid-template-columns: repeat(3, 1fr) !important; }
.rndnanthu-gallery-grid[data-columns="4"] { grid-template-columns: repeat(4, 1fr) !important; }
.rndnanthu-gallery-grid[data-columns="5"] { grid-template-columns: repeat(5, 1fr) !important; }
.rndnanthu-gallery-grid[data-columns="6"] { grid-template-columns: repeat(6, 1fr) !important; }

/* Make sure the grid respects the columns count even for elementor widgets */
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="1"] { grid-template-columns: repeat(1, 1fr) !important; }
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="2"] { grid-template-columns: repeat(2, 1fr) !important; }
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="3"] { grid-template-columns: repeat(3, 1fr) !important; }
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="4"] { grid-template-columns: repeat(4, 1fr) !important; }
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="5"] { grid-template-columns: repeat(5, 1fr) !important; }
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="6"] { grid-template-columns: repeat(6, 1fr) !important; }

/* For adaptive grid (when no data-columns is specified), use a default */
.rndnanthu-gallery-grid:not([data-columns]) {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* Properly handle grid items with responsive aspect ratio */
.rndnanthu-gallery-grid > .rndnanthu-gallery-item {
    position: relative; /* For absolute positioning of images */
    overflow: hidden;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    width: 100%;
    height: 0;
    padding-bottom: 100%; /* This maintains 1:1 aspect ratio */
    /* Make sure it works with Elementor responsive controls */
    flex: 1 1 auto;
    /* Allow items to size naturally based on grid and container */
    min-height: 0;
}

/* Actual image container inside the item */
.rndnanthu-gallery-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
    transition: transform 0.3s ease;
}

/* Hover effect for images */
.rndnanthu-gallery-grid > .rndnanthu-gallery-item:hover .rndnanthu-gallery-image {
    transform: scale(1.05);
}

/* Gallery image - positioned absolutely within container with robust cropping */
.rndnanthu-gallery-image {
    position: absolute;
    inset: 0; /* shorthand for top:0; right:0; bottom:0; left:0 */
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    object-position: center center !important; /* ensures central cropping */
    display: block;
    transition: transform 0.3s ease;
    max-width: 100% !important;
    max-height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
}

.rndnanthu-gallery-grid > .rndnanthu-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

/* Gallery image - positioned absolutely within container with robust cropping */
.rndnanthu-gallery-image {
    position: absolute;
    inset: 0; /* shorthand for top:0; right:0; bottom:0; left:0 */
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    object-position: center center !important; /* ensures central cropping */
    display: block;
    transition: transform 0.3s ease;
    max-width: 100% !important;
    max-height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
}

.rndnanthu-gallery-grid > .rndnanthu-gallery-item:hover .rndnanthu-gallery-image {
    transform: scale(1.05);
}

/* Hover animations */
.rndnanthu-gallery-grid > .rndnanthu-gallery-item.hover-zoom-in:hover .rndnanthu-gallery-image {
    transform: scale(1.1);
}

.rndnanthu-gallery-grid > .rndnanthu-gallery-item.hover-zoom-out:hover .rndnanthu-gallery-image {
    transform: scale(0.95);
}

.rndnanthu-gallery-grid > .rndnanthu-gallery-item.hover-lateral-move:hover .rndnanthu-gallery-image {
    transform: translateX(5px);
}

.rndnanthu-gallery-grid > .rndnanthu-gallery-item.hover-none .rndnanthu-gallery-image {
    transition: none;
}

.rndnanthu-gallery-grid > .rndnanthu-gallery-item.hover-none:hover .rndnanthu-gallery-image {
    transform: none;
}

/* Prevent any hover effects when hover-none is selected */
.rndnanthu-gallery-grid > .rndnanthu-gallery-item.hover-none:hover {
    transform: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

/* Loading state */
.rndnanthu-gallery-loading {
    text-align: center;
    padding: 40px;
}

.rndnanthu-gallery-loading-message {
    color: #666;
    font-style: italic;
}

/* Error message */
.rndnanthu-gallery-error {
    text-align: center;
    padding: 20px;
    color: #d63638;
    background-color: #fcf0f1;
    border: 1px solid #f1c6c8;
    border-radius: 4px;
    margin: 10px 0;
}

/* Empty gallery message */
.rndnanthu-gallery-empty {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-style: italic;
}

/* Fix lightbox content centering */
.rndnanthu-lightbox-overlay {
    display: flex;
    justify-content: center;
    align-items: center; /* Centers vertically */
    overflow: auto;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 9999;
}

/* Make sure content stays centered even with captions */
.rndnanthu-lightbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* vertically center */
    position: relative;
    text-align: center;
    max-width: 90vw;
    max-height: 90vh;
    margin: auto;
    box-sizing: border-box;
}

.rndnanthu-lightbox-image {
    max-width: 90vw;
    max-height: 80vh;
    display: block;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.rndnanthu-lightbox-close {
    position: absolute;
    top: 15px;
    right: 15px;
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10002;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0,0,0,0.7);
    border-radius: 50%;
    border: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.rndnanthu-lightbox-close:hover {
    background-color: rgba(0,0,0,0.9);
    color: #fff;
    transform: scale(1.1);
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
}

.rndnanthu-lightbox-caption {
    color: white;
    text-align: center;
    margin-top: 10px;
    font-size: 16px;
}

/* Lightbox navigation */
.rndnanthu-lightbox-nav {
    position: absolute;
    top: 50%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    transform: translateY(-50%);
    padding: 0 20px;
    z-index: 10000;
}

.rndnanthu-lightbox-prev,
.rndnanthu-lightbox-next {
    display: none;
}

/* Make sure navigation buttons are visible when lightbox is open */
.rndnanthu-lightbox-content:hover .rndnanthu-lightbox-nav .rndnanthu-lightbox-prev,
.rndnanthu-lightbox-content:hover .rndnanthu-lightbox-nav .rndnanthu-lightbox-next {
    opacity: 1;
}

/* Responsive adjustments for lightbox */
@media (max-width: 768px) {
    .rndnanthu-lightbox-close {
        top: -25px;
        right: -25px;
        font-size: 28px;
        width: 35px;
        height: 35px;
    }
    
    .rndnanthu-lightbox-nav {
        padding: 0 10px;
    }
    
    .rndnanthu-lightbox-prev,
    .rndnanthu-lightbox-next {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .rndnanthu-lightbox-image {
        max-width: 95vw;
        max-height: 70vh;
    }
}

/* Responsive design */
@media (max-width: 768px) {
    /* Mobile styles for gallery - preserve column data but make responsive */
    .rndnanthu-gallery-grid {
        gap: 10px;
    }
    
    /* On mobile, provide responsive fallbacks while trying to respect main settings */
    .rndnanthu-gallery-grid[data-columns="1"] { grid-template-columns: repeat(1, 1fr) !important; }
    .rndnanthu-gallery-grid[data-columns="2"] { grid-template-columns: repeat(2, 1fr) !important; }
    .rndnanthu-gallery-grid[data-columns="3"] { grid-template-columns: repeat(2, 1fr) !important; } /* Reduce from 3 to 2 on mobile */
    .rndnanthu-gallery-grid[data-columns="4"] { grid-template-columns: repeat(2, 1fr) !important; } /* Reduce from 4 to 2 on mobile */
    .rndnanthu-gallery-grid[data-columns="5"] { grid-template-columns: repeat(2, 1fr) !important; } /* Reduce from 5 to 2 on mobile */
    .rndnanthu-gallery-grid[data-columns="6"] { grid-template-columns: repeat(2, 1fr) !important; } /* Reduce from 6 to 2 on mobile */
    
    /* Fallback for adaptive grid */
    .rndnanthu-gallery-grid:not([data-columns]) {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); /* 2-3 columns on mobile */
    }
    
    /* Elementor widget specific responsive styles */
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="1"] { grid-template-columns: repeat(1, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="2"] { grid-template-columns: repeat(2, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="3"] { grid-template-columns: repeat(2, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="4"] { grid-template-columns: repeat(2, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="5"] { grid-template-columns: repeat(2, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="6"] { grid-template-columns: repeat(2, 1fr) !important; }
    
    /* Lightbox adjustments for mobile */
    .rndnanthu-lightbox-image {
        max-height: 70vh;
    }
    
    .rndnanthu-lightbox-close {
        font-size: 28px;
        top: -30px;
    }
}

@media (max-width: 480px) {
    /* Extra small mobile styles */
    .rndnanthu-gallery-grid {
        gap: 8px;
    }
    
    /* On very small screens, use single column while preserving user's intent */
    .rndnanthu-gallery-grid[data-columns="1"] { grid-template-columns: repeat(1, 1fr) !important; }
    .rndnanthu-gallery-grid[data-columns="2"] { grid-template-columns: repeat(1, 1fr) !important; } /* Reduce to 1 on small screens */
    .rndnanthu-gallery-grid[data-columns="3"] { grid-template-columns: repeat(1, 1fr) !important; }
    .rndnanthu-gallery-grid[data-columns="4"] { grid-template-columns: repeat(1, 1fr) !important; }
    .rndnanthu-gallery-grid[data-columns="5"] { grid-template-columns: repeat(1, 1fr) !important; }
    .rndnanthu-gallery-grid[data-columns="6"] { grid-template-columns: repeat(1, 1fr) !important; }
    
    /* Elementor widget specific responsive styles for small screens */
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="1"] { grid-template-columns: repeat(1, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="2"] { grid-template-columns: repeat(1, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="3"] { grid-template-columns: repeat(1, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="4"] { grid-template-columns: repeat(1, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="5"] { grid-template-columns: repeat(1, 1fr) !important; }
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid[data-columns="6"] { grid-template-columns: repeat(1, 1fr) !important; }
    
    /* Fallback for adaptive grid */
    .rndnanthu-gallery-grid:not([data-columns]) {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); /* 1-2 columns on small mobile */
    }
    
    /* Adjust aspect ratio for very small screens */
    .rndnanthu-gallery-item {
        aspect-ratio: 1 / 1;
    }
}

/* Carousel Styles */
.rndnanthu-carousel {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* Elementor Widget Responsive Fixes */
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery,
.rndnanthu-gallery.elementor-element {
    width: 100%;
    max-width: 100%;
    /* Make sure the gallery container respects Elementor's sizing controls */
    box-sizing: border-box;
}

/* Ensure gallery grid also respects parent container sizing */
.elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid {
    width: 100%;
    box-sizing: border-box;
}

/* Handle responsive behavior when container width changes */
@media (max-width: 768px) {
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important;
    }
}

@media (max-width: 480px) {
    .elementor-widget-rndnanthu_gallery .rndnanthu-gallery-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
    }
}

.rndnanthu-carousel-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
}

.rndnanthu-carousel-track {
    display: flex;
    transition: transform 0.5s ease-in-out;
    width: 100%;
}

/* Slide transition (default) */
.rndnanthu-carousel-track.slide {
    transition: transform 0.5s ease-in-out;
}

/* Fade transition */
.rndnanthu-carousel-track.fade {
    transition: opacity 0.5s ease-in-out;
}

.rndnanthu-carousel-track.fade .rndnanthu-carousel-item {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.rndnanthu-carousel-track.fade .rndnanthu-carousel-item.active {
    opacity: 1;
    z-index: 2;
}

.rndnanthu-carousel-track.fade .rndnanthu-carousel-item.prev,
.rndnanthu-carousel-track.fade .rndnanthu-carousel-item.next {
    opacity: 0;
}

/* Flip transition */
.rndnanthu-carousel-track.flip {
    perspective: 1000px;
}

.rndnanthu-carousel-track.flip .rndnanthu-carousel-item {
    backface-visibility: hidden;
    transition: transform 0.6s ease-in-out;
}

/* Coverflow transition */
.rndnanthu-carousel-track.coverflow .rndnanthu-carousel-item {
    transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
    position: relative;
    z-index: 1;
}

.rndnanthu-carousel-item {
    flex: 0 0 auto;
    position: relative;
    overflow: hidden;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    width: calc(100% / var(--carousel-count, 3));
    aspect-ratio: 1/1;
}

.rndnanthu-carousel-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
}

.rndnanthu-carousel-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.rndnanthu-carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    color: white;
    border: none;
    width: auto;
    height: auto;
    border-radius: 0;
    cursor: pointer;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    transition: all 0.3s ease;
    box-shadow: none;
    opacity: 0.8;
    padding: 0;
    margin: 0;
}

.rndnanthu-carousel-btn:hover {
    background: transparent;
    opacity: 1;
    transform: translateY(-50%) scale(1.2);
}

.rndnanthu-carousel-prev {
    left: 10px;
}

.rndnanthu-carousel-next {
    right: 10px;
}

.rndnanthu-carousel-indicators {
    display: flex;
    justify-content: center;
    margin-top: 15px;
    gap: 8px;
}

.rndnanthu-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: background 0.3s ease;
}

.rndnanthu-indicator.active {
    background: #2b8aef;
}

@media (max-width: 480px) {
    .rndnanthu-gallery-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); /* Single column on very small screens */
        gap: 8px;
    }
    
    .rndnanthu-gallery-grid[data-columns="1"],
    .rndnanthu-gallery-grid[data-columns="2"],
    .rndnanthu-gallery-grid[data-columns="3"],
    .rndnanthu-gallery-grid[data-columns="4"],
    .rndnanthu-gallery-grid[data-columns="5"],
    .rndnanthu-gallery-grid[data-columns="6"] { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
    
    /* Carousel responsive */
    .rndnanthu-carousel-item {
        width: 100%; /* Show one item at a time on mobile */
    }
    
    .rndnanthu-carousel-btn {
        width: auto;
        height: auto;
        font-size: 28px;
    }
    
    .rndnanthu-carousel-prev {
        left: 5px;
    }
    
    .rndnanthu-carousel-next {
        right: 5px;
    }
}

@media (max-width: 768px) {
    .rndnanthu-lightbox-content {
        max-width: 95vw;
        max-height: 80vh;
    }
}
