.form-control {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: $white;
  background-color: $dark-gray-lightest;
  background-clip: padding-box;
  border: 1px solid $dark-gray-lightest;
  border-radius: $border-radius-md;
  transition: $transition-base;

  &:focus {
    color: $white;
    background-color: $dark-gray-lightest;
    border-color: $primary-color;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba($primary-color, 0.25);
  }

  &::placeholder {
    color: $light-gray;
    opacity: 1;
  }

  &:disabled,
  &[readonly] {
    background-color: $dark-gray-lighter;
    opacity: 0.7;
    cursor: not-allowed;
  }
}

select.form-control {
  padding-right: 2.5rem;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 16px 12px;
  appearance: none;
}

.form-control-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border-radius: $border-radius-sm;
}

.form-control-lg {
  padding: 1rem 1.25rem;
  font-size: 1.125rem;
  border-radius: $border-radius-lg;
}

.form-group {
  margin-bottom: $spacing-md;
}

.form-text {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: $light-gray;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -0.5rem;
  margin-left: -0.5rem;

  > .col,
  > [class*="col-"] {
    padding-right: 0.5rem;
    padding-left: 0.5rem;
  }
}

.form-check {
  position: relative;
  display: block;
  padding-left: 1.5rem;

  .form-check-input {
    position: absolute;
    margin-top: 0.3rem;
    margin-left: -1.5rem;
  }

  .form-check-label {
    margin-bottom: 0;
    cursor: pointer;
  }
}

.form-check-inline {
  display: inline-flex;
  align-items: center;
  padding-left: 0;
  margin-right: 0.75rem;

  .form-check-input {
    position: static;
    margin-top: 0;
    margin-right: 0.3125rem;
    margin-left: 0;
  }
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-switch {
  padding-left: 2.5rem;

  .form-check-input {
    width: 2rem;
    margin-left: -2.5rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e");
    background-position: left center;
    border-radius: 2rem;
    transition: background-position 0.15s ease-in-out;

    &:checked {
      background-position: right center;
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e");
    }
  }
}

.input-group {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  width: 100%;

  > .form-control,
  > .form-select {
    position: relative;
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
    margin-bottom: 0;
  }

  > .form-control:not(:last-child),
  > .form-select:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  > .form-control:not(:first-child),
  > .form-select:not(:first-child) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
}

.input-group-text {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: $white;
  text-align: center;
  white-space: nowrap;
  background-color: $dark-gray-lighter;
  border: 1px solid $dark-gray-lighter;
  border-radius: $border-radius-md;
}

.input-group-prepend {
  margin-right: -1px;

  .input-group-text {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
}

.input-group-append {
  margin-left: -1px;

  .input-group-text {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
}

// Validation states
.is-valid.form-control {
  border-color: $success;

  &:focus {
    border-color: $success;
    box-shadow: 0 0 0 0.2rem rgba($success, 0.25);
  }
}

.is-invalid.form-control {
  border-color: $danger;

  &:focus {
    border-color: $danger;
    box-shadow: 0 0 0 0.2rem rgba($danger, 0.25);
  }
}

.valid-feedback {
  display: none;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: $success;
}

.invalid-feedback {
  display: none;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: $danger;
}

.was-validated .form-control:valid,
.form-control.is-valid {
  border-color: $success;

  ~ .valid-feedback {
    display: block;
  }
}

.was-validated .form-control:invalid,
.form-control.is-invalid {
  border-color: $danger;

  ~ .invalid-feedback {
    display: block;
  }
}

// Custom File Input
.custom-file {
  position: relative;
  display: inline-block;
  width: 100%;
  height: calc(1.5em + 1.5rem + 2px);
  margin-bottom: 0;
}

.custom-file-input {
  position: relative;
  z-index: 2;
  width: 100%;
  height: calc(1.5em + 1.5rem + 2px);
  margin: 0;
  opacity: 0;

  &:focus ~ .custom-file-label {
    border-color: $primary-color;
    box-shadow: 0 0 0 0.2rem rgba($primary-color, 0.25);
  }
}

.custom-file-label {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  height: calc(1.5em + 1.5rem + 2px);
  padding: 0.75rem 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: $white;
  background-color: $dark-gray-lightest;
  border: 1px solid $dark-gray-lightest;
  border-radius: $border-radius-md;

  &::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: block;
    height: calc(1.5em + 1.5rem);
    padding: 0.75rem 1rem;
    line-height: 1.5;
    color: $white;
    content: "Browse";
    background-color: $dark-gray-lighter;
    border-left: inherit;
    border-radius: 0 $border-radius-md $border-radius-md 0;
  }
}
