/* Variables para fácil personalización */
$sliderColor: $mainColor;
$trackColor: rgba(white, 0.2);
$thumbSize: 20px;
$trackHeight: 8px;
$tooltipBg: $sliderColor;
$tooltipColor: $black;
$rangeLabelsColors: rgba(white, 0.6);

.range-wrapper {
    width: 100%;

    .labels {
        display: flex;
        justify-content: space-between;
        align-items: center;

        span {
            color: $rangeLabelsColors;
        }
    }
}

/* 1. Contenedor Principal */
.range-slider-container {
    position: relative;
    width: 100%;
    padding-top: 0px;
    /* Espacio para que el tooltip no se corte */
}

/* 2. Estilos del Slider (Reset) */
.custom-slider {
    -webkit-appearance: none;
    /* Ocultar estilos por defecto en WebKit */
    appearance: none;
    width: 100%;
    height: $trackHeight;
    background: transparent;
    /* El fondo lo manejará el track */
    outline: none;
    margin: 10px 0;
}

/* 3. Estilos del Track (Barra) */
.custom-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: $trackHeight;
    cursor: pointer;
    background: linear-gradient(to right,
            $sliderColor var(--fill-percent, 0%),
            /* Relleno dinámico */
            $trackColor var(--fill-percent, 0%)
            /* Resto del track */
        );
    border-radius: 5px;
}

.custom-slider::-moz-range-track {
    width: 100%;
    height: $trackHeight;
    cursor: pointer;
    background: linear-gradient(to right,
            $sliderColor var(--fill-percent, 0%),
            $trackColor var(--fill-percent, 0%));
    border-radius: 5px;
}

/* 4. Estilos del Thumb (Perilla) */
.custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: $thumbSize;
    width: $thumbSize;
    background: $sliderColor;
    border-radius: 50%;
    cursor: pointer;
    margin-top: calc(($thumbSize - $trackHeight) / 2 * -1);
    /* Centrar verticalmente */
    position: relative;
    z-index: 2;
}

.custom-slider::-moz-range-thumb {
    height: $thumbSize;
    width: $thumbSize;
    background: $sliderColor;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    /* Firefox añade un borde por defecto */
    position: relative;
    z-index: 2;
}

/* 5. Estilos del Tooltip */
.tooltip {
    position: absolute;
    bottom: 32px;
    /* Posición sobre el slider */
    left: 0;
    /* JS controlará esto */
    background: $tooltipBg;
    color: $tooltipColor;
    font-weight: bold;
    padding: 6px 10px;
    border-radius: 5px;
    font-size: 14px;
    white-space: nowrap;
    /* Evitar que el texto se parta */

    /* Centrado y animación */
    transform: translateX(-50%);
    /* Oculto por defecto */
    transition: opacity 0.2s ease;
    z-index: 3;
    pointer-events: none;
    /* Para que no interfiera con el clic */
}

/* Flecha del tooltip */
.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: $sliderColor transparent transparent transparent;
}

/* Mostrar tooltip al interactuar */
.custom-slider:active+.tooltip,
.custom-slider:focus+.tooltip {
    opacity: 1;
}