// Variable for checkbox & radio
$btn-box-shadow: 0 3px 4px 1px rgba(0, 0, 0, 0.1);
$btn-box-shadow-hover: 0 1px 4px 0 rgba(0, 0, 0, 0.2);
$box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.1);
$text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
$material-colors: (
  red: #fb3a3a,
  pink: #e91e63,
  purple: #7460ee,
  deep-purple: #673ab7,
  indigo: #3f51b5,
  blue: #02bec9,
  light-blue: #03a9f4,
  cyan: #00bcd4,
  teal: #009688,
  green: #26c6da,
  light-green: #8bc34a,
  lime: #cddc39,
  yellow: #ffe821,
  amber: #ffc107,
  orange: #ff9800,
  deep-orange: #ff5722,
  brown: #795548,
  grey: #9e9e9e,
  blue-grey: #607d8b,
  black: #000000,
  white: #ffffff,
) !default;

// ########################################
// Checkbox
// ########################################
form p {
  margin-bottom: 10px;
  text-align: left;
}

form p:last-child {
  margin-bottom: 0;
}

/* Remove default checkbox */
[type="checkbox"]:not(:checked)[class*="material-inputs"],
[type="checkbox"]:checked[class*="material-inputs"] {
  position: absolute;
  left: -9999px;
  opacity: 0;
}

[type="checkbox"] {
  /* checkbox aspect */
}

[type="checkbox"].material-inputs + label {
  position: relative;
  padding-left: 26px;
  cursor: pointer;
  display: inline-block;
  height: 16px;
  line-height: 21px;
  font-size: 1rem;
  -webkit-user-select: none;
  /* webkit (safari, chrome) browsers */
  -moz-user-select: none;
  /* mozilla browsers */
  -khtml-user-select: none;
  /* webkit (konqueror) browsers */
  -ms-user-select: none;
  /* IE10+ */
}

[type="checkbox"].material-inputs + label:before,
[type="checkbox"].material-inputs:not(.filled-in) + label:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  z-index: 0;
  border: 1px solid #b1b8bb;
  border-radius: 1px;
  margin-top: 2px;
  transition: 0.2s;
}

[type="checkbox"].material-inputs:not(.filled-in) + label:after {
  border: 0;
  -webkit-transform: scale(0);
  transform: scale(0);
}

[type="checkbox"].material-inputs:not(:checked):disabled + label:before {
  border: none;
  background-color: rgba(0, 0, 0, 0.26);
}

[type="checkbox"].material-inputs.tabbed:focus + label:after {
  -webkit-transform: scale(1);
  transform: scale(1);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 10px rgba(0, 0, 0, 0.1);
  background-color: rgba(0, 0, 0, 0.1);
}

[type="checkbox"].material-inputs:checked + label:before {
  top: -4px;
  left: -5px;
  width: 12px;
  height: 22px;
  border-top: 2px solid transparent;
  border-left: 2px solid transparent;
  border-right: 2px solid #26a69a;
  border-bottom: 2px solid #26a69a;
  -webkit-transform: rotate(40deg);
  transform: rotate(40deg);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform-origin: 100% 100%;
  transform-origin: 100% 100%;
}

[type="checkbox"].material-inputs:checked:disabled + label:before {
  border-right: 2px solid rgba(0, 0, 0, 0.26);
  border-bottom: 2px solid rgba(0, 0, 0, 0.26);
}

/* Indeterminate checkbox */
[type="checkbox"].material-inputs:indeterminate + label:before {
  top: -11px;
  left: -12px;
  width: 10px;
  height: 22px;
  border-top: none;
  border-left: none;
  border-right: 2px solid #26a69a;
  border-bottom: none;
  -webkit-transform: rotate(90deg);
  transform: rotate(90deg);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform-origin: 100% 100%;
  transform-origin: 100% 100%;
}

[type="checkbox"].material-inputs:indeterminate:disabled + label:before {
  border-right: 2px solid rgba(0, 0, 0, 0.26);
  background-color: transparent;
}

[type="checkbox"].material-inputs.filled-in + label:after {
  border-radius: 2px;
}

[type="checkbox"].material-inputs.filled-in + label:before,
[type="checkbox"].material-inputs.filled-in + label:after {
  content: "";
  left: 0;
  position: absolute;
  /* .1s delay is for check animation */
  transition: border 0.25s, background-color 0.25s, width 0.2s 0.1s,
    height 0.2s 0.1s, top 0.2s 0.1s, left 0.2s 0.1s;
  z-index: 1;
}

[type="checkbox"].material-inputs.filled-in:not(:checked) + label:before {
  width: 0;
  height: 0;
  border: 3px solid transparent;
  left: 6px;
  top: 10px;
  -webkit-transform: rotateZ(37deg);
  transform: rotateZ(37deg);
  -webkit-transform-origin: 20% 40%;
  transform-origin: 100% 100%;
}

[type="checkbox"].material-inputs.filled-in:not(:checked) + label:after {
  height: 20px;
  width: 20px;
  background-color: transparent;
  border: 2px solid $border-color;
  top: 0px;
  z-index: 0;
}

[type="checkbox"].material-inputs.filled-in:checked + label:before {
  top: 0;
  left: 1px;
  width: 8px;
  height: 13px;
  border-top: 2px solid transparent;
  border-left: 2px solid transparent;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  -webkit-transform: rotateZ(37deg);
  transform: rotateZ(37deg);
  -webkit-transform-origin: 100% 100%;
  transform-origin: 100% 100%;
}

[type="checkbox"].material-inputs.filled-in:checked + label:after {
  top: 0;
  width: 20px;
  height: 20px;
  border: 2px solid #26a69a;
  background-color: #26a69a;
  z-index: 0;
}

[type="checkbox"].material-inputs.filled-in.tabbed:focus + label:after {
  border-radius: 2px;
  border-color: $border-color;
  background-color: rgba(0, 0, 0, 0.1);
}

[type="checkbox"].material-inputs.filled-in.tabbed:checked:focus + label:after {
  border-radius: 2px;
  background-color: #26a69a;
  border-color: #26a69a;
}

[type="checkbox"].material-inputs.filled-in:disabled:not(:checked)
  + label:before {
  background-color: transparent;
  border: 2px solid transparent;
}

[type="checkbox"].material-inputs.filled-in:disabled:not(:checked)
  + label:after {
  border-color: transparent;
  background-color: #bdbdbd;
}

[type="checkbox"].material-inputs.filled-in:disabled:checked + label:before {
  background-color: transparent;
}

[type="checkbox"].material-inputs.filled-in:disabled:checked + label:after {
  background-color: #bdbdbd;
  border-color: #bdbdbd;
}

// ########################################
// Radios
// ########################################
[type="radio"].material-inputs:not(:checked)[class*="material-inputs"],
[type="radio"].material-inputs:checked[class*="material-inputs"] {
  position: absolute;
  left: -9999px;
  opacity: 0;
}

[type="radio"].material-inputs:not(:checked) + label,
[type="radio"].material-inputs:checked + label {
  position: relative;
  padding-left: 26px;
  cursor: pointer;
  display: inline-block;
  height: 16px;
  line-height: 21px;
  font-size: 1rem;
  transition: 0.28s ease;
  /* webkit (konqueror) browsers */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

[type="radio"].material-inputs + label:before,
[type="radio"].material-inputs + label:after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  margin: 4px;
  width: 16px;
  height: 16px;
  z-index: 0;
  transition: 0.28s ease;
  border-radius: 50%;
}

/* Unchecked styles */
[type="radio"].material-inputss:not(:checked) + label:before,
[type="radio"].material-inputss:not(:checked) + label:after,
[type="radio"].material-inputss:checked + label:before,
[type="radio"].material-inputss:checked + label:after,
[type="radio"].material-inputss.with-gap:checked + label:before,
[type="radio"].material-inputss.with-gap:checked + label:after {
  border-radius: 50%;
}

[type="radio"].material-inputs:not(:checked) + label:before,
[type="radio"].material-inputs:not(:checked) + label:after {
  border: 2px solid $border-color;
}

[type="radio"].material-inputs:not(:checked) + label:after {
  z-index: -1;
  -webkit-transform: scale(0);
  transform: scale(0);
}

/* Checked styles */
[type="radio"].material-inputs:checked + label:before {
  border: 2px solid transparent;
  animation: ripple 0.2s linear forwards;
}

[type="radio"].material-inputs:checked + label:after,
[type="radio"].material-inputs.with-gap:checked + label:before,
[type="radio"].material-inputs.with-gap:checked + label:after {
  border: 2px solid #26a69a;
}

[type="radio"].material-inputs:checked + label:after,
[type="radio"].material-inputs.with-gap:checked + label:after {
  background-color: #26a69a;
  z-index: 0;
}

[type="radio"].material-inputs:checked + label:after {
  -webkit-transform: scale(1.02);
  transform: scale(1.02);
}

/* Radio With gap */
[type="radio"].material-inputs.with-gap:checked + label:after {
  -webkit-transform: scale(0.5);
  transform: scale(0.5);
}

/* Focused styles */
[type="radio"].material-inputs.tabbed:focus + label:before {
  box-shadow: 0 0 0 10px rgba(0, 0, 0, 0.1);
  animation: ripple 0.2s linear forwards;
}

/* Disabled Radio With gap */
[type="radio"].material-inputs.with-gap:disabled:checked + label:before {
  border: 2px solid rgba(0, 0, 0, 0.26);
  animation: ripple 0.2s linear forwards;
}

[type="radio"].material-inputs.with-gap:disabled:checked + label:after {
  border: none;
  background-color: rgba(0, 0, 0, 0.26);
}

/* Disabled style */
[type="radio"].material-inputs:disabled:not(:checked) + label:before,
[type="radio"].material-inputs:disabled:checked + label:before {
  background-color: transparent;
  border-color: rgba(0, 0, 0, 0.26);
  animation: ripple 0.2s linear forwards;
}

[type="radio"].material-inputs:disabled + label {
  color: rgba(0, 0, 0, 0.26);
}

[type="radio"].material-inputs:disabled:not(:checked) + label:before {
  border-color: rgba(0, 0, 0, 0.26);
}

[type="radio"].material-inputs:disabled:checked + label:after {
  background-color: rgba(0, 0, 0, 0.26);
  border-color: #bdbdbd;
}

//
// Mixin ad generate different color classes checkbox & radio
//
[type="checkbox"].material-inputs {
  + label {
    padding-left: 26px;
    height: 16px;
    line-height: 21px;

    font-weight: normal;
  }

  &:checked {
    + label {
      &:before {
        top: -4px;
        left: -2px;
        width: 11px;
        height: 19px;
      }
    }
  }

  @each $key, $val in $material-colors {
    &:checked.chk-col-#{$key} {
      + label {
        &:before {
          border-right: 2px solid $val;
          border-bottom: 2px solid $val;
        }
      }
    }
  }
}

[type="checkbox"].material-inputs.filled-in {
  &:checked {
    + label {
      &:after {
        top: 0;
        width: 20px;
        height: 20px;
        border: 2px solid #26a69a;
        background-color: #26a69a;
        z-index: 0;
      }

      &:before {
        border-right: 2px solid #fff !important;
        border-bottom: 2px solid #fff !important;
      }
    }
  }

  @each $key, $val in $material-colors {
    &:checked.chk-col-#{$key} {
      + label {
        &:after {
          border: 2px solid $val;
          background-color: $val;
        }
      }
    }
  }
}

[type="radio"].material-inputs {
  &:not(:checked) {
    + label {
      padding-left: 26px;
      height: 22px;
      line-height: 22px;

      font-weight: normal;
    }
  }

  &:checked {
    + label {
      padding-left: 26px;
      height: 22px;
      line-height: 22px;

      font-weight: normal;
    }
  }
}

@each $key, $val in $material-colors {
  [type="radio"].material-inputs.radio-col-#{$key} {
    &:checked {
      + label {
        &:after {
          background-color: $val;
          border-color: $val;
          animation: ripple 0.2s linear forwards;
        }
      }
    }
  }
}

@each $key, $val in $material-colors {
  [type="radio"].material-inputs.with-gap.radio-col-#{$key} {
    &:checked {
      + label {
        &:before {
          border: 2px solid $val;
          animation: ripple 0.2s linear forwards;
        }

        &:after {
          background-color: $val;
          border: 2px solid $val;
          animation: ripple 0.2s linear forwards;
        }
      }
    }
  }
}

//
// Switch
//
.switch,
.switch * {
  -webkit-user-select: none;
  -moz-user-select: none;
  -khtml-user-select: none;
  -ms-user-select: none;
}

.switch label {
  cursor: pointer;
}

.switch label input[type="checkbox"] {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch label input[type="checkbox"]:checked + .lever {
  background-color: #84c7c1;
}

.switch label input[type="checkbox"]:checked + .lever:after {
  background-color: #26a69a;
  left: 24px;
}

.switch label .lever {
  content: "";
  display: inline-block;
  position: relative;
  width: 40px;
  height: 15px;
  background-color: #818181;
  border-radius: 15px;
  margin-right: 10px;
  transition: background 0.3s ease;
  vertical-align: middle;
  margin: 0 16px;
}

.switch label .lever:after {
  content: "";
  position: absolute;
  display: inline-block;
  width: 21px;
  height: 21px;
  background-color: #f1f1f1;
  border-radius: 21px;
  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4);
  left: -5px;
  top: -3px;
  transition: left 0.3s ease, background 0.3s ease, box-shadow 0.1s ease;
}

input[type="checkbox"].material-inputs:checked:not(:disabled)
  ~ .lever:active::after,
input[type="checkbox"].material-inputs:checked:not(:disabled).tabbed:focus
  ~ .lever::after {
  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4),
    0 0 0 15px rgba(38, 166, 154, 0.1);
}

input[type="checkbox"].material-inputs:not(:disabled) ~ .lever:active:after,
input[type="checkbox"].material-inputs:not(:disabled).tabbed:focus
  ~ .lever::after {
  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px rgba(0, 0, 0, 0.08);
}

.switch input[type="checkbox"][disabled] + .lever {
  cursor: default;
}

.switch label input[type="checkbox"][disabled] + .lever:after,
.switch label input[type="checkbox"][disabled]:checked + .lever:after {
  background-color: #bdbdbd;
}

.switch {
  label {
    font-weight: normal;
    font-size: 13px;

    .lever {
      margin: 0 14px;
    }

    input[type="checkbox"] {
      &:checked {
        @each $key, $val in $material-colors {
          &:not(:disabled) {
            ~ .lever.switch-col-#{$key} {
              &:active {
                &:after {
                  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4),
                    0 0 0 15px rgba($val, 0.1);
                }
              }
            }
          }

          + .lever.switch-col-#{$key} {
            background-color: rgba($val, 0.5);

            &:after {
              background-color: $val;
            }
          }
        }
      }
    }
  }
}

//
// RTL
//
html[dir="rtl"] {
  [type="checkbox"]:not(:checked)[class*="material-inputs"],
  [type="checkbox"]:checked[class*="material-inputs"] {
    position: absolute;
    left: auto;
    right: -9999px;
    opacity: 0;
  }

  [type="checkbox"].material-inputs + label {
    padding-left: 0;
    padding-right: 26px;
  }

  [type="checkbox"].material-inputs:checked + label:before {
    left: auto;
    right: -5px;
  }

  [type="checkbox"].material-inputs.filled-in + label:before,
  [type="checkbox"].material-inputs.filled-in + label:after {
    left: auto;
    right: 0;
  }

  [type="checkbox"].material-inputs.filled-in:not(:checked) + label:before {
    left: auto;
    right: 6px;
  }

  [type="checkbox"].material-inputs + label:before,
  [type="checkbox"].material-inputs:not(.filled-in) + label:after {
    left: auto;
    right: 0;
  }

  [type="checkbox"].filled-in:checked + label:before {
    right: 2px;
  }

  [type="checkbox"].material-inputs:checked + label:before,
  [type="checkbox"].material-inputs.filled-in:checked + label:before {
    border-top: 2px solid transparent;
    border-left: 2px solid $success;
    border-right: 2px solid transparent;
    border-bottom: 2px solid $success;
    transform: rotate(-45deg);
  }

  .checkbox label::after,
  .checkbox label::before {
    margin-left: 0;
    margin-right: -5px;
  }

  [type="checkbox"].material-inputs {
    @each $key, $val in $material-colors {
      &:checked.chk-col-#{$key} {
        + label {
          &:before {
            border-right: 2px solid transparent;
            border-left: 2px solid $val;
            border-bottom: 2px solid $val;
            top: -5px;
          }
        }
      }
    }
  }

  [type="checkbox"].material-inputs.filled-in:checked + label:before {
    border-right: 0 !important;
    border-left: 2px solid #fff !important;
    border-bottom: 2px solid #fff !important;
  }

  [type="radio"].material-inputs:not(:checked)[class*="material-inputs"],
  [type="radio"].material-inputs:checked[class*="material-inputs"] {
    left: auto;
    right: -9999px;
  }

  [type="radio"].material-inputs:not(:checked) + label,
  [type="radio"].material-inputs:checked + label {
    padding-left: 0;
    padding-right: 26px;
  }

  [type="radio"].material-inputs + label:after,
  [type="radio"].material-inputs + label:before {
    left: auto;
    right: 0;
  }
}
