/* Narrow shared shell corrections. Existing menus, forms and media own their behavior. */
@media (max-width: 768px) {
  /* Absolute top-bar controls need reserved room when long headings or the
     panorama handle consume the hero's previous automatic top margin. */
  body > .container > .header {
    height: auto !important;
    padding-top: calc(72px + env(safe-area-inset-top, 0px)) !important;
  }

  /* The panorama hint previously used top:104px and covered variable-height
     hero headings. Keep its drag handle in a separate, compact flex row. */
  body > .container > .header > .mr-hint {
    position: relative !important;
    inset: auto !important;
    flex: 0 0 auto;
    align-self: center;
    box-sizing: border-box;
    width: max-content;
    max-width: 100%;
    min-height: 44px;
    margin: 8px auto 0 !important;
    padding: 8px 10px;
    white-space: normal;
    font-size: 13px;
    line-height: 18px;
    text-align: center;
  }

  body > .top-links .member-links a[href*="/contacts/"] {
    height: 44px !important;
    min-height: 44px;
  }

  body > .top-links .mr-burger.mr-burger-hero {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    min-height: 44px;
  }
}

/* Same control is used in the phone drawer and the intermediate-width menu. */
body #mr-drawer .mr-d-x {
  box-sizing: border-box;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

body > .container > .content :is(.block-comments, .block-share, .block-flagging) input:is(.textfield, .submit) {
  box-sizing: border-box;
  min-height: 44px;
}

/* Center short thumbnail collections without placing overflowing first items
   before scrollLeft=0. Native gallery code already centers the active item. */
body #mg-lb .mg-lb-strip {
  justify-content: flex-start;
}
body #mg-lb .mg-lb-strip > .mg-lb-thumb:first-child {
  margin-left: auto;
}
body #mg-lb .mg-lb-strip > .mg-lb-thumb:last-child {
  margin-right: auto;
}

@media (max-width: 900px) {
  /* Album navigation must be discoverable before a hover emulation occurs. */
  body .fancybox-wrap[data-mr-details-gallery="album"] .fancybox-nav span {
    visibility: visible !important;
  }

  body .fancybox-wrap[data-mr-details-gallery="album"] .fancybox-close {
    box-sizing: border-box;
    top: 4px;
    right: 4px;
    width: 44px;
    height: 44px;
    background: none !important;
    touch-action: manipulation;
  }

  /* Keep the familiar native close icon centered inside its larger hit area. */
  body .fancybox-wrap[data-mr-details-gallery="album"] .fancybox-close::before {
    content: "";
    position: absolute;
    inset: 4px;
    width: 36px;
    height: 36px;
    background: url("/static/images/fancybox/fancybox_sprite@2x.png") 0 0 / 44px 152px no-repeat;
    pointer-events: none;
  }
}

/* Let Leaflet fit popup text between the left controls and the map edge. */
body .cat-map-canvas.mr-map-narrow .leaflet-popup-content {
  width: var(--mr-map-popup-width, auto) !important;
  min-width: 0 !important;
  overflow-wrap: anywhere;
}

/* Keep map controls operable in portrait and fullscreen landscape. */
body .cat-map-canvas :is(.leaflet-control-zoom, .cat-map-ctl) > a {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px !important;
  height: 44px !important;
  padding: 0 !important;
  line-height: 44px !important;
}
body .cat-map-canvas .leaflet-popup-content-wrapper {
  padding-top: 44px !important;
}
body .cat-map-canvas a.leaflet-popup-close-button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  top: 0;
  right: 0;
  width: 44px !important;
  height: 44px !important;
  padding: 0 !important;
  line-height: 1 !important;
}

/* Compact contact actions; preserve existing visibility and overlay behavior. */
@media (max-width: 600px) {
  body > .mr-cta-bar {
    box-sizing: border-box;
    gap: 6px !important;
    padding: 8px max(12px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)) !important;
  }
  body > .mr-cta-bar > .mr-cta-status {
    min-width: 0;
    justify-content: center !important;
    gap: 0 !important;
    text-align: center !important;
  }
  body > .mr-cta-bar > .mr-cta-status .mr-sd-live {
    max-width: 100%;
    line-height: 16px !important;
  }
  body > .mr-cta-bar > .mr-cta-status .mr-sd-sub {
    display: none !important;
  }
  body > .mr-cta-bar > .mr-cta-row {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    align-items: stretch !important;
    width: 100% !important;
    min-width: 0;
    gap: 8px !important;
  }
  body > .mr-cta-bar > .mr-cta-row > a.mr-cta {
    box-sizing: border-box;
    display: flex !important;
    flex-direction: column;
    align-items: center !important;
    justify-content: center !important;
    min-width: 0;
    min-height: 52px !important;
    height: auto !important;
    padding: 6px !important;
    gap: 4px !important;
    border-radius: 10px !important;
    font-size: 13px !important;
    line-height: 16px !important;
    box-shadow: none !important;
    transform: none !important;
  }
  body > .mr-cta-bar > .mr-cta-row > a.mr-cta > svg {
    width: 18px !important;
    height: 18px !important;
    flex: none !important;
  }
  body > .mr-cta-bar > .mr-cta-row > a.mr-cta > span {
    display: block;
    max-width: 100%;
    font-size: inherit;
    line-height: inherit;
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
  }
}
