/**
 * Lightbox / Image Gallery Styles
 * Fancy lightbox for viewing thread images
 */

/* Lightbox Overlay */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Close Button */
.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    z-index: 10001;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.lightbox-close svg {
    width: 24px;
    height: 24px;
    stroke: white;
}

/* Image Container */
.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.lightbox-overlay.active .lightbox-image {
    opacity: 1;
    transform: scale(1);
}

/* Navigation Arrows */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    z-index: 10001;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.lightbox-nav:disabled:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-50%);
}

.lightbox-nav svg {
    width: 24px;
    height: 24px;
    stroke: white;
}

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

/* Image Counter */
.lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

/* Thumbnails Strip */
.lightbox-thumbnails {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    max-width: 90vw;
    overflow-x: auto;
}

.lightbox-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s ease, transform 0.2s ease;
    border: 2px solid transparent;
}

.lightbox-thumb:hover {
    opacity: 0.8;
}

.lightbox-thumb.active {
    opacity: 1;
    border-color: var(--primary-color, #ff4500);
    transform: scale(1.05);
}

/* Loading Spinner */
.lightbox-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: lightbox-spin 0.8s linear infinite;
}

@keyframes lightbox-spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Image Caption */
.lightbox-caption {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 14px;
    max-width: 80%;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* ============================================
   Thread Image Gallery Styles
   ============================================ */

.thread-gallery {
    display: grid;
    gap: 4px;
    border-radius: 12px;
    overflow: hidden;
    margin: 12px 0;
}

/* Single image */
.thread-gallery.gallery-1 {
    grid-template-columns: 1fr;
}

.thread-gallery.gallery-1 .gallery-item {
    max-height: 512px;
}

/* Two images */
.thread-gallery.gallery-2 {
    grid-template-columns: 1fr 1fr;
}

.thread-gallery.gallery-2 .gallery-item {
    aspect-ratio: 1;
}

/* Three images */
.thread-gallery.gallery-3 {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.thread-gallery.gallery-3 .gallery-item:first-child {
    grid-row: span 2;
}

.thread-gallery.gallery-3 .gallery-item {
    aspect-ratio: 1;
}

/* Four images */
.thread-gallery.gallery-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.thread-gallery.gallery-4 .gallery-item {
    aspect-ratio: 1;
}

/* Five images */
.thread-gallery.gallery-5 {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.thread-gallery.gallery-5 .gallery-item:nth-child(1),
.thread-gallery.gallery-5 .gallery-item:nth-child(2) {
    grid-column: span 1;
}

.thread-gallery.gallery-5 .gallery-item:first-child {
    grid-column: span 2;
}

/* Six images */
.thread-gallery.gallery-6 {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.thread-gallery.gallery-6 .gallery-item {
    aspect-ratio: 1;
}

/* Gallery Item */
.gallery-item {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-tertiary, #1a1a1b);
}

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

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

/* More images overlay */
.gallery-item.more-overlay::after {
    content: attr(data-more);
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    font-weight: 600;
}

/* ============================================
   Multi-Image Upload Styles
   ============================================ */

.multi-image-upload {
    border: 2px dashed var(--border-color, #343536);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    transition: border-color 0.2s ease, background 0.2s ease;
    cursor: pointer;
}

.multi-image-upload:hover,
.multi-image-upload.drag-over {
    border-color: var(--primary-color, #ff4500);
    background: rgba(255, 69, 0, 0.05);
}

.multi-image-upload .upload-icon {
    width: 48px;
    height: 48px;
    opacity: 0.5;
    margin-bottom: 12px;
}

.multi-image-upload .upload-text {
    font-size: 16px;
    color: var(--text-primary, #d7dadc);
    margin-bottom: 4px;
}

.multi-image-upload .upload-hint {
    font-size: 13px;
    color: var(--text-secondary, #818384);
}

.multi-image-upload .upload-count {
    margin-top: 8px;
    font-size: 13px;
    color: var(--primary-color, #ff4500);
    font-weight: 500;
}

/* Image Preview Grid */
.image-preview-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 16px;
}

@media (max-width: 640px) {
    .image-preview-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.image-preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-tertiary, #1a1a1b);
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-item .remove-image-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.image-preview-item .remove-image-btn:hover {
    background: rgba(255, 69, 0, 0.9);
    transform: scale(1.1);
}

.image-preview-item .remove-image-btn svg {
    width: 16px;
    height: 16px;
    stroke: white;
}

.image-preview-item .image-order {
    position: absolute;
    bottom: 6px;
    left: 6px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 600;
}

/* Drag handle for reordering */
.image-preview-item .drag-handle {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.image-preview-item:hover .drag-handle {
    opacity: 1;
}

.image-preview-item .drag-handle svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.image-preview-item.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

/* Upload Progress */
.upload-progress-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.upload-progress-bar {
    width: 80%;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    background: var(--primary-color, #ff4500);
    transition: width 0.2s ease;
}

.upload-progress-text {
    color: white;
    font-size: 12px;
}

/* Mobile Swipe Hint */
.lightbox-swipe-hint {
    position: absolute;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    display: none;
}

/* Gallery More Overlay (shows +X for additional images) */
.gallery-more-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    pointer-events: none;
}

/* Hidden gallery items (for lightbox navigation) */
.gallery-item-hidden {
    display: none !important;
}

@media (max-width: 768px) {
    .lightbox-swipe-hint {
        display: block;
    }
    
    .lightbox-nav {
        width: 40px;
        height: 40px;
    }
    
    .lightbox-prev {
        left: 10px;
    }
    
    .lightbox-next {
        right: 10px;
    }
    
    .lightbox-thumbnails {
        bottom: 80px;
    }
    
    .lightbox-thumb {
        width: 50px;
        height: 50px;
    }
}

/* Dark mode adjustments (already dark by default) */
