dialog {
    background: var(--modal-bg-color);
    color: var(--modal-text-color);
    box-shadow: 0 0 16px -4px #000000, 0 0 0 max(100vw, 100vh) rgba(0,0,0,0.7);
    border-color: var(--modal-border-color);
    border-width: 4px 1px 1px 1px;
    border-style: solid;
    border-radius: 3px;
    padding: 0;
    z-index: 999;
    pointer-events: initial;
    position: fixed;
    top: 0;
    left: 0;
    overflow: auto;
    margin: var(--vertical-margin) auto;
    max-height: calc(100vh - var(--vertical-margin) * 2);

    body:has(&[open]) {
        pointer-events: none;
        user-select: none;
    }

    @media (min-width: 700px) {
        --vertical-margin: 10vh;
        min-height: 100px;
        width: calc(100vw - 60px);
        max-width: 640px;
    }

    @media (max-width: 699px) {
        --vertical-margin: 2vh;
        width: calc(100vw - 30px);
    }

    @media (max-width: 500px) {
        &.large {
            height: 100%;
        }
    }

    &::backdrop {
        background-color: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    &:has(+ dialog) {
        box-shadow: none;
        pointer-events: none;
    }

    &[open] {
        display: flex;
        flex-direction: column;
        user-select: text;

        ~ dialog::backdrop {
            background-color: transparent;
            backdrop-filter: initial;
            -webkit-backdrop-filter: initial;
        }
    }

    &.confirm {
        max-width: 400px !important;
    }

    > header {
        position: sticky;
        top: 0;
        z-index: 10;
        width: 100%;
        background-color: var(--modal-bg-color);
        min-height: 32px;
        display: flex;
        align-items: center;
        flex-shrink: 0;

        h3 {
            margin: 8px 16px;
        }
    }

    > .content {
        margin: 8px 16px 16px 16px;
        flex: 1 0 auto;
        display: flex;
        flex-direction: column;
        gap: 8px;

        footer > * {
            margin-top: 8px;
            margin-bottom: 8px;
        }
    }

    .tabs > header {
        margin-bottom: 8px;
    }

    button.close {
        flex: 0 0 auto;
        margin-left: auto;
        cursor: pointer;
        aspect-ratio: 1;
        background: none;
        align-self: stretch;
        border-radius: 0 0 0 3px;
    }

    h3,
    h4,
    p {
        margin: 0;
    }

    > p {
        margin: 16px;
    }

    p.margin {
        margin: 16px 0 8px 0;
    }

    footer {
        background-color: var(--modal-bg-color);
        display: flex;
        align-items: flex-end;
        justify-content: flex-end;
        gap: 8px;
        position: sticky;
        bottom: 0;
        margin-top: auto;
        z-index: 1;

        [type="submit"],
        .submit {
            margin-left: auto;
        }

        &.non-sticky {
            position: initial;
            margin-top: 16px;
        }
    }

    > footer {
        padding: 16px;
    }

    @media (max-width: 640px) {
        &.mobile-fullscreen {
            margin: 0;
            max-width: initial;
            max-height: initial;
            width: 100%;
            height: 100%;
        }
    }

    @media (max-width: 640px) {
        &.mobile-full-width {
            max-width: initial;
            width: 100%;
        }
    }

    form {
        display: flex;
        flex-direction: column;
        gap: 8px;
        flex-grow: 1;
    }

    .post-edit label,
    .custom-css-form label {
        flex-grow: 1;
        display: flex;
    }

    .post-edit textarea,
    .custom-css-form textarea {
        flex-grow: 1;
        width: 100%;
    }

    @media (min-width: 500px) {
        .post-edit textarea,
        .custom-css-form textarea {
            min-height: 300px;
        }
    }

    label.no-grow {
        flex-grow: 0;
    }

    .edit-history {
        .message {
            margin: 8px 0;
            font-size: 1rem;
            white-space: pre-line;
        }

        .single-edit:not(:last-of-type) {
            margin-bottom: 8px;
            padding-bottom: 8px;
            border-bottom: 1px solid var(--h-ruler-color);
        }
    }

    &.lightbox {
        background: none;
        border: 0;
        box-shadow: none;
        height: 100%;
        max-width: initial;
        justify-content: center;
        --vertical-margin: 2vh;

        .file {
            max-height: 100%;
        }

        > header {
            background: none;
        }

        button.close {
            background-color: var(--modal-bg-color);
            border-radius: 3px;
            margin-bottom: 8px;
        }

        > .content {
            margin: 0;
            min-height: 0;
            flex: 0 1 auto;
        }

        img,
        video {
            object-fit: contain;
            background: #000;
        }
    }

    .overlay.ajax-loading {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        justify-content: center;
        background-color: #00000099;
        z-index: 11;
    }
}