/* Shared by the Astro, React and Vanilla Slider variants. */

/*
 * A row: label, track, readout. The label column is as wide as the label, or
 * --exo-slider-label-width to line up a stack of sliders (micrograph uses 92px).
 * The readout reserves --exo-slider-value-chars characters (set from the
 * formatted min and max), or --exo-slider-value-width, so the track doesn't
 * move as the value changes.
 */
.exo-slider {
  --exo-slider-fill: 0;
  --exo-slider-thumb-size: var(--exo-space-5, 16px);
  --exo-slider-track-height: var(--exo-space-1, 4px);
  --exo-slider-track-color: var(--exo-color-border, #dddddd);
  --exo-slider-fill-color: var(--exo-color-text, #333333);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: var(--exo-space-3, 8px);
  width: 100%;
  min-width: 0;
  font-family: var(--exo-font-family-sans, system-ui, sans-serif);
  font-size: var(--exo-font-size-sm, 14px);
  line-height: var(--exo-font-line-height-snug, 1.25);
  color: var(--exo-color-text, #333333);
}

.exo-slider__label {
  flex: 0 0 var(--exo-slider-label-width, auto);
  min-width: 0;
  overflow-wrap: anywhere;
}

.exo-slider__value {
  flex: none;
  min-width: var(--exo-slider-value-width, calc(var(--exo-slider-value-chars, 4) * 1ch));
  font-family: var(--exo-font-family-mono, ui-monospace, monospace);
  font-size: var(--exo-font-size-xs, 12px);
  font-variant-numeric: tabular-nums;
  color: var(--exo-color-text-muted, #666666);
  text-align: right;
  white-space: nowrap;
}

/* The input: native, with its own look removed so the parts below can draw it. */
.exo-slider__input {
  flex: 1 1 auto;
  min-width: 0;
  height: var(--exo-slider-thumb-size);
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.exo-slider__input:focus-visible {
  outline: none;
}

/*
 * Track. WebKit/Blink have no part for the filled range, so the track draws it
 * as a gradient that stops under the thumb's center: half a thumb in, plus the
 * fill of the distance the center travels. Firefox draws it with ::-moz-range-progress.
 */
.exo-slider__input::-webkit-slider-runnable-track {
  box-sizing: border-box;
  height: var(--exo-slider-track-height);
  background: linear-gradient(
    to right,
    var(--exo-slider-fill-color) 0
      calc(var(--exo-slider-thumb-size) / 2 + (100% - var(--exo-slider-thumb-size)) * var(--exo-slider-fill)),
    var(--exo-slider-track-color) 0
  );
  border: 0;
  border-radius: var(--exo-radius-full, 999px);
}

.exo-slider__input::-moz-range-track {
  box-sizing: border-box;
  height: var(--exo-slider-track-height);
  background: var(--exo-slider-track-color);
  border: 0;
  border-radius: var(--exo-radius-full, 999px);
}

.exo-slider__input::-moz-range-progress {
  height: var(--exo-slider-track-height);
  background: var(--exo-slider-fill-color);
  border-radius: var(--exo-radius-full, 999px);
}

/* Thumb: a disc in the page color with a hairline ring, like a TextInput's border. */
.exo-slider__input::-webkit-slider-thumb {
  box-sizing: border-box;
  width: var(--exo-slider-thumb-size);
  height: var(--exo-slider-thumb-size);
  /* Centers the thumb on the track, which WebKit/Blink align to the top. */
  margin-top: calc((var(--exo-slider-track-height) - var(--exo-slider-thumb-size)) / 2);
  background: var(--exo-color-bg, #ffffff);
  border: var(--exo-border-width-1, 1px) solid var(--exo-color-border-strong, #cccccc);
  border-radius: var(--exo-radius-full, 999px);
  box-shadow: 0 1px 2px var(--exo-color-shadow, rgb(0 0 0 / 0.2));
  -webkit-appearance: none;
  appearance: none;
}

.exo-slider__input::-moz-range-thumb {
  box-sizing: border-box;
  width: var(--exo-slider-thumb-size);
  height: var(--exo-slider-thumb-size);
  background: var(--exo-color-bg, #ffffff);
  border: var(--exo-border-width-1, 1px) solid var(--exo-color-border-strong, #cccccc);
  border-radius: var(--exo-radius-full, 999px);
  box-shadow: 0 1px 2px var(--exo-color-shadow, rgb(0 0 0 / 0.2));
}

/* States. Kept as separate rules: a browser drops a whole rule with a selector it doesn't know. */
.exo-slider__input:hover:not(:disabled)::-webkit-slider-thumb {
  border-color: var(--exo-color-text-muted, #666666);
}

.exo-slider__input:hover:not(:disabled)::-moz-range-thumb {
  border-color: var(--exo-color-text-muted, #666666);
}

/* The focus ring goes on the thumb, with the same color and gap as other controls' outlines. */
.exo-slider__input:focus-visible::-webkit-slider-thumb {
  box-shadow:
    0 0 0 var(--exo-border-width-2, 2px) var(--exo-color-bg, #ffffff),
    0 0 0 calc(var(--exo-border-width-2, 2px) * 2) var(--exo-color-accent, #2f5fdb);
}

.exo-slider__input:focus-visible::-moz-range-thumb {
  box-shadow:
    0 0 0 var(--exo-border-width-2, 2px) var(--exo-color-bg, #ffffff),
    0 0 0 calc(var(--exo-border-width-2, 2px) * 2) var(--exo-color-accent, #2f5fdb);
}

.exo-slider__input:disabled {
  cursor: not-allowed;
}

.exo-slider:has(> .exo-slider__input:disabled) {
  opacity: 0.5;
}

/* Forced colors drop backgrounds and shadows; draw the parts in system colors. */
@media (forced-colors: active) {
  .exo-slider__input {
    forced-color-adjust: none;
    --exo-slider-track-color: GrayText;
    --exo-slider-fill-color: Highlight;
  }

  .exo-slider__input::-webkit-slider-thumb {
    background: ButtonFace;
    border-color: ButtonText;
  }

  .exo-slider__input::-moz-range-thumb {
    background: ButtonFace;
    border-color: ButtonText;
  }

  .exo-slider__input:focus-visible::-webkit-slider-thumb {
    outline: var(--exo-border-width-2, 2px) solid Highlight;
    outline-offset: var(--exo-border-width-2, 2px);
  }

  .exo-slider__input:focus-visible::-moz-range-thumb {
    outline: var(--exo-border-width-2, 2px) solid Highlight;
    outline-offset: var(--exo-border-width-2, 2px);
  }
}
