%form-control {
  background-clip: padding-box;
  background-color: transparent;
  border-radius: 4px;
  border-style: solid;
  border-width: $textfield-border-width;
  box-shadow: none;
  color: $textfield-color;
  display: block;
  font-size: $textfield-font-size;
  line-height: $textfield-line-height;
  padding: $textfield-padding-y $textfield-padding-x;
  width: 100%;

  &::-ms-expand {
    background-color: transparent;
    border: 0;
  }

  &::placeholder {
    opacity: 1;
  }

  &:disabled,
  &[readonly] {
    border-style: dotted;
    opacity: 1;

    @include focus-hover {
      box-shadow: none;
    }
  }

  &:focus {
    outline: 0;
  }

  &:invalid:required {
    outline: 0;
  }
}

.form-control {
  @extend %form-control;

  &[type='file'] {
    max-height: $textfield-height;
  }
}

// Form control sizing

.form-control-lg {
  font-size: $textfield-font-size-lg;
  line-height: $textfield-line-height-lg;
  padding: $textfield-padding-y-lg $textfield-padding-x-lg calc(#{$textfield-padding-y-lg} - #{$textfield-border-width});

  &[type='file'] {
    max-height: $textfield-height-lg;
  }
}

.form-control-sm {
  font-size: $textfield-font-size-sm;
  line-height: $textfield-line-height-sm;
  padding: $textfield-padding-y-sm $textfield-padding-x-sm calc(#{$textfield-padding-y-sm} - #{$textfield-border-width});

  &[type='file'] {
    max-height: $textfield-height-sm;
  }
}

// Select and textarea

%form-select {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;

  @include media-moz-webkit {
    background-image: $caret-bg;
    background-position: 100% 50%;
    background-repeat: no-repeat;
    background-size: $textfield-select-bg-size $textfield-select-bg-size;
    padding-right: $textfield-select-bg-size;
  }
}

%form-textarea {
  border-radius: $textfield-box-border-radius;
  border-width: $textfield-border-width;
  min-height: $textfield-box-height;
  padding: $textfield-box-padding-y $textfield-box-padding-x;
}

// stylelint-disable selector-no-qualifying-type
select {
  &.form-control {
    @extend %form-select;

    &[multiple],
    &[size]:not([size='1']) {
      @extend %form-textarea;
    }
  }

  &.form-control-lg {
    &[multiple],
    &[size]:not([size='1']) {
      padding: calc(#{$textfield-box-padding-y-lg} - #{$textfield-border-width}) $textfield-box-padding-x-lg;
    }
  }

  &.form-control-sm {
    &[multiple],
    &[size]:not([size='1']) {
      padding: calc(#{$textfield-box-padding-y-sm} - #{$textfield-border-width}) $textfield-box-padding-x-sm;
    }
  }
}

textarea {
  &.form-control {
    min-height: $textfield-height;

    &:not([rows='1']) {
      @extend %form-textarea;
    }
  }

  &.form-control-lg {
    min-height: $textfield-height-lg;

    &:not([rows='1']) {
      min-height: $textfield-box-height-lg;
      padding: calc(#{$textfield-box-padding-y-lg} - #{$textfield-border-width}) $textfield-box-padding-x-lg;
    }
  }

  &.form-control-sm {
    min-height: $textfield-height-sm;

    &:not([rows='1']) {
      min-height: $textfield-box-height-sm;
      padding: calc(#{$textfield-box-padding-y-sm} - #{$textfield-border-width}) $textfield-box-padding-x-sm;
    }
  }
}

// stylelint-enable

.custom-file {
  display: inline-block;
  height: $textfield-height;
  margin-bottom: 0;
  position: relative;
  width: 100%;
}

.custom-file-input {
  height: $textfield-height;
  margin: 0;
  opacity: 0;
  position: relative;
  width: 100%;
  z-index: 1;
}

.custom-file-label {
  @include text-truncate;
  @include transition-standard(border-color, box-shadow);

  font-size: $textfield-font-size;
  height: $textfield-height;
  line-height: $textfield-line-height;
  padding: $textfield-padding-y ($material-icon-size + $selection-control-spacer-x) calc(#{$textfield-padding-y} - #{$textfield-border-width}) $textfield-padding-x;
  position: absolute;
  top: 0;
  right: 0;
  left: 0;

  &::after {
    @include setup-material-icons-bg();

    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
  }
}

.custom-select {
  @extend %form-control;
  @extend %form-select;

  &[multiple],
  &[size]:not([size='1']) {
    @extend %form-textarea;
  }
}

.custom-select-lg {
  font-size: $textfield-font-size-lg;
  line-height: $textfield-line-height-lg;
  padding: $textfield-padding-y-lg $textfield-select-bg-size calc(#{$textfield-padding-y-lg} - #{$textfield-border-width}) $textfield-padding-x-lg;

  &[multiple],
  &[size]:not([size='1']) {
    padding: calc(#{$textfield-box-padding-y-lg} - #{$textfield-border-width}) $textfield-box-padding-x-lg;
  }
}

.custom-select-sm {
  font-size: $textfield-font-size-sm;
  line-height: $textfield-line-height-sm;
  padding: $textfield-padding-y-sm $textfield-select-bg-size calc(#{$textfield-padding-y-sm} - #{$textfield-border-width}) $textfield-padding-x-sm;

  &[multiple],
  &[size]:not([size='1']) {
    padding: calc(#{$textfield-box-padding-y-sm} - #{$textfield-border-width}) $textfield-box-padding-x-sm;
  }
}

.form-control-file {
  @extend %form-control;

  max-height: $textfield-height;
}

.form-control-range {
  display: block;
  width: 100%;
}
