.navds-switch {
  position: relative;
  min-height: 3rem;
  width: fit-content;
}

.navds-switch--small {
  min-height: 2rem;
}

/* ------------------------------ Switch Input ------------------------------ */
.navds-switch__input {
  cursor: pointer;
  position: absolute;
  z-index: 1;
  width: 3rem;
  height: 3rem;
  opacity: 0;
  top: 0;

  .navds-switch--small > & {
    height: 2rem;
    top: 0;
  }
}

/* -------------------------- Switch content/label -------------------------- */
.navds-switch__label-wrapper {
  cursor: pointer;
  color: var(--ax-text-default);
}

.navds-switch__content {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.75rem 0 0.75rem 3.25rem;

  .navds-switch--right & {
    padding: 0.75rem 3.25rem 0.75rem 0;
  }

  .navds-switch--small & {
    padding: calc(var(--ax-spacing-2) - var(--ax-spacing-05)) 0 calc(var(--ax-spacing-2) - var(--ax-spacing-05)) 3.25rem;
  }

  .navds-switch--right.navds-switch--small & {
    padding: calc(var(--ax-spacing-2) - var(--ax-spacing-05)) 3.25rem calc(var(--ax-spacing-2) - var(--ax-spacing-05)) 0;
  }
}

.navds-switch--with-description {
  padding-bottom: 0;
}

.navds-switch__input:hover ~ .navds-switch__label-wrapper,
.navds-switch__label-wrapper:hover {
  color: var(--ax-text-accent-strong);
}

.navds-switch__input:disabled:hover ~ .navds-switch__label-wrapper {
  color: inherit;
}

/* ------------------------------ Switch Track ------------------------------ */
.navds-switch__track {
  width: 2.75rem;
  height: 1.5rem;
  background-color: var(--ax-bg-input);
  position: absolute;
  top: var(--ax-spacing-3);
  left: 0;
  border-radius: var(--ax-border-radius-full);
  border: 2px solid var(--ax-border-default);
  transition-property: background-color, border-color;
  transition-duration: 100ms;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);

  .navds-switch--small > & {
    top: var(--ax-spacing-1);
  }

  .navds-switch__input:checked ~ & {
    background-color: var(--ax-bg-accent-strong-pressed);
    border-color: var(--ax-bg-accent-strong-pressed);
  }

  .navds-switch__input:hover:checked ~ & {
    background-color: var(--ax-bg-accent-strong-hover);
    border-color: var(--ax-bg-accent-strong-hover);
  }

  .navds-switch__input:disabled ~ & {
    background-color: var(--ax-bg-input);
    border-color: var(--ax-border-default);
  }

  .navds-switch__input:checked:disabled ~ & {
    background-color: var(--ax-bg-accent-strong-pressed);
    border-color: var(--ax-bg-accent-strong-pressed);
  }

  .navds-switch__input:focus-visible ~ & {
    outline: 2px solid var(--ax-border-focus);
    outline-offset: 2px;
  }
}

/* ------------------------------ Switch Thumb ------------------------------ */
.navds-switch__thumb {
  background-color: var(--ax-bg-neutral-strong);
  border-radius: var(--ax-border-radius-full);
  width: 1.125rem;
  height: 1.125rem;
  position: absolute;
  transform: translateX(0);
  transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  left: 0.0625rem;
  top: 0.0625rem;

  .navds-switch__input:checked ~ .navds-switch__track > & {
    background-color: var(--ax-bg-raised);
    transform: translateX(1.25rem);
    color: var(--ax-text-accent-strong);
    width: 1.25rem;
    height: 1.25rem;
    left: 0;
    top: 0;
  }

  .navds-switch__input:checked ~ .navds-switch__track > & > .navds-switch__checkmark {
    visibility: visible;
    opacity: 1;
  }
}

.navds-switch__checkmark {
  visibility: hidden;
  opacity: 0;
  transition: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

@media (hover: hover) and (pointer: fine) {
  .navds-switch__input:hover:not(:disabled) ~ .navds-switch__track > .navds-switch__thumb {
    transform: translateX(0.0625rem);
  }

  .navds-switch__input:checked:hover:not(:disabled) ~ .navds-switch__track > .navds-switch__thumb {
    transform: translateX(1.19rem);
  }
}

.navds-switch--right {
  width: auto;

  & .navds-switch__input,
  & .navds-switch__track {
    right: 0;
    left: auto;
  }
}

/* -------------------------- Switch Disabled-state ------------------------- */
.navds-switch__input:disabled {
  appearance: none;
}

.navds-switch--disabled:not(.navds-switch--loading) {
  opacity: var(--ax-opacity-disabled);
}

.navds-switch__input:disabled,
.navds-switch__input:disabled ~ .navds-switch__label-wrapper {
  cursor: not-allowed;
}

/* -------------------------- Switch Readonly state ------------------------- */
.navds-switch--readonly {
  & > .navds-switch__track,
  & > .navds-switch__input:hover ~ .navds-switch__track,
  & > .navds-switch__input:checked ~ .navds-switch__track,
  & > .navds-switch__input:checked:hover ~ .navds-switch__track {
    background-color: var(--ax-bg-neutral-moderate);
    border-color: var(--ax-border-neutral-subtleA);
  }

  & > .navds-switch__label-wrapper,
  & > .navds-switch__input {
    cursor: default;
  }

  & > .navds-switch__input:hover ~ .navds-switch__label-wrapper,
  & .navds-switch__label-wrapper:hover {
    color: var(--ax-text-default);
  }

  & .navds-switch__label {
    display: inline-flex;
  }

  & .navds-switch__thumb {
    background-color: var(--ax-bg-neutral-strong);
  }

  & > .navds-switch__input:checked ~ .navds-switch__track > .navds-switch__thumb {
    background-color: var(--ax-bg-neutral-strong);
    color: var(--ax-text-neutral-contrast);
  }

  @media (hover: hover) and (pointer: fine) {
    & > .navds-switch__input:hover ~ .navds-switch__track > .navds-switch__thumb {
      transform: translateX(0);
    }

    & > .navds-switch__input:checked:hover ~ .navds-switch__track > .navds-switch__thumb {
      transform: translateX(1.25rem);
    }
  }
}

/* ------------------------ Switch Forced colors mode ----------------------- */
@media (forced-colors: active) {
  .navds-switch__input:hover ~ .navds-switch__label-wrapper,
  .navds-switch__label-wrapper:hover {
    color: highlight;
  }

  .navds-switch__thumb,
  .navds-switch--readonly .navds-switch__thumb {
    background-color: fieldtext !important;
  }

  .navds-switch__input:checked ~ .navds-switch__track > .navds-switch__thumb,
  .navds-switch--readonly .navds-switch__input:checked ~ .navds-switch__track > .navds-switch__thumb {
    color: field;
  }

  .navds-switch__input:focus-visible ~ .navds-switch__track {
    outline: 2px solid highlight;
    outline-offset: 2px;
  }

  .navds-switch--disabled:not(.navds-switch--loading) {
    opacity: 1;
  }

  .navds-switch--disabled:not(.navds-switch--loading) .navds-switch__thumb {
    background-color: graytext;
  }

  .navds-switch--disabled:not(.navds-switch--loading) .navds-switch__track {
    border-color: graytext !important;
  }

  .navds-switch--disabled:not(.navds-switch--loading) .navds-switch__label-wrapper,
  .navds-switch--disabled:not(.navds-switch--loading) .navds-switch__label-wrapper:hover {
    color: graytext !important;
  }
}
