/**
 * Modal
 */

@use '../../../css/icons';

.modal-wrapper {
    background: var(--modal--wrapper--background, rgba(0, 0, 0, 0.75));
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2000;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;

    .modal {
        text-align: left; // Ensures proper alignment if parent has it changed
        list-style: none;
        line-height: var(--modal--line-height, var(--line-height));
        display: block;
        width: calc(
            100% - var(--modal--margin-left, var(--margin-left)) - var(
                    --modal--margin-right,
                    var(--margin-right)
                )
        );
        max-width: var(--modal--width, 480px);
        border-radius: var(
            --modal--border-radius,
            var(--modal--border-top-left-radius, var(--border-top-left-radius))
                var(--modal--border-top-right-radius, var(--border-top-right-radius))
                var(--modal--border-bottom-right-radius, var(--border-bottom-right-radius))
                var(--modal--border-bottom-left-radius, var(--border-bottom-left-radius))
        );
        box-shadow: var(
            --modal--box-shadow,
            var(--modal--box-shadow-x-offset, var(--box-shadow-offset-x))
                var(--modal--box-shadow-y-offset, var(--box-shadow-offset-y))
                var(--modal--box-shadow-blur-radius, var(--box-shadow-blur-radius))
                var(--modal--box-shadow-spread-radius, var(--box-shadow-spread-radius))
                var(--modal--box-shadow-color, var(--box-shadow-color))
        );

        > .modal-header {
            display: flex;
            justify-content: space-between;
            background: var(--modal--header--background, var(--modal--background));
            border-style: var(
                --modal--header--border-style,
                var(
                        --modal--header--border-top-style,
                        var(--modal--border-top-style, var(--border-top-style))
                    )
                    var(
                        --modal--header--border-right-style,
                        var(--modal--border-right-style, var(--border-right-style))
                    )
                    var(
                        --modal--header--border-bottom-style,
                        var(--modal--border-bottom-style, var(--border-bottom-style))
                    )
                    var(
                        --modal--header--border-left-style,
                        var(--modal--border-left-style, var(--border-left-style))
                    )
            );
            border-width: var(
                --modal--header--border-width,
                var(
                        --modal--header--border-top-width,
                        var(--modal--border-top-width, var(--border-top-width))
                    )
                    var(
                        --modal--header--border-right-width,
                        var(--modal--border-right-width, var(--border-right-width))
                    )
                    var(
                        --modal--header--border-bottom-width,
                        var(--modal--border-bottom-width, var(--border-bottom-width))
                    )
                    var(
                        --modal--header--border-left-width,
                        var(--modal--border-left-width, var(--border-left-width))
                    )
            );
            border-color: var(
                --modal--header--border-color,
                var(
                        --modal--header--border-top-color,
                        var(--modal--border-top-color, var(--border-top-color))
                    )
                    var(
                        --modal--header--border-right-color,
                        var(--modal--border-right-color, var(--border-right-color))
                    )
                    var(
                        --modal--header--border-bottom-color,
                        var(--modal--border-bottom-color, var(--border-bottom-color))
                    )
                    var(
                        --modal--header--border-left-color,
                        var(--modal--border-left-color, var(--border-left-color))
                    )
            );
            padding: var(
                --modal--header--padding,
                var(--modal--header--padding-top, var(--modal--padding-top, var(--padding-top)))
                    var(
                        --modal--header--padding-right,
                        var(--modal--padding-right, var(--padding-right))
                    )
                    var(
                        --modal--header--padding-bottom,
                        var(--modal--padding-bottom, var(--padding-bottom))
                    )
                    var(
                        --modal--header--padding-left,
                        var(--modal--padding-left, var(--padding-left))
                    )
            );
            color: var(--modal--header--color, var(--modal--color));

            > .close {
                display: flex;
                justify-content: center;
                align-items: center;
                height: 1.5rem;
                width: 1.5rem;
                line-height: 1.5rem;
                font-size: 0.5rem;
                cursor: pointer;
                padding: 0;
                border: 0;
                transition: background-color 0.3s ease;
                background-color: transparent;
                border-radius: var(
                    --modal--border-radius,
                    var(--modal--border-top-left-radius, var(--border-top-left-radius))
                        var(--modal--border-top-right-radius, var(--border-top-right-radius))
                        var(--modal--border-bottom-right-radius, var(--border-bottom-right-radius))
                        var(--modal--border-bottom-left-radius, var(--border-bottom-left-radius))
                );

                > .icon {
                    mask-image: url('#{icons.$ink-times}');
                    -webkit-mask-image: url('#{icons.$ink-times}');
                    mask-position: center center;
                    -webkit-mask-position: center center;
                    mask-repeat: no-repeat;
                    -webkit-mask-repeat: no-repeat;
                    mask-size: calc(var(--modal--font-size, var(--font-size)) / 2);
                    -webkit-mask-size: calc(var(--modal--font-size, var(--font-size)) / 2);
                    background-color: var(--modal--header--color, var(--modal--color));
                    width: var(--modal--font-size, var(--font-size));
                    height: var(--modal--font-size, var(--font-size));
                }

                &:hover,
                &:focus {
                    outline: none;
                    background-color: rgba(0, 0, 0, 0.1);
                }

                &:active {
                    background-color: rgba(0, 0, 0, 0.15);
                }
            }
        }

        > .modal-body {
            display: flex;
            flex-direction: row;
            background: var(--modal--body--background, var(--modal--background));
            color: var(--modal--body--color, var(--modal--color));
            border-style: var(
                --modal--body--border-style,
                var(
                        --modal--body--border-top-style,
                        var(--modal--border-top-style, var(--border-top-style))
                    )
                    var(
                        --modal--body--border-right-style,
                        var(--modal--border-right-style, var(--border-right-style))
                    )
                    var(
                        --modal--body--border-bottom-style,
                        var(--modal--border-bottom-style, var(--border-bottom-style))
                    )
                    var(
                        --modal--body--border-left-style,
                        var(--modal--border-left-style, var(--border-left-style))
                    )
            );
            border-width: var(
                --modal--body--border-width,
                var(
                        --modal--body--border-top-width,
                        var(--modal--border-top-width, var(--border-top-width))
                    )
                    var(
                        --modal--body--border-right-width,
                        var(--modal--border-right-width, var(--border-right-width))
                    )
                    var(
                        --modal--body--border-bottom-width,
                        var(--modal--border-bottom-width, var(--border-bottom-width))
                    )
                    var(
                        --modal--body--border-left-width,
                        var(--modal--border-left-width, var(--border-left-width))
                    )
            );
            border-color: var(
                --modal--body--border-color,
                var(
                        --modal--body--border-top-color,
                        var(--modal--border-top-color, var(--border-top-color))
                    )
                    var(
                        --modal--body--border-right-color,
                        var(--modal--border-right-color, var(--border-right-color))
                    )
                    var(
                        --modal--body--border-bottom-color,
                        var(--modal--border-bottom-color, var(--border-bottom-color))
                    )
                    var(
                        --modal--body--border-left-color,
                        var(--modal--border-left-color, var(--border-left-color))
                    )
            );
            padding: var(
                --modal--body--padding,
                var(--modal--body--padding-top, var(--modal--padding-top, var(--padding-top)))
                    var(
                        --modal--body--padding-right,
                        var(--modal--padding-right, var(--padding-right))
                    )
                    var(
                        --modal--body--padding-bottom,
                        var(--modal--padding-bottom, var(--padding-bottom))
                    )
                    var(
                        --modal--body--padding-left,
                        var(--modal--padding-left, var(--padding-left))
                    )
            );

            .modal-icon {
                margin-right: var(
                    --modal--icon--margin-right,
                    var(--modal--body--padding-right, var(--padding-right))
                );
            }

            .modal-content {
                width: 100%;
                display: block;
            }
        }

        > .modal-footer {
            background: var(--modal--footer--background, var(--modal--background));
            color: var(--modal--footer--color, var(--modal--color));
            border-style: var(
                --modal--footer--border-style,
                var(
                        --modal--footer--border-top-style,
                        var(--modal--border-top-style, var(--border-top-style))
                    )
                    var(
                        --modal--footer--border-right-style,
                        var(--modal--border-right-style, var(--border-right-style))
                    )
                    var(
                        --modal--footer--border-bottom-style,
                        var(--modal--border-bottom-style, var(--border-bottom-style))
                    )
                    var(
                        --modal--footer--border-left-style,
                        var(--modal--border-left-style, var(--border-left-style))
                    )
            );
            border-width: var(
                --modal--footer--border-width,
                var(
                        --modal--footer--border-top-width,
                        var(--modal--border-top-width, var(--border-top-width))
                    )
                    var(
                        --modal--footer--border-right-width,
                        var(--modal--border-right-width, var(--border-right-width))
                    )
                    var(
                        --modal--footer--border-bottom-width,
                        var(--modal--border-bottom-width, var(--border-bottom-width))
                    )
                    var(
                        --modal--footer--border-left-width,
                        var(--modal--border-left-width, var(--border-left-width))
                    )
            );
            border-color: var(
                --modal--footer--border-color,
                var(
                        --modal--footer--border-top-color,
                        var(--modal--border-top-color, var(--border-top-color))
                    )
                    var(
                        --modal--footer--border-right-color,
                        var(--modal--border-right-color, var(--border-right-color))
                    )
                    var(
                        --modal--footer--border-bottom-color,
                        var(--modal--border-bottom-color, var(--border-bottom-color))
                    )
                    var(
                        --modal--footer--border-left-color,
                        var(--modal--border-left-color, var(--border-left-color))
                    )
            );
            padding: var(
                --modal--footer--padding,
                var(--modal--footer--padding-top, var(--modal--padding-top, var(--padding-top)))
                    var(
                        --modal--footer--padding-right,
                        var(--modal--padding-right, var(--padding-right))
                    )
                    var(
                        --modal--footer--padding-bottom,
                        var(--modal--padding-bottom, var(--padding-bottom))
                    )
                    var(
                        --modal--footer--padding-left,
                        var(--modal--padding-left, var(--padding-left))
                    )
            );
        }

        > *:first-child {
            border-top-left-radius: var(
                --modal--border-top-left-radius,
                var(--border-top-left-radius)
            );
            border-top-right-radius: var(
                --modal--border-top-right-radius,
                var(--border-top-right-radius)
            );
        }

        > *:last-child {
            border-bottom-left-radius: var(
                --modal--border-bottom-left-radius,
                var(--border-bottom-left-radius)
            );
            border-bottom-right-radius: var(
                --modal--border-bottom-right-radius,
                var(--border-bottom-right-radius)
            );
        }

        > .modal-header + .modal-body,
        > .modal-header + .modal-footer,
        > .modal-body + .modal-footer,
        > .modal-body + .modal-body {
            border-top-width: 0;
        }
    }

    &.-fullscreen {
        display: block;

        > .modal {
            width: 100%;
            height: 100%;
            max-width: 100%;
            display: flex;
            flex-direction: column;

            > .modal-header {
                border-radius: var(--modal--fullscreen--header--border-radius, 0);
            }

            > .modal-body {
                border-radius: var(--modal--fullscreen--body--border-radius, 0);
                flex: 1;
                overflow: auto;
            }

            > .modal-footer {
                border-radius: var(--modal--fullscreen--footer--border-radius, 0);
            }
        }
    }

    &.-alert,
    &.-confirm,
    &.-prompt {
        > .modal {
            > .modal-footer {
                display: flex;
                justify-content: flex-end;

                .button + .button {
                    margin-left: var(--modal--footer--button--margin-left, var(--margin-left-1-2));
                }
            }
        }
    }
}
