/**
 * APD 505 — unified iPhone viewport recovery.
 * Date/calendar geometry intentionally remains owned by the unchanged APD504
 * compatibility stylesheet and the canonical modular date files.
 */
@media (max-width: 767px) {
  html,
  body {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100% !important;
    text-size-adjust: 100% !important;
  }

  body > #page,
  body > .site,
  #page,
  .site,
  .site-content,
  .content-area,
  .apd5-app,
  .apd5-main,
  .apd23-discovery-page {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* Safari auto-zooms editable controls below 16px. The search destination is
     intentionally 17px so its computed value stays above the threshold even if
     an older theme selector tries to reduce it. */
  #apd5-search :is(input:not([type="hidden"]), textarea, select),
  #apd5-auth-modal :is(input:not([type="hidden"]), textarea, select),
  .apd54-auth-dialog :is(input:not([type="hidden"]), textarea, select),
  .apd5-auth-dialog :is(input:not([type="hidden"]), textarea, select) {
    font-size: 17px !important;
    max-width: 100% !important;
    min-width: 0 !important;
    -webkit-text-size-adjust: 100% !important;
    text-size-adjust: 100% !important;
  }

  /* Fixed search surfaces are pinned to the layout viewport, not to an old
     horizontal VisualViewport offset. width:auto with both insets avoids the
     100vw + scrollbar/safe-area overshoot that clipped the X on iPhone. */
  .apd186-search-topbar,
  .apd186-search-portal {
    box-sizing: border-box !important;
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    translate: none !important;
  }

  .apd186-search-topbar {
    padding-right: max(12px, env(safe-area-inset-right)) !important;
  }

  .apd186-search-close {
    right: max(12px, env(safe-area-inset-right)) !important;
  }

  /* A stale base class must never be allowed to keep the underlying document
     locked after the APD186 shell itself has closed. This is a CSS safety net;
     JS removes the class authoritatively as well. */
  html body.apd380-mobile-search-canonical.apd5-search-open:not(.apd186-search-modal-open) {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    position: static !important;
    transform: none !important;
    zoom: 1 !important;
  }

  html body.apd380-mobile-search-canonical.apd5-search-open:not(.apd186-search-modal-open) .apd10-mobile-nav {
    display: grid !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
  }

  /* Bottom navigation can also be hidden by scroll/keyboard helpers. APD505
     adds this class briefly after a real search close to override stale helpers. */
  html body.apd505-search-closed .apd10-mobile-nav:not([hidden]) {
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
  }

  html body.apd505-search-closed.apd-marketplace-ui:not(.single-listing) .apd10-mobile-nav:not([hidden]) {
    display: grid !important;
  }

  .apd5-stay-card a[href] {
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent;
  }

  /* Never let an abandoned transition mask block a second listing tap. */
  .apd505-navigation-recovering :is(.apd30-transition-skeleton, .apd29-page-skeleton) {
    pointer-events: none !important;
  }
}
