/* Unified CRM modal system. Kept separate from the compiled theme so plugin
 * updates cannot silently restore legacy Bootstrap modal styling. */
:root {
    --rise-modal-surface: #fff;
    --rise-modal-surface-muted: #f8f9fb;
    --rise-modal-border: #e2e7ef;
    --rise-modal-text: #273247;
    --rise-modal-muted: #7d8796;
    --rise-modal-primary: var(--bs-primary, #697eef);
    --rise-modal-shadow: 0 24px 70px rgba(29, 39, 61, .22), 0 5px 18px rgba(29, 39, 61, .08);
}

body.theme-dark,
body[data-bs-theme="dark"] {
    --rise-modal-surface: #272b35;
    --rise-modal-surface-muted: #222731;
    --rise-modal-border: #39414f;
    --rise-modal-text: #eef2f8;
    --rise-modal-muted: #a6afbd;
    --rise-modal-shadow: 0 28px 80px rgba(0, 0, 0, .52), 0 5px 20px rgba(0, 0, 0, .28);
}

/* The dimmed background is shared by AJAX forms, confirmations and plugins. */
.modal-backdrop {
    background: #111827;
}

.modal-backdrop.show,
.modal-backdrop.in {
    opacity: .5;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* Do not touch technical fullscreen canvases and the dedicated search view. */
.modal:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) {
    padding: 12px;
}

.modal.fade:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) {
    transform: translateY(8px) scale(.994);
    transition: transform .16s ease-out;
}

.modal.show:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) {
    transform: none;
}

.modal:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) > .modal-content {
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    overflow: hidden;
    border: 1px solid var(--rise-modal-border) !important;
    border-radius: 16px !important;
    background: var(--rise-modal-surface) !important;
    color: var(--rise-modal-text);
    box-shadow: var(--rise-modal-shadow) !important;
}

/* Some file/document previews intentionally provide their own transparent
 * canvas while still using the shared AJAX modal shell. */
.modal > .modal-dialog.custom-bg-modal > .modal-content {
    overflow: visible;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

.modal:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) > .modal-content > .modal-header,
.modal:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) > .modal-content #ajaxModalContent .modal-header {
    position: relative;
    min-height: 62px;
    padding: 16px 64px 16px 20px;
    border-bottom: 1px solid var(--rise-modal-border) !important;
    background: var(--rise-modal-surface) !important;
}

.modal:not(.global-search-modal) .modal-header .modal-title {
    margin: 0;
    overflow: hidden;
    color: var(--rise-modal-text);
    font-size: 17px;
    font-weight: 700;
    line-height: 1.35;
    text-overflow: ellipsis;
}

.modal:not(.global-search-modal) .modal-header .btn-close {
    position: absolute;
    top: 14px;
    right: 14px;
    left: auto;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    margin: 0 !important;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background-color: var(--rise-modal-surface-muted);
    background-size: 12px;
    opacity: .7;
    transition: background-color .14s ease, opacity .14s ease, transform .14s ease;
}

.modal:not(.global-search-modal) .modal-header .btn-close:hover,
.modal:not(.global-search-modal) .modal-header .btn-close:focus-visible {
    background-color: rgba(var(--bs-primary-rgb, 105, 126, 239), .13);
    box-shadow: none;
    opacity: 1;
    transform: scale(1.04);
}

body.theme-dark .modal:not(.global-search-modal) .modal-header .btn-close,
body[data-bs-theme="dark"] .modal:not(.global-search-modal) .modal-header .btn-close {
    filter: invert(1) grayscale(100%) brightness(180%);
}

.modal:not(.global-search-modal) .modal-body {
    max-height: calc(100vh - 174px);
    max-height: calc(100dvh - 174px);
    padding: 22px 24px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--rise-modal-surface) !important;
    color: var(--rise-modal-text);
    scrollbar-width: thin;
}

.modal:not(.global-search-modal) .modal-body > .container-fluid {
    padding-right: 0;
    padding-left: 0;
}

.modal:not(.global-search-modal) .modal-footer {
    min-height: 66px;
    gap: 8px;
    padding: 13px 20px !important;
    border-top: 1px solid var(--rise-modal-border) !important;
    background: var(--rise-modal-surface-muted) !important;
}

.modal:not(.global-search-modal) .modal-footer .btn {
    min-height: 39px;
    margin: 0 !important;
    padding: 8px 15px;
    border-radius: 9px;
    font-weight: 600;
}

.modal:not(.global-search-modal) .modal-body .form-control,
.modal:not(.global-search-modal) .modal-body .form-select,
.modal:not(.global-search-modal) .modal-body .select2-container .select2-choice,
.modal:not(.global-search-modal) .modal-body .select2-container .select2-choices {
    border-radius: 10px;
}

.modal:not(.global-search-modal) .modal-body .form-control:focus,
.modal:not(.global-search-modal) .modal-body .form-select:focus {
    border-color: var(--rise-modal-primary);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb, 105, 126, 239), .11);
}

.modal:not(.global-search-modal) .modal-body .form-group {
    border-color: var(--rise-modal-border);
}

/* Compact and deliberate confirmation dialogs, matching Mail. */
#confirmationModal > .modal-dialog,
#mailbox-delete-confirm > .modal-dialog {
    width: min(420px, calc(100% - 24px));
    margin-right: auto;
    margin-left: auto;
}

#confirmationModal .modal-body,
#mailbox-delete-confirm .modal-body {
    min-height: 92px;
    padding: 24px;
    color: var(--rise-modal-text);
    font-size: 14px;
    line-height: 1.6;
}

#confirmationModal .modal-footer,
#mailbox-delete-confirm .modal-footer {
    justify-content: flex-end;
}

/* Alerts are the other global floating surface in RISE. */
.app-alert {
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .2) !important;
    border-radius: 13px !important;
    box-shadow: 0 16px 42px rgba(31, 43, 67, .2) !important;
}

.app-alert .btn-close {
    width: 30px;
    height: 30px;
    margin: -5px -5px -5px 10px;
    padding: 0;
    border-radius: 9px;
    background-size: 11px;
}

@media (max-width: 767px) {
    .modal:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) {
        display: flex;
        width: auto;
        max-width: none;
        min-height: calc(100vh - 16px);
        min-height: calc(100dvh - 16px);
        margin: 8px;
        padding: 0;
        align-items: center;
    }

    .modal:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen) > .modal-content {
        width: 100%;
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
        border-radius: 15px !important;
    }

    .modal:not(.global-search-modal) .modal-header {
        min-height: 56px !important;
        padding: 13px 58px 13px 15px !important;
    }

    .modal:not(.global-search-modal) .modal-header .btn-close {
        top: 11px;
        right: 11px;
        left: auto;
    }

    .modal:not(.global-search-modal) .modal-header .modal-title {
        font-size: 16px;
    }

    .modal:not(.global-search-modal) .modal-body {
        max-height: calc(100vh - 146px);
        max-height: calc(100dvh - 146px);
        padding: 17px 15px;
    }

    .modal:not(.global-search-modal) .modal-footer {
        min-height: 58px;
        padding: 10px 12px !important;
    }

    .modal:not(.global-search-modal) .modal-footer .btn {
        min-height: 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .modal.fade:not(.global-search-modal) > .modal-dialog:not(.modal-fullscreen),
    .modal:not(.global-search-modal) .modal-header .btn-close {
        transition: none;
    }
}
