
input:not([type="radio"]), select, textarea {
  font-size: $input-font-size;
  font-family: $font-family;
  color: $text-color;
  padding: $input-padding-vertical $input-padding-horizontal;

  line-height: $line-height-base;
  border: $input-border-width solid $input-border-color;
  border-radius: $input-border-radius;

  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;

  &:disabled {
    cursor: not-allowed;
  }

  &:hover {
    color: $text-highlight-color;
  }
}

input:not([type="radio"]):not([type="checkbox"]), select, textarea {
  box-shadow: inset 0 pxToRem(1px) pxToRem(1px) rgba(0,0,0,.075);
}

select {
  background-color: $select-background-color;
  color: $text-color;

  &:hover {
    color: $text-highlight-color;
    background-color: $select-background-hover-color;
  }

  &:focus {
    outline: none;
    border-color: $accent-color;
    box-shadow: 0 0 0 1px $accent-color;
  }
}

input:not([type="radio"]), textarea {
  color: $input-color;
  background-color: $input-background-color;

  &:focus {
    color: $text-highlight-color;
    background-color: $input-active-bg-color;

    outline: none;
    border-color: $accent-color;
    box-shadow: 0 0 0 1px $accent-color;
  }

  &.has-success {
    border-color: $brand-success;
  }

  &.has-warning {
    border-color: $brand-warning;
  }

  &.has-error {
    border-color: $brand-danger;
  }
}

input[type="checkbox"] {
  -webkit-appearance: none;
  display: inline-block;
  position: relative;
  font-size: $input-font-size;
  margin: 0 0.25rem 0 0;
  vertical-align: -0.3rem;
  width: 1.5rem;
  height: 1.5rem;
  cursor: pointer;
  outline: 0;
  border-radius: $border-radius;
  background-color: $component-background-color;
  transition: background-color .16s cubic-bezier(0.5, 0.15, 0.2, 1);

  &:focus {
    background-color: $component-background-color;
  }

  &:disabled {
    background-color: $level-1-color;
  }

  &:active {
    background-color: $brand-info;
  }

  &::before,
  &::after {
    content: "";
    position: absolute;
    top: 1.1rem;
    left: .55rem;
    height: .16rem;
    min-height: pxToRem(2px);
    border-radius: pxToRem(1px);
    background-color: $background-color;
    transform-origin: 0% 0%;
    opacity: 0;
    transition: transform .1s cubic-bezier(0.5, 0.15, 0.2, 1), opacity .1s cubic-bezier(0.5, 0.15, 0.2, 1);
  }
  &::before {
    width: .45rem;
    transform: rotate(225deg) scale(0);
  }
  &::after {
    width: .9rem;
    margin: -1px;
    transform: rotate(-45deg) scale(0);
    transition-delay: .05s;
  }

  &:checked {
    background-color: $brand-info;
    &:active {
      background-color: $text-color-subtle;
    }
    &:disabled {
      background-color: $level-1-color;
    }

    &::before,
    &::after {
      opacity: 1;
    }
    &::before {
      transform: rotate(225deg) scale(1);
      transition-delay: .05s;
    }
    &::after {
      transform: rotate(-45deg) scale(1);
      transition-delay: 0;
    }
  }
}

$radio-size: 1.5rem;

input[type="radio"] {
  -webkit-appearance: none;
  display: inline-block;
  position: relative;

  outline: none;

  vertical-align: middle;

  margin: 0 0.25rem 0 0;
  padding: 0;
  width: $radio-size;
  height: $radio-size;
  font-size: $input-font-size;
  vertical-align: -0.3rem;

  border-radius: 50%;
  background-color: $component-background-color;
  transition: background-color .16s cubic-bezier(0.5, 0.15, 0.2, 1);

  &:before {
    content: "";
    position: absolute;
    box-sizing: border-box;
    padding: 0;
    top: 0;
    left: 0;
    width: $radio-size;
    height: $radio-size;
    border-radius: inherit;
    border: $radio-size/3 solid transparent;
    background-clip: content-box;
    background-color: $background-color;
    transform: scale(0);
    transition: transform .1s cubic-bezier(0.5, 0.15, 0.2, 1);
  }

  &:active {
    background-color: $brand-info;
  }

  &:checked {
    background-color: $brand-info;
    &:before {
      transform: scale(1);
    }
  }
}

input[type="range"] {
  -webkit-appearance: none;
  margin: 10px 0;
  height: 4px;
  border-radius: 3px;
  background-color: $component-background-color;
  box-sizing: border-box;

  &::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: $button-default-bg-selected-color;
    transition: transform .16s;
  }

  &::-webkit-slider-thumb:active {
    transition-duration: 0s;
    transform: scale(0.9);
  }
}

label {
  margin-right: 0.5rem;
  font-size: $input-font-size;
  user-select: none;
}

.gui-layout > label {
  justify-content: stretch;
  text-align: right;
}

.gui-packed-row > label {
  margin-right: 0;
}

span.group {
  display: inline-block;
  font-size: $input-font-size;

  & > span {
    display: inline-block;

    font-size: $button-font-size-small;
    padding: $input-padding-vertical $input-padding-horizontal;

    background-color: $group-text-bg-color;

    line-height: $line-height-base;

    border-top: $input-border-width solid $input-border-color;
    border-bottom: $input-border-width solid $input-border-color;
    border-radius: 0;

    &:after {
      content: "\200a";
      font-size: $input-font-size;
    }
  }

  & > span:first-child {
    border-left-width: $input-border-width;
    border-top-left-radius: $input-border-radius;
    border-bottom-left-radius: $input-border-radius;
  }

  & > input:not(:first-child) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  & > span:last-child {
    border-right: $input-border-width solid $input-border-color;
    border-top-right-radius: $input-border-radius;
    border-bottom-right-radius: $input-border-radius;
  }

  & > input:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
}

// This defines extra classes for setting widths.

// Max widths to comfortably support inputs with 'x' chars.
@mixin char-width($chars) {
  .char-width-#{$chars} {
    width: #{$chars}em;
    min-width: #{$chars}em;
    max-width: #{$chars}em;
  }

  select.char-width-#{$chars} {
    width: #{$chars + 1}em;
    min-width: #{$chars + 1}em;
    max-width: #{$chars + 1}em;
  }

  input[type="number"].char-width-#{$chars} {
    width: #{$chars + 3}ch;
    min-width: #{$chars + 3}ch;
    max-width: #{$chars + 3}ch;
  }
}

@include char-width(2);
@include char-width(3);
@include char-width(4);
@include char-width(6);
@include char-width(8);
@include char-width(12);
@include char-width(20);
@include char-width(30);
@include char-width(40);
@include char-width(60);
@include char-width(80);

// Max widths to comfortably support inputs with 'x' chars.
@mixin char-max-width($chars) {
  .char-max-width-#{$chars} {
    min-width: 0;
    max-width: #{$chars}em;
  }

  select.char-max-width-#{$chars} {
    min-width: 0;
    max-width: #{$chars + 1}em;
  }

  input[type="number"].char-max-width-#{$chars} {
    min-width: 0;
    max-width: #{$chars + 3}ch;
  }
}

@include char-max-width(2);
@include char-max-width(3);
@include char-max-width(4);
@include char-max-width(6);
@include char-max-width(8);
@include char-max-width(12);
@include char-max-width(20);
@include char-max-width(30);
@include char-max-width(40);
@include char-max-width(60);
@include char-max-width(80);
