/**
 * Gallery Section Styles
 * Modern photo gallery with category filtering and responsive design
 * Enhanced with better animations and modal functionality
 */

/* ============================================
   Gallery Section Base
   ============================================ */
.gallery-section {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 4rem 0;
    position: relative;
    overflow: hidden;
}

.gallery-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, #dee2e6 50%, transparent 100%);
}

.gallery-section::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, #dee2e6 50%, transparent 100%);
}

/* ============================================
   Section Header
   ============================================ */
.gallery-section .section-header {
    margin-bottom: 3rem;
    position: relative;
}

.gallery-section .section-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #212529;
    margin-bottom: 1rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: relative;
    display: inline-block;
}

.gallery-section .section-title::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 3px;
    background: linear-gradient(90deg, #007bff, #0056b3);
    border-radius: 2px;
}

.gallery-section .section-subtitle {
    font-size: 1.125rem;
    color: #6c757d;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ============================================
   Category Filter
   ============================================ */
.gallery-filter {
    text-align: center;
    margin-bottom: 2.5rem;
    position: relative;
}

.filter-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.filter-btn {
    background: white;
    border: 2px solid #e9ecef;
    color: #495057;
    padding: 0.75rem 1.25rem;
    border-radius: 50px;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.875rem;
    position: relative;
    overflow: hidden;
}

.filter-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s;
}

.filter-btn:hover::before {
    left: 100%;
}

.filter-btn:hover {
    background: #f8f9fa;
    border-color: #007bff;
    color: #007bff;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.2);
}

.filter-btn.active {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    border-color: #007bff;
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(0, 123, 255, 0.4);
}

.filter-btn .badge {
    background: rgba(255, 255, 255, 0.2);
    color: inherit;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    margin-left: 0.5rem;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.filter-btn:not(.active) .badge {
    background: #e9ecef;
    color: #6c757d;
}

/* ============================================
   Gallery Grid
   ============================================ */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    justify-content: center;
}

/* For small galleries (≤3 photos), use centered layout */
.gallery-grid:not(:has(.gallery-item:nth-child(4))) {
    grid-template-columns: repeat(auto-fit, minmax(300px, 400px));
    max-width: 1000px;
    margin: 0 auto 2rem;
}

.gallery-item {
    position: relative;
    border-radius: 15px;
    overflow: hidden;
    background: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    animation: fadeInUp 0.6s ease-out;
    opacity: 0;
    animation-fill-mode: 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; }

.gallery-item:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.gallery-item-wrapper {
    position: relative;
    width: 100%;
    height: 250px;
    overflow: hidden;
}

.gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    filter: brightness(0.9);
}

.gallery-item:hover .gallery-image {
    transform: scale(1.1);
    filter: brightness(1.1);
}

.gallery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.4) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(5px);
}

.gallery-item:hover .gallery-overlay {
    opacity: 1;
}

.gallery-overlay-content {
    text-align: center;
    color: white;
    padding: 1.5rem;
    transform: translateY(20px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.gallery-item:hover .gallery-overlay-content {
    transform: translateY(0);
}

.gallery-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.gallery-category {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-bottom: 1rem;
    font-weight: 500;
}

.gallery-actions {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    align-items: center;
}

.gallery-actions .btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 25px;
    font-size: 0.875rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.gallery-actions .btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.gallery-actions .badge {
    background: rgba(255, 193, 7, 0.9);
    color: #212529;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-weight: 600;
}

/* ============================================
   Enhanced Modal Styles
   ============================================ */
#galleryModal {
    backdrop-filter: blur(10px);
}

#galleryModal .modal-dialog {
    max-width: 95vw;
    max-height: 95vh;
    margin: 2.5vh auto;
}

#galleryModal .modal-content {
    background: rgba(0, 0, 0, 0.95);
    border: none;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

#galleryModal .modal-header {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#galleryModal .modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    margin: 0;
}

#galleryModal .modal-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#galleryModal .modal-controls .btn {
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

#galleryModal .modal-controls .btn:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.2);
}

#galleryModal .btn-close-white {
    filter: invert(1);
    opacity: 0.8;
    transition: opacity 0.3s ease;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

#galleryModal .btn-close-white:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

#galleryModal .modal-body {
    padding: 0;
    position: relative;
}

.gallery-modal-image-wrapper {
    position: relative;
    width: 100%;
    height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
}

.gallery-modal-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

#galleryModal .carousel-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    padding: 2rem 1.5rem 1.5rem;
    text-align: center;
    border-radius: 0 0 20px 20px;
    backdrop-filter: blur(10px);
}

#galleryModal .carousel-caption h5 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#galleryModal .carousel-caption p {
    font-size: 1rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

#galleryModal .photo-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

#galleryModal .carousel-control-prev,
#galleryModal .carousel-control-next {
    width: 60px;
    height: 60px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    top: 50%;
    transform: translateY(-50%);
    margin: 0 2rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#galleryModal .carousel-control-prev:hover,
#galleryModal .carousel-control-next:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: translateY(-50%) scale(1.1);
    border-color: rgba(255, 255, 255, 0.4);
}

#galleryModal .carousel-indicators {
    bottom: 20px;
    gap: 0.5rem;
    margin: 0;
}

#galleryModal .carousel-indicators button {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    transition: all 0.3s ease;
    margin: 0 0.25rem;
}

#galleryModal .carousel-indicators button:hover {
    background: rgba(255, 255, 255, 0.5);
    transform: scale(1.2);
}

#galleryModal .carousel-indicators button.active {
    background: #007bff;
    border-color: #007bff;
    transform: scale(1.2);
}

#galleryModal .modal-footer {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 1.5rem;
}

.gallery-modal-info {
    font-size: 0.875rem;
    opacity: 0.8;
}

.gallery-modal-counter,
.gallery-modal-category {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ============================================
   Keyboard Help Modal
   ============================================ */
#keyboardHelpModal .modal-content {
    border-radius: 15px;
    border: none;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

#keyboardHelpModal .modal-header {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border-radius: 15px 15px 0 0;
}

#keyboardHelpModal .modal-body {
    padding: 1.5rem;
}

#keyboardHelpModal kbd {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    font-family: monospace;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ============================================
   No Photos State
   ============================================ */
.no-photos-state {
    text-align: center;
    padding: 4rem 2rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.no-photos-icon {
    margin-bottom: 2rem;
}

.no-photos-state h4 {
    color: #6c757d;
    margin-bottom: 1rem;
    font-weight: 600;
}

.no-photos-state p {
    color: #868e96;
    font-size: 1.1rem;
    line-height: 1.6;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .gallery-section {
        padding: 3rem 0;
    }
    
    .gallery-section .section-title {
        font-size: 2rem;
    }
    
    .filter-buttons {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }
    
    .filter-btn {
        width: 100%;
        max-width: 300px;
        justify-content: center;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1rem;
    }
    
    .gallery-overlay-content {
        padding: 1rem;
    }
    
    .gallery-title {
        font-size: 1rem;
    }
    
    #galleryModal .modal-dialog {
        max-width: 98vw;
        margin: 1vh auto;
    }
    
    #galleryModal .modal-header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    #galleryModal .modal-controls {
        width: 100%;
        justify-content: center;
    }
    
    #galleryModal .carousel-caption {
        padding: 1.5rem 1rem 1rem;
    }
    
    #galleryModal .carousel-caption h5 {
        font-size: 1.25rem;
    }
    
    #galleryModal .carousel-control-prev,
    #galleryModal .carousel-control-next {
        width: 50px;
        height: 50px;
        margin: 0 1rem;
    }
    
    .gallery-modal-image-wrapper {
        height: 60vh;
    }
}

@media (max-width: 576px) {
    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .filter-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
    
    .filter-btn .badge {
        font-size: 0.7rem;
    }
    
    .gallery-overlay-content {
        padding: 0.75rem;
    }
    
    .gallery-actions .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    #galleryModal .modal-dialog {
        max-width: 100vw;
        margin: 0;
        height: 100vh;
    }
    
    #galleryModal .modal-content {
        height: 100vh;
        border-radius: 0;
    }
    
    .gallery-modal-image-wrapper {
        height: 70vh;
    }
    
    #galleryModal .carousel-caption {
        padding: 1rem;
    }
    
    #galleryModal .carousel-caption h5 {
        font-size: 1.1rem;
    }
    
    #galleryModal .carousel-caption p {
        font-size: 0.9rem;
    }
    
    .photo-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* ============================================
   Accessibility & Performance
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .gallery-item,
    .filter-btn,
    .gallery-image,
    .gallery-overlay,
    .gallery-overlay-content,
    #galleryModal .carousel-control-prev,
    #galleryModal .carousel-control-next,
    #galleryModal .carousel-indicators button {
        transition: none;
        animation: none;
    }
}

@media (prefers-contrast: high) {
    .gallery-overlay {
        background: rgba(0, 0, 0, 0.9);
    }
    
    .filter-btn {
        border-width: 3px;
    }
    
    .gallery-item {
        border: 2px solid #000;
    }
    
    #galleryModal .carousel-control-prev,
    #galleryModal .carousel-control-next {
        border-width: 3px;
    }
}

/* ============================================
   Loading States
   ============================================ */
.gallery-item.loading {
    position: relative;
    overflow: hidden;
}

.gallery-item.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: spin 1.5s infinite;
}

@keyframes spin {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* ============================================
   Enhanced Hover Effects
   ============================================ */
.gallery-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
    z-index: 1;
    pointer-events: none;
}

.gallery-item:hover::before {
    transform: translateX(100%);
}

/* ============================================
   Featured Photo Styling
   ============================================ */
/* Only apply featured spans when enough items exist */
.gallery-grid:has(.gallery-item:nth-child(4)) .gallery-item.featured:first-child {
    grid-column: span 2;
    grid-row: span 2;
}

.gallery-item.featured {
    /* Enhanced styling for featured items without grid spanning for small galleries */
    border: 2px solid #ffc107;
    box-shadow: 0 8px 30px rgba(255, 193, 7, 0.3);
}

/* Only increase height for featured items in larger galleries */
.gallery-grid:has(.gallery-item:nth-child(4)) .gallery-item.featured:first-child .gallery-item-wrapper {
    height: 400px;
}

.gallery-item.featured .gallery-item-wrapper {
    height: 280px; /* Consistent height for small galleries */
}

.gallery-item.featured .gallery-overlay-content {
    padding: 2rem;
}

.gallery-item.featured .gallery-title {
    font-size: 1.3rem;
}

@media (max-width: 768px) {
    .gallery-item.featured {
        grid-column: span 1;
        grid-row: span 1;
    }
    
    .gallery-item.featured .gallery-item-wrapper {
        height: 250px;
    }
    
    .gallery-item.featured .gallery-overlay-content {
        padding: 1.5rem;
    }
    
    .gallery-item.featured .gallery-title {
        font-size: 1.1rem;
    }
}

/* ============================================
   Focus States for Accessibility
   ============================================ */
.gallery-item:focus-within {
    outline: 3px solid #007bff;
    outline-offset: 2px;
}

.filter-btn:focus {
    outline: 3px solid #007bff;
    outline-offset: 2px;
}

#galleryModal .btn:focus {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .gallery-section {
        background: white;
        padding: 1rem 0;
    }
    
    .gallery-filter,
    .gallery-overlay,
    #galleryModal {
        display: none !important;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .gallery-item {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}