/**
 * SPDX-FileCopyrightText: 2026 Tony MageMEGA <https://magemega.com>
 * SPDX-License-Identifier: AFL-3.0
 *
 * Two-handle range slider for the layered navigation price filter: the component only.
 *
 * The track, the filled part, the two overlaid ranges and their thumbs live here. The
 * number fields - pill, currency symbol, separator, apply button - belong to the theme
 * and are never touched by this file.
 *
 * Themes customise the slider through the --lnps-* variables below. They are declared on
 * a zero-specificity selector, so any theme rule wins regardless of the stylesheet order:
 * for example '.price-filter-input { --lnps-track-on: #0b6d9f; }' is enough.
 */

:where(.price-filter-input) {
    --lnps-track-height: 4px;
    --lnps-track-off: var(--maho-color-border, color-mix(in oklab, currentColor 20%, transparent));
    --lnps-track-on: var(--color-base-content, var(--maho-color-primary, currentColor));
    --lnps-thumb-size: 16px;
    --lnps-thumb-border: 2px;
    --lnps-thumb-bg: var(--color-base-100, #fff);
    --lnps-thumb-ring: var(--color-secondary, currentColor);
}

/* the From/To labels of the handles are for screen readers only */
.price-filter-input .facet-range-wrapper > label {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    white-space: nowrap;
    clip-path: inset(50%);
}

/* The wrapper draws the filled part of the track: --range-min and --range-max are
   rewritten by price-slider.js on every movement and already rendered by the server for
   the initial state. */
.price-filter-input .facet-range-wrapper {
    position: relative;
    inline-size: 100%;
    block-size: var(--lnps-track-height);
    margin: 0 0 1.25rem;
    background: linear-gradient(
        to right,
        transparent var(--range-min, 0%),
        var(--lnps-track-on) var(--range-min, 0%),
        var(--lnps-track-on) var(--range-max, 100%),
        transparent var(--range-max, 100%)
    );
}

/* empty part of the track: transparent between the handles, so the filled part stays
   visible */
.price-filter-input .facet-range-wrapper::before {
    content: "";
    position: absolute;
    inset-inline: 0;
    inset-block-start: 50%;
    translate: 0 -50%;
    block-size: calc(var(--lnps-track-height) - 1px);
    background: linear-gradient(
        to right,
        var(--lnps-track-off) var(--range-min, 0%),
        transparent var(--range-min, 0%),
        transparent var(--range-max, 100%),
        var(--lnps-track-off) var(--range-max, 100%)
    );
}

/* Two overlaid range inputs: the first one in flow at full width, the second one
   absolutely positioned above it. They carry the same min/max (the category scale) and
   the two handles are independent because each input owns one value. The pointer is
   enabled on the thumbs only, so the track stays decorative and a click never moves a
   handle by accident. */
.price-filter-input .facet-range {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    inline-size: 100%;
    block-size: var(--lnps-track-height);
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    vertical-align: top;
    pointer-events: none;
}

.price-filter-input .facet-range__max {
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 0;
}

.price-filter-input .facet-range::-webkit-slider-runnable-track,
.price-filter-input .facet-range::-moz-range-track,
.price-filter-input .facet-range::-moz-range-progress {
    block-size: var(--lnps-track-height);
    border: 0;
    background: none;
}

.price-filter-input .facet-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    inline-size: var(--lnps-thumb-size);
    block-size: var(--lnps-thumb-size);
    /* no vertical margin: the engine centers the thumb on the runnable track, and here
       the track is as tall as the input box, so any offset would lift the thumb above
       the track drawn by the wrapper */
    border: var(--lnps-thumb-border) solid var(--lnps-track-on);
    border-radius: 100%;
    background: var(--lnps-thumb-bg);
    cursor: pointer;
    pointer-events: auto;
}

.price-filter-input .facet-range::-moz-range-thumb {
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    inline-size: var(--lnps-thumb-size);
    block-size: var(--lnps-thumb-size);
    border: var(--lnps-thumb-border) solid var(--lnps-track-on);
    border-radius: 100%;
    background: var(--lnps-thumb-bg);
    cursor: pointer;
    pointer-events: auto;
}

/* keyboard focus stays visible on the thumb */
.price-filter-input .facet-range:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--lnps-thumb-ring) 55%, transparent);
}

.price-filter-input .facet-range:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--lnps-thumb-ring) 55%, transparent);
}

/* a slightly larger thumb on touch screens, so it stays graspable */
@media (pointer: coarse) {
    :where(.price-filter-input) {
        --lnps-thumb-size: 20px;
    }
}
