.pty-modal,
.pty-panel {

    position: fixed;
    inset: 0;
    background: var(--overlay);
    backdrop-filter: saturate(180%) blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: zoom-out;
    animation: modal-fade-in 0.15s ease-out;

    & * { color: var(--text); }

    &.is-dialog {
        cursor: default;
    }

    &.is-top    { align-items: flex-start; }
    &.is-bottom { align-items: flex-end; }
    &.is-left   { align-items: stretch; justify-content: flex-start; }
    &.is-right  { align-items: stretch; justify-content: flex-end; }
    &.is-full   { align-items: stretch; justify-content: stretch; }

    &.is-top .pty-modal-box,
    &.is-bottom .pty-modal-box {
        max-width: none;
        width: 100%;
        border-radius: 0;
    }

    &.is-left .pty-modal-box,
    &.is-right .pty-modal-box {
        width: min(480px, 90vw);
        max-height: none;
        height: 100%;
        border-radius: 0;
    }

    &.is-full .pty-modal-box {
        max-width: none;
        width: 100%;
        max-height: none;
        height: 100%;
        border-radius: 0;
    }

    &.is-scrollable .pty-modal-box {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    &.is-scrollable .pty-modal-body {
        flex: 1 1 auto;
        overflow-y: auto;
    }

    &.is-carousel {
        align-items: stretch;
        padding: 0;
    }

    &.is-lightbox img {
        max-width: 90vw;
        max-height: 90vh;
        object-fit: contain;
        border-radius: var(--radius);
        cursor: default;
    }

    & .pty-modal-box {

        background: var(--header-bg);

        border-radius: var(--radius);

        max-width: 480px;
        width: 90%;
        max-height: 90vh;

        cursor: default;
        box-shadow: var(--box-shadow);

        animation: modal-drop-in 0.25s ease-out;

        &.is-closing {
            animation: modal-drop-out 0.2s ease-in forwards;
        }

        & .pty-modal-header {

            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid var(--border);

            padding: var(--padding);

            & strong {

                font-size: 24px;
                line-height: 36px;

            }

            & .pty-modal-close {

            }
        }

        & .pty-modal-body {

            padding: var(--padding);
            padding-bottom: 0;

            & .btn-group {

                display: flex;
                width: 100%;
                margin-bottom: var(--padding);

                & > button {
                    flex: 1 1 0;
                    min-width: 0;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                }
            }

            & .pty-modal-message {
                text-align: center;
                font-size: 20px;
                line-height: 30px;
            }

            & .pty-modal-attach {

                display: flex;
                justify-content: center;
                align-items: center;

            }

            & .fwd-selected {

                margin-bottom: var(--padding);
                display: flex;
                gap: var(--padding);

                & .fwd-pill {
                    padding: var(--padding);
                    background-color: var(--btn);

                    display: flex;
                    align-items: center;
                    gap: var(--padding);
                    border-radius: var(--badge-radius);
                }

            }

            & input {

            }

            & .dropdown-menu {

                position: absolute;
                top: 100%;
                left: 0;
                right: 0;
                width: auto !important;
                min-width: 0;
                margin: 0;
                max-height: 300px;
                overflow-y: auto;

                & a,
                & button {
                    padding: var(--padding);

                    & img {
                        width: var(--input-size);

                        transform: scale(.66);
                        border-radius: var(--radius);
                    }
                }
            }
        }

        & .pty-modal-footer {
            padding: var(--padding);
            display: flex;
            gap: var(--padding);
        }
    }

    & .pty-carousel {

        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        position: relative;

        & .pty-carousel-close {
            padding: var(--padding);
            margin: 0;
            width: auto;
            height: auto;
            min-width: var(--input-size);
            min-height: var(--input-size);

            position: absolute;
            top: var(--gap);
            right: var(--gap);
            z-index: 10;
            background: transparent;
            border-radius: var(--radius);

            opacity: .5;

            &:hover {
                background: var(--overlay);
                opacity: 1;
            }

            & * {
                padding: 0;
                margin: 0;
                color: var(--header-bg);
                font-size: 44px;
            }
        }

        & .pty-carousel-counter {
            position: absolute;
            top: var(--gap);
            left: 50%;
            transform: translateX(-50%);
            color: var(--header-bg);
            font-size: 24px;
            background: var(--overlay);
            padding: var(--padding);
            border-radius: var(--radius);
            z-index: 10;
        }

        & .pty-carousel-main {

            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;

            & img {
                max-width: 100%;
                max-height: 100%;
                object-fit: contain;
                border-radius: var(--radius);
            }

            & .pty-carousel-nav {
                padding: var(--padding);
                margin: 0;
                width: auto;
                height: auto;
                min-width: var(--input-size);
                min-height: var(--input-size);

                position: absolute;
                top: 50%;
                transform: translateY(-50%);
                background: transparent;
                color: var(--header-bg);
                border: none;
                border-radius: var(--radius);
                cursor: pointer;
                display: flex;
                align-items: center;
                justify-content: center;
                z-index: 5;
                transition: background 0.15s;
                opacity: .5;

                &:hover {
                    background: var(--overlay);
                    opacity: 1;
                }

                & * {
                    padding: 0;
                    margin: 0;
                    color: var(--header-bg);
                    font-size: 44px;
                }

                &.prev { left: var(--gap); }
                &.next { right: var(--gap); }

            }
        }

        & .pty-carousel-thumbs {
            display: flex;
            justify-content: center;
            align-items: center;

            gap: 4px;
            padding: 8px;
            overflow-x: auto;
            background: var(--overlay);
            flex-shrink: 0;
            scrollbar-width: thin;
            scrollbar-color: rgba(255,255,255,0.3) transparent;

            & .pty-carousel-thumb {
                flex-shrink: 0;
                width: 60px;
                height: 60px;
                border-radius: var(--radius);
                overflow: hidden;
                border: 2px solid transparent;
                cursor: pointer;
                padding: 0;
                background: none;
                opacity: 0.6;
                transition: opacity 0.15s, border-color 0.15s;

                &:hover {
                    opacity: .8;
                }

                &.active {

                    opacity: 1;
                }

                & img {
                    width: 100%;
                    height: 100%;
                    object-fit: cover;
                }
            }
        }
    }
}

@keyframes modal-drop-in {
    from {
        opacity: 0;
        transform: translateY(-24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modal-drop-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-24px);
    }
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}