/* V1.23.9 — modais sempre abaixo da barra fixa no mobile.
   Mantém o cabeçalho do modal e o botão de fechar sempre acessíveis. */

@media (max-width:700px), (min-width:701px){
  :root{
    --v1239-modal-header-height:var(--campaign-header-height,60px);
    --v1239-modal-top-gap:6px;
    --v1239-modal-side-gap:8px;
    --v1239-modal-bottom-gap:8px;
  }

  /* Na página pública não há controlador de pilha; o modal aberto precisa
     ficar acima da barra fixa. No Admin, o modal-stack mantém a ordem. */
  body:not(.admin-dedicated-page) .modal.open,
  body:not(.admin-dedicated-page) .account-sheet-modal.open,
  body:not(.admin-dedicated-page) .account-orders-modal.open,
  body:not(.admin-dedicated-page) dialog[open],
  body:not(.admin-dedicated-page) [role="alertdialog"].open{
    z-index:2147483647!important;
  }

  body .modal.open,
  body .account-sheet-modal.open,
  body .account-orders-modal.open,
  body dialog[open],
  body [role="alertdialog"].open{
    position:fixed!important;
    inset:0!important;
    box-sizing:border-box!important;
    align-items:flex-start!important;
    justify-content:center!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch!important;
    padding-top:calc(var(--v1239-modal-header-height) + var(--v1239-modal-top-gap) + env(safe-area-inset-top,0px))!important;
    padding-right:max(var(--v1239-modal-side-gap),env(safe-area-inset-right,0px))!important;
    padding-bottom:max(var(--v1239-modal-bottom-gap),env(safe-area-inset-bottom,0px))!important;
    padding-left:max(var(--v1239-modal-side-gap),env(safe-area-inset-left,0px))!important;
  }

  body .modal.open > .modal-card,
  body .modal.open > .account-sheet-card,
  body .account-sheet-modal.open > .account-sheet-card,
  body .account-orders-modal.open > .account-orders-modal-card,
  body dialog[open] > .modal-card,
  body [role="alertdialog"].open > .modal-card{
    position:relative!important;
    inset:auto!important;
    box-sizing:border-box!important;
    width:100%!important;
    margin:0 auto!important;
    max-height:calc(
      100dvh - var(--v1239-modal-header-height) - var(--v1239-modal-top-gap) - var(--v1239-modal-bottom-gap)
      - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px)
    )!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch!important;
    scroll-padding-top:64px!important;
    transform:none!important;
  }

  body .modal.open > .modal-card > .modal-head,
  body .modal.open > .account-sheet-card > .account-sheet-head,
  body .account-sheet-modal.open > .account-sheet-card > .account-sheet-head,
  body .account-orders-modal.open > .account-orders-modal-card > .account-orders-head,
  body dialog[open] > .modal-card > .modal-head,
  body [role="alertdialog"].open > .modal-card > .modal-head{
    position:sticky!important;
    top:0!important;
    z-index:2147483600!important;
    isolation:isolate!important;
  }

  body .modal.open .modal-head .icon-btn,
  body .modal.open .account-sheet-head .icon-btn,
  body .modal.open .account-orders-head .icon-btn,
  body dialog[open] .modal-head .icon-btn,
  body [role="alertdialog"].open .modal-head .icon-btn{
    position:relative!important;
    z-index:2147483601!important;
    flex:0 0 auto!important;
    pointer-events:auto!important;
    touch-action:manipulation!important;
  }

  /* Os modais de cadastro e edição costumam ser longos. O cabeçalho não
     encolhe, e o conteúdo rola abaixo dele. */
  body #authModal.open > .modal-card,
  body #completeProfileModal.open > .modal-card,
  body #campaignEditorModal.open > .modal-card{
    display:block!important;
  }

  body #authModal.open .modal-head,
  body #completeProfileModal.open .modal-head,
  body #campaignEditorModal.open .modal-head{
    min-height:48px!important;
    flex:0 0 auto!important;
  }
}
