/* Base Switch */
.ds-switch {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--size3, 12px);
  cursor: pointer;
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
}

.ds-switch--disabled {
  cursor: not-allowed;
}

/* Visually hidden native input */
.ds-switch__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Track */
.ds-switch__track {
  position: relative;
  display: flex;
  align-items: center;
  width: 52px;
  height: 32px;
  padding: var(--size1, 4px);
  border-radius: var(--br-full, 9999px);
  background-color: var(--switch-unselected-bg-default);
  box-shadow: inset 0 0 0 1px var(--switch-border-default);
  transition: all 0.2s ease-in-out;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* Handle */
.ds-switch__handle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background-color: var(--switch-bg-default);
  border-radius: var(--br-full, 9999px);
  box-shadow: inset 0 0 0 1px var(--switch-border-default);
  transform: translateX(0);
  transition: all 0.2s ease-in-out;
}

/* Icons */
.ds-switch__icon {
  position: absolute;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
}

.ds-switch__icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.ds-switch__icon--check {
  opacity: 0;
  color: var(--semantic-icon-brand-bold);
}

.ds-switch__icon--cross {
  opacity: 1;
  color: var(--semantic-icon-brand-disabled);
}

/* Label & description */
.ds-switch__label-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--size1, 4px);
}

.ds-switch__label {
  font-family: var(--body-regular-fontFamily, var(--font-family, 'Satoshi', sans-serif));
  font-size: var(--body-regular-fontSize, 16px);
  font-weight: var(--body-regular-fontWeight, 400);
  line-height: var(--body-regular-lineHeight, 150%);
  color: var(--semantic-text-corp-primary);
}

.ds-switch__description {
  font-family: var(--body-small-fontFamily, var(--font-family, 'Satoshi', sans-serif));
  font-size: var(--body-small-fontSize, 14px);
  line-height: var(--body-small-lineHeight, 150%);
  color: var(--semantic-text-corp-secondary);
}

/* Checked state */
.ds-switch__input:checked + .ds-switch__track {
  background-color: var(--switch-selected-bg-default);
  box-shadow: inset 0 0 0 1px var(--switch-selected-bg-default);
}

.ds-switch__input:checked + .ds-switch__track .ds-switch__handle {
  transform: translateX(20px);
}

.ds-switch__input:checked + .ds-switch__track .ds-switch__icon--check {
  opacity: 1;
}

.ds-switch__input:checked + .ds-switch__track .ds-switch__icon--cross {
  opacity: 0;
}

/* Hover */
.ds-switch:hover .ds-switch__track {
  background-color: var(--switch-unselected-bg-hover);
}

.ds-switch:hover .ds-switch__input:checked + .ds-switch__track {
  background-color: var(--switch-selected-bg-hover);
  box-shadow: inset 0 0 0 1px var(--switch-selected-bg-hover);
}

/* Focus */
.ds-switch__input:focus-visible + .ds-switch__track {
  box-shadow: inset 0 0 0 1px var(--switch-border-default), var(--semantic-focus-indigo);
  outline: none;
}

.ds-switch__input:checked:focus-visible + .ds-switch__track {
  box-shadow: inset 0 0 0 1px var(--switch-selected-bg-default), var(--semantic-focus-bright-blue);
}

/* Disabled */
.ds-switch__input:disabled + .ds-switch__track {
  background-color: var(--switch-bg-disabled);
  box-shadow: inset 0 0 0 1px var(--switch-border-disabled);
  cursor: not-allowed;
  opacity: 0.7;
}

.ds-switch__input:disabled + .ds-switch__track .ds-switch__handle {
  background-color: var(--switch-bg-default);
  box-shadow: inset 0 0 0 1px var(--switch-border-disabled);
}

.ds-switch__input:disabled + .ds-switch__track .ds-switch__icon {
  color: var(--semantic-icon-brand-disabled);
}

.ds-switch__input:disabled ~ .ds-switch__label-wrapper .ds-switch__label,
.ds-switch__input:disabled ~ .ds-switch__label-wrapper .ds-switch__description {
  color: var(--semantic-text-corp-disabled);
}

/* Disable hover when disabled */
.ds-switch:hover .ds-switch__input:disabled + .ds-switch__track {
  background-color: var(--switch-bg-disabled);
}

/* Error state */
.ds-switch--error .ds-switch__track {
  box-shadow: inset 0 0 0 1px var(--semantic-border-error-default);
}

.ds-switch--error .ds-switch__label {
  color: var(--semantic-text-error);
}
