/* Анимация лоадера */

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

    100% {
        transform: rotate(360deg);
    }
}

/* Скрываем изображение пока оно загружается */
.modal-content img {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-content img.loaded {
    opacity: 1;
}

/* Оверлей модального окна */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

/* Заголовок модалки + крестик */

.modal-header {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    z-index: 1001;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 20px;
}

/* Левая колонка (пустая, чтобы центр был центр) */
.modal-left {
    justify-self: start;
}

/* Центр */
.modal-counter-wrapper {
    justify-self: center;
}

/* Правая колонка — tools + close */
.modal-right {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-self: end;
}




.modal-close {
    background: rgba(122, 31, 50, 0.8);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.modal-close:hover {
    background: var(--marsala);
}

.modal-nav:focus,
.modal-close:focus {
    outline: 2px solid var(--marsala-light);
    outline-offset: 2px;
}

/* Кнопки навигации */

.modal-nav {
    background: rgba(122, 31, 50, 0.8);
    border: none;
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1001;
}

.modal-nav:hover {
    background: var(--marsala);
}

.modal-prev {
    left: 20px;
}

.modal-next {
    right: 20px;
}

.modal-nav svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Счётчик */

.modal-counter {
    color: white;
    font-size: 14px;
    min-width: 60px;
    text-align: center;
}

.modal-counter-wrapper {
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    color: white;
}

/* Лоадер в модалке */

.modal-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1002;
    display: none;
    text-align: center;
}

.modal-loading.active {
    display: block;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(122, 31, 50, 0.3);
    border-top: 3px solid var(--marsala-light);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: relative;
}

.loading-spinner::after {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top: 3px solid var(--marsala-light);
}

.loading-percentage {
    margin-top: 12px;
    font-size: 14px;
    color: var(--marsala-light);
    font-weight: 500;
    letter-spacing: 0.05em;
    min-height: 20px;
}

.modal-tools {
    display: flex;
    gap: 8px;
    margin-right: 8px;
    z-index: 20;
}

.modal-tool-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    background: rgba(10, 24, 21, 0.75);
    border: 1px solid rgba(241, 156, 171, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
    transition: all 0.2s ease;
}

.modal-tool-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--text-main);
    pointer-events: none;
}

.modal-tool-btn:hover {
    background: rgba(122, 31, 50, 0.85);
    border-color: var(--marsala-light);
    transform: scale(1.07);
}

.modal-tool-btn:active {
    transform: scale(0.94);
}


@media (max-width: 768px) {
    .modal-overlay {
        backdrop-filter: none;
        /* чуть более плотный фон вместо blur */
        background: rgba(0, 0, 0, 0.97);
    }

    .modal-content img {
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.7);
    }

    .modal-nav {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    .modal-prev {
        left: 10px;
    }

    .modal-next {
        right: 10px;
    }
}