/**
 * Gallery Layout CSS - Smooth animations and transitions for gallery rearrangement
 * 
 * This file provides the visual styling for the dynamic gallery layout system
 * that rearranges the upload area and gallery sections based on content.
 */

/* Base layout container */
.gallery-layout-managed {
    position: relative;
    overflow: hidden;
}

/* Main interface container - support both flexbox and DOM reordering */
.gallery-layout-managed .photo-uploader-interface {
    display: block; /* Changed from flex to support DOM rearrangement */
    position: relative;
}

/* Add spacing between sections */
.gallery-layout-managed .photo-uploader-interface > * {
    margin-bottom: 1rem;
}

.gallery-layout-managed .photo-uploader-interface > *:last-child {
    margin-bottom: 0;
}

/* Smooth transitions for all managed elements */
.upload-interface-managed,
.gallery-section-managed {
    transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, opacity, order;
    transform-origin: center top;
}

/* Upload area states - removed order property since we use DOM rearrangement */
.upload-interface-managed.upload-primary {
    transform: translateY(0) scale(1);
    opacity: 1;
    z-index: 2;
}

.upload-interface-managed.upload-secondary {
    transform: translateY(0) scale(0.98);
    opacity: 0.95;
    z-index: 1;
}

/* Gallery section states - removed order property since we use DOM rearrangement */
.gallery-section-managed.gallery-empty {
    opacity: 0.7;
    transform: translateY(8px) scale(0.99);
    z-index: 1;
}

.gallery-section-managed.gallery-active {
    opacity: 1;
    transform: translateY(0) scale(1);
    z-index: 2;
}

/* Enhanced transitions during layout changes */
.layout-transitioning .upload-interface-managed,
.layout-transitioning .gallery-section-managed {
    transition: all 450ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* DOM movement specific animations */
.dom-moving {
    transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
    position: relative !important;
}

/* Smooth DOM rearrangement support */
.gallery-layout-managed.layout-transitioning {
    overflow: hidden;
}

.gallery-layout-managed.layout-transitioning .upload-interface-managed,
.gallery-layout-managed.layout-transitioning .gallery-section-managed {
    transition: transform 450ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 300ms ease-out,
                margin 300ms ease-out;
}

/* Gallery grid smooth height transitions */
.gallery-grid {
    transition: height 300ms ease-out, min-height 300ms ease-out;
    overflow: hidden;
}

/* Gallery item entrance animations */
.gallery-item {
    animation: galleryItemEnter 300ms ease-out;
    transform-origin: center top;
    transition: all 200ms ease-out;
}

@keyframes galleryItemEnter {
    0% {
        opacity: 0;
        transform: scale(0.85) translateY(-12px) rotateX(10deg);
    }
    30% {
        opacity: 0.6;
        transform: scale(0.92) translateY(-6px) rotateX(5deg);
    }
    70% {
        opacity: 0.9;
        transform: scale(1.02) translateY(2px) rotateX(-2deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0) rotateX(0deg);
    }
}

/* Gallery item hover effects */
.gallery-item:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Upload area micro-animations */
.upload-area {
    transition: all 250ms ease-out;
    transform-origin: center;
}

.upload-area:hover {
    transform: translateY(-3px) scale(1.01);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.upload-area.drag-over {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 123, 186, 0.2);
}

/* Gallery header smooth transitions */
.gallery-header {
    transition: all 300ms ease-out;
    transform-origin: left center;
}

.gallery-empty .gallery-header {
    opacity: 0.8;
    transform: translateY(4px) scale(0.98);
}

.gallery-active .gallery-header {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Gallery placeholder animations */
.gallery-placeholder {
    transition: all 300ms ease-out;
    animation: placeholderPulse 3s ease-in-out infinite;
    transform-origin: center;
}

@keyframes placeholderPulse {
    0%, 100% { 
        opacity: 0.6; 
        transform: scale(1);
    }
    50% { 
        opacity: 0.85; 
        transform: scale(1.01);
    }
}

/* Hide placeholder when gallery is active */
.gallery-active .gallery-placeholder {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

/* Smooth button transitions */
.add-more-button {
    transition: all 200ms ease-out;
    transform-origin: center;
}

.add-more-button:hover {
    transform: translateY(-1px) scale(1.05);
}

/* Section dividers with subtle animations */
.gallery-section-managed::before {
    content: '';
    position: absolute;
    top: -0.5rem;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), transparent);
    opacity: 0;
    transition: opacity 300ms ease-out;
}

.gallery-active::before {
    opacity: 1;
}

/* Staggered animation for multiple gallery items */
.gallery-item:nth-child(1) { animation-delay: 0ms; }
.gallery-item:nth-child(2) { animation-delay: 50ms; }
.gallery-item:nth-child(3) { animation-delay: 100ms; }
.gallery-item:nth-child(4) { animation-delay: 150ms; }
.gallery-item:nth-child(5) { animation-delay: 200ms; }
.gallery-item:nth-child(6) { animation-delay: 250ms; }
.gallery-item:nth-child(7) { animation-delay: 300ms; }
.gallery-item:nth-child(8) { animation-delay: 350ms; }
.gallery-item:nth-child(n+9) { animation-delay: 400ms; }

/* Focus states for accessibility */
.upload-interface-managed:focus-within,
.gallery-section-managed:focus-within {
    outline: 2px solid var(--pu-primary, #007cba);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Loading state animations */
.gallery-loading {
    position: relative;
    overflow: hidden;
}

.gallery-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .upload-interface-managed,
    .gallery-section-managed {
        transition-duration: 250ms;
    }
    
    .gallery-item {
        animation-duration: 250ms;
    }
    
    .upload-area:hover,
    .gallery-item:hover {
        transform: translateY(-1px) scale(1.01);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .upload-interface-managed,
    .gallery-section-managed,
    .gallery-item,
    .upload-area,
    .gallery-header,
    .gallery-placeholder {
        transition-duration: 0.1s;
        animation-duration: 0.1s;
    }
    
    .gallery-item {
        animation: none;
    }
    
    .gallery-placeholder {
        animation: none;
    }
    
    @keyframes galleryItemEnter {
        0% { opacity: 0; }
        100% { opacity: 1; }
    }
    
    @keyframes placeholderPulse {
        0%, 100% { opacity: 0.6; }
        50% { opacity: 0.8; }
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .gallery-section-managed.gallery-empty {
        opacity: 0.9;
    }
    
    .upload-interface-managed.upload-secondary {
        opacity: 1;
    }
    
    .gallery-placeholder {
        opacity: 0.8;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .gallery-section-managed::before {
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    }
    
    .gallery-loading::after {
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    }
}

/* Print styles */
@media print {
    .upload-interface-managed,
    .gallery-section-managed {
        transition: none;
        animation: none;
        transform: none !important;
        opacity: 1 !important;
    }
    
    .gallery-item {
        animation: none;
        break-inside: avoid;
    }
}

/* Ensure sections never completely disappear */
.gallery-section-managed,
.upload-interface-managed {
    min-height: 1px;
    visibility: visible !important;
    display: block !important;
}

/* Smooth scrolling when layout changes */
.gallery-layout-managed {
    scroll-behavior: smooth;
}

/* Container spacing adjustments */
.gallery-active + .upload-interface-managed {
    margin-top: 0.5rem;
}

.upload-primary + .gallery-section-managed {
    margin-top: 0.5rem;
}

/* Performance optimizations */
.gallery-layout-managed * {
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Ensure proper stacking context */
.gallery-layout-managed {
    isolation: isolate;
}

/* Fallback styles for older browsers */
.no-flexbox .photo-uploader-interface {
    display: block;
}

.no-flexbox .upload-interface-managed.upload-secondary {
    margin-top: 1rem;
}

.no-flexbox .gallery-section-managed.gallery-active {
    margin-bottom: 1rem;
}