/* ═════════════════════════════════════════════════════════════
   modal-core.css — UI-MODAL-LIFECYCLE-AND-ROUTE-CLEANUP-V1
   (2026-05-26)

   Canonical modal/slide-out chrome consumed by modalCore.js.
   Distinct from .emr-modal-* design-system rules so existing
   CSS-only consumers stay untouched.

   z-index slotting (REVISED 2026-07-01 — modals are TOPMOST chrome):
     10050 — backdrop  (above every drawer/overlay: settlement drawer
                        9998/9999, statementDetail backdrops 9999,
                        prefs 3000 — previously 1900/1910 buried
                        emrPrompt/emrConfirm under the settlement
                        slide-out + detail view; these are the values
                        the drawer's body.emr-stmt-drawer-open lift
                        already used, now the app-wide default)
     10060 — wrapper   (just above backdrop)
     10070 — drawer-owned prompts (statementDetailDrawer _promptOrigin)
     10100 — autocomplete dropdown (a picker inside a modal must drop
                        its list over that modal)
     99999 — toasts    (.emr-toast, preserved above everything)
   ═════════════════════════════════════════════════════════════ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 10050;
  animation: modalCoreFadeIn 140ms ease-out;
}

.modal-wrapper {
  position: fixed;
  z-index: 10060;
  background: var(--emr-modal-bg, var(--bg, #0b1220));
  color: var(--emr-text, var(--text, #fff));
  border: 1px solid var(--emr-card-border, var(--border, #2a3441));
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalCoreSlideIn 180ms ease-out;
  max-height: calc(100vh - 32px);
}

.modal-wrapper .modal-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

/* Variants — positioning. */
.modal-wrapper--centered {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.modal-wrapper--slide-right {
  top: 0;
  right: 0;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  animation: modalCoreSlideRight 200ms ease-out;
}
.modal-wrapper--slide-bottom {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 8px 8px 0 0;
  animation: modalCoreSlideUp 200ms ease-out;
}

/* Widths. */
.modal-wrapper--narrow   { width: 480px;  max-width: 96vw; }
.modal-wrapper--default  { width: 720px;  max-width: 96vw; }
.modal-wrapper--wide     { width: 1100px; max-width: 96vw; }
.modal-wrapper--full     { width: 96vw;   max-width: 96vw; }

/* slide-right overrides default width so the side panel reads
   correctly at 720px without the centered transform. */
.modal-wrapper--slide-right.modal-wrapper--narrow  { width: 480px; }
.modal-wrapper--slide-right.modal-wrapper--default { width: 720px; }
.modal-wrapper--slide-right.modal-wrapper--wide    { width: 900px; }
.modal-wrapper--slide-right.modal-wrapper--full    { width: 96vw;  }

/* Body scroll lock — keep the underlying page from scrolling
   while a modal is open. */
body.modal-open {
  overflow: hidden;
}

/* Mobile responsive override: collapse everything to a near-
   fullscreen experience on narrow viewports. */
@media (max-width: 640px) {
  .modal-wrapper--centered,
  .modal-wrapper--slide-right,
  .modal-wrapper--slide-bottom {
    top: 0; left: 0; right: 0; bottom: 0;
    transform: none;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}

@keyframes modalCoreFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modalCoreSlideIn {
  from { opacity: 0; transform: translate(-50%, -48%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}
@keyframes modalCoreSlideRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0);    }
}
@keyframes modalCoreSlideUp {
  from { transform: translate(-50%, 100%); }
  to   { transform: translate(-50%, 0);    }
}
