:root {
  --filter-panel-width: clamp(320px, 25vw, 400px);
  --filter-panel-surface: var(--bs-body-bg, #ffffff);
  --filter-panel-border: var(--bs-border-color, rgba(15, 23, 42, 0.16));
  --filter-panel-text: var(--bs-body-color, #172033);
  --filter-panel-accent: #176b55;
  --filter-panel-accent-hover: #0f5945;
  --filter-panel-shadow: 0 24px 70px rgba(15, 23, 42, 0.26);
}

.listing-page-layout {
  display: grid;
  grid-template-columns: var(--filter-panel-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.responsive-filter-panel.options-col {
  position: relative;
  z-index: 2;
  display: flex;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--filter-panel-border);
  background: var(--filter-panel-surface);
  color: var(--filter-panel-text);
}

.responsive-filter-panel__header,
.responsive-filter-panel__footer {
  display: none;
}

.responsive-filter-panel__body {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.responsive-filter-panel__body > .card,
.responsive-filter-panel__body > div > .card {
  border-right: 0;
  border-left: 0;
  border-radius: 0;
}

.listing-map-col.map-col {
  position: relative;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.listing-map-col > .card,
.listing-map-col > .card > .card-body,
.listing-map-col > .card > .card-body > div {
  height: 100%;
}

.filter-panel-backdrop,
.map-filter-toolbar {
  display: none;
}

/* RangeSlider tooltips are absolutely positioned and therefore do not add to
   the slider's layout height. Reserve a row for bottom tooltips before laying
   out the missing-value switch so its label cannot overlap them. */
.range-filter__slider-with-switch {
  padding-bottom: 2.75rem;
}

.range-filter__exact-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.25rem 0 0.9rem;
}

.range-filter__exact-input {
  min-width: 0;
}

.range-filter__exact-input input {
  font-variant-numeric: tabular-nums;
}

/* Hybrid filters use the fields for exact values and the rail for quick,
   approximate adjustment. The inset keeps endpoint labels centered on their
   knobs without clipping against the filter panel. */
.range-filter__hybrid-slider-wrap {
  padding: 0.25rem 0 1.25rem;
}

.range-filter__hybrid-slider {
  width: calc(100% - 2.5rem);
  margin: 0 1.25rem;
}

/* Open-ended sliders reserve room for numeric value tooltips above the rail.
   At the Unlimited endpoint the mark below the knob already communicates the
   value, so its duplicate tooltip is hidden. */
.range-filter__open-ended-slider {
  width: calc(100% - 2rem);
  margin-top: 2.5rem;
  margin-right: 2rem;
}

/* Keep the first and open-ended final tick inside the narrow filter panel.
   Dash centers mark labels by default, which clips half of the final label. */
.range-filter__controls .dash-slider-mark {
  white-space: nowrap;
}

.range-filter__controls .dash-slider-mark:first-of-type {
  transform: translateX(0) !important;
  text-align: left;
}

.range-filter__open-ended-slider .dash-slider-mark:nth-last-of-type(2) {
  transform: translateX(calc(-100% - 0.25rem)) !important;
  text-align: right;
}

.range-filter__controls .dash-slider-mark:last-of-type {
  transform: translateX(-100%) !important;
  text-align: right;
  color: var(--filter-panel-accent);
  font-weight: 600;
}

.range-filter__hybrid-slider .dash-slider-mark:first-of-type,
.range-filter__hybrid-slider .dash-slider-mark:last-of-type {
  transform: translateX(-50%) !important;
  text-align: center;
}

.range-filter__hybrid-slider .dash-slider-mark:last-of-type {
  color: inherit;
  font-weight: 400;
}

/* Reserve enough width for the positive open-ended label while keeping the
   exact cap immediately before it distinct and selectable. */
.range-filter__open-ended-slider .dash-slider-mark:last-of-type {
  width: 4rem;
  transform: translateX(-50%) !important;
  text-align: center;
  white-space: nowrap;
  line-height: 1.05;
}

.range-filter__open-ended-slider
  .dash-slider-thumb[aria-label="Maximum"]
  .dash-slider-tooltip
  > div {
  /* The endpoint value is a short discrete label (for example, “Unlimited”),
     not a second input. Let the bubble hug its content. */
  min-width: 0;
  width: max-content;
  padding: 0.4rem 0.55rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

.range-filter__open-ended-slider
  .dash-slider-thumb[aria-label="Maximum"][data-unlimited="true"]
  .dash-slider-tooltip {
  display: none;
}

/* The ISP control has two stacked sliders and does not use build_range_filter.
   Give both bottom tooltip rows space so they clear the next heading/switch. */
.isp-speed-filter__range {
  padding-bottom: 2.75rem;
}

@media (max-width: 1099.98px) {
  .listing-page-layout {
    display: block;
  }

  .listing-map-col.map-col {
    width: 100%;
  }

  .responsive-filter-panel.options-col {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 2400;
    width: min(440px, 100vw);
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-left: 1px solid var(--filter-panel-border);
    border-radius: 22px 0 0 22px;
    box-shadow: var(--filter-panel-shadow);
    visibility: hidden;
    transform: translateX(102%);
    transition: transform 220ms ease, visibility 0s linear 220ms;
  }

  .responsive-filter-panel.options-col.is-open {
    visibility: visible;
    transform: translateX(0);
    transition-delay: 0s;
  }

  .responsive-filter-panel__header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 70px;
    padding: max(14px, env(safe-area-inset-top)) 18px 12px;
    border-bottom: 1px solid var(--filter-panel-border);
    background: var(--filter-panel-surface);
  }

  .responsive-filter-panel__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 750;
    line-height: 1.2;
  }

  .responsive-filter-panel__title:focus {
    outline: none;
  }

  .responsive-filter-panel__count {
    margin-top: 3px;
    color: var(--bs-secondary-color, #657084);
    font-size: 0.85rem;
  }

  .responsive-filter-panel__close,
  .map-filter-toolbar__open,
  .map-filter-chip,
  .responsive-filter-panel__clear,
  .responsive-filter-panel__apply {
    min-width: 44px;
    min-height: 44px;
  }

  .responsive-filter-panel__close {
    display: inline-grid;
    flex: 0 0 44px;
    place-items: center;
    border: 1px solid var(--filter-panel-border);
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 1.05rem;
  }

  .responsive-filter-panel__close:hover,
  .responsive-filter-panel__close:focus-visible {
    background: var(--bs-tertiary-bg, #eef1f4);
  }

  .responsive-filter-panel__body {
    padding-bottom: 8px;
    scrollbar-gutter: stable;
  }

  .responsive-filter-panel__body .title-card .card-body {
    padding: 12px 16px;
  }

  .responsive-filter-panel__body .title-card .card-title,
  .responsive-filter-panel__body .title-card p,
  .responsive-filter-panel__body .title-card .title-card-links {
    display: none;
  }

  .responsive-filter-panel__body .title-card > .card-body > .row {
    justify-content: space-between;
    margin: 0;
  }

  .responsive-filter-panel__body .title-card > .card-body > .row > .col-auto:first-child {
    display: none;
  }

  .responsive-filter-panel__body .title-card .btn {
    min-height: 40px;
  }

  .responsive-filter-panel__body .card-text:first-child {
    margin-bottom: 12px;
  }

  .responsive-filter-panel__body .accordion-button {
    min-height: 50px;
    font-weight: 650;
  }

  .responsive-filter-panel__footer {
    display: grid;
    grid-template-columns: minmax(110px, 0.7fr) minmax(190px, 1.3fr);
    flex: 0 0 auto;
    gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--filter-panel-border);
    background: color-mix(in srgb, var(--filter-panel-surface) 94%, transparent);
    box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(14px);
  }

  .responsive-filter-panel__clear,
  .responsive-filter-panel__apply {
    border-radius: 12px;
    padding: 10px 14px;
    font-weight: 700;
  }

  .responsive-filter-panel__clear {
    border: 1px solid var(--filter-panel-border);
    background: transparent;
    color: inherit;
  }

  .responsive-filter-panel__apply {
    border: 1px solid var(--filter-panel-accent);
    background: var(--filter-panel-accent);
    color: #ffffff;
  }

  .responsive-filter-panel__apply:hover,
  .responsive-filter-panel__apply:focus-visible {
    border-color: var(--filter-panel-accent-hover);
    background: var(--filter-panel-accent-hover);
  }

  .filter-panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2390;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgba(8, 15, 28, 0.48);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 200ms ease, visibility 0s linear 200ms;
  }

  .filter-panel-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
  }

  body.filter-panel-open {
    overflow: hidden;
    touch-action: none;
  }

  body.filter-panel-open .responsive-filter-panel {
    touch-action: pan-y;
  }

  .map-filter-toolbar {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    z-index: 1300;
    display: block;
    max-width: 760px;
    margin: 0 auto;
    color: #172033;
    pointer-events: none;
  }

  .map-filter-toolbar__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 58px;
    padding: 8px 9px 8px 14px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(14px);
    pointer-events: auto;
  }

  .map-filter-toolbar__identity {
    min-width: 0;
  }

  .map-filter-toolbar__brand {
    display: block;
    overflow: hidden;
    color: #15213b;
    font-size: 0.96rem;
    font-weight: 800;
    line-height: 1.2;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .map-filter-toolbar__result-count {
    display: block;
    margin-top: 2px;
    color: #5c6677;
    font-size: 0.76rem;
    line-height: 1.2;
  }

  .map-filter-toolbar__actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
  }

  .map-filter-toolbar__mode {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 3px;
    border: 1px solid #cbd3dc;
    border-radius: 12px;
    background: #f2f5f7;
  }

  .map-filter-toolbar__mode-button {
    display: inline-flex;
    min-width: 66px;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 0;
    border-radius: 8px;
    padding: 7px 11px;
    color: #344054;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
  }

  .map-filter-toolbar__mode-button:hover {
    background: #e5eaee;
    color: #172033;
  }

  .map-filter-toolbar__mode-button .bi-check2 {
    display: none;
    font-size: 1rem;
    line-height: 1;
  }

  .map-filter-toolbar__mode-button.is-selected,
  .map-filter-toolbar__mode-button.is-selected:hover {
    background: #176b55;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(23, 107, 85, 0.26);
  }

  .map-filter-toolbar__mode-button.is-selected .bi-check2 {
    display: inline-block;
  }

  .map-filter-toolbar__mode-button:focus-visible {
    outline: 3px solid rgba(23, 107, 85, 0.3);
    outline-offset: 2px;
  }

  .map-filter-toolbar__open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid #1a6d58;
    border-radius: 12px;
    padding: 8px 12px;
    background: #176b55;
    color: #ffffff;
    font-weight: 750;
    box-shadow: 0 4px 12px rgba(23, 107, 85, 0.2);
  }

  .map-filter-toolbar__badge {
    display: inline-grid;
    min-width: 21px;
    height: 21px;
    place-items: center;
    border-radius: 999px;
    background: #ffffff;
    color: #145442;
    font-size: 0.72rem;
    font-weight: 850;
  }

  .map-filter-toolbar__badge[hidden] {
    display: none;
  }

  .map-filter-toolbar__chips {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding: 0 2px 5px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    pointer-events: auto;
  }

  .map-filter-toolbar__chips::-webkit-scrollbar {
    display: none;
  }

  .map-filter-chip {
    flex: 0 0 auto;
    border: 1px solid rgba(15, 23, 42, 0.18);
    border-radius: 999px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.97);
    color: #263349;
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.13);
    backdrop-filter: blur(12px);
  }

  .map-filter-chip--active {
    border-color: #176b55;
    background: #e0f4ed;
    color: #104f3f;
  }

  .listing-map-col .leaflet-top {
    top: 128px;
  }

  .listing-map-col .school-layer-map-prompt {
    bottom: max(14px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 767.98px) {
  .responsive-filter-panel.options-col {
    top: auto;
    left: 0;
    width: 100%;
    height: calc(100dvh - 8px);
    max-height: calc(100dvh - 8px);
    border-left: 0;
    border-radius: 22px 22px 0 0;
    transform: translateY(102%);
  }

  .responsive-filter-panel.options-col::before {
    position: absolute;
    top: 7px;
    left: 50%;
    z-index: 1;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--filter-panel-text) 30%, transparent);
    content: "";
    transform: translateX(-50%);
  }

  .responsive-filter-panel.options-col.is-open {
    transform: translateY(0);
  }

  .responsive-filter-panel__header {
    padding-top: max(18px, env(safe-area-inset-top));
  }

  .map-filter-toolbar {
    left: 8px;
    right: 8px;
  }

  .map-filter-toolbar__top {
    min-height: 56px;
    border-radius: 16px;
  }

  .map-filter-toolbar__open {
    padding-right: 11px;
    padding-left: 11px;
  }

  .map-filter-chip {
    min-height: 42px;
    padding-right: 13px;
    padding-left: 13px;
  }

  .listing-map-col .leaflet-top {
    top: 126px;
  }
}

@media (max-width: 410px) {
  .map-filter-toolbar__brand {
    max-width: 128px;
  }

  .map-filter-toolbar__open > span:not(.map-filter-toolbar__badge) {
    display: none;
  }
}

@media (max-width: 899.98px) and (max-height: 520px) and (orientation: landscape) {
  .responsive-filter-panel.options-col {
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .responsive-filter-panel.options-col::before {
    display: none;
  }

  .responsive-filter-panel__header {
    min-height: 58px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .responsive-filter-panel__footer {
    padding-top: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .responsive-filter-panel.options-col,
  .filter-panel-backdrop {
    transition: none;
  }
}

:root[data-mantine-color-scheme="dark"] {
  --filter-panel-surface: var(--wttl-dark-panel, #202427);
  --filter-panel-border: var(--wttl-dark-border, rgba(232, 238, 241, 0.14));
  --filter-panel-text: var(--wttl-dark-text, #e7ecef);
  --filter-panel-accent: var(--wttl-dark-accent, #4fc3b4);
  --filter-panel-accent-hover: #3db2a4;
}

:root[data-mantine-color-scheme="dark"] .responsive-filter-panel__apply {
  color: #10211f;
}

:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__top,
:root[data-mantine-color-scheme="dark"] .map-filter-chip {
  border-color: var(--wttl-dark-border, rgba(232, 238, 241, 0.18));
  background: rgba(32, 36, 39, 0.96);
  color: var(--wttl-dark-text, #e7ecef);
}

:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__brand {
  color: var(--wttl-dark-text, #e7ecef);
}

:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__result-count {
  color: var(--wttl-dark-text-muted, rgba(231, 236, 239, 0.68));
}

:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__mode {
  border-color: var(--wttl-dark-border, rgba(232, 238, 241, 0.18));
  background: rgba(13, 17, 19, 0.5);
}

:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__mode-button {
  color: var(--wttl-dark-text, #e7ecef);
}

:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__mode-button:hover {
  background: rgba(231, 236, 239, 0.1);
}

:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__mode-button.is-selected,
:root[data-mantine-color-scheme="dark"] .map-filter-toolbar__mode-button.is-selected:hover {
  background: var(--wttl-dark-accent, #4fc3b4);
  color: #10211f;
}

:root[data-mantine-color-scheme="dark"] .map-filter-chip--active {
  border-color: var(--wttl-dark-accent, #4fc3b4);
  background: rgba(79, 195, 180, 0.18);
  color: #93e6dc;
}
