/* Стили для галереи */

#gallery-section {
    margin: 2rem 0;
}

.gallery-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

/* Сетка галереи */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.gallery-item {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
}

.gallery-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 24px rgba(74, 144, 226, 0.3);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease, filter 0.5s ease, opacity 0.5s ease;
}

/* Прогрессивная загрузка изображений */
.progressive-image {
    background-color: var(--surface-color);
    position: relative;
}

.progressive-image.loading {
    filter: blur(10px);
    opacity: 0.6;
}

.progressive-image.loaded {
    filter: blur(0);
    opacity: 1;
}

.progressive-image.error {
    filter: blur(0);
    opacity: 0.3;
}

/* Индикатор загрузки */
.gallery-item {
    position: relative;
}

.gallery-item::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(74, 144, 226, 0.3);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.gallery-item:has(.progressive-image.loading)::before {
    opacity: 1;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

.gallery-item-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(74, 144, 226, 0.7), rgba(74, 144, 226, 0.3));
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    text-align: center;
    padding: 1rem;
}

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

.gallery-item-overlay-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.gallery-item-overlay-icon {
    font-size: 2rem;
}

/* Модальное окно */
.gallery-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.gallery-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-content {
    position: relative;
    width: 90%;
    max-width: 900px;
    height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: slideUp 0.3s ease;
}

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

.modal-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transition: filter 0.5s ease, opacity 0.5s ease;
    background-color: rgba(255, 255, 255, 0.05);
}

/* Прогрессивная загрузка в модальном окне */
.modal-image.loading {
    filter: blur(20px);
    opacity: 0.5;
}

.modal-image.loaded {
    filter: blur(0);
    opacity: 1;
}

.modal-image.error {
    filter: blur(0);
    opacity: 0.3;
}

/* Индикатор загрузки для модального окна */
.modal-content::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    margin: -30px 0 0 -30px;
    border: 4px solid rgba(74, 144, 226, 0.3);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    opacity: 0;
    pointer-events: none;
    z-index: 1002;
    transition: opacity 0.3s ease;
}

.modal-content:has(.modal-image.loading)::after {
    opacity: 1;
}

/* Кнопки управления модалью */
.modal-close {
    position: absolute;
    top: -50px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 2.5rem;
    cursor: pointer;
    transition: color 0.2s ease;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--accent-color);
}

.modal-prev,
.modal-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(74, 144, 226, 0.7);
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 1rem;
    transition: all 0.2s ease;
    border-radius: 4px;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
}

.modal-prev:hover,
.modal-next:hover {
    background-color: var(--accent-color);
    transform: translateY(-50%) scale(1.1);
}

.modal-prev {
    left: 1rem;
}

.modal-next {
    right: 1rem;
}

/* Подпись к изображению */
.modal-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    color: white;
    padding: 2rem 1rem 1rem;
    text-align: center;
    border-radius: 0 0 4px 4px;
}

.modal-caption p {
    margin: 0;
    padding: 0;
}

#modal-title {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

#modal-counter {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Адаптивный дизайн */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1rem;
    }

    .modal-prev,
    .modal-next {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
        padding: 0.5rem;
    }

    .modal-prev {
        left: 0.5rem;
    }

    .modal-next {
        right: 0.5rem;
    }

    .modal-close {
        top: -40px;
        font-size: 2rem;
    }

    .modal-content {
        height: 60vh;
    }
}

@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }

    .modal-prev,
    .modal-next {
        width: 35px;
        height: 35px;
        font-size: 1.2rem;
        padding: 0.25rem;
    }

    .modal-close {
        top: -35px;
        font-size: 1.8rem;
    }

    .modal-content {
        height: 50vh;
    }

    .modal-caption {
        padding: 1.5rem 0.75rem 0.75rem;
    }

    #modal-title {
        font-size: 1rem;
    }

    #modal-counter {
        font-size: 0.8rem;
    }
}

/* Печать */
@media print {
    .gallery-grid {
        display: none;
    }
}
