$icon-size: 24px;

// This generate classes layer-1, layer-2, ..., layer-10.
@mixin generate-layers($nbr-layers, $base) {
    @for $i from 1 through $nbr-layers {
        &.layer-#{$i} {
            z-index: $base + ($i - 1) * 20;
        }
    }
}

.modal-backdrop,
.modal-container {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;

    &.prompt-backdrop {
        width: 100%;
        height: 100%;
    }

    .modal-container,
    .modal-container + .modal-backdrop {
        top: calc((100vh - 100%) / -2);
        left: calc((100vw - 100%) / -2);

        &.mod-stick-bottom {
            bottom: 0;
        }
    }

    &.mod-stick-bottom {
        .modal-container,
        .modal-container + .modal-backdrop {
            top: calc((100vh - 95%) / -2);
        }
    }
}

.modal-backdrop {
    z-index: $base-backdrop-z-index;
    background: rgb(var(--deprecated-purple-blue-rgb) / $transparency-1);
    opacity: 1;
    transition: all 0.3s;

    @include generate-layers(10, $base-backdrop-z-index);

    &.--react-modal {
        opacity: 0;
    }

    &.prompt-backdrop {
        position: absolute;
        opacity: 0.5;

        .mask {
            position: fixed;
            inset: 0;
        }
    }

    &.opened {
        opacity: 1;
    }

    &.clear,
    &.closed {
        opacity: 0;
    }

    &.closed {
        visibility: hidden;
    }
}

.modal-container {
    z-index: $base-modal-z-index;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none; // Required to allow clicking through the modal-container on the modal-backdrop. Known issue: wont work on IE 10.

    @include generate-layers(10, $base-modal-z-index);

    &:not(.--react-modal) {
        visibility: hidden;
    }

    &.opening,
    &.opened {
        visibility: visible;

        > .modal-content {
            opacity: 1;
        }
    }

    .modal-content {
        position: relative;
        display: flex;
        flex-direction: column;
        width: $modal-width;
        height: $modal-height;
        transform: translate3d(0, 0, 0); // Required for drag and drop positioning with dragula inside the modal.
        opacity: 0;
        pointer-events: auto; // Required to reverse "pointer-events: none" effects on modal-content. Known issue: wont work on IE 10.
    }

    &.mod-medium > .modal-content {
        width: $modal-medium-width;
        height: $modal-medium-height;
    }

    &.mod-big > .modal-content {
        width: $modal-big-width;
        height: $modal-big-height;
    }

    // need to be after other mod to combine with other below
    &.mod-width-small > .modal-content {
        width: $modal-form-width-small + 2 * $header-padding;
    }

    &.mod-stick-bottom {
        align-items: flex-end;

        > .modal-content {
            height: $modal-height-stick;

            > .modal-footer {
                border-radius: 0;
            }
        }

        &.mod-medium > .modal-content {
            height: $modal-medium-height-stick;
        }

        &.mod-big > .modal-content {
            height: $modal-big-height-stick;
        }
    }

    &.mod-fade-in-scale > .modal-content,
    &.closed.mod-fade-in-scale > .modal-content {
        transform: scale(0.7);
        transition: all 0.3s;
    }

    &.opened.mod-fade-in-scale > .modal-content {
        transform: scale(1);
    }

    &.mod-slide-in-bottom > .modal-content,
    &closed.mod-slide-in-bottom > .modal-content {
        transform: translate3d(0, 20%, 0);
        transition: all 0.3s;
    }

    &.opened.mod-slide-in-bottom > .modal-content {
        transform: translate3d(0, 0, 0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    height: $modal-header-height;
    padding: 0 $header-padding;
    color: var(--white);
    background-color: var(--white);
    border-radius: $border-radius $border-radius 0 0;

    &:not(.mod-no-border-bottom) {
        border-bottom: $default-border;
    }

    &.mod-success {
        background-color: var(--success-60);
    }

    &.mod-warning {
        background-color: var(--warning-70);
    }

    &.mod-critical {
        background-color: var(--critical-70);
    }

    &.mod-info {
        background-color: var(--info-60);
    }

    h1 {
        overflow: hidden;
        line-height: 30px;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    &.mod-success h4,
    &.mod-warning h4,
    &.mod-critical h4,
    &.mod-info h4 {
        color: var(--white);
    }

    .small-close {
        position: absolute;
        top: -($icon-size + 10px);
        right: 0;
        color: var(--white);
        cursor: pointer;
    }
}

.modal-body {
    flex-basis: 0;
    flex-grow: 1;
    overflow: auto;
    background-color: var(--white);
    -webkit-overflow-scrolling: touch;

    .tab-content {
        height: 100%;
    }
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: $modal-footer-padding;
    overflow: hidden;
    background-color: var(--white);
    border-top: $default-border;
    border-radius: 0 0 $border-radius $border-radius;

    &.mod-small {
        padding: $modal-footer-small-padding;
    }
}

.modal-radio-button {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-bottom: 21px;
}
