/* Oficina Portatil V75.42 - popups/erros dentro da viewport em iOS/Android */
:root{
  --op-mobile-popup-top: calc(env(safe-area-inset-top, 0px) + 12px);
}

@media (max-width: 820px), (hover: none) and (pointer: coarse){
  /* Toast principal do React: antes podia nascer abaixo/fora da area util. */
  body .toast{
    position: fixed !important;
    top: var(--op-mobile-popup-top) !important;
    bottom: auto !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-width: min(560px, calc(100vw - 24px)) !important;
    max-height: min(42dvh, 320px) !important;
    margin: 0 auto !important;
    overflow: auto !important;
    overscroll-behavior: contain;
    z-index: 2147483646 !important;
  }

  /* Elementos detectados em runtime como popup de erro/alerta. */
  [data-op-mobile-popup-top="1"]{
    position: fixed !important;
    top: var(--op-mobile-popup-top) !important;
    bottom: auto !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-width: min(560px, calc(100vw - 24px)) !important;
    max-height: calc(100dvh - var(--op-mobile-popup-top) - 24px) !important;
    margin: 0 auto !important;
    overflow: auto !important;
    overscroll-behavior: contain;
    z-index: 2147483646 !important;
  }

  /* Bibliotecas/overlays de alerta conhecidas. */
  .swal2-container,
  .Toastify__toast-container,
  [data-sonner-toaster],
  .apk-alert-container,
  .apk-alert,
  .app-alert,
  .error-toast,
  .error-popup,
  .alert-popup,
  .portal-toast{
    top: var(--op-mobile-popup-top) !important;
    bottom: auto !important;
  }

  /* Se o popup de erro usar uma camada modal, começa pelo topo útil,
     sem alterar modais normais de calculadora/quantidade. */
  [data-op-error-overlay="1"]{
    align-items: flex-start !important;
    justify-content: center !important;
    padding-top: var(--op-mobile-popup-top) !important;
    padding-bottom: 16px !important;
    overflow-y: auto !important;
  }
}
