{
  "id": 118,
  "slug": "visual-range-histogram-filter",
  "name": "Visual Range Histogram Slider Filter",
  "kind": "ui",
  "family": "Search & Filtering",
  "sourceSite": {
    "name": "Turo",
    "url": "https://turo.com",
    "verifiedStatus": 200
  },
  "tagline": "Dual-handle price range slider overlaid directly on a live distribution histogram that filters listings in real time.",
  "whyUnique": "Eliminates blind min/max guessing by showing exactly where inventory clusters before the user drags a single handle.",
  "theme": "light",
  "mobileStrength": "high",
  "tags": [
    "histogram-slider",
    "range-filter",
    "dual-handle",
    "data-viz-input",
    "marketplace"
  ],
  "bestFor": [
    "Car & travel rental search",
    "Real estate price filters",
    "Flight & hotel aggregators",
    "E-commerce spec filters"
  ],
  "palette": [
    {
      "role": "canvas",
      "hex": "#F9F8F6",
      "name": "Warm Alabaster"
    },
    {
      "role": "surface",
      "hex": "#FFFFFF",
      "name": "Card White"
    },
    {
      "role": "ink",
      "hex": "#18181B",
      "name": "Asphalt Ink"
    },
    {
      "role": "accent",
      "hex": "#593CFB",
      "name": "Drive Violet"
    },
    {
      "role": "muted",
      "hex": "#71717A",
      "name": "Roadway Gray"
    }
  ],
  "typography": {
    "display": "Plus Jakarta Sans",
    "body": "Inter",
    "mono": "JetBrains Mono",
    "googleFontsUrl": "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@600&family=Plus+Jakarta+Sans:wght@700;800&display=swap",
    "scaleNotes": "Tabular mono price readouts ($45 — $165/day) paired with crisp 15px vehicle titles and spec chips."
  },
  "layoutNotes": "Top filter card housing the 20-bar distribution histogram + dual-handle slider + synchronized numeric inputs, followed by a responsive vehicle card grid.",
  "interactionNotes": "Dragging either handle highlights in-range histogram bars in accent violet, dims out-of-range bars, prevents handle crossover, and live-filters matching cards with an instant reset pill.",
  "mobileNotes": "Oversized 44px touch hit-zones around both slider thumbs ensure effortless dragging on 390px screens without fighting scroll.",
  "agentGuardrails": {
    "do": [
      "Enforce a minimum separation gap so min and max handles never overlap into an ungrabbable stack",
      "Pair the visual slider with synchronized min/max readouts and keyboard arrow support on both thumbs",
      "Show the exact matching listing count and average price dynamically as the user drags"
    ],
    "dont": [
      "Do not render a decorative static histogram that ignores the actual underlying dataset distribution",
      "Do not force users to hit a separate Apply button when filtering a local client-side dataset"
    ]
  },
  "demoFile": "demos/visual-range-histogram-filter.html",
  "thumbDesktop": "thumbs/visual-range-histogram-filter-desktop.webp",
  "thumbMobile": "thumbs/visual-range-histogram-filter-mobile.webp",
  "urls": {
    "page": "https://templates.michaelpitts.net/t/visual-range-histogram-filter",
    "markdown": "https://templates.michaelpitts.net/t/visual-range-histogram-filter.md",
    "api": "https://templates.michaelpitts.net/api/templates/visual-range-histogram-filter",
    "demo": "https://templates.michaelpitts.net/demos/visual-range-histogram-filter.html",
    "thumbDesktop": "https://templates.michaelpitts.net/thumbs/visual-range-histogram-filter-desktop.webp",
    "thumbMobile": "https://templates.michaelpitts.net/thumbs/visual-range-histogram-filter-mobile.webp"
  },
  "agentPrompt": "Design & build using template #118 \"Visual Range Histogram Slider Filter\" (ui / Search & Filtering, light theme).\nFull AI blueprint & standalone starter code: https://templates.michaelpitts.net/t/visual-range-histogram-filter.md\nLive demo: https://templates.michaelpitts.net/demos/visual-range-histogram-filter.html\nReal-world inspiration: Turo (https://turo.com)\n\nCore aesthetic: Eliminates blind min/max guessing by showing exactly where inventory clusters before the user drags a single handle.\nPalette: canvas: #F9F8F6 (Warm Alabaster), surface: #FFFFFF (Card White), ink: #18181B (Asphalt Ink), accent: #593CFB (Drive Violet), muted: #71717A (Roadway Gray)\nTypography: Display=\"Plus Jakarta Sans\", Body=\"Inter\", Mono=\"JetBrains Mono\"\nLayout: Top filter card housing the 20-bar distribution histogram + dual-handle slider + synchronized numeric inputs, followed by a responsive vehicle card grid.\nInteractions: Dragging either handle highlights in-range histogram bars in accent violet, dims out-of-range bars, prevents handle crossover, and live-filters matching cards with an instant reset pill.\nMobile: Oversized 44px touch hit-zones around both slider thumbs ensure effortless dragging on 390px screens without fighting scroll.\n\nGuardrails:\n- DO: Enforce a minimum separation gap so min and max handles never overlap into an ungrabbable stack\n- DO: Pair the visual slider with synchronized min/max readouts and keyboard arrow support on both thumbs\n- DO: Show the exact matching listing count and average price dynamically as the user drags\n- DON'T: Do not render a decorative static histogram that ignores the actual underlying dataset distribution\n- DON'T: Do not force users to hit a separate Apply button when filtering a local client-side dataset",
  "sourceCode": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>DriveGrid — Visual Range Histogram Filter</title>\n<style>\n  :root {\n    --canvas: #F9F8F6;\n    --surface: #FFFFFF;\n    --ink: #18181B;\n    --accent: #593CFB;\n    --accent-soft: #F3F0FF;\n    --muted: #71717A;\n    --border: #E5E4E0;\n    --bar-off: #E4E4E7;\n    --font: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", system-ui, sans-serif;\n  }\n\n  * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }\n\n  body {\n    background: var(--canvas);\n    color: var(--ink);\n    font-family: var(--font);\n    min-height: 100dvh;\n    overflow-x: hidden;\n  }\n\n  .page {\n    max-width: 1120px;\n    margin: 0 auto;\n    padding: 18px 14px 64px;\n  }\n\n  @media (min-width: 760px) {\n    .page { padding: 30px 28px 80px; }\n  }\n\n  .header {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: flex-end;\n    justify-content: space-between;\n    gap: 12px;\n    margin-bottom: 18px;\n  }\n\n  .header h1 {\n    font-size: 25px;\n    font-weight: 800;\n    letter-spacing: -0.025em;\n  }\n\n  .header p {\n    font-size: 13px;\n    color: var(--muted);\n    margin-top: 2px;\n  }\n\n  .trip-badge {\n    font-size: 12px;\n    font-weight: 650;\n    color: var(--ink);\n    background: var(--surface);\n    border: 1px solid var(--border);\n    padding: 8px 13px;\n    border-radius: 999px;\n  }\n\n  /* Histogram Filter Card */\n  .filter-card {\n    background: var(--surface);\n    border: 1px solid var(--border);\n    border-radius: 20px;\n    padding: 18px 18px 16px;\n    box-shadow: 0 10px 28px rgba(24, 24, 27, 0.05);\n    margin-bottom: 22px;\n  }\n\n  .filter-top {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: center;\n    justify-content: space-between;\n    gap: 10px;\n    margin-bottom: 14px;\n  }\n\n  .price-summary {\n    display: flex;\n    align-items: baseline;\n    gap: 10px;\n    flex-wrap: wrap;\n  }\n\n  .range-readout {\n    font-size: 20px;\n    font-weight: 800;\n    color: var(--ink);\n    letter-spacing: -0.02em;\n  }\n\n  .range-readout span { color: var(--accent); }\n\n  .avg-readout {\n    font-size: 12px;\n    font-weight: 600;\n    color: var(--muted);\n  }\n\n  .filter-actions {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n  }\n\n  .cat-strip {\n    display: flex;\n    gap: 6px;\n    flex-wrap: wrap;\n  }\n\n  .cat-btn {\n    min-height: 44px;\n    padding: 0 13px;\n    border-radius: 10px;\n    border: 1px solid var(--border);\n    background: var(--canvas);\n    color: var(--muted);\n    font-size: 12px;\n    font-weight: 650;\n    cursor: pointer;\n    transition: all 0.14s;\n  }\n  .cat-btn[aria-pressed=\"true\"] {\n    background: var(--accent-soft);\n    color: var(--accent);\n    border-color: rgba(89, 60, 251, 0.45);\n  }\n\n  .reset-btn {\n    min-height: 44px;\n    padding: 0 14px;\n    border-radius: 10px;\n    border: 1px solid var(--border);\n    background: var(--surface);\n    color: var(--ink);\n    font-size: 12px;\n    font-weight: 650;\n    cursor: pointer;\n  }\n  .reset-btn:hover { border-color: var(--accent); color: var(--accent); }\n\n  /* Histogram + Overlaid Dual-Handle Slider */\n  .hist-slider-box {\n    position: relative;\n    padding: 8px 14px 26px;\n    user-select: none;\n    -webkit-user-select: none;\n  }\n\n  .bars {\n    height: 92px;\n    display: grid;\n    grid-template-columns: repeat(20, 1fr);\n    align-items: end;\n    gap: 4px;\n    padding-bottom: 2px;\n  }\n\n  .bar {\n    border-radius: 4px 4px 1px 1px;\n    background: var(--bar-off);\n    transition: background 0.14s, transform 0.14s;\n    min-height: 6px;\n  }\n\n  .bar.in-range {\n    background: var(--accent);\n  }\n\n  .track-wrap {\n    position: relative;\n    height: 24px;\n    display: flex;\n    align-items: center;\n    touch-action: none;\n  }\n\n  .track-bg {\n    position: absolute;\n    left: 0;\n    right: 0;\n    height: 4px;\n    border-radius: 999px;\n    background: var(--bar-off);\n  }\n\n  .track-fill {\n    position: absolute;\n    height: 4px;\n    border-radius: 999px;\n    background: var(--accent);\n  }\n\n  .thumb {\n    position: absolute;\n    top: 50%;\n    width: 28px;\n    height: 28px;\n    margin-left: -14px;\n    transform: translateY(-50%);\n    border-radius: 50%;\n    background: #FFFFFF;\n    border: 2.5px solid var(--accent);\n    box-shadow: 0 4px 12px rgba(89, 60, 251, 0.28);\n    cursor: grab;\n    touch-action: none;\n    z-index: 3;\n    transition: transform 0.1s, box-shadow 0.1s;\n  }\n\n  /* Invisible 44px touch halo */\n  .thumb::after {\n    content: \"\";\n    position: absolute;\n    inset: -10px;\n  }\n\n  .thumb:hover, .thumb:focus-visible {\n    outline: none;\n    box-shadow: 0 0 0 5px rgba(89, 60, 251, 0.2);\n  }\n  .thumb.active {\n    cursor: grabbing;\n    transform: translateY(-50%) scale(1.12);\n    z-index: 4;\n  }\n\n  .scale-labels {\n    display: flex;\n    justify-content: space-between;\n    font-size: 11px;\n    font-weight: 600;\n    color: var(--muted);\n    margin-top: 6px;\n  }\n\n  /* Results bar */\n  .results-bar {\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    margin-bottom: 12px;\n    padding: 0 2px;\n    font-size: 13px;\n    color: var(--muted);\n  }\n  .results-bar strong { color: var(--ink); }\n\n  /* Vehicle Grid */\n  .car-grid {\n    display: grid;\n    grid-template-columns: 1fr;\n    gap: 14px;\n  }\n\n  @media (min-width: 640px) {\n    .car-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }\n  }\n  @media (min-width: 980px) {\n    .car-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }\n  }\n\n  .car-card {\n    background: var(--surface);\n    border: 1px solid var(--border);\n    border-radius: 16px;\n    overflow: hidden;\n    display: flex;\n    flex-direction: column;\n    transition: transform 0.16s, box-shadow 0.16s;\n  }\n  .car-card:hover {\n    transform: translateY(-2px);\n    box-shadow: 0 12px 26px rgba(24, 24, 27, 0.08);\n  }\n\n  .car-visual {\n    height: 128px;\n    width: 100%;\n    display: block;\n  }\n\n  .car-body {\n    padding: 13px 15px 15px;\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n    flex: 1;\n  }\n\n  .car-head {\n    display: flex;\n    justify-content: space-between;\n    align-items: flex-start;\n    gap: 8px;\n  }\n\n  .car-name {\n    font-size: 15px;\n    font-weight: 750;\n    color: var(--ink);\n  }\n\n  .car-rating {\n    font-size: 12px;\n    font-weight: 700;\n    color: var(--ink);\n    white-space: nowrap;\n  }\n  .car-rating span { color: var(--accent); }\n\n  .car-specs {\n    font-size: 12px;\n    color: var(--muted);\n  }\n\n  .car-footer {\n    margin-top: auto;\n    padding-top: 10px;\n    border-top: 1px solid #F4F4F5;\n    display: flex;\n    justify-content: space-between;\n    align-items: baseline;\n  }\n\n  .car-tag {\n    font-size: 11px;\n    font-weight: 700;\n    padding: 3px 8px;\n    border-radius: 6px;\n    background: var(--accent-soft);\n    color: var(--accent);\n  }\n\n  .car-price {\n    font-size: 17px;\n    font-weight: 800;\n    color: var(--ink);\n  }\n  .car-price small { font-size: 12px; font-weight: 500; color: var(--muted); }\n\n  .empty-box {\n    grid-column: 1 / -1;\n    text-align: center;\n    padding: 44px 16px;\n    background: var(--surface);\n    border: 1px dashed var(--border);\n    border-radius: 16px;\n    color: var(--muted);\n  }\n</style>\n</head>\n<body>\n  <div class=\"page\">\n    <header class=\"header\">\n      <div>\n        <h1>San Francisco · Car Search</h1>\n        <p>Drag either price handle directly beneath the live distribution histogram</p>\n      </div>\n      <div class=\"trip-badge\">Fri 10:00 AM → Sun 6:00 PM</div>\n    </header>\n\n    <section class=\"filter-card\" aria-label=\"Daily Price Range Histogram Filter\">\n      <div class=\"filter-top\">\n        <div class=\"price-summary\">\n          <div class=\"range-readout\" id=\"rangeReadout\"><span>$45</span> – <span>$215</span> / day</div>\n          <div class=\"avg-readout\" id=\"avgReadout\">Avg $118/day</div>\n        </div>\n        <div class=\"filter-actions\">\n          <div class=\"cat-strip\" role=\"group\" aria-label=\"Vehicle type\">\n            <button class=\"cat-btn\" data-cat=\"all\" aria-pressed=\"true\">All</button>\n            <button class=\"cat-btn\" data-cat=\"EV\" aria-pressed=\"false\">EV</button>\n            <button class=\"cat-btn\" data-cat=\"SUV\" aria-pressed=\"false\">SUV</button>\n            <button class=\"cat-btn\" data-cat=\"Sport\" aria-pressed=\"false\">Sport</button>\n          </div>\n          <button class=\"reset-btn\" id=\"resetBtn\">Reset</button>\n        </div>\n      </div>\n\n      <div class=\"hist-slider-box\">\n        <div class=\"bars\" id=\"histBars\" aria-hidden=\"true\"></div>\n        <div class=\"track-wrap\" id=\"trackWrap\">\n          <div class=\"track-bg\"></div>\n          <div class=\"track-fill\" id=\"trackFill\"></div>\n          <div class=\"thumb\" id=\"thumbMin\" role=\"slider\" tabindex=\"0\" aria-label=\"Minimum daily price\" aria-valuemin=\"35\" aria-valuemax=\"245\" aria-valuenow=\"45\"></div>\n          <div class=\"thumb\" id=\"thumbMax\" role=\"slider\" tabindex=\"0\" aria-label=\"Maximum daily price\" aria-valuemin=\"35\" aria-valuemax=\"245\" aria-valuenow=\"215\"></div>\n        </div>\n        <div class=\"scale-labels\">\n          <span>$35/day</span>\n          <span>$105</span>\n          <span>$175</span>\n          <span>$245+/day</span>\n        </div>\n      </div>\n    </section>\n\n    <div class=\"results-bar\">\n      <span id=\"matchCount\"><strong>12 vehicles</strong> available in range</span>\n      <span>Instant Book · Free Cancellation</span>\n    </div>\n\n    <main class=\"car-grid\" id=\"carGrid\"></main>\n  </div>\n\n<script>\n(() => {\n  const MIN_PRICE = 35;\n  const MAX_PRICE = 245;\n  const STEP = 5;\n\n  // 20-bin market distribution curve (simulated local fleet inventory density)\n  const BIN_COUNTS = [2, 4, 6, 9, 12, 15, 18, 16, 14, 13, 11, 9, 10, 8, 7, 5, 4, 3, 2, 2];\n\n  const VEHICLES = [\n    { name: '2023 Honda Civic Hatch', cat: 'Compact', price: 48, rating: '4.94', trips: 112, specs: '36 MPG · Apple CarPlay · Mission Dist.', tint: ['#EEF2FF','#6366F1'] },\n    { name: '2024 Hyundai Ioniq 5', cat: 'EV', price: 68, rating: '4.98', trips: 84, specs: '303 mi range · Fast Charge · SoMa', tint: ['#ECFEFF','#0891B2'] },\n    { name: '2023 Subaru Outback AWD', cat: 'SUV', price: 76, rating: '4.91', trips: 147, specs: 'AWD · Roof Rack · Marina', tint: ['#ECFDF5','#059669'] },\n    { name: '2024 Tesla Model 3 Highland', cat: 'EV', price: 84, rating: '4.97', trips: 203, specs: '341 mi range · Autopilot · Hayes Valley', tint: ['#F5F3FF','#7C3AED'] },\n    { name: '2023 Mazda MX-5 Miata RF', cat: 'Sport', price: 96, rating: '4.99', trips: 61, specs: 'Retractable Hardtop · 6-Speed · Nob Hill', tint: ['#FFF1F2','#E11D48'] },\n    { name: '2024 Volvo XC40 Recharge', cat: 'SUV', price: 108, rating: '4.95', trips: 53, specs: 'AWD EV · Panoramic Roof · Noe Valley', tint: ['#F0F9FF','#0284C7'] },\n    { name: '2023 Polestar 2 Dual Motor', cat: 'EV', price: 115, rating: '4.96', trips: 79, specs: '408 hp · Pilot Pack · Dogpatch', tint: ['#F4F4F5','#52525B'] },\n    { name: '2024 Rivian R1S Adventure', cat: 'SUV', price: 148, rating: '5.00', trips: 38, specs: '7 Seats · Quad-Motor · Presidio', tint: ['#FEFCE8','#CA8A04'] },\n    { name: '2023 BMW M240i xDrive', cat: 'Sport', price: 162, rating: '4.93', trips: 45, specs: '382 hp · AWD Coupe · Embarcadero', tint: ['#EFF6FF','#2563EB'] },\n    { name: '2024 Porsche Macan T', cat: 'SUV', price: 185, rating: '4.98', trips: 67, specs: 'Sport Chrono · PASM · Pacific Heights', tint: ['#FAF5FF','#9333EA'] },\n    { name: '2023 Porsche Taycan 4S', cat: 'EV', price: 212, rating: '4.99', trips: 29, specs: '522 hp · 800V Fast Charge · FiDi', tint: ['#F0FDFA','#0D9488'] },\n    { name: '2024 Porsche 911 Carrera', cat: 'Sport', price: 238, rating: '5.00', trips: 19, specs: 'PDK · Sport Exhaust · North Beach', tint: ['#FFF7ED','#EA580C'] }\n  ];\n\n  let rangeMin = 45;\n  let rangeMax = 215;\n  let activeCat = 'all';\n\n  const histBarsEl = document.getElementById('histBars');\n  const trackWrap = document.getElementById('trackWrap');\n  const trackFill = document.getElementById('trackFill');\n  const thumbMin = document.getElementById('thumbMin');\n  const thumbMax = document.getElementById('thumbMax');\n  const rangeReadout = document.getElementById('rangeReadout');\n  const avgReadout = document.getElementById('avgReadout');\n  const matchCount = document.getElementById('matchCount');\n  const carGrid = document.getElementById('carGrid');\n\n  // Build 20 histogram bars\n  const maxBin = Math.max(...BIN_COUNTS);\n  const barEls = BIN_COUNTS.map((count, i) => {\n    const bar = document.createElement('div');\n    bar.className = 'bar';\n    bar.style.height = `${Math.max(10, Math.round((count / maxBin) * 100))}%`;\n    bar.dataset.bin = i;\n    histBarsEl.appendChild(bar);\n    return bar;\n  });\n\n  function carSvg([bg, accent], cat) {\n    const isSuv = cat === 'SUV';\n    const roof = isSuv\n      ? 'M 66 76 L 90 46 L 194 46 L 216 76 Z'\n      : cat === 'Sport'\n        ? 'M 74 78 L 108 54 L 184 54 L 214 78 Z'\n        : 'M 70 76 L 100 50 L 188 50 L 216 76 Z';\n    return `\n      <svg class=\"car-visual\" viewBox=\"0 0 280 128\" aria-hidden=\"true\">\n        <rect width=\"280\" height=\"128\" fill=\"${bg}\"/>\n        <ellipse cx=\"140\" cy=\"106\" rx=\"98\" ry=\"8\" fill=\"rgba(24,24,27,0.10)\"/>\n        <path d=\"${roof}\" fill=\"${accent}\" opacity=\"0.22\"/>\n        <path d=\"M 42 86 Q 48 70 72 68 L 208 68 Q 234 70 240 86 L 240 96 Q 240 100 232 100 L 48 100 Q 42 100 42 94 Z\" fill=\"${accent}\"/>\n        <path d=\"${roof}\" fill=\"none\" stroke=\"${accent}\" stroke-width=\"3.5\" stroke-linejoin=\"round\"/>\n        <circle cx=\"84\" cy=\"98\" r=\"14\" fill=\"#18181B\"/>\n        <circle cx=\"84\" cy=\"98\" r=\"6\" fill=\"#E4E4E7\"/>\n        <circle cx=\"198\" cy=\"98\" r=\"14\" fill=\"#18181B\"/>\n        <circle cx=\"198\" cy=\"98\" r=\"6\" fill=\"#E4E4E7\"/>\n      </svg>\n    `;\n  }\n\n  function pctFromVal(val) {\n    return ((val - MIN_PRICE) / (MAX_PRICE - MIN_PRICE)) * 100;\n  }\n\n  function valFromClientX(clientX) {\n    const rect = trackWrap.getBoundingClientRect();\n    const ratio = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));\n    const raw = MIN_PRICE + ratio * (MAX_PRICE - MIN_PRICE);\n    return Math.round(raw / STEP) * STEP;\n  }\n\n  function updateUI() {\n    const pMin = pctFromVal(rangeMin);\n    const pMax = pctFromVal(rangeMax);\n\n    thumbMin.style.left = `${pMin}%`;\n    thumbMax.style.left = `${pMax}%`;\n    trackFill.style.left = `${pMin}%`;\n    trackFill.style.width = `${pMax - pMin}%`;\n\n    thumbMin.setAttribute('aria-valuenow', rangeMin);\n    thumbMax.setAttribute('aria-valuenow', rangeMax);\n\n    rangeReadout.innerHTML = `<span>$${rangeMin}</span> – <span>$${rangeMax}${rangeMax === MAX_PRICE ? '+' : ''}</span> / day`;\n\n    // Highlight histogram bars inside selected price range\n    const binWidth = (MAX_PRICE - MIN_PRICE) / BIN_COUNTS.length;\n    barEls.forEach((bar, idx) => {\n      const binMid = MIN_PRICE + (idx + 0.5) * binWidth;\n      bar.classList.toggle('in-range', binMid >= rangeMin && binMid <= rangeMax);\n    });\n\n    // Filter vehicles\n    const matches = VEHICLES.filter(v => {\n      const priceOk = v.price >= rangeMin && (rangeMax === MAX_PRICE ? true : v.price <= rangeMax);\n      const catOk = activeCat === 'all' || v.cat === activeCat;\n      return priceOk && catOk;\n    });\n\n    matchCount.innerHTML = `<strong>${matches.length} ${matches.length === 1 ? 'vehicle' : 'vehicles'}</strong> available in range`;\n\n    if (matches.length > 0) {\n      const avg = Math.round(matches.reduce((s, v) => s + v.price, 0) / matches.length);\n      avgReadout.textContent = `Avg $${avg}/day in view`;\n    } else {\n      avgReadout.textContent = 'Expand range to see cars';\n    }\n\n    carGrid.innerHTML = '';\n    if (matches.length === 0) {\n      carGrid.innerHTML = `<div class=\"empty-box\">No vehicles between <strong>$${rangeMin}</strong> and <strong>$${rangeMax}/day</strong>. Try widening the slider handles or resetting filters.</div>`;\n      return;\n    }\n\n    matches.forEach(v => {\n      const card = document.createElement('article');\n      card.className = 'car-card';\n      card.innerHTML = `\n        ${carSvg(v.tint, v.cat)}\n        <div class=\"car-body\">\n          <div class=\"car-head\">\n            <h2 class=\"car-name\">${v.name}</h2>\n            <span class=\"car-rating\"><span>★</span> ${v.rating} (${v.trips})</span>\n          </div>\n          <div class=\"car-specs\">${v.specs}</div>\n          <div class=\"car-footer\">\n            <span class=\"car-tag\">${v.cat}</span>\n            <span class=\"car-price\">$${v.price}<small>/day</small></span>\n          </div>\n        </div>\n      `;\n      carGrid.appendChild(card);\n    });\n  }\n\n  // Dual-handle dragging\n  let dragging = null; // 'min' | 'max'\n\n  function startDrag(which, e) {\n    dragging = which;\n    const el = which === 'min' ? thumbMin : thumbMax;\n    el.classList.add('active');\n    el.setPointerCapture(e.pointerId);\n  }\n\n  function moveDrag(e) {\n    if (!dragging) return;\n    const val = valFromClientX(e.clientX);\n    if (dragging === 'min') {\n      rangeMin = Math.max(MIN_PRICE, Math.min(rangeMax - STEP * 2, val));\n    } else {\n      rangeMax = Math.min(MAX_PRICE, Math.max(rangeMin + STEP * 2, val));\n    }\n    updateUI();\n  }\n\n  function endDrag() {\n    if (!dragging) return;\n    thumbMin.classList.remove('active');\n    thumbMax.classList.remove('active');\n    dragging = null;\n  }\n\n  thumbMin.addEventListener('pointerdown', e => startDrag('min', e));\n  thumbMax.addEventListener('pointerdown', e => startDrag('max', e));\n  window.addEventListener('pointermove', moveDrag);\n  window.addEventListener('pointerup', endDrag);\n  window.addEventListener('pointercancel', endDrag);\n\n  // Clicking on the track jumps the nearest handle\n  trackWrap.addEventListener('pointerdown', e => {\n    if (e.target === thumbMin || e.target === thumbMax) return;\n    const val = valFromClientX(e.clientX);\n    const distMin = Math.abs(val - rangeMin);\n    const distMax = Math.abs(val - rangeMax);\n    if (distMin <= distMax) {\n      rangeMin = Math.max(MIN_PRICE, Math.min(rangeMax - STEP * 2, val));\n      startDrag('min', e);\n    } else {\n      rangeMax = Math.min(MAX_PRICE, Math.max(rangeMin + STEP * 2, val));\n      startDrag('max', e);\n    }\n    updateUI();\n  });\n\n  // Keyboard support on both thumbs\n  thumbMin.addEventListener('keydown', e => {\n    if (e.key === 'ArrowRight' || e.key === 'ArrowUp') { e.preventDefault(); rangeMin = Math.min(rangeMax - STEP * 2, rangeMin + STEP); updateUI(); }\n    if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') { e.preventDefault(); rangeMin = Math.max(MIN_PRICE, rangeMin - STEP); updateUI(); }\n  });\n  thumbMax.addEventListener('keydown', e => {\n    if (e.key === 'ArrowRight' || e.key === 'ArrowUp') { e.preventDefault(); rangeMax = Math.min(MAX_PRICE, rangeMax + STEP); updateUI(); }\n    if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') { e.preventDefault(); rangeMax = Math.max(rangeMin + STEP * 2, rangeMax - STEP); updateUI(); }\n  });\n\n  // Category buttons & reset\n  document.querySelectorAll('.cat-btn').forEach(btn => {\n    btn.addEventListener('click', () => {\n      document.querySelectorAll('.cat-btn').forEach(b => b.setAttribute('aria-pressed', 'false'));\n      btn.setAttribute('aria-pressed', 'true');\n      activeCat = btn.dataset.cat;\n      updateUI();\n    });\n  });\n\n  document.getElementById('resetBtn').addEventListener('click', () => {\n    rangeMin = MIN_PRICE;\n    rangeMax = MAX_PRICE;\n    activeCat = 'all';\n    document.querySelectorAll('.cat-btn').forEach(b => b.setAttribute('aria-pressed', String(b.dataset.cat === 'all')));\n    updateUI();\n  });\n\n  updateUI();\n})();\n</script>\n</body>\n</html>\n"
}
