/* ===================================================================== */
/*                         Универсальное модальное окно                  */
/* ===================================================================== */

.universal-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.universal-modal.show {
    opacity: 1;
    visibility: visible;
}

/* ЕДИНОЕ ПРАВИЛО ДЛЯ ДИАЛОГА - ФИКСИРОВАННАЯ ШИРИНА 400px */
.universal-modal-dialog {
    position: fixed;
    top: 0;
    left: 88px;
    width: 400px;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    transform: translateX(-100%);
    transition: transform 0.6s ease-out;
    z-index: 10001;
}

.universal-modal.show .universal-modal-dialog {
    transform: translateX(0);
}

.universal-modal-content {
    background-color: var(--color-1);
    border: 1px solid var(--color-5);
    border-radius: 0;
    border-left: none;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* ===== ЗАГОЛОВОК ===== */
.universal-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-5);
    background-color: var(--color-1);
    flex-shrink: 0;
    min-height: 70px;
}

.universal-modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-2);
    margin: 0;
    flex: 1;
}

.universal-modal-header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Кнопка "Назад" */
.universal-modal-back {
    background: transparent;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-2);
    opacity: 0.6;
    transition: all var(--tran-03);
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    flex-shrink: 0;
}

.universal-modal-back:hover {
    opacity: 1;
    background-color: var(--color-4);
    transform: translateX(-2px);
}

.universal-modal-back:focus {
    outline: 2px solid var(--color-3);
    outline-offset: 2px;
    opacity: 1;
}

.universal-modal-back:active {
    transform: translateX(-2px) scale(0.95);
}

.universal-modal-back svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5;
}

/* Кнопка "Закрыть" */
.universal-modal-close {
    background: transparent;
    border: none;
    padding: 8px;
    margin: -8px -8px -8px 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-2);
    opacity: 0.6;
    transition: all var(--tran-03);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    flex-shrink: 0;
}

.universal-modal-close:hover {
    opacity: 1;
    background-color: var(--color-4);
}

.universal-modal-close:focus {
    outline: 2px solid var(--color-3);
    outline-offset: 2px;
    opacity: 1;
}

.universal-modal-close:active {
    transform: scale(0.95);
}

.universal-modal-close svg {
    width: 18px;
    height: 18px;
}

.universal-modal-close:not(:has(svg))::before {
    content: '×';
    font-weight: bold;
    font-size: 1.5rem;
}

/* ===== ТЕЛО МОДАЛЬНОГО ОКНА ===== */
.universal-modal-body {
    background-color: #f5f5f5;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    transition: opacity 0.2s ease;
}

.universal-modal-body.transitioning {
    opacity: 0.5;
}

/* ===== ПОДВАЛ ===== */
.universal-modal-footer {
    border-top: 1px solid var(--color-5);
    padding: 1rem 1.25rem;
    background-color: var(--color-1);
    flex-shrink: 0;
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* ===== СОСТОЯНИЯ ЗАГРУЗКИ ===== */
.universal-modal-loading {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 40px 20px;
    position: relative;
}

.universal-modal-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loader-spinner {
    position: relative;
    width: 50px;
    height: 50px;
}

.spinner-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
}

.spinner-ring:nth-child(1) {
    border-top-color: var(--color-3);
    animation-delay: 0s;
}

.spinner-ring:nth-child(2) {
    border-right-color: var(--color-6);
    animation-delay: 0.3s;
}

.spinner-ring:nth-child(3) {
    border-bottom-color: var(--color-2);
    animation-delay: 0.6s;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-text {
    font-size: 14px;
    color: var(--color-2);
    opacity: 0.7;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* Старый лоадер для совместимости */
.universal-modal-body.universal-modal-loading:not(:has(.universal-modal-loader))::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.universal-modal-body.universal-modal-loading:not(:has(.universal-modal-loader))::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-5);
    border-top: 3px solid var(--color-3);
    border-radius: 50%;
    animation: spin-old 1s linear infinite;
    z-index: 2;
}

@keyframes spin-old {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ===== СОСТОЯНИЕ ОШИБКИ ===== */
.universal-modal-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 40px 20px;
    text-align: center;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--color-9);
}

.universal-modal-error h4 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-9);
}

.universal-modal-error p {
    margin: 0 0 20px 0;
    font-size: 14px;
    color: var(--color-2);
    opacity: 0.7;
    line-height: 1.5;
}

.btn-retry {
    background: var(--color-2);
    color: var(--color-1);
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--tran-03);
}

.btn-retry:hover {
    background: #2a2a2a;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 33, 33, 0.3);
}

/* ===== ПУСТОЕ СОСТОЯНИЕ ===== */
.universal-modal-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--color-2);
    opacity: 0.6;
}

.universal-modal-empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.universal-modal-empty-text {
    font-size: 1rem;
    margin: 0;
}

/* ===== АНИМАЦИИ ===== */
.universal-modal-body > *:not(.universal-modal-loader):not(.universal-modal-error) {
    animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== ПРОКРУТКА ===== */
.universal-modal-body::-webkit-scrollbar {
    width: 6px;
}

.universal-modal-body::-webkit-scrollbar-track {
    background: var(--color-4);
}

.universal-modal-body::-webkit-scrollbar-thumb {
    background: var(--color-5);
    border-radius: 3px;
}

.universal-modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--color-2);
}

/* ===== ДОСТУПНОСТЬ ===== */
.universal-modal button:focus,
.universal-modal input:focus,
.universal-modal select:focus,
.universal-modal textarea:focus {
    outline: 2px solid var(--color-3);
    outline-offset: 2px;
}

/* ===== АДАПТИВНОСТЬ ===== */

/* Планшеты */
@media (max-width: 768px) {
    .universal-modal-dialog {
        left: 0;
        width: 400px;
    }

    .universal-modal-content {
        border-left: 1px solid var(--color-5);
    }

    .universal-modal-header {
        padding: 0.75rem 1rem;
        min-height: 60px;
    }

    .universal-modal-title {
        font-size: 1rem;
    }

    .universal-modal-body {
        padding: 0;
    }

    .universal-modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .universal-modal-footer .btn {
        width: 100%;
        margin: 0;
    }

    .universal-modal-loading {
        min-height: 150px;
        padding: 30px 15px;
    }

    .loader-spinner {
        width: 40px;
        height: 40px;
    }

    .loader-text {
        font-size: 13px;
    }
}

/* Мобильные телефоны */
@media (max-width: 480px) {
    .universal-modal-dialog {
        left: 0;
        width: 100%;
    }

    .universal-modal-header {
        padding: 0.75rem 1rem;
        min-height: 60px;
    }

    .universal-modal-back {
        min-width: 28px;
        min-height: 28px;
        padding: 6px;
    }

    .universal-modal-close {
        min-width: 28px;
        min-height: 28px;
        padding: 6px;
    }

    .universal-modal-title {
        font-size: 1rem;
    }

    .universal-modal-back svg {
        width: 18px;
        height: 18px;
    }

    .universal-modal-header-buttons {
        gap: 4px;
    }

    .universal-modal-body {
        padding: 0.75rem;
    }

    .universal-modal-footer {
        padding: 0.5rem 0.75rem;
    }

    .universal-modal-loading {
        min-height: 120px;
        padding: 20px 10px;
    }

    .loader-spinner {
        width: 35px;
        height: 35px;
    }

    .spinner-ring {
        border-width: 2px;
    }
}