/* 🔄 Before/After Slider Styles - Professional image comparison component */

.before-after-container {
    position: relative;
    width: 100%;
    max-width: 400px; /* Constrain width for proper aspect ratio */
    aspect-ratio: 2/3; /* Default 2:3 aspect ratio to match most output images */
    margin: 0 auto; /* Center the container */
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    background: #f8f9fa;
    cursor: ew-resize; /* Show horizontal resize cursor for dragging */
    user-select: none;
    opacity: 1; /* Show immediately - remove invisible start */
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Smooth fade-in when slider is ready */
.before-after-container.slider-ready {
    opacity: 1;
}

/* 🍕 Square aspect ratio for Food Ways and other 1:1 presets */
.before-after-container.square-aspect {
    aspect-ratio: 1/1; /* 1:1 aspect ratio for square output presets */
}

/* 🎨 Explicit portrait aspect ratio for Indian 3Pc and traditional garments */
.before-after-container.portrait-aspect {
    aspect-ratio: 2/3 !important; /* 2:3 aspect ratio for portrait output presets (same as default, but explicit) */
}

/* 🔧 Mobile-specific fixes for portrait presets to prevent flickering */
@media (max-width: 768px) {
    .before-after-container.portrait-aspect {
        aspect-ratio: 2/3 !important; /* Force 2:3 aspect ratio on mobile for Indian Female, etc. */
        height: auto !important; /* Override any fixed heights */
        max-width: 350px !important; /* Appropriate mobile width */
    }
}

@media (max-width: 480px) {
    .before-after-container.portrait-aspect {
        max-width: 320px !important; /* Smaller width for very small screens */
    }
}

.before-after-container:hover {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
}

.before-after-container.loading {
    pointer-events: none;
}

.before-after-container.slider-active {
    cursor: ew-resize;
}

/* Image Wrappers */
.before-image-wrapper,
.after-image-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.after-image-wrapper {
    clip-path: inset(0 0% 0 0); /* Show 100% of Generated image by default */
    transition: clip-path 0.1s ease-out;
}

/* Images */
.before-image,
.after-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: transform 0.3s ease;
}

.before-after-container:hover .before-image,
.before-after-container:hover .after-image {
    transform: scale(1.02);
}

/* Image Labels */
.image-label {
    position: absolute;
    top: 16px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 14px;
    font-weight: 600;
    border-radius: 20px;
    backdrop-filter: blur(8px);
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 10;
}

.before-label {
    left: 16px;
}

.after-label {
    right: 16px;
}

.before-after-container:hover .image-label,
.before-after-container.slider-active .image-label {
    opacity: 1;
    transform: translateY(0);
}

/* Slider Control */
.slider-control {
    position: absolute;
    top: 0;
    left: 100%; /* Default to show full Generated image */
    width: 2px;
    height: 100%;
    z-index: 20;
    pointer-events: none;
}

.slider-line {
    display: none; /* Remove the line - slider effect still works */
}

.slider-handle {
    display: none; /* Remove the slider handle - we'll use invisible drag area instead */
}

.slider-handle:hover {
    transform: translateX(-50%) scale(1.15);
    box-shadow: 0 10px 35px rgba(102, 126, 234, 0.6), 0 4px 20px rgba(0, 0, 0, 0.2);
}

.slider-handle:focus {
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.3);
}

.slider-handle.dragging {
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 8px 40px rgba(102, 126, 234, 0.5);
}

.handle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.handle-icon svg {
    width: 20px;
    height: 20px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

/* Loading State */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    backdrop-filter: blur(4px);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e3e3e3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

.loading-text {
    font-size: 16px;
    color: #333;
    font-weight: 600;
    margin-bottom: 4px;
}

.loading-subtext {
    font-size: 12px;
    color: #666;
    font-weight: 400;
    opacity: 0.8;
}

/* Error State */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 32px;
    text-align: center;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.error-message {
    font-size: 16px;
    color: #666;
    margin-bottom: 24px;
    font-weight: 500;
}

.retry-button {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.retry-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.4);
}

/* Responsive Design */
@media (max-width: 768px) {
    .before-after-container {
        /* Keep aspect-ratio instead of fixed height to prevent flickering and wrong ratios */
        max-width: 350px; /* Slightly smaller for mobile */
        border-radius: 8px;
    }
    
    .slider-handle {
        width: 44px;
        height: 44px;
    }
    
    .image-label {
        font-size: 13px;
        padding: 6px 12px;
        top: 12px;
    }
    
    .before-label {
        left: 12px;
    }
    
    .after-label {
        right: 12px;
    }
    
    /* Touch-friendly adjustments */
    .slider-handle {
        width: 52px;
        height: 52px;
    }
}

@media (max-width: 480px) {
    .before-after-container {
        /* Keep aspect-ratio instead of fixed height for small mobile devices */
        max-width: 320px; /* Even smaller for very small screens */
    }
    
    .image-label {
        font-size: 12px;
        padding: 4px 8px;
        top: 8px;
    }
    
    .before-label {
        left: 8px;
    }
    
    .after-label {
        right: 8px;
    }
}

/* Enhanced animations and effects */
.before-after-container.images-loaded {
    animation: slideIn 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    60% {
        opacity: 0.8;
        transform: translateY(-5px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Pulse effect for slider handle when first loaded */
.before-after-container.images-loaded .slider-handle {
    animation: handlePulse 2s ease-in-out 0.5s;
}

@keyframes handlePulse {
    0%, 100% {
        box-shadow: 0 6px 25px rgba(102, 126, 234, 0.4), 0 2px 10px rgba(0, 0, 0, 0.1);
    }
    50% {
        box-shadow: 0 8px 35px rgba(102, 126, 234, 0.6), 0 4px 15px rgba(0, 0, 0, 0.15);
        transform: translate(-50%, -50%) scale(1.05);
    }
}

/* Enhanced loading spinner */
.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e3e3e3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
    margin-bottom: 20px;
}

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

/* Improved image quality and loading */
.before-image,
.after-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .slider-handle {
        border: 4px solid white;
        box-shadow: 0 0 0 2px #000;
    }
    
    .slider-line {
        background: #000;
        box-shadow: 0 0 0 1px #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .before-after-container,
    .before-image,
    .after-image,
    .slider-handle,
    .image-label {
        transition: none;
    }
    
    .before-after-container.images-loaded {
        animation: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .before-after-container {
        background: #1a1a1a;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }
    
    .loading-overlay {
        background: rgba(26, 26, 26, 0.95);
    }
    
    .loading-text,
    .error-message {
        color: #ccc;
    }
    
    .image-label {
        background: rgba(255, 255, 255, 0.9);
        color: #1a1a1a;
    }
}

/* Focus indicators for accessibility */
.slider-handle:focus-visible {
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.5);
    outline: 2px solid transparent;
}

/* Comparison Control Buttons */
.comparison-btn {
    padding: 8px 16px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
    outline: none;
}

.comparison-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.comparison-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.comparison-btn:focus {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

@media (max-width: 768px) {
    .comparison-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* Print styles */
@media print {
    .before-after-container {
        position: relative;
        page-break-inside: avoid;
    }
    
    .slider-control {
        display: none;
    }
    
    .after-image-wrapper {
        clip-path: none;
    }
    
    .before-image-wrapper {
        width: 48%;
        margin-right: 4%;
    }
    
    .after-image-wrapper {
        width: 48%;
        left: 52%;
    }
    
    #comparisonControls {
        display: none !important;
    }
}
