/* Gallery Specific Styles */

/* Gallery Grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 0.25rem;
    cursor: pointer;
    background: #e7e5e4;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.gallery-item img,
.gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

/* Disable hover effects on touch devices */
@media (hover: hover) {
    .gallery-item:hover img,
    .gallery-item:hover video {
        transform: scale(1.05);
    }
}

/* Active state for touch */
.gallery-item:active {
    transform: scale(0.98);
}

.gallery-item-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: flex-end;
    padding: 1rem;
}

@media (hover: hover) {
    .gallery-item:hover .gallery-item-overlay {
        opacity: 1;
    }
}

/* Video Badge */
.video-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    pointer-events: none;
}

/* Edit Mode Styles */
.edit-gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 0.25rem;
    overflow: hidden;
}

.delete-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    background: #dc2626;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
    touch-action: manipulation;
}

@media (hover: hover) {
    .edit-gallery-item:hover .delete-btn {
        opacity: 1;
    }
}

/* Always show delete button on touch devices */
@media (hover: none) {
    .delete-btn {
        opacity: 1;
        width: 2.25rem;
        height: 2.25rem;
    }
}

.delete-btn:hover {
    background: #b91c1c;
    transform: scale(1.1);
}

.delete-btn:active {
    transform: scale(0.95);
}

/* Lightbox Styles */
#lightbox {
    transition: opacity 0.3s ease;
    touch-action: pan-y pinch-zoom;
}

#lightbox.hidden {
    opacity: 0;
    pointer-events: none;
}

#lightbox:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

#lightbox button {
    touch-action: manipulation;
    min-width: 44px;
    min-height: 44px;
}

/* Modal Transitions */
[id$="-modal"] {
    transition: opacity 0.3s ease;
}

[id$="-modal"].hidden {
    opacity: 0;
    pointer-events: none;
}

[id$="-modal"]:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

/* File List Items */
.file-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: #f5f5f4;
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
    min-height: 48px;
}

.file-list-item .file-name {
    flex: 1;
    font-size: 0.875rem;
    color: #44403c;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-list-item .file-size {
    font-size: 0.75rem;
    color: #78716c;
    margin-left: 1rem;
    flex-shrink: 0;
}

.file-list-item .remove-file {
    color: #dc2626;
    cursor: pointer;
    margin-left: 1rem;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    touch-action: manipulation;
}

.file-list-item .remove-file:hover {
    color: #b91c1c;
    background: rgba(220, 38, 38, 0.1);
}

.file-list-item .remove-file:active {
    transform: scale(0.95);
}

/* Gallery Section Header */
.gallery-section {
    border-bottom: 2px solid #e7e5e4;
    padding-bottom: 2rem;
    margin-bottom: 2rem;
}

.gallery-section:last-child {
    border-bottom: none;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.gallery-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.875rem;
    color: #1c1917;
}

.gallery-date {
    font-size: 0.875rem;
    color: #78716c;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.75rem;
    }
    
    .gallery-title {
        font-size: 1.5rem;
    }
    
    .delete-btn {
        opacity: 1;
        width: 2rem;
        height: 2rem;
        top: 0.25rem;
        right: 0.25rem;
    }
    
    .gallery-item-overlay {
        opacity: 1;
        background: linear-gradient(to top, rgba(0,0,0,0.5) 0%, transparent 40%);
    }
    
    /* Larger touch targets on mobile */
    .gallery-item {
        border-radius: 0.375rem;
    }
    
    .video-badge {
        font-size: 0.625rem;
        padding: 0.125rem 0.375rem;
    }
}

@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .gallery-section {
        padding-bottom: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    /* Optimize lightbox for small screens */
    #lightbox button {
        padding: 0.5rem;
    }
    
    #lightbox button svg {
        width: 24px;
        height: 24px;
    }
}

/* Loading State */
.loading-spinner {
    border: 3px solid #e7e5e4;
    border-top: 3px solid #92400e;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    animation: spin 1s linear infinite;
}

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

/* Drag and Drop Active State */
.drag-active {
    border-color: #92400e !important;
    background: #fff7ed !important;
}

/* Touch-friendly buttons on mobile */
@media (max-width: 768px) {
    button, 
    a {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Ensure proper touch targets for form elements */
    input[type="file"] {
        min-height: 44px;
    }
    
    /* Better spacing for mobile forms */
    [id$="-modal"] .space-y-4 > * + * {
        margin-top: 1rem;
    }
    
    /* Full-width buttons on mobile modals */
    [id$="-modal"] button {
        width: 100%;
    }
}

/* Prevent text selection on interactive elements */
.gallery-item,
.delete-btn,
button {
    -webkit-user-select: none;
    user-select: none;
}

/* Loading skeleton for images */
.gallery-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #e7e5e4 25%, #d6d3d1 50%, #e7e5e4 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    z-index: 0;
}

.gallery-item img,
.gallery-item video {
    position: relative;
    z-index: 1;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .loading-spinner,
    .gallery-item::before,
    .gallery-item img,
    .gallery-item video,
    .delete-btn,
    #lightbox,
    [id$="-modal"] {
        animation: none !important;
        transition: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .gallery-item {
        border: 2px solid currentColor;
    }
    
    .delete-btn {
        border: 2px solid white;
    }
}
