/* Responsive */
@media (max-width: 768px) {
    .header-content {
        flex-direction: row;
        gap: 0.5rem;
        text-align: left;
        padding: 0.5rem 1rem;
        justify-content: space-between;
    }

    .wedding-header .header-content {
        text-align: center;
        justify-content: center;
    }

    .header h1 {
        display: none;
    }

    .nav {
        gap: 0.4rem;
        flex-wrap: nowrap;
        flex-shrink: 1;
        min-width: 0;
        width: 100%;
        justify-content: center;
    }

    .nav-link .nav-text {
        display: none;
    }

    .nav-link .nav-icon {
        display: inline;
        font-size: 1.2rem;
    }

    .nav-link {
        padding: 0.4rem 0.6rem;
        font-size: 1.2rem;
        white-space: nowrap;
    }

    .nav-user {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
    }

    .main-container {
        padding-top: 60px;
    }

    .gallery-container {
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px);
    }

    .wedding-section {
        min-height: calc(100vh - 60px);
        min-height: calc(100dvh - 60px);
        padding: 0.5rem;
    }

    .wedding-header {
        padding: 1rem 1rem 0.5rem 1rem;
    }

    .wedding-header .wedding-title {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }

    .wedding-header h2 {
        font-size: 1.5rem;
        white-space: normal;
    }

    .wedding-header .date {
        font-size: 0.85rem;
        margin-bottom: 0.5rem;
    }

    .wedding-header .description {
        font-size: 0.85rem;
        line-height: 1.5;
        white-space: normal;
        overflow: visible;
    }

    .wedding-section[data-state="collapsed"] .wedding-header {
        padding: 0.5rem 1rem 0.25rem 1rem;
    }

    .wedding-section[data-state="collapsed"] .wedding-header .wedding-title {
        font-size: 1.1rem;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }

    .album-card {
        flex: 0 0 260px;
    }

    .album-card h3 {
        font-size: 1.1rem;
        padding: 0.75rem;
    }

    .media-grid {
        padding: 0 1rem 3rem 1rem;
        gap: 1rem;
    }

    /* Height synced with gallery.js mobile containerHeight (280px) */
    .media-item {
        height: 280px;
    }

    .modal-content {
        padding: 1rem;
    }

    .modal-header h2 {
        font-size: 1.3rem;
    }

    .filmstrip-thumb {
        height: 56px;
    }
}

/* PhotoPrism Link Icon */
.photoprism-link-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: var(--shadow);
}

/* Progressive Image Loading */
.img-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Carousel video */
.carousel-video {
    height: 100%;
    width: 100%;
    display: block;
    object-fit: contain;
    background: #000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.carousel-video.loaded {
    opacity: 1;
}

/* Play icon overlay — kept for potential future use but hidden when controls are native */
.video-play-overlay {
    display: none;
}

.skeleton-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, var(--secondary-color) 25%, var(--border-color) 50%, var(--secondary-color) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

.skeleton-loader.hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

.lazy-image {
    height: 100%;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    object-position: center;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.lazy-image.loaded {
    opacity: 1;
}

/* Fullscreen Photo Viewer */
.fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.fullscreen-overlay.active {
    opacity: 1;
}

.fullscreen-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.1);
    z-index: 2001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: fit-content;
    height: fit-content;
    max-width: 95vw;
    max-height: 95vh;
    max-height: 95dvh;
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease, left 0.3s ease-out, top 0.3s ease-out;
}

.fullscreen-modal.active {
    opacity: 1;
}

.fullscreen-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 44px;
    height: 44px;
    border: 2px solid var(--accent-color);
    background: rgba(0, 0, 0, 0.7);
    color: var(--accent-bright);
    font-size: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 2003;
    line-height: 1;
    padding-bottom: 4px;
}

.fullscreen-close:hover {
    background: rgba(201, 160, 99, 0.3);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(201, 160, 99, 0.5);
}

/* Prev / Next navigation buttons */
.fullscreen-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border: 2px solid var(--accent-color);
    background: rgba(0, 0, 0, 0.7);
    color: var(--accent-bright);
    font-size: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 2003;
    line-height: 1;
    /* Keep buttons within safe area on iOS */
    padding: 0;
}

.fullscreen-nav:hover {
    background: rgba(201, 160, 99, 0.3);
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 0 20px rgba(201, 160, 99, 0.5);
}

.fullscreen-nav:disabled {
    opacity: 0.2;
    cursor: default;
}

.fullscreen-nav:disabled:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: translateY(-50%);
    box-shadow: none;
}

.fullscreen-nav-prev {
    left: max(16px, env(safe-area-inset-left, 16px));
}

.fullscreen-nav-next {
    right: max(16px, env(safe-area-inset-right, 16px));
}

/* Image counter (e.g. "3 / 12") */
.fullscreen-counter {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 1px;
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 12px;
    border-radius: 20px;
    z-index: 2003;
    white-space: nowrap;
}

.fullscreen-img-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    overflow: visible;
    box-shadow: 
        0 0 60px 20px rgba(201, 160, 99, 0.3),
        0 0 100px 40px rgba(201, 160, 99, 0.15),
        0 25px 50px rgba(0, 0, 0, 0.5);
    transition: box-shadow 0.4s ease;
}

.fullscreen-img-container.loaded {
    box-shadow: 
        0 0 80px 30px rgba(201, 160, 99, 0.4),
        0 0 120px 50px rgba(201, 160, 99, 0.2),
        0 30px 60px rgba(0, 0, 0, 0.6);
}

.fullscreen-image {
    max-width: 90vw;
    max-height: 85vh;
    max-height: 85dvh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.4s ease, transform 0.4s ease;
    transform-origin: center center;
    cursor: default;
    border-radius: 12px;
}

.fullscreen-image.loaded {
    opacity: 1;
    transform: scale(1);
    /* Remove transform transition so zoom/pan is instant */
    transition: opacity 0.4s ease;
}

/* Fullscreen video element — sized like images, backdrop shows through */
.fullscreen-video {
    max-width: 90vw;
    max-height: 85vh;
    max-height: 85dvh;
    width: auto;
    height: auto;
    display: none;
    border-radius: 12px;
    background: #000;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.fullscreen-video.loaded {
    opacity: 1;
    transform: scale(1);
}

/* When showing video, controls auto-hide and reappear on interaction */
.fullscreen-modal.video-controls-hidden .fullscreen-close,
.fullscreen-modal.video-controls-hidden ~ .fullscreen-nav,
.fullscreen-modal.video-controls-hidden .fullscreen-counter {
    opacity: 0;
    pointer-events: none;
}

/* Smooth fade transition for controls */
.fullscreen-modal .fullscreen-close,
.fullscreen-modal .fullscreen-counter {
    transition: all 0.3s ease, opacity 0.4s ease;
}

/* Fullscreen Loading Spinner */
.fullscreen-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 10;
}

.fullscreen-img-container.loaded .fullscreen-loader {
    display: none;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 30px;
    border: 1px solid var(--border-color);
    z-index: 2003;
    /* Respect iOS home-indicator safe area */
    padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
}

.zoom-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--accent-color);
    background: rgba(201, 160, 99, 0.1);
    color: var(--accent-bright);
    font-size: 20px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

.zoom-btn:hover {
    background: rgba(201, 160, 99, 0.3);
    transform: scale(1.1);
}

.zoom-btn.zoom-reset {
    font-size: 18px;
}

/* Tablet breakpoint (769px–1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .wedding-header .wedding-title {
        font-size: 2.2rem;
    }

    .wedding-header {
        padding: 4rem 2rem 1.5rem 2rem;
    }

    .media-item {
        height: 320px;
    }

    .media-grid {
        padding: 0 2rem 4rem 2rem;
    }

    .fullscreen-nav {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }
}

/* Responsive adjustments for fullscreen viewer */
@media (max-width: 768px) {
    .fullscreen-close {
        /* Position inside safe area, and away from gesture zone */
        top: max(10px, env(safe-area-inset-top, 10px));
        right: max(10px, env(safe-area-inset-right, 10px));
        width: 44px;
        height: 44px;
        font-size: 24px;
    }
    
    .fullscreen-image {
        max-width: 100vw;
        /* dvh accounts for collapsing browser chrome; vh is the fallback */
        max-height: 78vh;
        max-height: 78dvh;
    }
    
    .zoom-controls {
        bottom: max(15px, env(safe-area-inset-bottom, 15px));
        padding: 6px 12px;
    }
    
    .zoom-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .fullscreen-img-container {
        box-shadow: 
            0 0 40px 15px rgba(201, 160, 99, 0.3),
            0 0 80px 30px rgba(201, 160, 99, 0.15),
            0 20px 40px rgba(0, 0, 0, 0.5);
    }

    .fullscreen-nav {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    .fullscreen-nav-prev {
        left: max(8px, env(safe-area-inset-left, 8px));
    }

    .fullscreen-nav-next {
        right: max(8px, env(safe-area-inset-right, 8px));
    }

    .fullscreen-counter {
        bottom: max(72px, calc(env(safe-area-inset-bottom, 0px) + 72px));
        font-size: 13px;
    }
}

/* Prevent page scroll when fullscreen modal is open */
body.modal-open {
    overflow: hidden;
}

/* Selection mode styles */
/* Selection overlay on images */
.selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 10px;
    pointer-events: none;
    z-index: 10;
}

.selection-overlay:hover {
    background: rgba(201, 160, 99, 0.15);
}

.selection-overlay.selected {
    background: rgba(201, 160, 99, 0.3);
}

.selection-checkbox {
    width: 28px;
    height: 28px;
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    cursor: pointer;
}

.selection-overlay:hover .selection-checkbox {
    border-color: var(--accent-bright);
    transform: scale(1.1);
}

.selection-overlay.selected .selection-checkbox {
    background: var(--accent-color);
    border-color: var(--accent-bright);
}

.selection-overlay.selected .selection-checkbox::after {
    content: '✓';
    color: var(--primary-color);
    font-size: 18px;
    font-weight: bold;
}

/* Download bar */
.download-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.95);
    border-top: 2px solid var(--accent-color);
    padding: 16px 24px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 999;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

.download-bar.visible {
    transform: translateY(0);
}

.download-bar-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#selection-count {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
}

.download-bar-actions {
    display: flex;
    gap: 12px;
}

.download-btn {
    padding: 10px 24px;
    border-radius: 6px;
    border: 1px solid var(--accent-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.download-btn.primary {
    background: var(--accent-color);
    color: var(--primary-color);
}

.download-btn.primary:hover:not(:disabled) {
    background: var(--accent-bright);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(201, 160, 99, 0.4);
}

.download-btn.secondary {
    background: transparent;
    color: var(--accent-color);
}

.download-btn.secondary:hover {
    background: rgba(201, 160, 99, 0.1);
}

.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Ensure media items have relative positioning for overlay */
.media-item {
    position: relative;
}

/* Hide selection button on mobile initially */
@media (max-width: 768px) {
    .selection-toggle-btn {
        bottom: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
    
    .download-bar {
        padding: 12px 16px;
    }
    
    .download-bar-content {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .download-bar-actions {
        width: 100%;
    }
    
    .download-btn {
        flex: 1;
    }
    
    #selection-count {
        text-align: center;
    }
    
    .selection-checkbox {
        width: 32px;
        height: 32px;
    }
}
