/* ==========================================================================
   Component â€” Advanced Filters
   Sidebar, results toolbar, active-filter chips, price range, mobile drawer.

   THE CONTRACT
   Every control carries data-filter-field="<param>". The param names are the
   ones the service managers already understand, so the UI never translates:

     all services   q Â· priceMin Â· priceMax Â· rating Â· sort Â· page
     hotel          stars Â· amenities Â· propertyType Â· maxDistance
     tour           activity Â· difficulty Â· duration Â· language
     flight         airline Â· stops Â· departWindow Â· maxDuration Â· cabin
     transfer       vehicleType Â· passengers Â· luggage Â· instantBooking Â·
                    driverRating

   Multi-value controls (checkbox groups) are joined with commas by filters.js.
   Adding a filter is markup plus a line in the manager's matchesItem().
   ========================================================================== */

/* --- Results toolbar ----------------------------------------------------- */
.wu-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wu-space-3);
  padding: var(--wu-space-3) var(--wu-space-4);
  margin-bottom: var(--wu-space-5);
  background: var(--wu-surface);
  border: 1px solid var(--wu-border);
  border-radius: var(--wu-radius-lg);
}
.wu-filter-bar .wu-select { width: auto; min-width: 170px; }
.wu-filter-bar-count { font-size: var(--wu-fs-sm); color: var(--wu-text-muted); }
.wu-filter-bar-count strong { color: var(--wu-heading); }

/* View switcher: grid / list / masonry / map */
.wu-view-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--wu-surface-sunken);
  border-radius: var(--wu-radius);
}
/* Buttons when the view swaps in place (search.html), links when each view is
   its own page (the hotel listing set). Both look and behave identically. */
.wu-view-switch button,
.wu-view-switch a {
  width: 36px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--wu-radius-sm);
  background: transparent;
  color: var(--wu-text-muted);
  cursor: pointer;
}
.wu-view-switch a:hover { color: var(--wu-heading); }
.wu-view-switch button.is-active,
.wu-view-switch a.is-active {
  background: var(--wu-surface);
  color: var(--wu-primary);
  box-shadow: var(--wu-shadow-xs);
}
.wu-view-switch svg { width: 16px; height: 16px; }

/* --- Sidebar ------------------------------------------------------------- */
.wu-filters {
  background: var(--wu-surface);
  border: 1px solid var(--wu-border);
  border-radius: var(--wu-radius-lg);
  padding: var(--wu-space-5);
}

.wu-filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wu-space-3);
  margin-bottom: var(--wu-space-4);
  padding-bottom: var(--wu-space-3);
  border-bottom: 1px solid var(--wu-border);
}
.wu-filters-head h3 { margin: 0; font-size: var(--wu-fs-base); }

/* --- Group, collapsible -------------------------------------------------- */
.wu-filter-group + .wu-filter-group {
  margin-top: var(--wu-space-5);
  padding-top: var(--wu-space-5);
  border-top: 1px solid var(--wu-border);
}

.wu-filter-group > h4,
.wu-filter-group > button.wu-filter-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  /* Full width already, but only as tall as its label — under the 24px
     WCAG 2.5.8 floor on touch. */
  min-block-size: 24px;
  margin: 0 0 var(--wu-space-3);
  padding: 0;
  border: 0;
  background: none;
  transition: color var(--wu-duration-sm) var(--wu-ease);
  font-family: inherit;
  font-size: var(--wu-fs-sm);
  font-weight: var(--wu-fw-semibold);
  color: var(--wu-heading);
  text-transform: none;
  letter-spacing: 0;
  text-align: start;
  cursor: pointer;
}
/* The chevron is the legend's own child; the glyph sits inside the label. */
.wu-filter-legend > svg {
  width: 12px;
  height: 12px;
  color: var(--wu-text-muted);
  transition: transform var(--wu-duration-sm) var(--wu-ease);
}
.wu-filter-legend[aria-expanded="false"] > svg { transform: rotate(-90deg); }

/* Group title with its glyph, in the service colour, so a hotel, tour or
   transfer panel reads as that service at a glance. */
.wu-filter-legend-label {
  display: inline-flex;
  align-items: center;
  gap: var(--wu-space-2);
}
.wu-filter-legend-label svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--wu-service);
}
.wu-filter-legend[aria-expanded="false"] + .wu-filter-body { display: none; }

/* Long option lists scroll rather than pushing the results out of view. */
.wu-filter-body-scroll {
  max-height: 220px;
  overflow-y: auto;
  padding-inline-end: var(--wu-space-2);
}

/* A whole row is clickable, so it needs to say so on hover - it was the one
   interactive element in the template with no feedback at all. The inline
   padding keeps the tint clear of the text without moving anything. */
.wu-filter-check {
  display: flex;
  align-items: center;
  gap: var(--wu-space-2);
  padding: var(--wu-space-1) var(--wu-space-2);
  margin-inline: calc(var(--wu-space-2) * -1);
  border-radius: var(--wu-radius-sm);
  font-size: var(--wu-fs-sm);
  cursor: pointer;
  transition: background-color var(--wu-duration-sm) var(--wu-ease),
              color var(--wu-duration-sm) var(--wu-ease);
}
.wu-filter-check:hover { background-color: var(--wu-surface-alt); color: var(--wu-heading); }
.wu-filter-check:has(input:checked) { color: var(--wu-heading); font-weight: var(--wu-fw-medium); }
.wu-filter-check input {
  accent-color: var(--wu-service);
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
.wu-filter-check .wu-count {
  margin-inline-start: auto;
  font-size: var(--wu-fs-xs);
  color: var(--wu-text-muted);
}
.wu-filter-check:hover { color: var(--wu-heading); }

/* Star rows reuse the rating component */
.wu-filter-check .wu-stars svg { width: 12px; height: 12px; }

/* --- Long lists: the first few, then "View all" (WayUgo.filters) --------- */
.wu-filter-check[hidden] { display: none; }

.wu-filter-more {
  display: inline-flex;
  align-items: center;
  gap: var(--wu-space-1);
  margin-top: var(--wu-space-2);
  padding: 0;
  border: 0;
  background: none;
  transition: color var(--wu-duration-sm) var(--wu-ease);
  font: inherit;
  font-size: var(--wu-fs-sm);
  font-weight: var(--wu-fw-semibold);
  color: var(--wu-primary);
  cursor: pointer;
}
.wu-filter-more:hover { text-decoration: underline; }
.wu-filter-more:focus-visible {
  outline: 2px solid var(--wu-primary);
  outline-offset: 2px;
  border-radius: 2px;
}
.wu-filter-more span { font-weight: var(--wu-fw-normal); color: var(--wu-text-muted); }
.wu-filter-more svg {
  width: 10px;
  height: 10px;
  transition: transform var(--wu-duration-sm) var(--wu-ease);
}
.wu-filter-more[aria-expanded="true"] svg { transform: rotate(180deg); }
.wu-filter-more[hidden] { display: none; }

/* --- Price range ---------------------------------------------------------
   Two native range inputs stacked over one track. Native sliders keep
   keyboard and screen-reader support for free; a custom drag implementation
   would have to rebuild both. Pointer events are disabled on the track and
   re-enabled on the thumbs so the lower one stays grabbable.
   -------------------------------------------------------------------------- */
.wu-range {
  padding-top: var(--wu-space-2);
  /* Thumb positions as percentages, written by filters.js on every input
     event. Declared here so the selected span renders correctly before the
     first sync, and so the contract is visible in the stylesheet. */
  --wu-range-from: 0%;
  --wu-range-to: 100%;
}

.wu-range-values {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wu-space-2);
  margin-bottom: var(--wu-space-3);
  font-size: var(--wu-fs-sm);
  font-weight: var(--wu-fw-semibold);
  color: var(--wu-heading);
}
.wu-range-values span { font-weight: var(--wu-fw-normal); color: var(--wu-text-muted); }

.wu-range-track {
  position: relative;
  height: 28px;
}

/* The visible rail and the selected span between the two thumbs. */
.wu-range-track::before,
.wu-range-rail {
  content: "";
  position: absolute;
  top: 50%;
  height: 4px;
  border-radius: var(--wu-radius-pill);
  transform: translateY(-50%);
}
.wu-range-track::before {
  left: 0;
  right: 0;
  background: var(--wu-surface-sunken);
}
.wu-range-rail {
  left: var(--wu-range-from, 0%);
  right: calc(100% - var(--wu-range-to, 100%));
  background: var(--wu-service);
}

.wu-range-track input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 28px;
  margin: 0;
  background: none;
  appearance: none;
  pointer-events: none;   /* re-enabled on the thumbs below */
}
.wu-range-track input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  pointer-events: auto;
  width: 18px;
  height: 18px;
  border: 2px solid var(--wu-service);
  border-radius: 50%;
  background: var(--wu-surface);
  box-shadow: var(--wu-shadow-xs);
  cursor: grab;
}
.wu-range-track input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 18px;
  height: 18px;
  border: 2px solid var(--wu-service);
  border-radius: 50%;
  background: var(--wu-surface);
  box-shadow: var(--wu-shadow-xs);
  cursor: grab;
}
.wu-range-track input[type="range"]:focus-visible::-webkit-slider-thumb {
  outline: 3px solid rgba(var(--wu-primary-rgb), .45);
}

/* --- Active filter chips -------------------------------------------------- */
.wu-active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wu-space-2);
  margin-bottom: var(--wu-space-4);
}
.wu-active-filters:empty { display: none; }

.wu-active-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--wu-space-2);
  padding: 0.3rem 0.4rem 0.3rem 0.75rem;
  border: 1px solid var(--wu-border);
  border-radius: var(--wu-radius-pill);
  background: var(--wu-surface);
  font-size: var(--wu-fs-xs);
  color: var(--wu-text);
}
.wu-active-chip button {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--wu-surface-sunken);
  color: var(--wu-text-muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--wu-duration-sm) var(--wu-ease),
              color var(--wu-duration-sm) var(--wu-ease);
}
.wu-active-chip button:hover { background: var(--wu-danger); color: #fff; }
.wu-active-chip-label { color: var(--wu-text-muted); }

/* --- Pagination ---------------------------------------------------------- */
.wu-pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--wu-space-2);
  margin-top: var(--wu-space-6);
}
.wu-pagination button {
  min-width: 40px;
  height: 40px;
  padding: 0 var(--wu-space-3);
  border: 1px solid var(--wu-border);
  border-radius: var(--wu-radius);
  background: var(--wu-surface);
  font-family: inherit;
  font-size: var(--wu-fs-sm);
  color: var(--wu-text);
  cursor: pointer;
  transition: border-color var(--wu-duration-sm) var(--wu-ease),
              color var(--wu-duration-sm) var(--wu-ease);
}
.wu-pagination button:hover:not(:disabled) { border-color: var(--wu-service); color: var(--wu-service); }
.wu-pagination button.is-current {
  background: var(--wu-service-text);
  border-color: var(--wu-service);
  color: #fff;
  font-weight: var(--wu-fw-semibold);
}
.wu-pagination button:disabled { opacity: .45; cursor: not-allowed; }
.wu-pagination .wu-pagination-gap {
  align-self: center;
  padding-inline: var(--wu-space-1);
  color: var(--wu-text-muted);
}

/* --- Mobile drawer -------------------------------------------------------
   Below 992px the sidebar becomes an off-canvas sheet. Same markup â€” only the
   positioning changes, so there is one filter DOM, not two.
   -------------------------------------------------------------------------- */
.wu-filter-toggle { display: none; }

@media (max-width: 991.98px) {
  .wu-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--wu-space-2);
  }
  .wu-filter-toggle .wu-badge { margin-inline-start: var(--wu-space-1); }

  .wu-listing-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--wu-z-drawer);
    width: min(360px, 90vw);
    max-height: none;
    overflow-y: auto;
    border-radius: 0;
    transform: translateX(-100%);
    /* Same reason as the always-drawer variant: off screen is not hidden. */
    visibility: hidden;
    transition: transform var(--wu-duration) var(--wu-ease-out),
                visibility var(--wu-duration);
  }
  .wu-listing-sidebar.is-open { transform: translateX(0); visibility: visible; }

  .wu-filters {
    height: 100%;
    border: 0;
    border-radius: 0;
    padding-bottom: var(--wu-space-9);
  }

  /* Sticky apply/clear bar at the foot of the sheet. */
  .wu-filters-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: var(--wu-space-2);
    margin: var(--wu-space-5) calc(var(--wu-space-5) * -1) calc(var(--wu-space-5) * -1);
    padding: var(--wu-space-4) var(--wu-space-5);
    background: var(--wu-surface);
    border-top: 1px solid var(--wu-border);
  }
  .wu-filters-actions .wu-btn { flex: 1 1 0; }
}

@media (min-width: 992px) {
  /* On desktop the sheet chrome is meaningless â€” the sidebar is just a panel. */
  .wu-filters-actions { display: none; }
  .wu-filters-close { display: none; }
}

/* --- Map view: filter panel on top of the map ----------------------------
   The map view has no room for a permanent sidebar column, and sliding a
   full-height sheet in from the left covered the very thing the filters are
   meant to narrow. Instead the panel rides on the map as a collapsed bar and
   opens downward.

   Both classes on purpose (0,2,0): responsive.css loads after this file and
   its `@media (min-width:992px) .wu-listing-sidebar { position: sticky }` has
   equal specificity, so it would otherwise drag this back into the flow and
   reserve 856px of empty column beside the map.
   -------------------------------------------------------------------------- */
.wu-map-pane { position: relative; }

.wu-listing-sidebar.wu-listing-sidebar-drawer {
  position: absolute;
  top: var(--wu-space-3);
  left: var(--wu-space-3);
  right: var(--wu-space-3);
  bottom: auto;
  /* Above Leaflet, which paints its own panes at z-index 400 and its controls
     at 1000 — a small value here left the panel behind the tiles. Still below
     the sticky header (1030) and the nav drawer. */
  z-index: calc(var(--wu-z-sticky) - 1);
  width: auto;
  max-height: none;
  overflow: visible;
  transform: none;
  visibility: visible;
}

.wu-listing-sidebar-drawer .wu-filters {
  padding: 0;
  border-radius: var(--wu-radius-lg);
  box-shadow: var(--wu-shadow);
  background: rgba(255, 255, 255, .94);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  backdrop-filter: blur(12px) saturate(160%);
  /* Muted text over a translucent panel drops under AA otherwise - the same
     correction the search widget and the menus already carry. */
  --wu-text-muted: #33403A;
}

.wu-listing-sidebar-drawer .wu-filters-head {
  margin: 0;
  padding: var(--wu-space-3) var(--wu-space-4);
  border-bottom: 1px solid transparent;
  transition: border-color var(--wu-duration-sm) var(--wu-ease);
}
.wu-listing-sidebar-drawer.is-open .wu-filters-head { border-bottom-color: var(--wu-border); }

.wu-listing-sidebar-drawer .wu-filters-toggle { display: inline-flex; }
.wu-listing-sidebar-drawer .wu-filters-close,
.wu-listing-sidebar-drawer .wu-filters-actions { display: none; }

.wu-filters-toggle { display: none; }
.wu-filters-toggle svg { transition: transform var(--wu-duration-sm) var(--wu-ease); }
.wu-filters-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

/* The accordion.
   grid-template-rows 0fr -> 1fr animates to the content's natural height, so
   no hardcoded max-height can clip a longer filter set. */
.wu-listing-sidebar-drawer .wu-filters-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--wu-duration) var(--wu-ease);
}
.wu-listing-sidebar-drawer.is-open .wu-filters-body { grid-template-rows: 1fr; }

.wu-listing-sidebar-drawer .wu-filters-body-inner {
  min-height: 0;
  overflow-y: auto;
  /* Capped so a long filter list cannot swallow the whole map. */
  max-height: min(60vh, 460px);
  padding: 0 var(--wu-space-4);
}
.wu-listing-sidebar-drawer.is-open .wu-filters-body-inner { padding-bottom: var(--wu-space-4); }

/* Backdrop belongs to the off-canvas sheet, not the accordion. Its own class
   rather than the nav drawer's, which responsive.css display:none's at 992px. */
.wu-filters-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--wu-z-drawer) - 1);
  background: var(--wu-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--wu-duration) var(--wu-ease),
              visibility var(--wu-duration);
}
.wu-filters-backdrop.is-open { opacity: 1; visibility: visible; }

@media (max-width: 575.98px) {
  .wu-filter-bar { padding: var(--wu-space-3); }
  .wu-filter-bar .wu-select { width: 100%; min-width: 0; }
}
