/* Общий стиль затемнения */
.modal-backdrop {
    z-index: 1055;
    position: fixed;
    inset: 0;
    background: light-dark(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.5));
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Модалка базовая */
.modal {
    --modal-max-width: 80dvw;
    --modal-max-height: 80dvh;
    --modal-bg-color: var(--fnd-surface-1);

    width: var(--modal-width);
    max-width: var(--modal-max-width);
    max-height: var(--modal-max-height);

    z-index: 1056;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) translateY(20px);
    background-color: var(--modal-bg-color);
    border-radius: var(--shape-xl);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease,
    transform 0.3s ease;
    overflow-y: auto;
    display: flex;
}

.modal.dimmer {
    --modal-bg-color: var(--fnd-surface-2);
}

/* Когда open - показываем */
.modal[open] {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) translateY(0);
}

/* Размеры */
.modal.compact {
    --modal-width: 500px;
}

.modal.medium {
    --modal-width: 700px;
}

.modal.fullscreen, .modal.fullfullscreen {
    --modal-width: 100dvw;
    --modal-max-width: 100dvw;
    --modal-max-height: 100dvh;

    height: 100dvh;

    top: 0;
    left: 0;
    border-radius: 0;
}

.modal.right {
    --modal-width: 400px;
    --modal-max-width: 400px;
    --modal-max-height: calc(100dvh - 40px);

    height: 100dvh;

    top: 20px;
    left: unset;
    right: 20px;
    border-radius: var(--shape-xl);
}

.modal > .modal-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: var(--modal-max-height);
    padding: 20px 20px var(--inset-bottom-or-20) 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* для плавного скролла на iOS */
}

.modal > .modal-content > .modal-footer {
    position: sticky;
    bottom: 0;
    padding-top: 20px;
    margin-top: auto;
}

@media (min-width: 993px) {
    .modal.fullscreen, .modal.fullfullscreen, .modal.right {
        transform: none !important;
    }
}

/* Мобильная версия: bottom sheet */
@media (max-width: 992px) {
    .modal, .modal.compact, .modal.medium {
        --modal-max-width: 100dvw;
        --modal-max-height: 90dvh;

        top: auto !important;
        left: 50% !important;;
        bottom: 0;
        transform: translateX(-50%) translateY(100%);
        transition: transform 0.3s ease, opacity 0.3s ease;

        border-radius: var(--shape-xxl) var(--shape-xxl) 0 0;
    }

    .modal.fullscreen, .modal.right {
        --modal-width: 100dvw;
        --modal-max-width: 100dvw;
        --modal-max-height: 90dvh;
        height: unset;
        transform: translateX(-50%) translateY(100%);

        border-radius: var(--shape-xxl) var(--shape-xxl) 0 0;
    }

    .modal.fullfullscreen {
        --modal-width: 100dvw;
        --modal-max-width: 100dvw;
        --modal-max-height: 100dvh;
        height: 100dvh;
        transform: translateX(-50%) translateY(100%);
    }

    .modal[open] {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .modal, .modal.compact, .modal.medium {
        --modal-width: 100dvw;
        --modal-max-width: 100dvw;
        --modal-max-height: 90dvh;
    }
}