/**
 * iOS PWA — viewport + modal overlay fixes.
 * UNLAYERED — load after mobile-admin-responsive.css.
 * Fixes white gap below app/modal and POS modal pushed up on iPhone standalone.
 */

@supports (height: 100dvh) {
  html,
  body.use-new-ui,
  body.use-new-ui #app {
    min-height: 100dvh;
  }
}

@media (max-width: 900px) {
  html,
  body.use-new-ui {
    width: 100%;
    min-height: 100%;
    min-height: -webkit-fill-available;
    margin: 0;
    overflow-x: hidden;
  }

  /* Scroll lock — overflow only; avoid body position:fixed (iOS PWA white gap) */
  html:has(body.use-new-ui.modal-open),
  html.hydra-modal-scroll-lock {
    overflow: hidden !important;
    height: 100% !important;
    height: 100dvh !important;
    height: -webkit-fill-available !important;
  }

  body.use-new-ui.modal-open {
    overflow: hidden !important;
    position: static !important;
    top: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
  }

  body.use-new-ui.modal-open #app,
  body.use-new-ui.modal-open .app.app-layout {
    overflow: hidden !important;
  }

  body.use-new-ui.modal-open #mobileOwnerBottomNav,
  body.use-new-ui.modal-open #mobileOwnerFab {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* Modal overlay — full dynamic viewport, safe-area on overlay only */
  body.use-new-ui #modal.modal,
  body.use-new-ui #modal.modal:not(.hidden) {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    height: -webkit-fill-available !important;
    min-height: 100dvh !important;
    min-height: -webkit-fill-available !important;
    max-height: 100dvh !important;
    max-height: -webkit-fill-available !important;
    margin: 0 !important;
    padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px)) !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
    transform: none !important;
  }

  body.use-new-ui #modal .modal-card,
  body.use-new-ui #modal .modal-content {
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px) !important;
    margin: 0 !important;
    overflow: hidden !important;
  }

  /* POS / order modal — full-bleed shell inside safe-area-padded overlay */
  body.use-new-ui #modal .modal-card.pos-modal,
  body.use-new-ui #modal .modal-content.pos-modal {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px) !important;
    border-radius: 16px !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  body.use-new-ui #modal .modal-card.pos-modal #modalForm,
  body.use-new-ui #modal .modal-card.pos-modal #modalForm.modal-body,
  body.use-new-ui #modal .modal-card.pos-modal #modalForm.order-pos-modal-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  body.use-new-ui #modal .modal-card.pos-modal .pos-shell,
  body.use-new-ui #modal .modal-card.pos-modal .order-pos-shell {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  body.use-new-ui #modal .modal-card.pos-modal .pos-main,
  body.use-new-ui #modal .modal-card.pos-modal .pos-main.pos-order-layout,
  body.use-new-ui #modal .modal-card.pos-modal .pos-order-layout.pos-real {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body.use-new-ui #modal .modal-card.pos-modal .pos-modal-footer {
    flex: 0 0 auto !important;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
  }

  /* POS suggest dropdowns — above modal scroll/overflow; iOS keyboard safe */
  body.use-new-ui #modal .modal-card.pos-modal .customer-search-wrapper,
  body.use-new-ui #modal .modal-card.pos-modal .product-search-wrapper {
    position: relative !important;
    overflow: visible !important;
  }

  body.use-new-ui #modal .modal-card.pos-modal .customer-search-wrapper.is-suggest-open,
  body.use-new-ui #modal .modal-card.pos-modal .product-search-wrapper.is-suggest-open {
    z-index: 10060 !important;
  }

  body.use-new-ui #modal .modal-card.pos-modal .pos-head-grid > label:first-child,
  body.use-new-ui #modal .modal-card.pos-modal .pos-global-search {
    overflow: visible !important;
  }

  body.use-new-ui #modal .modal-card.pos-modal #customerSuggest,
  body.use-new-ui #modal .modal-card.pos-modal #posProductSuggest {
    z-index: 10070 !important;
    max-height: min(42vh, 260px) !important;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.16) !important;
  }

  body.use-new-ui.pwa-standalone #modal.modal {
    height: 100dvh !important;
    height: -webkit-fill-available !important;
  }
}
