/*
 * pandabu V2.0.4 RC16.217
 * MOBILE MODAL LAYER / REAUTH VISIBILITY FIX
 *
 * Problem:
 * RC16.213 raised bottom-nav/FAB to z-index 125/120 while the generic modal
 * backdrop stayed at z-index 50. Mobile modals could therefore sit BEHIND
 * the navigation and their action buttons were hidden.
 *
 * Fix:
 * - every genuine modal sits above bottom-nav + FAB
 * - dynamic viewport height (dvh) for iOS/PWA
 * - modal content itself scrolls when space is tight
 * - safe areas remain respected
 * - desktop behavior remains unchanged
 */
@media (max-width:899px){
  body.pandabu-authenticated .modal-backdrop{
    position:fixed!important;
    inset:0!important;
    z-index:220!important;
    height:100dvh!important;
    max-height:100dvh!important;
    box-sizing:border-box;
    overflow:hidden!important;
    padding:
      max(0px, env(safe-area-inset-top))
      0
      0!important;
    align-items:flex-end!important;
    justify-content:center!important;
  }

  body.pandabu-authenticated .modal-backdrop > .modal{
    position:relative;
    z-index:221!important;
    width:min(100%,620px)!important;
    max-height:calc(100dvh - max(10px, env(safe-area-inset-top)))!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    box-sizing:border-box;
    padding-bottom:calc(24px + env(safe-area-inset-bottom))!important;
  }

  /* Critical actions remain reachable even on short screens. */
  body.pandabu-authenticated .modal-backdrop > .modal .actions{
    position:sticky;
    bottom:calc(-24px - env(safe-area-inset-bottom));
    z-index:3;
    background:var(--surface);
    padding-top:10px;
    padding-bottom:calc(8px + env(safe-area-inset-bottom));
    margin-bottom:calc(-24px - env(safe-area-inset-bottom));
  }

  /* The global navigation is visually behind the modal and not clickable. */
  body.pandabu-authenticated .modal-backdrop ~ .bottom-nav,
  body.pandabu-authenticated .modal-backdrop ~ .fab{
    pointer-events:none;
  }
}
