.modal-dialog .modal-content {
    min-height: auto;
}
/* Let modals grow to the full viewport height minus Bootstrap's
   .modal-dialog margins (1.75rem top + bottom on sm-and-up) instead of
   capping at 80vh, which left tall modals scrolling inside unused space. */
.modal-dialog:not(.modal-dialog-slideout) .modal-content {
    max-height: calc(100vh - 3.5rem);
}

.modal-content {
    background-color: var(--modal-background-color);
    color: var(--modal-text-color);
    border: 0;
}
.modal-content .modal-header {
    padding: 1rem;
    border-bottom-color: var(--separator-color);
}
.modal-content .modal-header .close {
    color: var(--modal-text-color);
    line-height: var(--text-line-height-2xl); /* 1.75rem; */
    margin: 0;
    padding: 0;
}
.modal-content .modal-header .modal-title {
    color: var(--modal-title-color);
    font-size: var(--text-size-2xl);
    font-weight: var(--font-weight-light);
    line-height: var(--text-line-height-2xl);
    letter-spacing: 0;
}
.modal-content .modal-header .modal-subtitle {
    font-size: var(--text-size-base);
    font-weight: var(--font-weight-light);
    line-height: var(--text-line-height-base);
    margin-top: 4px;
    padding-top: 4px;
    margin-bottom: 0;
    margin-left: 3px;
}
.modal-content .modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}
.modal-dialog:not(.modal-dialog-slideout) .modal-body {
    height: fit-content;
}

/* WCAG 1.4.4 / 1.4.10: a zoomed window is shorter than these dialogs.
   Let the box grow and scroll Bootstrap's .modal overlay instead. Do not
   make the box a scroller: Select2 attaches its menu to .modal-content,
   and an overflow box clips that menu, dropdowns and listboxes at its
   edge. The header and footer stick to the overlay's edges so Close /
   Create / Continue stay on screen. Scrollable dialogs keep Bootstrap's
   own cap with a scrolling body. */
.modal-dialog:not(.modal-dialog-slideout):not(.modal-dialog-scrollable) .modal-content {
    max-height: none;
}

.modal-dialog:not(.modal-dialog-slideout) .modal-header,
.modal-dialog:not(.modal-dialog-slideout) .modal-footer {
    position: sticky;
    z-index: 2;
}

/* Sticky bars need a solid fill so scrolled content does not show
   through. Zero specificity: a dialog that colors its own header or
   footer (AI Chat Settings, auto TTS settings) keeps that color. A bar
   directly inside the box takes the box's color; a bar nested in a
   form or wrapper uses the theme color. */
:where(.modal-dialog:not(.modal-dialog-slideout)) :where(.modal-header, .modal-footer) {
    background-color: var(--modal-background-color);
}

:where(.modal-dialog:not(.modal-dialog-slideout) .modal-content) > :where(.modal-header, .modal-footer) {
    background-color: inherit;
}

.modal-dialog:not(.modal-dialog-slideout) .modal-header {
    top: 0;
}

.modal-dialog:not(.modal-dialog-slideout) .modal-footer {
    bottom: 0;
}

@media (max-width: 767px) {
    /* Stay in the middle of the window. A fixed side margin pinned the
       box to the left at 250% and 300%. Do not shrink the content to its
       text either; that cut the search button off the field. The box
       never grows past its dialog (x-modal writes an inline width). */
    .modal-dialog:not(.modal-dialog-slideout) {
        margin-left: auto;
        margin-right: auto;
    }

    .modal-dialog:not(.modal-dialog-slideout) .modal-content {
        width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 575px) {
    /* From 576px up Bootstrap's 500px / 300px dialog widths already fit,
       so only cap the width where Bootstrap has no limit. */
    .modal-dialog:not(.modal-dialog-slideout) {
        width: auto;
        max-width: calc(100vw - 1rem);
    }
}

.modal-content .modal-tabs {
    bottom: 0px;
    margin: 1rem 1rem 0 1rem;
}
.modal-content .tab-content {
    margin: 0 -1rem -1rem -1rem;
    padding: 24px 1.5rem 24px 1.5rem;
    font-weight: var(--font-weight-light);
}
.modal-content .tab-content p {
    margin-bottom: .5rem;
}
.modal-content .tab-content form label {
    margin-bottom: -.5rem;
    margin-top: .5rem;
}
.modal-content .tab-content form .errors label {
    line-height: 1.5rem;
    font-style: italic;
}
.modal-content .tab-content form .errors .error-list {
    line-height: 1.5rem;
}
.modal-content .tab-content .input-group-text {
    border-right: none;
}

.modal-content label {
    font-weight: var(--font-weight-regular);
}
.modal-content .form-control,
.modal-content .input-group .input-group-text {
    background: transparent;
}

.modal-content .modal-footer .modal-status {
    font-weight: var(--font-weight-light);
    display: flex;
    justify-content: center;
    flex-direction: column;
    flex-grow: 1;
}

.modal-content .modal-footer {
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: var(--separator-color);
    padding: 1rem;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-end;
    align-items: center;
    align-content: center;
}
.modal-content .modal-footer .btn:last-child:not(.btn-link) {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}
.modal-content .modal-footer .btn.btn-primary:last-child {
    padding-left: 2.5rem;
    padding-right: 2.5rem;
}
.modal-content .modal-footer .btn:not(:last-child) {
    margin-right: 1.5rem;
}
.modal-content .modal-footer .btn.btn-secondary {
    border: none;
}

.modal .jstree-default .jstree-wholerow-clicked {
    background: var(--modal-nav-link-background-color-selected);
    border-left: 5px solid var(--modal-nav-link-left-border-color-selected);
}
.modal .jstree-default .jstree-wholerow-hovered {
    background-color: var(--modal-nav-link-background-color-hover);
}
.modal .jstree-hovered, .modal .jstree-clicked {
    z-index: 1;
}

.modal-content .btn.copy img {
    height: 21px;
    margin-right: 4px;
}
.modal-content .text-sm {
    font-size: 85%;
}
.modal-new {
    cursor: pointer;
}
.modal .close:focus {
    box-shadow: 0 0 0 1.5px var(--sp-element-focus-ring-color);
}

@media (max-width: 600px) {
    .modal {
        min-height: 100%;
        max-height: 100%;
        height: 100%;
        margin: 0;
        border-radius: 0;
    }
    .modal-dialog {
        min-height: 100%;
        max-height: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        border-radius: 0;
    }
    .modal-dialog .modal-content {
        min-height: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
    }
    .modal-footer > div, .modal-footer button {
        margin-top: 0.25rem;
        margin-bottom: 0.25rem;
    }
    .modal-footer button.close-modal {
        margin-top: 0.5rem;
    }
}
