/* Reusable toggle switch */
/* ====================== */
/*
  A self-contained, theme-aware switch — no Bootstrap classes required. A bare
  checkbox is restyled into a track + knob that fills with the theme accent when
  on. Markup:

    <div class="pg-switch">
      <input class="pg-switch__input" type="checkbox" id="…">
      <label class="pg-switch__label" for="…">Label</label>
    </div>

  The label renders to the left of the switch regardless of source order, and the
  whole row stretches to fill its container (label left, switch right).

  Modifier:
    .pg-switch--sm   slightly smaller track/knob with a wider label gap
*/

/* Row: label left, switch right. */
.pg-switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  column-gap: 0.75rem;

  padding: 0.5rem 0.65rem;
}

/* Track + knob */
.pg-switch__input {
  --pg-switch-track: 2.25rem;
  --pg-switch-height: 1.25rem;
  --pg-switch-knob: 0.95rem;
  --pg-switch-knob-inset: 0.15rem;

  flex: 0 0 auto;
  margin: 0;

  width: var(--pg-switch-track);
  height: var(--pg-switch-height);

  appearance: none;
  background-color: color-mix(in oklab, var(--bs-secondary-color) 35%, transparent);
  border: none;
  border-radius: 1rem;
  cursor: pointer;

  /* Knob drawn as a positioned pseudo-element for a smooth slide */
  position: relative;
  transition: background-color 0.2s ease;

  &::before {
    content: "";
    position: absolute;
    top: 50%;
    left: var(--pg-switch-knob-inset);
    width: var(--pg-switch-knob);
    height: var(--pg-switch-knob);
    border-radius: 50%;
    background-color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transform: translateY(-50%);
    transition: left 0.2s ease;
  }

  &:checked {
    background-color: var(--pg-accent, var(--bs-primary));
  }

  &:checked::before {
    left: calc(100% - var(--pg-switch-knob) - var(--pg-switch-knob-inset));
  }

  &:focus-visible {
    outline: none;
    box-shadow: 0 0 0 0.2rem color-mix(in oklab, var(--pg-accent, var(--bs-primary)) 30%, transparent);
  }

  &:disabled {
    opacity: 0.5;
    cursor: default;
  }
}

.pg-switch__label {
  flex: 1 1 auto;
  order: -1;

  line-height: 1.2;
  cursor: pointer;
}

.pg-switch__input:disabled + .pg-switch__label {
  cursor: default;
}

/* Small variant: slightly smaller track/knob, with extra space between the label
   and the switch (the label sits to the left, so widen the gap). */
.pg-switch--sm {
  column-gap: 1rem;
}

.pg-switch--sm .pg-switch__input {
  --pg-switch-track: 1.9rem;
  --pg-switch-height: 1.05rem;
  --pg-switch-knob: 0.8rem;
  --pg-switch-knob-inset: 0.125rem;
}
