/* Image Comparison Gallery Widget */
.serenity-image-comparison-gallery {
    --aspect-width: 16;
    --aspect-height: 9;
    --max-card-height: 600px;
    --grid-gap: 20px;
    --grid-columns: 2;
    --slides-to-show: 3;
    --slides-to-show-tablet: 2;
    --slides-to-show-mobile: 1;
    --carousel-gap: 20px;
    --carousel-gap-tablet: 20px;
    --carousel-gap-mobile: 10px;
    width: 100%;
}

/* Full-width section support */
.elementor-section.elementor-section-full-width .serenity-image-comparison-gallery,
.elementor-section.elementor-section-stretched .serenity-image-comparison-gallery {
    width: 100%;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
}

/* Base Comparison Card */
.comparison-card {
    position: relative;
    width: 100%;
    max-height: var(--max-card-height);
    overflow: hidden;
    background: #f5f5f5;
}

.comparison-container {
    position: relative;
    width: 100%;
    height: 100%;
    aspect-ratio: var(--aspect-width) / var(--aspect-height);
    max-height: var(--max-card-height);
}

.comparison-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.comparison-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.comparison-image.before {
    z-index: 1;
}

.comparison-image.after {
    z-index: 2;
}

.comparison-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: left center;
}

.comparison-label {
    position: absolute;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 4px;
    z-index: 15;
    user-select: none;
}

.comparison-label.before-label {
    top: 20px;
    left: 20px;
}

.comparison-label.after-label {
    top: 20px;
    right: 20px;
}

/* Comparison Handle */
/* Handle: full-height drag zone, centered on the divider line */
.comparison-handle {
    position: absolute;
    top: 0;
    left: 50%;
    width: 44px;
    height: 100%;
    background: transparent;
    cursor: ew-resize;
    z-index: 20;
    transform: translateX(-50%);
    overflow: visible;
}

/* The white divider line */
.handle-line {
    position: absolute;
    top: 0;
    left: 50%;
    width: 3px;
    height: 100%;
    background: #ffffff;
    transform: translateX(-50%);
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
    pointer-events: none;
}

/* Left arrow half-circle: sits to the left of the divider line */
.handle-arrow {
    position: absolute;
    top: 50%;
    width: 44px;
    height: 44px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 21;
    font-size: 13px;
    color: #333;
}

/* Left arrow: right half of circle, positioned to the left of divider */
.handle-arrow.left {
    left: 50%;
    transform: translate(-100%, -50%);
    border-radius: 50% 0 0 50%;
    padding-right: 4px;
}

/* Right arrow: left half of circle, positioned to the right of divider */
.handle-arrow.right {
    left: 50%;
    transform: translate(0%, -50%);
    border-radius: 0 50% 50% 0;
    padding-left: 4px;
}

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

.comparison-carousel-track {
    display: flex;
    transition: transform 0.5s ease;
    gap: var(--carousel-gap);
}

.comparison-slide {
    flex: 0 0 auto;
    width: calc((100% - var(--carousel-gap)) / var(--slides-to-show, 3));
}

/* Responsive carousel slides */
@media (max-width: 1024px) {
    .comparison-carousel-track {
        gap: var(--carousel-gap-tablet);
    }
    
    .comparison-slide {
        width: calc((100% - var(--carousel-gap-tablet)) / var(--slides-to-show-tablet, 2));
    }
}

@media (max-width: 768px) {
    .comparison-carousel-track {
        gap: var(--carousel-gap-mobile);
    }
    
    .comparison-slide {
        width: calc((100% - var(--carousel-gap-mobile)) / var(--slides-to-show-mobile, 1));
    }
}

.carousel-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #333;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.carousel-nav:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.carousel-nav.prev {
    left: 20px;
}

.carousel-nav.next {
    right: 20px;
}

.carousel-dots {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
}

.carousel-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
}

.carousel-dot:hover {
    background: rgba(255, 255, 255, 0.8);
}

.carousel-dot.active {
    background: #ffffff;
    transform: scale(1.2);
}

/* Grid Styles */
.comparison-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
    gap: var(--grid-gap);
    width: 100%;
}

.comparison-grid-item {
    width: 100%;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .comparison-label {
        /* Font size controlled by Elementor responsive control */
        padding: 6px 12px;
    }
    
    .comparison-label.before-label {
        top: 15px;
        left: 15px;
    }
    
    .comparison-label.after-label {
        top: 15px;
        right: 15px;
    }
    
    .carousel-nav {
        /* Size and font size controlled by Elementor responsive controls */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .carousel-nav.prev {
        left: 15px;
    }
    
    .carousel-nav.next {
        right: 15px;
    }
}

@media (max-width: 768px) {
    .comparison-label {
        /* Font size controlled by Elementor responsive control */
        padding: 4px 8px;
    }
    
    .comparison-label.before-label {
        top: 10px;
        left: 10px;
    }
    
    .comparison-label.after-label {
        top: 10px;
        right: 10px;
    }
    
    .handle-arrow {
        /* Size and font size controlled by Elementor responsive controls */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .carousel-nav {
        /* Size and font size controlled by Elementor responsive controls */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .carousel-nav.prev {
        left: 10px;
    }
    
    .carousel-nav.next {
        right: 10px;
    }
    
    .carousel-dots {
        bottom: 15px;
        gap: 6px;
    }
    
    .carousel-dot {
        width: 10px;
        height: 10px;
    }
}

@media (max-width: 480px) {
    .comparison-label {
        /* Font size controlled by Elementor responsive control */
        padding: 3px 6px;
    }
    
    .comparison-label.before-label {
        top: 8px;
        left: 8px;
    }
    
    .comparison-label.after-label {
        top: 8px;
        right: 8px;
    }
    
    .handle-arrow {
        /* Size and font size controlled by Elementor responsive controls */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .carousel-nav {
        /* Size and font size controlled by Elementor responsive controls */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .carousel-nav.prev {
        left: 8px;
    }
    
    .carousel-nav.next {
        right: 8px;
    }
    
    .carousel-dots {
        bottom: 10px;
        gap: 4px;
    }
    
    .carousel-dot {
        width: 8px;
        height: 8px;
    }
}

/* Auto Aspect Ratio Handling */
.serenity-image-comparison-gallery[data-aspect-ratio="auto"] .comparison-container {
    aspect-ratio: auto;
    height: auto;
    min-height: 300px;
}

.serenity-image-comparison-gallery[data-aspect-ratio="auto"] .comparison-image img {
    object-fit: contain;
}

/* Grid Responsive Columns */
@media (max-width: 1024px) {
    .serenity-image-comparison-gallery[data-grid-columns="4"] .comparison-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .serenity-image-comparison-gallery[data-grid-columns="3"] .comparison-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .serenity-image-comparison-gallery[data-grid-columns="2"] .comparison-grid,
    .serenity-image-comparison-gallery[data-grid-columns="3"] .comparison-grid,
    .serenity-image-comparison-gallery[data-grid-columns="4"] .comparison-grid {
        grid-template-columns: 1fr;
    }
}

/* Elementor Editor Support */
.elementor-editor-active .comparison-card {
    min-height: 400px;
}

.elementor-editor-active .comparison-handle {
    cursor: move;
}

/* Loading State */
.comparison-card.loading {
    opacity: 0.6;
    pointer-events: none;
}

.comparison-card.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #333;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
    z-index: 20;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

@media (hover: none) and (pointer: coarse) {
    .comparison-handle {
        width: 52px;
    }
    
    .handle-arrow {
        width: 52px;
        height: 52px;
        font-size: 15px;
    }
}

/* Animation States */
.comparison-overlay {
    transition: clip-path 0.05s linear;
}

.comparison-card.dragging .comparison-overlay {
    transition: none;
}

.comparison-card.dragging .comparison-handle {
    cursor: grabbing;
}

/* Focus States for Accessibility */
.carousel-nav:focus,
.carousel-dot:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.comparison-handle:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .comparison-carousel-track {
        transition: none;
    }
    
    .comparison-overlay {
        transition: none;
    }
    
    .comparison-handle {
        transition: none;
    }
    
    .carousel-nav {
        transition: none;
    }
    
    .carousel-dot {
        transition: none;
    }
    
    .comparison-card.loading::after {
        animation: none;
    }
}
