.overlay-panel {
    $padding: var(--baseSpacing);
    $compactPadding: calc(#{$padding} - 7px);

    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-self: flex-end;
    margin-left: auto; // push to right edge
    background: var(--baseColor);
    height: 100%;
    width: 580px;
    max-width: 100%;
    word-wrap: break-word;
    @include shadowize();

    .overlay-panel-section {
        position: relative;
        width: 100%;
        margin: 0;
        padding: $padding;
        transition: box-shadow var(--baseAnimationSpeed);
        &:empty {
            display: none;
        }
        &:first-child {
            border-top-left-radius: inherit;
            border-top-right-radius: inherit;
        }
        &:last-child {
            border-bottom-left-radius: inherit;
            border-bottom-right-radius: inherit;
        }
        .btn {
            flex-grow: 0;
        }
    }

    img {
        max-width: 100%;
    }

    // header
    .panel-header {
        position: relative;
        z-index: 2;
        display: flex;
        flex-wrap: wrap;
        align-items:center;
        column-gap: 10px;
        row-gap: var(--baseSpacing);
        padding: $compactPadding $padding;
        & > * {
            margin-top: 0;
            margin-bottom: 0;
        }
        .btn-back {
            margin-left: -10px; // visual alignment
        }
        .overlay-close {
            $size: 35px;
            z-index: 3;
            outline: 0;
            position: absolute;
            right: 100%;
            top: 20px;
            margin: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: $size;
            height: $size;
            cursor: pointer;
            text-align: center;
            font-size: 1.6rem;
            line-height: 1;
            border-top-left-radius: 50%;
            border-bottom-left-radius: 50%;
            border-top-right-radius: 0;
            border-bottom-right-radius: 0;
            color: #fff;
            background: var(--primaryColor);
            opacity: 0.5;
            transition: opacity var(--baseAnimationSpeed);
            user-select: none;
            i {
                font-size: inherit;
            }
            &:hover,
            &:focus-visible,
            &:active {
                opacity: 0.7;
            }
            &:active {
                transition-duration: var(--activeAnimationSpeed);
                opacity: 1;
            }
        }
        .btn-close {
            margin-right: -10px;
        }
        .tabs-header {
            margin-bottom: -24px;
        }
    }

    // content
    .panel-content {
        @extend .content;
        z-index: auto; // not fixed to allow overlapping
        flex-grow: 1;
        overflow-x: hidden;
        overflow-y: auto; /* fallback */
        overflow-y: overlay;
        scroll-behavior: smooth;
        .tox-fullscreen & {
            z-index: 9;
        }
    }
    .panel-header ~ .panel-content {
        padding-top: 5px;
    }

    // footer
    .panel-footer {
        z-index: 2;
        column-gap: var(--smSpacing);
        display: flex;
        align-items:center;
        justify-content: flex-end;
        border-top: 1px solid var(--baseAlt2Color);
        padding: $compactPadding $padding;
    }

    // scroll markers
    &.scrollable {
        .panel-header {
            box-shadow: 0px 4px 5px 0px rgba(#000, 0.05);
        }
        .panel-footer {
            box-shadow: 0px -4px 5px 0px rgba(#000, 0.05);
        }
        &.scroll-top-reached .panel-header {
            box-shadow: none;
        }
        &.scroll-bottom-reached .panel-footer {
            box-shadow: none;
        }
    }

    // sizes
    &.overlay-panel-xl {
        width: 850px;
    }
    &.overlay-panel-lg {
        width: 700px;
    }
    &.overlay-panel-sm {
        width: 460px;
    }

    // popup style
    &.popup {
        height: auto;
        max-height: 100%;
        align-self: center;
        border-radius: var(--baseRadius);
        margin: 0 auto;
        .panel-footer {
            background: var(--bodyColor);
        }
    }
    &.hide-content {
        .panel-content {
            display: none;
        }
    }
    &.colored-header {
        .panel-header {
            background: var(--bodyColor);
            border-bottom: 1px solid var(--baseAlt1Color);
            .tabs-header {
                border-bottom: 0;
                .tab-item {
                    border: 1px solid transparent;
                    border-bottom: 0;
                    &:hover,
                    &:focus-visible {
                        background: var(--baseAlt1Color);
                    }
                    &:after {
                        content: none;
                        display: none;;
                    }
                }
                .tab-item.active {
                    background: var(--baseColor);
                    border-color: var(--baseAlt1Color);

                }
            }
        }
        .panel-header ~ .panel-content {
            padding-top: calc(var(--baseSpacing) - 5px);
        }
    }
    &.compact-header {
        .panel-header {
            row-gap: var(--smSpacing);
        }
    }
    &.full-width-popup {
        width: 100%;
    }
    &.preview {
        .panel-header {
            position: absolute;
            z-index: 99;
            box-shadow: none;
            .overlay-close {
                left: 100%;
                right: auto;
                border-top-left-radius: 0;
                border-bottom-left-radius: 0;
                border-top-right-radius: 50%;
                border-bottom-right-radius: 50%;
                i {
                    margin-right: 5px;
                }
            }
        }
        .panel-header,
        .panel-footer {
            padding: 10px 15px;
        }
        .panel-content {
            padding: 0;
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        // preview elements
        img {
            max-width: 100%;
            border-top-left-radius: var(--baseRadius);
            border-top-right-radius: var(--baseRadius);
        }
        object {
            position: absolute;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
        }

        // preview variants
        &.preview-image {
            width: auto;
            min-width: 320px;
            min-height: 300px;
            max-width: 75%;
            max-height: 90%;
            img {
                align-self: flex-start;
                margin: auto;
            }
        }

        &.preview-document,
        &.preview-video {
            width: 75%;
            height: 90%;
        }
        &.preview-audio {
            min-width: 320px;
            min-height: 300px;
            max-width: 90%;
            max-height: 90%;
        }
    }

    @media (max-width: 900px) {
        .overlay-panel-section {
            padding: var(--smSpacing);
        }
    }
}

.overlay-panel-container {
    display: flex;
    position: fixed;
    z-index: 1000;
    flex-direction: row;
    align-items: center;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
    outline: 0;
    .overlay {
        position: absolute;
        z-index: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        user-select: none;
        background: var(--overlayColor);
    }
    &.padded {
        padding: 10px;
    }
}

.overlay-panel-wrapper {
    position: relative;
    z-index: 1000;
    outline: 0;
}
