/* Gallery-specific styles */
:root {
    --gallery-gap: 1rem;
    --gallery-columns: 4;
    --lightbox-bg: rgba(0, 0, 0, 0.95);
    --nav-height: 70px;
}

/* Gallery navigation */
.gallery-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.nav-container {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    height: 100%;
    position: relative;
}

.nav-logo {
    position: absolute;
    left: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-dark);
    text-decoration: none;
    font-weight: 600;
    transition: all var(--transition-fast);
}

.nav-logo:hover {
    color: var(--primary-color);
    transform: translateX(-5px);
}

.nav-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0;
    text-align: center;
}

/* Gallery container */
.gallery-container {
    padding-top: calc(var(--nav-height) + 2rem);
    padding-bottom: 2rem;
    min-height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--gallery-gap);
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Gallery item */
.gallery-item {
    position: relative;
    aspect-ratio: 4/3;
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-light);
    background: #f0f0f0;
}

.gallery-item:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-medium);
}

.gallery-item:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
    transform: translateY(-5px);
}

.gallery-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        135deg,
        transparent 0%,
        rgba(0, 0, 0, 0.1) 50%,
        rgba(0, 0, 0, 0.3) 100%
    );
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 2;
}

.gallery-item:hover::before {
    opacity: 1;
}

.gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.gallery-item:hover .gallery-image {
    transform: scale(1.05);
}

.gallery-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: white;
    padding: 1.5rem 1rem 1rem;
    transform: translateY(100%);
    transition: transform var(--transition-fast);
    z-index: 3;
    pointer-events: none; /* Allow clicks to pass through */
}

.gallery-item:hover .gallery-overlay {
    transform: translateY(0);
}

.gallery-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.gallery-description {
    font-size: 0.9rem;
    opacity: 0.9;
    line-height: 1.4;
}

.gallery-description:empty {
    display: none;
}

/* Loading placeholder */
.gallery-item.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Lightbox styles */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--lightbox-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    backdrop-filter: blur(5px);
}

.lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0.8);
    transition: transform var(--transition-fast);
}

.lightbox.active .lightbox-content {
    transform: scale(1);
}

.lightbox-close {
    position: absolute;
    top: -42px;
    right: -100px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    z-index: 10;
    backdrop-filter: blur(10px);
}

.lightbox-close:hover,
.lightbox-close:focus {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    z-index: 10;
    backdrop-filter: blur(10px);
}

.lightbox-nav:hover,
.lightbox-nav:focus {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(1.1);
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.lightbox-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.lightbox-prev {
    left: -80px;
}

.lightbox-next {
    right: -80px;
}

.lightbox-image-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 100%;
    max-height: 100%;
}

.lightbox-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: var(--shadow-heavy);
    transition: opacity var(--transition-fast);
    cursor: zoom-out;
}

/* Loading state for lightbox image */
.lightbox-image-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 0;
    z-index: 5;
    transition: opacity var(--transition-fast);
}

.lightbox-image[style*="opacity: 0"] + .lightbox-info::before {
    opacity: 1;
}

.lightbox-info {
    margin-top: 1.5rem;
    text-align: center;
    color: white;
    max-width: 600px;
    padding: 0 1rem;
}

.lightbox-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.lightbox-description {
    font-size: 1rem;
    line-height: 1.6;
    opacity: 0.9;
    margin-bottom: 1rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.lightbox-description:empty {
    display: none;
}

.lightbox-counter {
    font-size: 0.9rem;
    opacity: 0.7;
    font-weight: 500;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    display: inline-block;
    backdrop-filter: blur(5px);
}

/* Filter and sort controls */
.gallery-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-label {
    font-weight: 600;
    color: var(--text-dark);
}

.control-select {
    padding: 0.5rem 1rem;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius);
    background: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.control-select:hover,
.control-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(255, 90, 95, 0.2);
}

/* Responsive design */
@media (max-width: 1200px) {
    :root {
        --gallery-columns: 3;
    }
}

@media (max-width: 768px) {
    :root {
        --gallery-columns: 2;
        --gallery-gap: 0.75rem;
    }
    
    .nav-container {
        padding: 0 1rem;
    }
    
    .nav-logo {
        left: 1rem;
    }
    
    .nav-title {
        font-size: 1.2rem;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        padding: 0 1rem;
    }
    
    .lightbox-content {
        max-width: 95vw;
        max-height: 95vh;
    }
    
    .lightbox-nav {
        width: 44px;
        height: 44px;
    }
    
    .lightbox-prev {
        left: -60px;
    }
    
    .lightbox-next {
        right: -60px;
    }
    
    .lightbox-close {
        top: -50px;
        width: 40px;
        height: 40px;
    }
    
    .lightbox-image {
        max-height: 60vh;
    }
    
    .gallery-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .gallery-item:active {
        transform: scale(0.95);
    }
}

@media (max-width: 480px) {
    :root {
        --gallery-columns: 1;
        --gallery-gap: 0.5rem;
    }
    
    .gallery-grid {
        grid-template-columns: 1fr;
        padding: 0 0.5rem;
    }
    
    .lightbox-prev,
    .lightbox-next {
        /* Keep navigation arrows but make them smaller on mobile */
        display: flex;
        width: 40px;
        height: 40px;
        left: 10px;
        right: 10px;
    }
    
    .lightbox-prev {
        left: 10px;
    }
    
    .lightbox-next {
        right: 10px;
    }
    
    .lightbox-image {
        max-height: 60vh;
    }
    
    .lightbox-close {
        top: 10px;
        right: 10px;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(10px);
    }
    
    .nav-container {
        padding: 0 0.5rem;
    }
    
    .nav-logo {
        left: 0.5rem;
    }
    
    .gallery-item {
        min-height: 200px;
    }
    
    /* Better touch targets */
    .lightbox-nav,
    .lightbox-close {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .gallery-container {
        background: linear-gradient(135deg, #2c3e50 0%, #3a3a3a 100%);
    }
    
    .gallery-nav {
        background: rgba(0, 0, 0, 0.95);
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }
    
    .nav-logo,
    .nav-title {
        color: white;
    }
    
    .control-select {
        background: #333;
        color: white;
        border-color: rgba(255, 255, 255, 0.2);
    }
    
    .control-label {
        color: white;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .gallery-item {
        border: 2px solid #000;
    }
    
    .lightbox-nav,
    .lightbox-close {
        border: 2px solid #fff;
    }
}

/* Animation for gallery items appearing */
.gallery-item {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s ease forwards;
}

.gallery-item:nth-child(1) { animation-delay: 0.1s; }
.gallery-item:nth-child(2) { animation-delay: 0.2s; }
.gallery-item:nth-child(3) { animation-delay: 0.3s; }
.gallery-item:nth-child(4) { animation-delay: 0.4s; }
.gallery-item:nth-child(5) { animation-delay: 0.5s; }
.gallery-item:nth-child(6) { animation-delay: 0.6s; }

/* For items beyond the 6th, use a repeating pattern */
.gallery-item:nth-child(n+7) {
    animation-delay: 0.1s;
}

/* Search functionality */
.search-container {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
    padding: 0 2rem;
}

.search-input {
    width: 100%;
    max-width: 400px;
    padding: 1rem 1.5rem;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 50px;
    font-size: 1rem;
    background: white;
    transition: all var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.2);
}

.search-input::placeholder {
    color: #999;
}

/* Loading state for lightbox image */
.lightbox-image-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 0;
    z-index: 5;
    transition: opacity var(--transition-fast);
}

.lightbox-image[style*="opacity: 0"] + .lightbox-info::before {
    opacity: 1;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}
