/* Gallery Section */
.gallery-filter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1.5rem 0;
    border-bottom: 1px solid #e9ecef;
}

.filter-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}

.filter-btn {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid transparent;
    color: #2c3e50;
    padding: 0.7rem 1.3rem;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    font-size: 0.95rem;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

.filter-btn:hover,
.filter-btn.active {
    background: #2c3e50;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(44, 62, 80, 0.3);
    border-color: #2c3e50;
}

.gallery {
    padding: 2.5rem 0;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 70vh;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.2rem;
    margin-top: 1.5rem;
}

.gallery-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    background: white;
    aspect-ratio: 4/3;
    /* تأكد من أن العنصر يأخذ الحجم الكامل */
    width: 100%;
    height: auto;
}

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

.gallery-image-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* تأكد من ملء الحاوية بالكامل */
    object-position: center; /* مركز الصورة */
    display: block;
    transition: transform 0.3s ease;
    /* منع الصورة من أن تكون أصغر من الحاوية */
    min-width: 100%;
    min-height: 100%;
}

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

.gallery-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    color: white;
    padding: 1.5rem 0.8rem 0.8rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    text-align: center;
    z-index: 2;
}

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

.gallery-overlay h3 {
    margin: 0 0 0.4rem 0;
    font-size: 1.2rem;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

.gallery-overlay p {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.9;
    line-height: 1.3;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
    touch-action: manipulation;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    position: relative;
    margin: auto;
    padding: 15px;
    width: 98%;
    max-width: 1100px;
    height: 96vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#modalImage {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    animation: zoomIn 0.3s ease;
    /* تأكد من أن الصورة تأخذ الحجم المناسب في المودال */
    display: block;
    margin: 0 auto;
}

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

.modal-close {
    position: absolute;
    top: 20px;
    right: 25px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
    transition: all 0.3s ease;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: none;
}

.modal-close:hover {
    color: #ff6b6b;
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 1.2rem;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    transition: all 0.3s ease;
    z-index: 10001;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    min-height: 50px;
}

.modal-prev {
    left: 30px;
}

.modal-next {
    right: 30px;
}

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

.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 2.5rem;
}

/* Counter */
.image-counter {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.4rem 0.8rem;
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

/* Responsive Design - Tablet */
@media (max-width: 1024px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 1rem;
    }
    
    .gallery {
        padding: 2rem 0;
    }
    
    .modal-nav {
        font-size: 24px;
        padding: 1rem;
        min-width: 45px;
        min-height: 45px;
    }
    
    .modal-prev {
        left: 20px;
    }
    
    .modal-next {
        right: 20px;
    }
}

/* Responsive Design - Mobile Large */
@media (max-width: 768px) {
    .gallery-filter {
        padding: 1.2rem 0;
    }
    
    .filter-buttons {
        gap: 0.6rem;
        margin-bottom: 1.2rem;
    }
    
    .filter-btn {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
        border-radius: 20px;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 0.8rem;
    }
    
    .gallery {
        padding: 1.5rem 0;
        min-height: 60vh;
    }
    
    .gallery-item {
        border-radius: 10px;
    }
    
    .gallery-overlay {
        padding: 1.2rem 0.6rem 0.6rem;
    }
    
    .gallery-overlay h3 {
        font-size: 1.1rem;
        margin-bottom: 0.3rem;
    }
    
    .gallery-overlay p {
        font-size: 0.8rem;
    }
    
    /* Modal Mobile Improvements */
    .modal-content {
        padding: 10px;
        height: 95vh;
        width: 99%;
    }
    
    .modal-close {
        top: 15px;
        right: 15px;
        font-size: 35px;
        width: 40px;
        height: 40px;
    }
    
    .modal-nav {
        font-size: 20px;
        padding: 0.8rem;
        min-width: 40px;
        min-height: 40px;
        border-width: 1px;
    }
    
    .modal-prev {
        left: 10px;
    }
    
    .modal-next {
        right: 10px;
    }
    
    .loading-spinner {
        font-size: 2rem;
    }
    
    .image-counter {
        bottom: 20px;
        font-size: 0.9rem;
        padding: 0.3rem 0.6rem;
    }
}

/* Responsive Design - Mobile Small */
@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 0.6rem;
    }
    
    .filter-buttons {
        gap: 0.4rem;
    }
    
    .filter-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
        flex: 1;
        min-width: 120px;
        max-width: 140px;
    }
    
    .gallery {
        padding: 1rem 0;
    }
    
    .gallery-item {
        border-radius: 8px;
        aspect-ratio: 1/1;
    }
    
    .gallery-overlay {
        padding: 1rem 0.5rem 0.5rem;
    }
    
    .gallery-overlay h3 {
        font-size: 1rem;
    }
    
    .gallery-overlay p {
        font-size: 0.75rem;
        line-height: 1.2;
    }
    
    /* Modal Extra Small Screens */
    .modal-content {
        padding: 5px;
        height: 94vh;
    }
    
    .modal-close {
        top: 10px;
        right: 10px;
        font-size: 30px;
        width: 35px;
        height: 35px;
    }
    
    .modal-nav {
        font-size: 18px;
        padding: 0.6rem;
        min-width: 35px;
        min-height: 35px;
    }
    
    .modal-prev {
        left: 8px;
    }
    
    .modal-next {
        right: 8px;
    }
    
    #modalImage {
        border-radius: 6px;
    }
    
    .loading-spinner {
        font-size: 1.8rem;
    }
    
    .image-counter {
        bottom: 15px;
        font-size: 0.8rem;
        padding: 0.2rem 0.5rem;
    }
}

/* Responsive Design - Very Small Screens */
@media (max-width: 360px) {
    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .filter-buttons {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }
    
    .filter-btn {
        width: 90%;
        max-width: 200px;
        margin: 0 auto;
    }
    
    .modal-nav {
        font-size: 16px;
        padding: 0.5rem;
        min-width: 32px;
        min-height: 32px;
    }
    
    .modal-prev {
        left: 5px;
    }
    
    .modal-next {
        right: 5px;
    }
}

/* Animation for gallery items */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gallery-item {
    animation: fadeInUp 0.5s ease forwards;
    opacity: 0;
}

/* Staggered animation */
.gallery-item:nth-child(6n+1) { animation-delay: 0.1s; }
.gallery-item:nth-child(6n+2) { animation-delay: 0.15s; }
.gallery-item:nth-child(6n+3) { animation-delay: 0.2s; }
.gallery-item:nth-child(6n+4) { animation-delay: 0.25s; }
.gallery-item:nth-child(6n+5) { animation-delay: 0.3s; }
.gallery-item:nth-child(6n+6) { animation-delay: 0.35s; }

/* Loading state */
.gallery-loading {
    text-align: center;
    padding: 2rem;
    font-size: 1.1rem;
    color: #666;
    grid-column: 1 / -1;
}

.gallery-loading .spinner {
    font-size: 1.8rem;
    margin-bottom: 0.8rem;
    color: #2c3e50;
}

/* Touch improvements for mobile */
@media (hover: none) {
    .gallery-item:hover {
        transform: none;
    }
    
    .gallery-item:hover img {
        transform: none;
    }
    
    .gallery-overlay {
        transform: translateY(0);
        background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    }
    
    .filter-btn:hover {
        transform: none;
    }
    
    .modal-nav:hover,
    .modal-close:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.15);
    }
}

/* Prevent zoom on double tap for mobile */
@media (max-width: 768px) {
    .gallery-item {
        -webkit-tap-highlight-color: transparent;
    }
    
    .modal {
        -webkit-overflow-scrolling: touch;
    }
}

/* تأكيد أن الصور تأخذ الحجم الكامل دون تشويه */
.gallery-item {
    container-type: inline-size;
}

@container (max-width: 300px) {
    .gallery-item img {
        object-fit: cover;
        object-position: center;
    }
}

/* ضمان أن الصور لا تتقلص أبداً */
.gallery-item img {
    flex-shrink: 0;
    flex-grow: 0;
}