/*
 * popup-responsive.css
 * Site-wide safety net so every popup (Bootstrap modals, toasts, date pickers,
 * select2 dropdowns, custom dialogs) fits the viewport and works on phones.
 * Loaded last in every layout so it wins over library defaults.
 * Page-specific popups are tuned in their own stylesheets; this file only sets
 * limits (max sizes, scrolling, wrapping) and never sets desktop widths.
 */

/* ---------- Bootstrap modals: all viewports ---------- */
.modal {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal-content {
    max-width: 100%;
}

.modal-body img,
.modal-body video,
.modal-body iframe,
.modal-body canvas,
.modal-body svg {
    max-width: 100%;
}

.modal-body img,
.modal-body video {
    height: auto;
}

.modal-title {
    overflow-wrap: anywhere;
    min-width: 0;
}

.modal-header .close,
.modal-header .btn-close {
    flex-shrink: 0;
}

.modal-footer {
    flex-wrap: wrap;
    gap: .5rem;
}

.modal-footer > * {
    margin: 0;
}

/* Large / extra-large dialogs on tablets and small laptops. */
@media (max-width: 1199.98px) {
    .modal-xl {
        max-width: calc(100vw - 2rem);
    }
}

@media (max-width: 991.98px) {
    .modal-lg,
    .modal-xl {
        max-width: calc(100vw - 2rem);
    }
}

/* ---------- Phones ---------- */
@media (max-width: 575.98px) {
    .modal-dialog,
    .modal-dialog.modal-sm,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        /* !important beats inline style="max-width:900px" / width on dialogs */
        max-width: calc(100vw - 1rem) !important;
        width: auto !important;
        margin: .5rem auto !important;
    }

    .modal-dialog-centered {
        min-height: calc(100% - 1rem);
    }

    /* Keep header + footer visible and scroll only the body. */
    .modal-content:has(> .modal-body),
    .modal-content:has(> form > .modal-body) {
        max-height: calc(100vh - 1rem);
        max-height: calc(100dvh - 1rem);
        overflow: hidden;
    }

    .modal-content:has(> .modal-body) > .modal-body,
    .modal-content > form:has(> .modal-body) > .modal-body {
        overflow-y: auto;
        min-height: 0;
        flex: 1 1 auto;
    }

    .modal-content > form:has(> .modal-body) {
        display: flex;
        flex-direction: column;
        min-height: 0;
        max-height: calc(100vh - 1rem);
        max-height: calc(100dvh - 1rem);
    }

    /* Wide tables scroll sideways inside the body instead of pushing the dialog off screen. */
    .modal-body {
        overflow-x: auto;
        overflow-wrap: break-word;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: .875rem;
        padding-right: .875rem;
    }

    .modal-footer > .btn {
        flex: 1 1 auto;
    }

    /* Bigger close "x" tap target */
    .modal-header .close,
    .modal-header .btn-close {
        min-width: 40px;
        min-height: 40px;
        padding: .5rem;
        margin: -.5rem -.5rem -.5rem auto;
    }

    /* Touch-sized controls (and 16px inputs so iOS does not zoom on focus). */
    .modal .btn {
        min-height: 40px;
    }

    .modal input:not([type="checkbox"]):not([type="radio"]),
    .modal select,
    .modal textarea {
        font-size: 16px;
        max-width: 100%;
    }

    /* Bootstrap grid columns inside modals stack instead of squeezing. */
    .modal-body .row > [class*="col-"]:not([class*="col-sm"]):not([class*="col-12"]) {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ---------- Library popups ---------- */

/* Toastr notifications */
@media (max-width: 575.98px) {
    #toast-container > div {
        width: calc(100vw - 1.5rem) !important;
        max-width: calc(100vw - 1.5rem);
    }

    #toast-container.toast-top-right,
    #toast-container.toast-bottom-right,
    #toast-container.toast-top-left,
    #toast-container.toast-bottom-left {
        right: .75rem;
        left: .75rem;
    }
}

/* daterangepicker: stack the two calendars and keep the panel on screen */
.daterangepicker {
    max-width: calc(100vw - 1rem);
}

@media (max-width: 575.98px) {
    .daterangepicker {
        left: .5rem !important;
        right: .5rem !important;
        width: auto;
    }

    .daterangepicker .drp-calendar {
        float: none;
        max-width: none;
        width: 100%;
    }

    .daterangepicker .ranges {
        float: none;
        width: 100%;
    }
}

/* select2 dropdowns opened inside narrow screens / modals */
.select2-container--open .select2-dropdown {
    max-width: calc(100vw - 1rem);
}

/* Bootstrap dropdown menus and popovers */
.dropdown-menu {
    max-width: calc(100vw - 1rem);
}

@media (max-width: 575.98px) {
    .dropdown-menu {
        max-height: 70vh;
        overflow-y: auto;
    }

    .dropdown-item {
        white-space: normal;
    }
}

/* Cap only; never shrinks a popover that a page made wider on purpose. */
body .popover {
    max-width: calc(100vw - 1rem) !important;
}

/* Native <dialog> elements (zero specificity so page/app dialog rules still win) */
:where(dialog) {
    max-width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    overflow: auto;
    box-sizing: border-box;
}

/* Opt-in helper for custom overlays: add class="edspire-popup" to any panel. */
.edspire-popup {
    max-width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    overflow: auto;
    box-sizing: border-box;
}

/* Bootstrap 5 style close buttons used on a Bootstrap 4 site: give them a visible "x". */
.btn-close {
    box-sizing: content-box;
    width: 1em;
    height: 1em;
    padding: .25em;
    color: #000;
    background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center / 1em auto no-repeat;
    border: 0;
    border-radius: .25rem;
    opacity: .5;
    cursor: pointer;
}

.btn-close:hover,
.btn-close:focus {
    opacity: .85;
}

.btn-close-white {
    filter: invert(1) grayscale(100%) brightness(200%);
}
