/* Global modal overlay unification (loaded after Vite bundles). */

html.app-has-governed-modal,
body.app-has-governed-modal {
    overflow: hidden !important;
    overscroll-behavior: none;
    scrollbar-gutter: stable;
}

/* All modal mask layers must share same visual effect. */
body .modal > .modal-overlay,
body .modal-overlay,
.modal-backdrop,
.app-transient-overlay.app-inline-overlay,
.app-self-overlay-modal,
[data-app-modal-self-overlay="1"],
body > [data-app-modal-legacy-wrapper="1"] > [data-app-modal-self-overlay="1"],
.accounting-modal,
#accounting-detail-modal,
.case-12315-detail-modal,
#complaint-letter-template-modal,
.import-cases-modal__overlay,
.mail-track-case-modal,
.case-type-stats-modal,
.recon-platform-login-modal,
.recon-offline-tracking-modal,
.recon-fingerprint-modal,
.modal-overlay.recon-offline-image-picker-modal,
.pdf-preview-modal .pdf-preview__overlay,
.modal-overlay.recon-offline-select-case-modal,
.case-detail-modal,
#doc-location-records-modal .modal-overlay,
#doc-location-logs-modal .modal-overlay,
.doc-location-modal .modal-overlay {
    background: var(--app-modal-mask-bg) !important;
    backdrop-filter: var(--app-modal-mask-filter) !important;
    -webkit-backdrop-filter: var(--app-modal-mask-filter) !important;
}

/* Unified overlay shell z-index. */
.app-transient-overlay.app-inline-overlay,
.app-self-overlay-modal,
[data-app-modal-self-overlay="1"],
body > [data-app-modal-legacy-wrapper="1"] > [data-app-modal-self-overlay="1"],
.accounting-modal,
#accounting-detail-modal,
.case-12315-detail-modal,
#complaint-letter-template-modal,
.mail-track-case-modal,
.case-type-stats-modal,
.recon-platform-login-modal,
.recon-offline-tracking-modal,
.recon-fingerprint-modal,
.case-detail-modal {
    z-index: var(--z-modal-max, 2147483210) !important;
}

/* Unified backdrop/panel stacking inside modal shells. */
body .modal {
    z-index: var(--z-modal-max, 2147483610) !important;
}

body .modal[hidden] {
    display: none !important;
    pointer-events: none !important;
}

body .modal.import-cases-modal:not(.is-open),
body .modal.notify-status-modal:not(.is-open) {
    display: none !important;
    pointer-events: none !important;
}

/* Complaint letter modal is already a full-screen shell.
   Soften nested confirm masks to avoid near-black stacked overlays. */
body.clt-modal-open .enhanced-confirm-overlay,
body.clt-modal-open .enhanced-confirm__overlay,
body.clt-modal-open #confirm-modal > .modal-overlay {
    background: rgba(11, 14, 17, 0.36) !important;
    backdrop-filter: blur(8px) saturate(1.04) !important;
    -webkit-backdrop-filter: blur(8px) saturate(1.04) !important;
}

body .modal > .modal-overlay,
body .modal-overlay,
.modal-backdrop,
.import-cases-modal__overlay,
.modal-overlay.recon-offline-image-picker-modal,
#doc-location-records-modal .modal-overlay,
#doc-location-logs-modal .modal-overlay,
.doc-location-modal .modal-overlay {
    z-index: var(--z-modal-backdrop-max, 2147483600) !important;
}

body .modal .modal-container,
[data-app-modal-panel="1"],
.generic-modal-dialog,
.legal-modal,
.analytics-modal__container {
    position: relative;
    z-index: var(--z-modal-max, 2147483610) !important;
}

/* Keep tool prompts above modal layers so they are never covered. */
#toast-container,
.toast-container,
.recon-sync-progress-container,
.progress-toast,
.recon-sync-progress-toast,
.undo-toast,
.undo-history-panel,
#location-change-notification {
    z-index: var(--z-modal-preview-panel, 2147483647) !important;
}

.help-tooltip,
.due-date-tooltip,
.case-stats-chart-tooltip,
.operation-tips-popup,
.operation-tips-popup-complaint,
.operation-tips-popup-id,
.app-popup-select-menu,
.local-helper-guide,
[data-popper-placement],
[data-role="tooltip"],
[role="tooltip"],
.tooltip,
.tooltip-text {
    z-index: var(--z-modal-preview-panel, 2147483647) !important;
}

/* File preview should fully take over the viewport.
   Hide floating helper/tool panels that otherwise leak above the preview shell. */
body.app-file-preview-open .site-notification-panel,
body.app-file-preview-open #chat-widget,
body.app-file-preview-open .undo-history-panel,
body.app-file-preview-open .undo-toast,
body.app-file-preview-open #location-change-notification,
body.app-file-preview-open .help-tooltip,
body.app-file-preview-open .due-date-tooltip,
body.app-file-preview-open .case-stats-chart-tooltip,
body.app-file-preview-open .operation-tips-popup,
body.app-file-preview-open .operation-tips-popup-complaint,
body.app-file-preview-open .operation-tips-popup-id,
body.app-file-preview-open .app-popup-select-menu,
body.app-file-preview-open .local-helper-guide,
body.app-file-preview-open [data-popper-placement],
body.app-file-preview-open [data-role="tooltip"],
body.app-file-preview-open [role="tooltip"],
body.app-file-preview-open .tooltip,
body.app-file-preview-open .tooltip-text {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Governor authoritative rules:
   if a root modal has its own direct .modal-overlay, shell must stay transparent
   and only the child overlay renders the mask. */
body .modal[data-governed-modal-overlay="1"] {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    z-index: var(--z-modal-max, 2147483610) !important;
}

body .modal[data-governed-modal-overlay="1"] > .modal-overlay[data-governed-modal-overlay="1"] {
    position: fixed !important;
    inset: 0 !important;
    background: var(--app-modal-mask-bg-base, rgba(0, 0, 0, 0.66)) !important;
    backdrop-filter: var(--app-modal-mask-filter-base, blur(14px) saturate(1.02)) !important;
    -webkit-backdrop-filter: var(--app-modal-mask-filter-base, blur(14px) saturate(1.02)) !important;
    z-index: var(--z-modal-backdrop-max, 2147483600) !important;
}

body .modal[data-governed-modal-overlay="1"] .modal-container {
    position: relative;
    z-index: var(--z-modal-max, 2147483610) !important;
}

body .modal[data-governed-modal-overlay="1"].app-stacked-modal {
    z-index: var(--z-modal-stacked-panel, 2147483647) !important;
}

body .modal[data-governed-modal-overlay="1"].app-stacked-modal > .modal-overlay[data-governed-modal-overlay="1"] {
    background: var(--app-modal-mask-bg-stacked, rgba(0, 0, 0, 0.24)) !important;
    backdrop-filter: var(--app-modal-mask-filter-stacked, blur(10px) saturate(1.02)) !important;
    -webkit-backdrop-filter: var(--app-modal-mask-filter-stacked, blur(10px) saturate(1.02)) !important;
    z-index: var(--z-modal-stacked-backdrop, 2147483646) !important;
}

body .modal[data-governed-modal-overlay="1"].app-stacked-modal .modal-container {
    z-index: var(--z-modal-stacked-panel, 2147483647) !important;
}

/* Complaint case detail opened from relation picker should stack above the picker shell. */
body > [data-app-modal-self-overlay="1"].app-stacked-modal {
    z-index: var(--z-modal-stacked-panel, 2147483647) !important;
    background: var(--app-modal-mask-bg-stacked, rgba(0, 0, 0, 0.24)) !important;
    backdrop-filter: var(--app-modal-mask-filter-stacked, blur(10px) saturate(1.02)) !important;
    -webkit-backdrop-filter: var(--app-modal-mask-filter-stacked, blur(10px) saturate(1.02)) !important;
}

body > [data-app-modal-self-overlay="1"].app-stacked-modal [data-app-modal-panel="1"] {
    position: relative;
    z-index: var(--z-modal-stacked-panel, 2147483647) !important;
}

body > [data-app-modal-legacy-wrapper="1"] > [data-app-modal-self-overlay="1"].app-stacked-modal {
    z-index: var(--z-modal-stacked-panel, 2147483647) !important;
    background: var(--app-modal-mask-bg-stacked, rgba(0, 0, 0, 0.24)) !important;
    backdrop-filter: var(--app-modal-mask-filter-stacked, blur(10px) saturate(1.02)) !important;
    -webkit-backdrop-filter: var(--app-modal-mask-filter-stacked, blur(10px) saturate(1.02)) !important;
}

body > [data-app-modal-legacy-wrapper="1"] > [data-app-modal-self-overlay="1"].app-stacked-modal [data-app-modal-panel="1"] {
    position: relative;
    z-index: var(--z-modal-stacked-panel, 2147483647) !important;
}
