.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.85);
    animation: modalOverlayIn 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Анимация появления */
@keyframes modalOverlayIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalContentIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Контент модального окна */
.modal-content {
    position: relative;
    width: 440px;
    max-width: 90vw;
    max-height: 90vh;
    background-color: var(--background-primary);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    animation: modalContentIn 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 0.1px solid var(--background-primary-hover);
}

@keyframes modalContentIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Заголовок модального окна */
.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--background-modifier-accent);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--background-secondary);
}

.modal-title {
    font-family: var(--font-main);
    font-size: 18px;
    font-weight: 700;
    color: var(--header-primary);
    line-height: 1.2;
    margin: 0;
}

.modal-subtitle {
    font-family: var(--font-main);
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

/* Кнопка закрытия */
.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10000;
    background: var(--background-secondary);
    border: none;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:hover {
    color: var(--text-normal);
    background-color: var(--background-modifier-hover);
}

.modal-close:active {
    transform: translateY(1px);
}

[data-theme="light"] .modal-close img {
    filter: brightness(0.5);
}

/* Тело модального окна */
.modal-body {
    padding: 20px;
    max-height: 50vh;
    overflow-y: auto;
}

/* Секции контента */
.modal-section {
    margin-bottom: 24px;
}

.modal-section:last-child {
    margin-bottom: 0;
}

.modal-section-title {
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

/* Текст и описания */
.modal-description {
    font-family: var(--font-main);
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 8px 0;
}

.modal-warning {
    background-color: var(--status-danger-muted);
    border-left: 3px solid var(--status-danger);
    padding: 12px;
    border-radius: 4px;
    margin: 12px 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.modal-warning-text {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Поля ввода и формы */
.modal-input-group {
    margin-bottom: 16px;
}

.modal-label {
    display: block;
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.modal-input {
    width: 100%;
    padding: 10px;
    background-color: var(--background-secondary);
    border: 1px solid var(--background-modifier-accent);
    border-radius: 4px;
    color: var(--text-normal);
    font-family: var(--font-main);
    font-size: 14px;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--highlight-color);
}

.modal-input:hover:not(:focus) {
    border-color: var(--background-accent);
}

.modal-input::placeholder {
    color: var(--text-muted);
}

.modal-input-error {
    border-color: var(--status-danger) !important;
}

.modal-error-message {
    font-size: 12px;
    color: var(--status-danger);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Нижняя часть модального окна */
.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--background-modifier-accent);
    background-color: var(--background-secondary);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Кнопки */
.modal-button {
    padding: 8px 16px;
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    min-width: 96px;
    text-align: center;
}

.modal-button-primary {
    background-color: var(--brand);
    color: white;
}

.modal-button-primary:hover {
    background-color: var(--brand-hover);
}

.modal-button-secondary {
    background-color: var(--background-secondary);
    color: var(--text-normal);
    border: 1px solid var(--background-modifier-accent);
}

.modal-button-secondary:hover {
    background-color: var(--background-modifier-hover);
    border-color: var(--background-accent);
}

.modal-button-danger {
    background-color: var(--danger);
    color: white;
}

.modal-button-danger:hover {
    background-color: var(--danger-hover);
}

.modal-button-danger:active {
    background-color: var(--danger-active);
}

.modal-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.modal-button:active:not(:disabled) {
    transform: translateY(1px);
}

/* Состояния загрузки */
.modal-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.modal-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--background-modifier-accent);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: modalSpinner 1s linear infinite;
}

@keyframes modalSpinner {
    to {
        transform: rotate(360deg);
    }
}

/* Модификаторы размеров */
.modal-sm {
    width: 360px;
}

.modal-md {
    width: 440px;
}

.modal-lg {
    width: 600px;
}

.modal-xl {
    width: 800px;
}

/* Прокрутка */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background-color: var(--background-modifier-accent);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background-color: var(--background-accent);
}

/* Списки и элементы */
.modal-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.modal-list-item {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-list-item:hover {
    background-color: var(--background-modifier-hover);
}

.modal-list-item.selected {
    background-color: var(--selected);
}

.modal-list-item-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.modal-list-item-title {
    font-size: 14px;
    color: var(--text-normal);
    font-weight: 500;
}

.modal-list-item-description {
    font-size: 12px;
    color: var(--text-muted);
}

/* Аватар и иконки */
.modal-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
}

.modal-icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Группы элементов */
.modal-radio-group,
.modal-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-radio,
.modal-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.modal-radio:hover,
.modal-checkbox:hover {
    background-color: var(--background-modifier-hover-muted);
}

.modal-radio input,
.modal-checkbox input {
    margin: 0;
}

.modal-radio-label,
.modal-checkbox-label {
    font-size: 14px;
    color: var(--text-normal);
    cursor: pointer;
}

/* Разделители */
.modal-divider {
    height: 1px;
    background-color: var(--background-modifier-accent);
    margin: 16px 0;
    border: none;
}

/* Уведомления внутри модалки */
.modal-notification {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.modal-notification.success {
    background-color: var(--sucess-muted);
    border-left: 3px solid var(--success);
}

.modal-notification.warning {
    background-color: rgba(250, 168, 26, 0.1);
    border-left: 3px solid var(--status-warning);
}

.modal-notification.error {
    background-color: var(--status-danger-muted);
    border-left: 3px solid var(--status-danger);
}

/* Адаптивность */
@media (max-width: 768px) {
    .modal-content {
        width: 95vw;
        margin: 0;
        border-radius: 8px;
    }

    .modal-body {
        max-height: 50vh;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 12px;
    }

    .modal-button {
        width: 100%;
        min-width: auto;
    }
}

/* Темная тема по умолчанию */
.modal {
    color-scheme: dark;
}