/* --- ID 401: search pages (classic + IA) - landscape sticky map + 4-col grid --- */

@media (min-width: 992px) {
  body.hr-search-page,
  body.post-type-archive-hp_listing {
    --hr-search-map-sticky-top: env(safe-area-inset-top, 0px);
    --hr-search-map-height: clamp(240px, 31vh, 360px);
    --hr-search-grid-gap: 22px;
    --hr-search-fade-bg: #f4f6fb;
  }

  /* Desktop: tighten the gap between search bar and sticky map without touching sticky behavior. */
  body.hr-search-page .header-hero,
  body.post-type-archive-hp_listing .header-hero {
    padding-bottom: 8px !important;
  }

  body.hr-search-page .header-hero .hp-form--listing-search,
  body.post-type-archive-hp_listing .header-hero .hp-form--listing-search {
    margin-bottom: 0 !important;
  }

  /* Keep sticky behavior reliable. */
  body.hr-search-page .site-content,
  body.hr-search-page .site-content .container,
  body.hr-search-page .content-area,
  body.hr-search-page .hp-page,
  body.hr-search-page .hp-page > .hp-row,
  body.post-type-archive-hp_listing .site-content,
  body.post-type-archive-hp_listing .site-content .container,
  body.post-type-archive-hp_listing .content-area,
  body.post-type-archive-hp_listing .hp-page,
  body.post-type-archive-hp_listing .hp-page > .hp-row {
    overflow: visible !important;
  }

  /* Map is moved into .hr-search-map-wrap by dedicated JS, so sidebar stays hidden on desktop. */
  body.hr-search-page .hp-page__sidebar,
  body.post-type-archive-hp_listing .hp-page__sidebar {
    display: none !important;
  }

  body.hr-search-page .hp-page__content.hp-col-sm-8,
  body.post-type-archive-hp_listing .hp-page__content.hp-col-sm-8 {
    float: none !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    min-width: 0 !important;
  }

  /* Landscape map under the search bar, sticky to top while scrolling. */
  body.hr-search-page .hr-search-map-wrap,
  body.post-type-archive-hp_listing .hr-search-map-wrap {
    position: sticky !important;
    top: var(--hr-search-map-sticky-top) !important;
    z-index: 46 !important;
    isolation: isolate !important;
    width: 100% !important;
    height: var(--hr-search-map-height) !important;
    min-height: var(--hr-search-map-height) !important;
    max-height: var(--hr-search-map-height) !important;
    margin: 2px 0 -10px !important;
    border-radius: 22px !important;
    overflow: hidden !important;
    background: #e8edf6 !important;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.10) !important;
    transform: translateZ(0) !important;
    box-sizing: border-box !important;
  }

  body.hr-search-page .hr-search-map-wrap.hr-map-fixed,
  body.post-type-archive-hp_listing .hr-search-map-wrap.hr-map-fixed {
    position: fixed !important;
    margin: 0 !important;
    transform: none !important;
    left: 0 !important;
    box-sizing: border-box !important;
    z-index: 60 !important;
  }

  body.hr-search-page .hr-search-map-placeholder,
  body.post-type-archive-hp_listing .hr-search-map-placeholder {
    display: none !important;
    width: 100% !important;
    min-height: var(--hr-search-map-height) !important;
  }

  body.hr-search-page .hr-search-map-placeholder.is-active,
  body.post-type-archive-hp_listing .hr-search-map-placeholder.is-active {
    display: block !important;
  }

  body.hr-search-page .hr-search-map-wrap::after,
  body.post-type-archive-hp_listing .hr-search-map-wrap::after {
    content: "" !important;
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    height: 84px !important;
    pointer-events: none !important;
    z-index: 6 !important;
    background: linear-gradient(
      180deg,
      rgba(244, 246, 251, 0) 0%,
      rgba(244, 246, 251, 0.62) 55%,
      var(--hr-search-fade-bg) 100%
    ) !important;
  }

  body.hr-search-page .hr-search-map-wrap > .hp-map,
  body.hr-search-page .hr-search-map-wrap > .widget.hp-map,
  body.post-type-archive-hp_listing .hr-search-map-wrap > .hp-map,
  body.post-type-archive-hp_listing .hr-search-map-wrap > .widget.hp-map {
    width: 100% !important;
    height: 100% !important;
    border-radius: inherit !important;
    overflow: hidden !important;
  }

  body.hr-search-page .hr-search-map-wrap .mapboxgl-canvas-container,
  body.hr-search-page .hr-search-map-wrap .mapboxgl-canvas,
  body.hr-search-page .hr-search-map-wrap canvas,
  body.post-type-archive-hp_listing .hr-search-map-wrap .mapboxgl-canvas-container,
  body.post-type-archive-hp_listing .hr-search-map-wrap .mapboxgl-canvas,
  body.post-type-archive-hp_listing .hr-search-map-wrap canvas {
    width: 100% !important;
    height: 100% !important;
  }

  /* Topbar remains active between map and cards. */
  body.hr-search-page .hp-page__topbar,
  body.post-type-archive-hp_listing .hp-page__topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    row-gap: 10px !important;
    align-items: start !important;
    position: relative !important;
    z-index: 8 !important;
    margin: 0 0 14px !important;
    padding-top: 20px !important;
  }

  body.hr-search-page .hp-page__topbar > .hp-result-count,
  body.post-type-archive-hp_listing .hp-page__topbar > .hp-result-count {
    order: 1 !important;
    margin: 0 !important;
    text-align: left !important;
  }

  body.hr-search-page .hp-page__topbar .hr-topbar-actions,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions {
    order: 2 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 14px !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  body.hr-search-page .hp-page__topbar .hr-topbar-actions form.hp-form--listing-sort,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions form.hp-form--listing-sort {
    flex: 0 0 auto !important;
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
  }

  body.hr-search-page .hp-page__topbar .hr-topbar-actions form.hp-form--listing-sort .hp-form__fields,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions form.hp-form--listing-sort .hp-form__fields {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 10px !important;
  }

  body.hr-search-page .hp-page__topbar .hr-topbar-actions form.hp-form--listing-sort .hp-form__field,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions form.hp-form--listing-sort .hp-form__field {
    margin: 0 !important;
  }

  body.hr-search-page .hp-page__topbar .hr-topbar-actions .hr-filter-actions-wrap,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions .hr-filter-actions-wrap,
  body.hr-search-page .hp-page__topbar .hr-topbar-actions > .hr-filter-btn,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions > .hr-filter-btn {
    margin-left: auto !important;
    flex: 0 0 auto !important;
    width: auto !important;
  }

  body.hr-search-page .hp-page__topbar .hr-topbar-actions .hr-filter-actions-wrap,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions .hr-filter-actions-wrap {
    display: inline-flex !important;
    align-items: center !important;
  }

  body.hr-search-page .hp-form--listing-sort select,
  body.post-type-archive-hp_listing .hp-form--listing-sort select {
    min-width: 220px;
  }

  /* Results grid on desktop: 4 columns + normal pagination. */
  body.hr-search-page .hp-listings.hp-grid > .hp-row,
  body.post-type-archive-hp_listing .hp-listings.hp-grid > .hp-row {
    position: relative !important;
    z-index: 5 !important;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: var(--hr-search-grid-gap) !important;
    margin: 0 !important;
  }

  body.hr-search-page .hp-listings.hp-grid > .hp-row > .hp-grid__item,
  body.post-type-archive-hp_listing .hp-listings.hp-grid > .hp-row > .hp-grid__item {
    float: none !important;
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
  }

  body.hr-search-page nav.hp-pagination,
  body.post-type-archive-hp_listing nav.hp-pagination,
  body.hr-search-page .hp-pagination,
  body.post-type-archive-hp_listing .hp-pagination {
    position: relative !important;
    z-index: 5 !important;
    margin-top: 18px !important;
    display: block !important;
  }

  body.hr-search-page .hp-page__topbar .hr-topbar-actions > .hp-button--listing-filter:not(.hr-filter-btn),
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions > .hp-button--listing-filter:not(.hr-filter-btn),
  body.hr-search-page .hp-page__topbar .hr-topbar-actions > [data-url="#listing_filter_modal"]:not(.hr-filter-btn),
  body.post-type-archive-hp_listing .hp-page__topbar .hr-topbar-actions > [data-url="#listing_filter_modal"]:not(.hr-filter-btn) {
    display: none !important;
  }
}

@media (max-width: 991px) {
  body.hr-search-page .hr-search-map-wrap,
  body.post-type-archive-hp_listing .hr-search-map-wrap {
    display: none !important;
  }

  body.hr-search-page .hp-page__sidebar,
  body.post-type-archive-hp_listing .hp-page__sidebar {
    display: block !important;
  }

  body.hr-search-page .hp-page__topbar,
  body.post-type-archive-hp_listing .hp-page__topbar {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  body.hr-search-page .hp-page__topbar > .hp-result-count,
  body.post-type-archive-hp_listing .hp-page__topbar > .hp-result-count {
    order: 1 !important;
    margin: 0 !important;
  }

  body.hr-search-page .hp-page__topbar form.hp-form--listing-sort,
  body.post-type-archive-hp_listing .hp-page__topbar form.hp-form--listing-sort {
    order: 2 !important;
    margin: 0 !important;
    width: 100% !important;
    text-align: left !important;
  }

  body.hr-search-page .hp-page__topbar form.hp-form--listing-sort .hp-form__fields,
  body.post-type-archive-hp_listing .hp-page__topbar form.hp-form--listing-sort .hp-form__fields,
  body.hr-search-page .hp-page__topbar form.hp-form--listing-sort .hp-form__field,
  body.post-type-archive-hp_listing .hp-page__topbar form.hp-form--listing-sort .hp-form__field {
    justify-content: flex-start !important;
    text-align: left !important;
  }

  body.hr-search-page .hp-page__topbar .hr-mobile-filter-row,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-mobile-filter-row {
    order: 3 !important;
    width: 100% !important;
    margin: 0 !important;
    display: block !important;
  }

  body.hr-search-page .hp-page__topbar .hr-mobile-filter-row .hr-filter-btn,
  body.hr-search-page .hp-page__topbar .hr-mobile-filter-row .hp-button--listing-filter,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-mobile-filter-row .hr-filter-btn,
  body.post-type-archive-hp_listing .hp-page__topbar .hr-mobile-filter-row .hp-button--listing-filter {
    width: 100% !important;
    margin: 0 !important;
    display: inline-flex !important;
    justify-content: center !important;
  }

  /* Search cards: move divider slightly lower from "Ajoute le..." line */
  body.hr-search-page .hp-listing.hp-listing--view-block .hp-listing__details--primary,
  body.post-type-archive-hp_listing .hp-listing.hp-listing--view-block .hp-listing__details--primary {
    margin-bottom: 8px !important;
  }

  body.hr-search-page .hp-listing.hp-listing--view-block .hp-listing__footer,
  body.post-type-archive-hp_listing .hp-listing.hp-listing--view-block .hp-listing__footer {
    padding-top: 14px !important;
  }
}

/* Search filter popup: final normalized rendering (desktop + mobile). */
.fancybox-container .fancybox-content.hr-listing-filter-content,
.fancybox__container .fancybox__content.hr-listing-filter-content,
#listing_filter_modal.hp-modal.hr-listing-filter-inline-open {
  width: min(920px, calc(100vw - 24px)) !important;
  max-width: min(920px, calc(100vw - 24px)) !important;
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;
  box-sizing: border-box !important;
  border-radius: 22px !important;
  padding: 18px 16px 16px !important;
  background: #f8fbff !important;
  color: #1f2a44 !important;
  opacity: 1 !important;
  visibility: visible !important;
}

.fancybox-container .fancybox-content.hr-listing-filter-content #listing_filter_modal,
.fancybox__container .fancybox__content.hr-listing-filter-content #listing_filter_modal,
#listing_filter_modal.hr-listing-filter-inline-open {
  position: static !important;
  transform: none !important;
  left: auto !important;
  top: auto !important;
  margin: 0 !important;
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}

#listing_filter_modal.hr-listing-filter-inline-open {
  position: fixed !important;
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) !important;
  z-index: 2147483647 !important;
}

.fancybox-container .fancybox-slide.hr-listing-filter-slide,
.fancybox-container .fancybox__slide.hr-listing-filter-slide,
.fancybox__container .fancybox-slide.hr-listing-filter-slide,
.fancybox__container .fancybox__slide.hr-listing-filter-slide {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.fancybox-container .fancybox-content.hr-listing-filter-content .fancybox-close-small,
.fancybox__container .fancybox__content.hr-listing-filter-content .fancybox-close-small,
#listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hr-modal-fallback-close {
  top: 12px !important;
  right: 12px !important;
  width: 40px !important;
  height: 40px !important;
  padding: 0 !important;
  border-radius: 999px !important;
  border: 1px solid rgba(143, 162, 220, 0.3) !important;
  background: #f8fbff !important;
  color: #5f7198 !important;
  z-index: 6 !important;
}

@media (max-width: 991px) {
  .fancybox-container .fancybox-slide.hr-listing-filter-slide,
  .fancybox-container .fancybox__slide.hr-listing-filter-slide,
  .fancybox__container .fancybox-slide.hr-listing-filter-slide,
  .fancybox__container .fancybox__slide.hr-listing-filter-slide {
    padding: max(10px, env(safe-area-inset-top, 0px)) 10px max(10px, env(safe-area-inset-bottom, 0px)) !important;
  }

  .fancybox-container .fancybox-content.hr-listing-filter-content,
  .fancybox__container .fancybox__content.hr-listing-filter-content,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px) !important;
    border-radius: 16px !important;
    padding: 60px 10px 12px !important;
  }

  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter .hp-form__field--number-range > .hp-field__label,
  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter .hp-form__field--number-range > .hp-form__label,
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter .hp-form__field--number-range > .hp-field__label,
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter .hp-form__field--number-range > .hp-form__label,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter .hp-form__field--number-range > .hp-field__label,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter .hp-form__field--number-range > .hp-form__label {
    display: block !important;
    margin-bottom: 12px !important;
    padding-right: 56px !important;
  }

  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter .hp-form__field--number-range .hp-field--number-range,
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter .hp-form__field--number-range .hp-field--number-range,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter .hp-form__field--number-range .hp-field--number-range {
    margin-top: 8px !important;
  }

  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter input[type="text"],
  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter input[type="number"],
  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter input[type="search"],
  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter textarea,
  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter select,
  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter .select2-search__field,
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter input[type="text"],
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter input[type="number"],
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter input[type="search"],
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter textarea,
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter select,
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter .select2-search__field,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter input[type="text"],
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter input[type="number"],
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter input[type="search"],
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter textarea,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter select,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter .select2-search__field {
    font-size: 16px !important;
  }

  .fancybox-container .fancybox-content.hr-listing-filter-content .hp-form--listing-filter .hr-tags-search__input,
  .fancybox__container .fancybox__content.hr-listing-filter-content .hp-form--listing-filter .hr-tags-search__input,
  #listing_filter_modal.hp-modal.hr-listing-filter-inline-open .hp-form--listing-filter .hr-tags-search__input {
    font-size: 16px !important;
    -webkit-text-size-adjust: 100% !important;
    line-height: 1.35 !important;
  }
}
