/* Shared form sheets: reserve the status area and scroll the body, not actions.
   Full-screen document/photo viewers and public portals keep their own layout. */
@media screen and (max-width: 767.98px) {
  :root.ep-ios:not(#ep-ios-x) {
    --ep-modal-safe-top: max(24px, calc(env(safe-area-inset-top, 0px) + 12px));
    --ep-modal-safe-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 12px));
    --ep-modal-room: calc(var(--ep-modal-viewport-height, 100dvh) - var(--ep-modal-safe-top) - var(--ep-modal-safe-bottom));
  }

  :root.ep-ios:not(#ep-ios-x) :is(.iosn-modal:has(> .iosn-sheet), .ipg-sheet, .iose-sheet, .ixp-sheet:has(> .ixp-sheet-card)) {
    top: var(--ep-modal-viewport-top, 0px);
    bottom: auto;
    height: var(--ep-modal-viewport-height, 100dvh);
    box-sizing: border-box;
    padding: var(--ep-modal-safe-top) 0 0 !important;
    align-items: flex-end;
  }
  :root.ep-ios:not(#ep-ios-x) .iosn-modal:not(.isd-modal):has(> .iosn-sheet) { z-index: 10000; }
  :root.ep-ios:not(#ep-ios-x) :is(.iosn-modal > .iosn-sheet, .ipg-sheet > .ipg-sheet-card, .iose-sheet > .iose-sheet-card, .ixp-sheet > .ixp-sheet-card) {
    min-height: 0;
    max-height: 100% !important;
  }
  :root.ep-ios:not(#ep-ios-x) .ixp-sheet.is-sb-full > .ixp-sheet-card { height: 100% !important; }
  :root.ep-ios:not(#ep-ios-x) :is(.iosn-sheet-nav, .ipg-sheet-nav, .iose-sheet-nav, .ixp-sheet-nav) {
    position: relative;
    z-index: 2;
    min-height: 56px !important;
    flex-shrink: 0;
  }
  :root.ep-ios:not(#ep-ios-x) :is(.iosn-sheet-nav, .ipg-sheet-nav, .iose-sheet-nav, .ixp-sheet-nav) button {
    min-height: 44px !important;
    min-width: 44px !important;
    touch-action: manipulation;
  }
  :root.ep-ios:not(#ep-ios-x) :is(.iosn-sheet-body, .ipg-sheet-body, .iose-sheet-body, .ixp-sheet-body) {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-block: 16px;
  }
  :root.ep-ios:not(#ep-ios-x) .iosn-sheet-body { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }

  /* Other form shells use a centered safe rectangle, including supplier payments. */
  :root.ep-ios:not(#ep-ios-x) :is(.mip-overlay, .supplier-batch-overlay, .dw-scrim, .edq-overlay, .ep-delivery-review-backdrop, .ep-invoice-draft-overlay, .ado-backdrop) {
    top: var(--ep-modal-viewport-top, 0px);
    bottom: auto;
    height: var(--ep-modal-viewport-height, 100dvh);
    box-sizing: border-box;
    padding: var(--ep-modal-safe-top) 12px var(--ep-modal-safe-bottom) !important;
  }
  :root.ep-ios:not(#ep-ios-x) :is(.mip-sheet, .supplier-batch-sheet, .dw-sheet, .edq-dialog, .ep-delivery-review, .ep-invoice-draft, .ado-detail) {
    min-height: 0;
    max-height: 100% !important;
  }
  :root.ep-ios:not(#ep-ios-x) :is(.mip-body, .edq-dialog-body) { min-height: 0; overscroll-behavior-y: contain; }
  :root.ep-ios:not(#ep-ios-x) :is(.edq-close, .eid-close, .supplier-batch-close) { min-width: 44px; min-height: 44px; }

  /* These older order forms are identified by their existing accessible names. */
  :root.ep-ios:not(#ep-ios-x) :is([role="dialog"][aria-label="Una factura para varios pedidos"], .fixed:has(> [role="dialog"][aria-labelledby="return-shipment-title"]), .fixed:has(> [role="dialog"][aria-label="Compra para stock"]), .fixed:has(> [role="dialog"][aria-label="Editar compra de stock"])) {
    top: var(--ep-modal-viewport-top, 0px);
    bottom: auto;
    height: var(--ep-modal-viewport-height, 100dvh);
    box-sizing: border-box;
    padding: var(--ep-modal-safe-top) 12px var(--ep-modal-safe-bottom) !important;
  }
  :root.ep-ios:not(#ep-ios-x) :is([role="dialog"][aria-label="Una factura para varios pedidos"] > section, [role="dialog"][aria-labelledby="return-shipment-title"], [role="dialog"][aria-label="Compra para stock"], [role="dialog"][aria-label="Editar compra de stock"]) { max-height: 100% !important; min-height: 0; }

  /* Native form dialogs share safe bounds; media and compact menus are excluded. */
  :root.ep-ios:not(#ep-ios-x) dialog[open]:not(.iosw-media-viewer, .ep-purchase-image-dialog, .iosw-template-menu) {
    top: calc(var(--ep-modal-viewport-top, 0px) + var(--ep-modal-safe-top));
    bottom: calc(100dvh - var(--ep-modal-viewport-top, 0px) - var(--ep-modal-viewport-height, 100dvh) + var(--ep-modal-safe-bottom));
    height: auto;
    max-height: var(--ep-modal-room) !important;
    box-sizing: border-box;
    margin-block: auto;
    overscroll-behavior-y: contain;
  }
  :root.ep-ios:not(#ep-ios-x) dialog[open].epquote-dialog .epquote-head { position: sticky; top: 0; z-index: 3; padding-top: 18px; background: #fff; }
  :root.ep-ios:not(#ep-ios-x) dialog[open].epquote-dialog .epquote-footer { position: sticky; bottom: 0; z-index: 2; padding-bottom: 14px; }
  :root.ep-ios:not(#ep-ios-x) dialog[open] > header button,
  :root.ep-ios:not(#ep-ios-x) dialog[open] > footer button,
  :root.ep-ios:not(#ep-ios-x) dialog[open] .epquote-footer button { min-height: 44px; min-width: 44px; }

  /* Radix centered dialogs must fit inside the same visible, safe rectangle. */
  :root.ep-ios:not(#ep-ios-x) .fixed[role="dialog"][data-state="open"][class*="translate-y-"] {
    top: calc(var(--ep-modal-viewport-top, 0px) + var(--ep-modal-safe-top) + var(--ep-modal-room) / 2);
    max-height: var(--ep-modal-room);
    max-width: calc(100vw - 24px);
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }
}
