/* ===================================
   BUSINESS GALLERY STYLES
   Professional photo gallery system
   =================================== */

/* Gallery Grid - Main Container */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin: 20px 0;
    animation: fadeIn 0.4s ease;
}

/* Individual Gallery Items */
.gallery-item {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 12px;
    background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1;
}

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

/* Gallery Item Error State */
.gallery-item-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: #f5f5f5;
    color: #999;
}

.gallery-item-error i {
    font-size: 2rem;
    margin-bottom: 8px;
}

.gallery-item-error span {
    font-size: 0.75rem;
}

/* Empty Gallery State */
.gallery-empty {
    text-align: center;
    padding: 60px 20px;
    color: #999;
    background: #f9f9f9;
    border-radius: 12px;
    border: 2px dashed #ddd;
}

.gallery-empty i {
    color: #ccc;
    margin-bottom: 15px;
}

.gallery-empty p {
    font-size: 1rem;
    margin: 10px 0;
}

/* Thumbnail Gallery - For Business Cards */
.thumbnail-gallery {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-top: 12px;
}

.thumbnail-item {
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 8px;
    background: #f5f5f5;
    position: relative;
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.2s;
}

.thumbnail-item img:hover {
    opacity: 0.8;
}

/* "+X more" indicator */
.thumbnail-more {
    background: linear-gradient(135deg, rgba(0, 78, 100, 0.9), rgba(0, 96, 128, 0.9));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.thumbnail-more:hover {
    background: linear-gradient(135deg, rgba(0, 78, 100, 1), rgba(0, 96, 128, 1));
    transform: scale(1.05);
}

/* View All Photos Button */
.view-all-photos {
    margin-top: 15px;
    width: 100%;
}

/* ===================================
   LIGHTBOX - Full Screen Gallery
   ⭐ FIXED: Proper close functionality
   =================================== */

.gallery-lightbox {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 99999 !important;
    display: flex !important;
    justify-content: center;
    align-items: center;
    background: transparent !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Active state - lightbox is visible */
.gallery-lightbox.active {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: all !important;
}

/* ⭐ CRITICAL FIX: Hidden state that OVERRIDES everything */
.gallery-lightbox.lightbox-hidden {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Lightbox Overlay */
.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    z-index: 1;
}

/* Lightbox Content */
.lightbox-content {
    position: relative;
    z-index: 2;
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px 20px;
}

/* Lightbox Close Button */
.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    z-index: 10;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* Navigation Buttons */
.lightbox-prev,
.lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    z-index: 10;
}

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

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

.lightbox-prev:active,
.lightbox-next:active {
    transform: translateY(-50%) scale(0.95);
}

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

#lightboxImage {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transition: opacity 0.3s ease;
}

/* Loader */
.lightbox-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    display: none;
}

/* Lightbox Info */
.lightbox-info {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    padding: 15px 30px;
    border-radius: 30px;
    backdrop-filter: blur(10px);
}

.lightbox-counter {
    display: block;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 5px;
    color: #FFB627;
}

.lightbox-caption {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Lightbox Actions (for delete button etc) */
.lightbox-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */

/* Tablets */
@media (max-width: 968px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }
    
    .lightbox-prev,
    .lightbox-next {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
    
    .lightbox-prev {
        left: 10px;
    }
    
    .lightbox-next {
        right: 10px;
    }
}

/* Mobile Phones */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .thumbnail-gallery {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .lightbox-content {
        padding: 80px 10px 100px;
    }
    
    .lightbox-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .lightbox-prev,
    .lightbox-next {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .lightbox-info {
        bottom: 20px;
        padding: 12px 20px;
        max-width: 90%;
    }
    
    .lightbox-counter {
        font-size: 1rem;
    }
    
    .lightbox-caption {
        font-size: 0.85rem;
    }
    
    #lightboxImage {
        max-height: 70vh;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }
    
    .thumbnail-gallery {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===================================
   ANIMATIONS
   =================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Smooth image loading */
.gallery-item img {
    animation: imageLoad 0.4s ease;
}

@keyframes imageLoad {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===================================
   UPLOAD MODAL STYLES
   =================================== */

.modal-sm {
    max-width: 600px;
}

/* Upload Area */
.upload-area {
    text-align: center;
    padding: 40px 20px;
    border: 2px dashed var(--medium-gray);
    border-radius: 12px;
    background: var(--light-gray);
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
}

.upload-area:hover {
    border-color: var(--deep-teal);
    background: rgba(77, 208, 225, 0.05);
}

.upload-area.drag-over {
    border-color: var(--sunset-orange);
    background: rgba(255, 107, 53, 0.1);
}

.upload-area i {
    color: var(--medium-gray);
    margin-bottom: 15px;
}

.upload-area h3 {
    margin: 10px 0;
    color: var(--dark-charcoal);
}

.upload-area p {
    color: #888;
    margin: 5px 0 15px;
}

.upload-hint {
    font-size: 0.85rem;
    color: #999;
    margin-top: 10px;
}

/* Upload Preview */
.upload-preview {
    margin-bottom: 20px;
    background: var(--light-sand);
    border-radius: 12px;
    padding: 20px;
}

.upload-preview h4 {
    margin: 0 0 15px 0;
    color: var(--dark-charcoal);
}

.preview-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.preview-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: var(--white);
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--medium-gray);
}

.preview-item img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
}

.preview-info {
    flex: 1;
}

.file-name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--dark-charcoal);
}

.file-size {
    display: block;
    font-size: 0.8rem;
    color: #888;
}

.remove-file {
    background: none;
    border: none;
    color: var(--error-red);
    font-size: 1.2rem;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.remove-file:hover {
    background: rgba(239, 83, 80, 0.1);
}

/* Upload Progress */
.upload-progress {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--medium-gray);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--sunset-orange), var(--warm-yellow));
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

#progressText {
    font-weight: 600;
    color: var(--deep-teal);
    min-width: 40px;
}

/* Gallery Upload Section */
.gallery-upload-section {
    margin-bottom: 20px;
}

.upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.upload-header h3 {
    margin: 0;
    color: var(--deep-charcoal);
    font-size: 1.25rem;
}

/* ===================================
   BUSINESS CARD GALLERY THUMBNAILS
   =================================== */

.gallery-thumbnail-section {
    margin: 15px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid var(--medium-gray);
}

.thumbnail-gallery {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.business-card .thumbnail-gallery {
    grid-template-columns: repeat(2, 1fr);
}

.thumbnail-item {
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 6px;
    background: var(--light-gray);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

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

.thumbnail-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

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

.thumbnail-more {
    background: linear-gradient(135deg, var(--deep-teal), var(--sunset-orange));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1rem;
}

.thumbnail-more:hover {
    opacity: 0.9;
}

/* Upload photos button */
.upload-photos-btn {
    margin-top: 10px !important;
    font-size: 0.9rem !important;
    padding: 8px 12px !important;
}

.btn-text {
    background: none;
    border: none;
    color: var(--deep-teal);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: color 0.3s ease;
}

.btn-text:hover {
    color: var(--sunset-orange);
    text-decoration: underline;
}

/* Owner badge */
.business-card .featured-badge:not(:first-child) {
    top: 45px;
}

.listing-badge:last-child {
    margin-left: 5px;
}

/* Delete Button Styles */
.lightbox-delete-btn {
    background: #EF4444;
    color: white;
    border: none;
    transition: all 0.3s ease;
}

.lightbox-delete-btn:hover {
    background: #DC2626;
    transform: scale(1.05);
}

.lightbox-delete-btn i {
    margin-right: 5px;
}

/* Photo count warning */
.delete-warning {
    background: #FEF3C7;
    border: 1px solid #F59E0B;
    border-radius: 8px;
    padding: 10px;
    margin: 10px 0;
    font-size: 0.9rem;
}

.delete-warning i {
    color: #F59E0B;
    margin-right: 8px;
}

/* Confirmation modal styles */
.delete-confirm-modal {
    background: white;
    border-radius: 12px;
    padding: 25px;
    max-width: 400px;
    margin: 0 auto;
}

.delete-confirm-modal h4 {
    color: #DC2626;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.delete-confirm-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.delete-btn-danger {
    background: #DC2626;
    color: white;
    border: none;
}

.delete-btn-danger:hover {
    background: #B91C1C;
}

/* Gallery thumbnail delete buttons */
.thumbnail-delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.thumbnail-item:hover .thumbnail-delete-btn {
    opacity: 1;
}

/* Empty gallery state */
.empty-gallery {
    text-align: center;
    padding: 40px 20px;
    color: #6B7280;
}

.empty-gallery i {
    font-size: 3rem;
    color: #D1D5DB;
    margin-bottom: 15px;
    display: block;
}