/* 
 * Photo Gallery - Main Stylesheet
 * 
 * This file contains all styles for the photo gallery.
 * 
 * @version 3.0
 * @author Corstiaan
 */

/* Reset and base styles */
:root {
    --primary-color: #333;
    --secondary-color: #666;
    --accent-color: #0078d7;
    --text-color: #f5f5f5;
    --background-color: #121212;
    --card-background: #1e1e1e;
    --hover-color: #2a2a2a;
    --border-color: #333;
    --error-color: #e74c3c;
    --success-color: #2ecc71;
    --thumbnail-size: 300px;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 2rem;
    --border-radius: 4px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    padding: 0;
    margin: 0;
}

.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--spacing-md);
}

a {
    color: var(--accent-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

/* Header styles */
header {
    text-align: center;
    padding: var(--spacing-lg) 0;
    margin-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}


header h1 {
    font-size: 2.5rem;
    margin-bottom: var(--spacing-sm);
    color: var(--text-color);
    transition: opacity 0.3s ease;
}

header h1 a {
    color: inherit;
    text-decoration: none;
}

header h1 a:hover {
    opacity: 0.8;
}

header .description {
    font-size: 1.1rem;
    color: var(--secondary-color);
    max-width: 800px;
    margin: 0 auto;
}

/* Gallery styles */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, var(--thumbnail-size));
    gap: 16px;
    justify-content: center;
    margin: 0 auto;
    width: fit-content;
    max-width: 100%;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--border-radius);
    cursor: pointer;
    background-color: var(--card-background);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border 0.3s ease;
    aspect-ratio: 1 / 1;
    width: var(--thumbnail-size);
    height: var(--thumbnail-size);
    border: 2px solid transparent;
    touch-action: pan-y;
}

.gallery-item.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(0, 120, 215, 0.35);
}

.gallery-item.filtered-out {
    display: none !important;
}

.thumbnail-select {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 15;
}

.thumbnail-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.thumbnail-checkbox:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.gallery-item:hover {
    transform: translateY(-5px);
}

.gallery-item img.thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease;
}

.gallery-item:hover img.thumbnail {
    opacity: 0.9;
}

.thumbnail-filename {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 8px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 0.75rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 10;
}

/* Like star overlay on thumbnails */
.thumbnail-like {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 11;
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    padding: 0 5px 4px;
    background: rgba(0, 0, 0, 0.45);
    user-select: none;
    -webkit-user-select: none;
    line-height: 1;
}

.thumbnail-like .like-star {
    font-size: 1.8rem;
    color: rgba(255, 255, 255, 0.55);
    transition: color 0.2s ease;
    display: inline-block;
}

.thumbnail-like .like-star.liked {
    color: #f5c518;
}

.thumbnail-like .like-count {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.75);
}

/* Lightbox chrome — outside the photo, CSS-positioned */
.lightbox-close {
    position: fixed;
    top: calc(15px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1020;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 3.4rem;
    line-height: 1;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    padding: 0;
}

/* Share + download — chrome level, flanking the close button */
.lightbox-share,
.lightbox-download {
    position: fixed;
    top: calc(15px + env(safe-area-inset-top, 0px));
    z-index: 1020;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
}

.lightbox-share {
    right: calc(50% + 43px); /* gap from left edge of close button */
}

.lightbox-download {
    left: calc(50% + 43px);  /* gap from right edge of close button */
}

.lightbox-share svg,
.lightbox-download svg {
    display: block;
}

/* Lightbox in-photo overlays — JS positions these at the actual photo corners */
.lightbox-like-btn,
.lightbox-select,
.lightbox-counter,
.lightbox-fullscreen {
    position: fixed;
    z-index: 1020;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
}

.lightbox-like-btn {
    padding: 0 14px 0 12px;
}

.lightbox-like-btn .like-star {
    font-size: 2.2rem;
    line-height: 1;
    color: rgba(255, 255, 255, 0.7);
    transition: color 0.2s ease;
}

.lightbox-like-btn.liked .like-star {
    color: #f5c518;
}

.lightbox-like-btn .like-count {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.85);
}

.lightbox-select {
    font-size: 0.9rem;
    padding: 0 12px;
}

.lightbox-select span {
    white-space: nowrap;
}

.lightbox-counter {
    font-size: 0.85rem;
    padding: 0 12px;
    color: rgba(255, 255, 255, 0.85);
    pointer-events: none;
}

.lightbox-fullscreen {
    width: 44px;
    padding: 0;
}

.lightbox-fullscreen svg {
    display: block;
}

/* Caption EXIF styles */
.caption-filename {
    display: block;
}

.caption-exif {
    display: block;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 3px;
}

.caption-exif-missing {
    font-style: italic;
    color: rgba(255, 255, 255, 0.3);
}

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    overflow: hidden;
}

.lightbox.active {
    display: block;
}

.lightbox-close,
.lightbox-share,
.lightbox-download,
.lightbox-like-btn,
.lightbox-select,
.lightbox-counter,
.lightbox-fullscreen,
.lightbox-caption,
.lightbox-nav {
    transition: opacity 0.2s ease;
}

.lightbox.ui-hidden .lightbox-close,
.lightbox.ui-hidden .lightbox-share,
.lightbox.ui-hidden .lightbox-download,
.lightbox.ui-hidden .lightbox-like-btn,
.lightbox.ui-hidden .lightbox-select,
.lightbox.ui-hidden .lightbox-counter,
.lightbox.ui-hidden .lightbox-fullscreen,
.lightbox.ui-hidden .lightbox-caption,
.lightbox.ui-hidden .lightbox-nav {
    opacity: 0;
    pointer-events: none;
}

.lightbox-image-wrapper {
    position: absolute;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    cursor: grab;
}

.lightbox-image-wrapper:active {
    cursor: grabbing;
}


.lightbox-select input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-color);
    cursor: pointer;
}



.lightbox-photo {
    position: absolute;
    inset: 0;
    margin: auto;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    transform: translate3d(0, 0, 0) scale(1);
    transform-origin: center center;
    will-change: transform;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: none;
}

.lightbox-caption {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1020;
    color: white;
    text-align: center;
    padding: 8px 20px 10px;
    font-size: 1rem;
    line-height: 1.4;
    pointer-events: none;
}

.lightbox-caption.overlay {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
    padding-top: 24px;
}

.lightbox-close:focus-visible,
.lightbox-select input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    color: white;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1010;
    width: 50px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, opacity 0.2s ease;
}

.lightbox-nav:hover {
    background: rgba(0, 0, 0, 0.6);
}

.lightbox-prev {
    left: 15px;
    border-radius: 0 5px 5px 0;
}

.lightbox-next {
    right: 15px;
    border-radius: 5px 0 0 5px;
}

/* Download button styles */
.download-container {
    margin-top: var(--spacing-lg);
    text-align: center;
}

.download-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.share-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.share-button {
    padding: 8px 16px;
    background-color: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.share-button.secondary {
    background-color: rgba(0, 120, 215, 0.08);
}

.share-button.secondary:hover {
    background-color: rgba(0, 120, 215, 0.18);
}

.share-button:hover {
    background-color: rgba(0, 120, 215, 0.1);
}

.share-button:disabled {
    border-color: var(--border-color);
    color: var(--border-color);
    cursor: not-allowed;
    background-color: transparent;
}

.download-button {
    padding: 10px 20px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.download-button:hover {
    background-color: #005fa3;
}

.download-button.secondary {
    background-color: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
}

.download-button.secondary:hover {
    background-color: rgba(0, 120, 215, 0.1);
}

.download-progress {
    display: none;
    margin-top: var(--spacing-md);
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.progress-bar {
    height: 20px;
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    overflow: hidden;
    margin-bottom: var(--spacing-sm);
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--accent-color);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--secondary-color);
}

.download-notes {
    margin-top: var(--spacing-sm);
    font-size: 0.85rem;
    color: var(--secondary-color);
    text-align: left;
}

.download-notes p {
    margin: 0 0 0.35rem 0;
}

/* Error page styles */
.error-container {
    text-align: center;
    padding: var(--spacing-lg);
}

.error-container h1 {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    color: var(--error-color);
}

.error-container p {
    font-size: 1.2rem;
    margin-bottom: var(--spacing-md);
}

.error-container a {
    display: inline-block;
    padding: 10px 20px;
    background-color: var(--accent-color);
    color: white;
    border-radius: var(--border-radius);
    text-decoration: none;
    margin-top: var(--spacing-md);
}

/* Empty gallery styles */
.empty-gallery {
    text-align: center;
    padding: var(--spacing-lg);
    background-color: var(--card-background);
    border-radius: var(--border-radius);
}

/* Footer styles */
footer {
    text-align: center;
    padding: var(--spacing-lg) 0;
    margin-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    color: var(--secondary-color);
}

/* Responsive styles */
@media (max-width: 768px) {
    :root {
        --mobile-thumb-size: calc((100vw - 2 * var(--spacing-md) - 10px) / 2);
    }

    .container {
        padding: var(--spacing-md);
    }
    
    /* Mobile portrait: 2 columns */
    .gallery {
        grid-template-columns: repeat(2, minmax(var(--mobile-thumb-size), 1fr));
        gap: 10px;
        width: 100%;
        max-width: 100%;
        justify-content: stretch;
        margin: 0;
    }
    
    .gallery-item {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
        tap-highlight-color: rgba(255, 255, 255, 0.1);
    }
    
    .gallery-item.selected {
        border-color: var(--accent-color);
        box-shadow: 0 0 0 3px rgba(0, 120, 215, 0.35);
    }
    
    .gallery-item:active {
        transform: scale(0.98);
    }
    
    /* Prevent text selection on touch */
    .gallery-item, .lightbox-nav, .lightbox-close {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
    
    .lightbox-nav {
        font-size: 2rem;
        width: 44px; /* Minimum touch target size for iOS/Android */
        height: 60px;
    }
    



    .lightbox-like-btn,
    .lightbox-select,
    .lightbox-counter,
    .lightbox-fullscreen {
        height: 35px;
        gap: 6px;
    }

    .lightbox-fullscreen {
        width: 35px;
    }

    .lightbox-like-btn {
        padding: 0 11px 0 10px;
    }

    .lightbox-like-btn .like-star {
        font-size: 1.75rem;
    }

    .lightbox-select {
        font-size: 0.75rem;
        padding: 0 10px;
    }
    
    .lightbox-prev {
        left: 10px;
    }
    
    .lightbox-next {
        right: 10px;
    }

    .thumbnail-like {
        top: 6px;
        left: 6px;
        padding: 2px 4px;
    }

    .thumbnail-like .like-star { font-size: 1.5rem; }
    .thumbnail-like .like-count { font-size: 0.65rem; }
}

/* Mobile landscape: as many columns as possible with portrait sizing */
@media (max-width: 768px) and (orientation: landscape) {
    .gallery {
        grid-template-columns: repeat(auto-fit, minmax(var(--mobile-thumb-size), 1fr));
    }
}

@media (max-width: 480px) {
    .container {
        padding: var(--spacing-sm);
    }
    
    header {
        padding: var(--spacing-md) 0;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .gallery {
        gap: 8px;
    }
    
    .lightbox-nav {
        width: 40px;
        height: 50px;
        font-size: 1.8rem;
    }
    
    
    /* Gallery index responsive */
    .gallery-index {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Adjust filename overlay for smaller screens */
    .thumbnail-filename {
        font-size: 0.7rem;
        padding: 3px 6px;
    }
}

/* Gallery Index Styles */
.gallery-index {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.gallery-card {
    display: block;
    background-color: var(--card-background);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    text-decoration: none;
    color: var(--text-color);
}

.gallery-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.gallery-card-image {
    height: 200px;
    overflow: hidden;
    background-color: #222;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.gallery-card:hover .gallery-card-image img {
    transform: scale(1.05);
}

.placeholder-thumbnail {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--theme-color, #333);
    color: white;
}

.placeholder-thumbnail span {
    font-size: 72px;
    font-weight: bold;
    text-transform: uppercase;
    opacity: 0.7;
}

.gallery-card-content {
    padding: 15px;
}

.gallery-card-content h2 {
    margin: 0 0 10px;
    font-size: 1.2rem;
    color: var(--heading-color);
}

.gallery-card-content p {
    margin: 0 0 10px;
    font-size: 0.9rem;
    color: var(--text-color-secondary);
    line-height: 1.4;
}

.gallery-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-color-tertiary);
    margin-top: 10px;
}

.folder-card .gallery-card-image {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.folder-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 60px;
}

/* Thumbnail pending placeholder (while async generation is in progress) */
.gallery-item.thumb-pending img.thumbnail {
    opacity: 0;
}

.gallery-item.thumb-pending::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 5;
    background-color: #2d2d2d;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23555' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 22h14M5 2h14M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22M7 2v4.172a2 2 0 0 1 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 40px;
}

/* Thumbnail generation progress bar */
.thumbnail-progress {
    display: none;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 16px;
}

.thumbnail-progress.active {
    display: block;
}

.thumbnail-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--theme-color, var(--accent-color));
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ── Video support ──────────────────────────────────────────
   Videos sit in the same grid and lightbox as photos. The grid tile is a
   normal thumbnail (an ffmpeg-generated poster frame, or an inline SVG
   placeholder when ffmpeg is unavailable) with a play badge over it. */

.video-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    pointer-events: none;
    transition: background 0.2s ease, transform 0.2s ease;
    z-index: 2;
}

.gallery-item:hover .video-badge {
    background: rgba(0, 0, 0, 0.75);
    transform: translate(-50%, -50%) scale(1.08);
}

.gallery-item.is-video .thumbnail {
    background-color: #2b2b2b;
}

/* The player replaces the still image rather than layering over it, so the
   three <img> slide layers must be hidden while a video is showing. */
.lightbox-video {
    display: none;
    background: #000;
}

.lightbox.showing-video .lightbox-video {
    display: block;
}

.lightbox.showing-video #lightbox-image-current,
.lightbox.showing-video #lightbox-image-prev,
.lightbox.showing-video #lightbox-image-next {
    display: none;
}

/* The player fills the frame and owns its own controls, so the nav arrows have
   to sit clearly above it and stay legible against moving video. They are also
   the only way to leave a video: pointer gestures are suppressed there. */
.lightbox.showing-video .lightbox-nav {
    bottom: auto;
    z-index: 1030;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
}

.lightbox.showing-video .lightbox-close {
    z-index: 1030;
}

@media (max-width: 768px) {
    /* Bigger targets on touch, and lifted above the native control bar */
    .lightbox.showing-video .lightbox-nav {
        width: 48px;
        height: 64px;
        top: 42%;
    }
}

@media (max-width: 768px) {
    .video-badge {
        width: 36px;
        height: 36px;
    }
}
