:root {
  --switch-checked-background-color: var(--switch-highlight-color); /* background color active */
  --switch-thumb-background-color: white;
  --switch-thumb-border-color: var(--border-color);
  --switch-thumb-border-color-active: var(--switch-highlight-color);
  --switch-height: 32px;
  --switch-width: 51px;

  --switch: {
    display: inline-block;
    vertical-align: top;
    @apply(--reset-box-model);
    @apply(--hide-input-parent);
    min-width: 51px;
  }

  --switch__toggle: {
    position: relative;
    display: inline-block;
    vertical-align: top;
    @apply(--reset-box-model);
    @apply(--reset-base);
    @apply(--reset-cursor);
  }
}

/*~
  name: Switch
  category: Switch
  elements: ons-switch
  markup: |
    <label class="switch">
      <input type="checkbox" class="switch__input">
      <div class="switch__toggle">
        <div class="switch__handle"></div>
      </div>
    </label>
    <label class="switch">
      <input type="checkbox" class="switch__input" checked>
      <div class="switch__toggle">
        <div class="switch__handle"></div>
      </div>
    </label>
    <label class="switch">
      <input type="checkbox" class="switch__input" disabled>
      <div class="switch__toggle">
        <div class="switch__handle"></div>
      </div>
    </label>
*/

.switch {
  @apply(--switch);
  font-size: var(--font-size);
  padding: 0 20px;
  border: none;
  overflow: visible;
  width: var(--switch-width);
  height: var(--switch-height);
  z-index: 0;
  text-align: left;
}

.switch__input {
  @apply(--hide-input);
  z-index: 0;
}

/* switch toggle background */
.switch__toggle {
  background-color: var(--switch-background-color);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 30px;
  transition-property: all;
  transition-duration: 0.35s;
  transition-timing-function: ease-out;
  box-shadow: inset 0 0 0 2px var(--switch-border-color);
}

/* switch toggle circle */
.switch__handle {
  @apply(--reset-box-model);
  position: absolute;
  content: '';
  border-radius: 28px;
  height: 28px;
  width: 28px;
  background-color: var(--switch-thumb-background-color);
  left: 1px;
  top: 2px;
  transition-property: all;
  transition-duration: 0.35s;
  transition-timing-function: cubic-bezier(.59, .01, .5, .99);
  box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.25), 0 3px 2px rgba(0, 0, 0, 0.25);
}

.switch--active__handle {
  transition: none;
}

:checked + .switch__toggle {
  box-shadow: inset 0 0 0 2px var(--switch-checked-background-color);
  background-color: var(--switch-checked-background-color);
}

:checked + .switch__toggle > .switch__handle {
  left: 21px;
  box-shadow: 0 3px 2px rgba(0, 0, 0, 0.25);
}

:disabled + .switch__toggle {
  @apply(--disabled);
}

.switch__touch {
  position: absolute;
  top: -5px;
  bottom: -5px;
  left: -10px;
  right: -10px;
}

/*~
  name: Material Switch
  category: Switch
  elements: ons-switch
  markup: |
    <label class="switch switch--material">
      <input type="checkbox" class="switch__input switch--material__input">
      <div class="switch__toggle switch--material__toggle">
        <div class="switch__handle switch--material__handle">
        </div>
      </div>
    </label>
    <label class="switch switch--material">
      <input type="checkbox" class="switch__input switch--material__input" checked>
      <div class="switch__toggle switch--material__toggle">
        <div class="switch__handle switch--material__handle">
        </div>
      </div>
    </label>
    <label class="switch switch--material">
      <input type="checkbox" class="switch__input switch--material__input" disabled>
      <div class="switch__toggle switch--material__toggle">
        <div class="switch__handle switch--material__handle">
        </div>
      </div>
    </label>
*/

.switch--material {
  width: 36px;
  height: 24px;
  padding: 0 10px;
  min-width: 36px;
}

.switch--material__toggle {
  background-color: var(--material-switch-inactive-background-color);
  margin-top: 5px;
  height: 14px;
  box-shadow: none;
}

.switch--material__input {
  @apply(--hide-input);
  z-index: 0;
}

.switch--material__handle {
  background-color: var(--material-switch-inactive-thumb-color);
  left: 0;
  margin-top: -5px;
  width: 20px;
  height: 20px;
  @apply(--material-shadow-2);
}

:checked + .switch--material__toggle {
  background-color: var(--material-switch-active-background-color);
  box-shadow: none;
}

:checked + .switch--material__toggle > .switch--material__handle {
  left: 16px;
  background-color: var(--material-switch-active-thumb-color);
  @apply(--material-shadow-1);
}

:disabled + .switch--material__toggle {
  @apply(--disabled);
}

.switch--material__handle:before {
  background: transparent;
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  z-index: 0;
  box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.12);
  transition: box-shadow 0.1s linear;
}

.switch--material__toggle > .switch--active__handle:before {
  box-shadow: 0 0 0 14px rgba(0, 0, 0, 0.12);
}

:checked + .switch--material__toggle > .switch--active__handle:before {
  box-shadow: 0 0 0 14px color(var(--material-switch-active-thumb-color) alpha(20%));
}

.switch--material__touch {
  position: absolute;
  top: -10px;
  bottom: -10px;
  left: -15px;
  right: -15px;
}
