$switch-w: 56px;
$switch-h: 28px;
$knob: 22px;
$gap: 3px;

.switch {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 0 0 24px;

  & input[type='checkbox'] {
    height: 0;
    width: 0;
    display: none;
  }

  & label {
    cursor: pointer;
    width: $switch-w;
    height: $switch-h;
    background: $blue-grey-200;
    display: block;
    border-radius: $switch-h;
    position: relative;
    margin: 0;
    overflow: hidden;
    transition: background 0.25s ease, box-shadow 0.25s ease;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);

    &:after {
      content: '';
      position: absolute;
      top: $gap;
      left: $gap;
      width: $knob;
      height: $knob;
      background: $white;
      border-radius: $knob;
      transition: all 0.28s ease;
      z-index: 1;
      box-shadow: 0 1px 2px rgba(0, 0, 0, .14);
    }

    .switch__icon {
      position: absolute;
      top: $gap;
      left: 0;
      width: $knob;
      height: $knob;
      display: flex;
      align-items: center;
      justify-content: center;
      pointer-events: none;
      line-height: 1;
      transition: all 0.28s ease;
      z-index: 3;

      >.material-icons {
        width: $knob;
        height: $knob;
        font-size: 16px;
        line-height: $knob;
        text-align: center;
      }

      >.material-symbols-outlined,
      >.material-symbols-rounded,
      >.material-symbols-sharp {
        width: $knob;
        height: $knob;
        font-size: 18px;
        line-height: $knob;
        text-align: center;
        font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
      }

      >svg,
      >i {
        width: $knob - 2px;
        height: $knob - 2px;
        display: inline-block;
      }
    }

    .switch__state {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      right: 8px;
      left: auto;
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 0.02em;
      color: $grey-dark;
      z-index: 2;
      pointer-events: none;
      white-space: nowrap;
      line-height: 1;
      max-width: calc(100% - (#{$knob} + #{$gap * 2} + 8px));
      overflow: hidden;
      text-overflow: ellipsis;
      opacity: 0.9;
    }

    &:active:after {
      width: $knob + 12px;
    }
  }

  & input:checked+label {
    background: $grey;

    &:after {
      left: calc(100% - #{$gap});
      transform: translateX(-100%);
      background: $grey-dark;
    }

    .switch__icon {
      left: calc(100% - #{$gap});
      transform: translateX(-100%);
    }

    .switch__state {
      left: 8px;
      right: auto;
      color: $white;
      opacity: 1;
      text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
    }
  }

  &--primary {
    & input:checked+label {
      background: $primary-color;

      &:after {
        background: lighten($primary-color, 30%);
      }

      .switch__state {
        color: #fff;
        opacity: 1;
      }
    }
  }

  &--secondary {
    & input:checked+label {
      background: $secondary-color;

      &:after {
        background: lighten($secondary-color, 30%);
      }

      .switch__state {
        color: #fff;
        opacity: 1;
      }
    }
  }

  &--disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;

    & label {
      cursor: not-allowed;
    }
  }

  &--label-left,
  &--label--left {
    flex-direction: row;
  }

  &--label-right,
  &--label--right {
    flex-direction: row-reverse;
    justify-content: flex-end;
  }

  &--label-top,
  &--label--top {
    flex-direction: column;
  }

  &--label-base,
  &--label--base {
    flex-direction: column-reverse;
  }

  &--label--right .switch__text,
  &--label-right .switch__text {
    margin-right: 10px;
    margin-left: 0;
  }

  &--label--left .switch__text,
  &--label-left .switch__text {
    margin-left: 10px;
    margin-right: 0;
  }

  &--label--top .switch__text,
  &--label-top .switch__text {
    margin: 0 0 8px;
  }

  &--label--base .switch__text,
  &--label-base .switch__text {
    margin: 8px 0 0;
  }

  &+.switch {
    margin-top: 8px;
  }

  &__wrapper {
    display: flex;
  }

  &__item {
    display: flex;
    padding: 6px;
  }

  &__text {
    font-weight: 500;
    font-size: 0.95rem;
    line-height: 1.25;
    white-space: nowrap;
    margin: 0 6px;
  }

  &.switch--vertical {

    &.switch--label--right,
    &.switch--label-right,
    &.switch--label--left,
    &.switch--label-left,
    &.switch--label--top,
    &.switch--label-top,
    &.switch--label--base,
    &.switch--label-base {
      flex-direction: column;
      align-items: center;

      .switch__text {
        margin: 6px 0 4px;
        white-space: normal;
        text-align: center;
      }
    }

    & label {
      width: $switch-h;
      height: $switch-w;

      &:after {
        top: $gap;
        left: $gap;
        width: $knob;
        height: $knob;
        border-radius: $knob;
      }

      .switch__icon {
        top: $gap;
        left: 0;
        transform: none;
      }

      .switch__state {
        left: 35%;
        right: auto;
        top: auto;
        bottom: 9px;
        transform: translateX(-50%);
        max-width: 100%;
        text-align: center;
        font-size: 10px;
      }

      &:active:after {
        height: $knob + 12px;
        width: $knob;
      }
    }

    & input:checked+label {
      &:after {
        top: calc(100% - #{$gap});
        left: $gap;
        transform: translateY(-100%);
      }

      .switch__icon {
        top: calc(100% - #{$gap});
        left: 0;
        transform: translateY(-100%);
      }

      .switch__state {
        bottom: auto;
        top: 9px;
        transform: translateX(-50%);
      }
    }
  }
}