/* One item per destination. The outer surface also covers the home-indicator inset. */
@media screen and (max-width:760px), screen and (max-width:1100px) and (orientation:portrait), screen and (max-width:1100px) and (any-pointer:coarse) {
  body:not(.account-workspace-mode):not(.people-active):has(> #marketTabBar) {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  }
  body:not(.account-workspace-mode):not(.people-active) > #marketTabBar {
    position: fixed;
    inset: auto 0 0;
    z-index: 60;
    display: grid !important;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    align-items: stretch;
    justify-content: center !important;
    gap: 4px !important;
    box-sizing: border-box;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 4px max(7px, env(safe-area-inset-right), calc((100% - 680px)/2))
      calc(4px + env(safe-area-inset-bottom, 0px))
      max(7px, env(safe-area-inset-left), calc((100% - 680px)/2));
    border: 0;
    border-top: 1px solid var(--theme-border, #dce5ed);
    border-radius: 0;
    background: var(--theme-surface, #fff);
    box-shadow: 0 -2px 8px rgb(25 52 72 / 4%);
    backdrop-filter: none;
  }
  #marketTabBar > a, #marketTabBar > [hidden] { display: none !important; }
  #marketTabBar > button:not([hidden]) {
    box-sizing: border-box;
    display: flex;
    flex-direction: var(--tab-direction, column);
    align-items: center;
    justify-content: center;
    gap: var(--tab-gap, 3px);
    min-width: 0;
    width: 100%;
    height: auto;
    min-height: 51px;
    margin: 0;
    padding: 5px 2px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted, #526577);
    font-family: inherit;
    line-height: 1;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
  }
  #marketTabBar > button > span {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    margin: 0;
  }
  #marketTabBar > button svg {
    display: block;
    width: 21px;
    height: 21px;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  #marketTabBar > button small {
    min-width: 0;
    margin: 0;
    font-family: inherit;
    font-size: var(--tab-font-size, 11px);
    font-weight: 550;
    line-height: 1.25;
    color: inherit;
    letter-spacing: 0;
    overflow-wrap: anywhere;
  }
  #marketTabBar > button[aria-current="page"] {
    background: var(--storefront-accent-soft, #e7f3fa);
    color: var(--storefront-accent-ink, #125679);
  }
  #marketTabBar > button[aria-current="page"] small { font-weight: 700; }
  #marketTabBar > button:active { background: var(--theme-raised, #f1f5f8); }
  #marketTabBar > button:focus-visible {
    outline: 2px solid var(--storefront-accent-ink, #125679);
    outline-offset: -2px;
  }
  body:has(> #modalBackdrop:not(.hidden)) > #marketTabBar { visibility: hidden; }
}
@media (min-width:560px) {
  #marketTabBar { --tab-direction: row; --tab-gap: 9px; --tab-font-size: 14px; }
}

/* Keep the original dialog and gallery controls, including their history handlers. */
@media screen and (max-width:760px), screen and (max-width:1100px) and (any-pointer:coarse) {
  #modalBackdrop > .modal:has(#modalContent > .member-seller) {
    --listing-left: max(14px, env(safe-area-inset-left, 0px));
    --listing-right: max(14px, env(safe-area-inset-right, 0px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 !important;
  }
  #modalBackdrop .site-modal-navigation:has(> .touch-listing-heading) {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex: none;
    gap: 13px;
    min-width: 0;
    margin: 0;
    padding: max(9px, env(safe-area-inset-top, 0px)) var(--listing-right) 9px var(--listing-left);
    border: 0;
    border-bottom: 1px solid var(--theme-border, #dce5ed);
    background: var(--theme-surface, #fff);
    color: var(--theme-text, #26394b);
  }
  #modalBackdrop .site-modal-navigation:has(> .touch-listing-heading) > [data-site-modal-back] { display: none; }
  #modalBackdrop .modal:has(#modalContent > .member-seller) .site-modal-navigation > #closeModal,
  #pgPhotoViewer .pg-viewer-top > [data-pg-view="close"] {
    position: static !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    gap: 7px;
    box-sizing: border-box;
    width: auto;
    min-width: 44px;
    height: auto;
    min-height: 44px;
    margin: 0;
    padding: 8px 12px;
    border: 1px solid var(--theme-border, #dce5ed);
    border-radius: 10px;
    background: var(--theme-raised, #f3f6f9);
    color: var(--theme-text, #26394b);
    box-shadow: none;
    font: inherit;
    font-weight: 650;
    font-size: 14px;
    line-height: 1.2;
    touch-action: manipulation;
  }
  #modalBackdrop .modal:has(#modalContent > .member-seller) .site-modal-navigation > #closeModal::after {
    content: attr(aria-label);
  }
  #modalBackdrop .modal:has(#modalContent > .member-seller) .site-modal-navigation > #closeModal svg {
    position: static;
    flex: none;
    width: 17px;
    height: 17px;
    margin: 0;
    transform: none;
  }
  #modalBackdrop .site-modal-navigation > .touch-listing-heading {
    display: block !important;
    min-width: 0;
    max-height: max(4em, 26dvh);
    overflow: auto;
    overflow-wrap: anywhere;
    font-size: clamp(16px, 2.8vw, 18px);
    font-weight: 650;
    line-height: 1.3;
    text-align: start;
  }
  #modalBackdrop .modal:has(.touch-listing-heading) > #modalContent {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: auto;
    padding: 12px var(--listing-right) max(16px, env(safe-area-inset-bottom, 0px)) var(--listing-left);
    overscroll-behavior: contain;
  }
  #modalBackdrop .modal:has(.touch-listing-heading) > #modalContent > #modalTitle {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    padding: 0;
    margin: 0;
  }
  #modalBackdrop #closeModal:focus-visible,
  #pgPhotoViewer [data-pg-view="close"]:focus-visible {
    outline: 2px solid var(--storefront-accent-ink, #125679);
    outline-offset: 2px;
  }
  #pgPhotoViewer .pg-viewer-top {
    gap: 12px;
    min-height: 0;
    padding: max(9px, env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right)) 9px max(14px, env(safe-area-inset-left));
  }
  #pgPhotoViewer .pg-viewer-top > div { flex: 1; min-width: 0; }
  #pgPhotoViewer .pg-viewer-top > [data-pg-view="close"] { max-width: 49%; }
  #pgPhotoViewer .pg-viewer-top > [data-pg-view="close"] :is(svg, span) { display: none; }
  #pgPhotoViewer .pg-viewer-top > [data-pg-view="close"]::before {
    content: "";
    flex: none;
    box-sizing: border-box;
    width: 9px;
    height: 9px;
    border: solid currentColor;
    border-width: 0 0 2px 2px;
    transform: rotate(45deg);
  }
  #pgPhotoViewer .pg-viewer-top > [data-pg-view="close"]::after { content: attr(data-listing-label); }
  #pgPhotoViewer #pgViewerTitle { max-width: 100%; }
}
@media screen and (max-width:760px) {
  /* Size an opened listing immediately, before the deferred contact dock mounts. */
  #modalBackdrop:has(> .modal > #modalContent > .member-seller) {
    padding: 0 !important;
  }
  #modalBackdrop > .modal:has(> #modalContent > .member-seller) {
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh !important;
    margin: 0;
    border: 0;
    border-radius: 0 !important;
    transform: none !important;
  }
  #modalBackdrop .modal:has(.touch-listing-heading) > #modalContent:has(> .mm-contact-dock) {
    padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    scroll-padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  }
}
