// scss-lint:disable QualifyingElement

//
// Textual form controls
//

.form-control {
  display: block;
  width: 100%;
  // // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  // height: $input-height;
  padding: $input-padding-y $input-padding-x;
  font-size: $input-font-size;
  line-height: $input-line-height;
  color: $input-color;
  background-color: $input-bg;
  // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214.
  background-image: none;
  background-clip: padding-box;
  border: $input-border-width solid $input-border-color;
  border-radius: $input-border-radius;
  box-shadow: $input-box-shadow;
  transition: $input-transition;

  @include media-breakpoint-down(sm) {
    padding: ($input-padding-y / 2) ($input-padding-x / 2);
  }
  @include media-breakpoint-down(xs) {
    padding: ($input-padding-y / 2) ($input-padding-x / 4);
  }

  // Unstyle the caret on `<select>`s in IE10+.
  &::-ms-expand {
    background-color: transparent;
    border: 0;
  }

  // Customize the `:focus` state to imitate native WebKit styles.
  @include form-control-focus();

  // Placeholder
  &::placeholder {
    color: $input-color-placeholder;
    // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526.
    opacity: 1;
  }

  // Disabled and read-only inputs
  //
  // HTML5 says that controls under a fieldset > legend:first-child won't be
  // disabled if the fieldset is disabled. Due to implementation difficulty, we
  // don't honor that edge case; we style them as disabled anyway.
  &:disabled,
  &[readonly] {
    background-color: $input-bg-disabled;
    // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
    opacity: 1;
  }

  &:disabled {
    cursor: not-allowed;
  }
}

select.form-control {
  &:not([size]):not([multiple]) {
    $select-border-width: ($border-width * 2);
    height: calc(#{$input-height} + #{$select-border-width});
  }

  &:focus::-ms-value {
    // Suppress the nested default white text on blue background highlight given to
    // the selected option text when the (still closed) <select> receives focus
    // in IE and (under certain conditions) Edge, as it looks bad and cannot be made to
    // match the appearance of the native widget.
    // See https://github.com/twbs/bootstrap/issues/19398.
    color: $input-color;
    background-color: $input-bg;
  }
}

// Make file inputs better match text inputs by forcing them to new lines.
.form-control-file,
.form-control-range {
  display: block;
}


//
// Labels
//

label {
  font-family: $font-family-secondary;
  font-size: $font-size-sm;
  letter-spacing: .1em;
  max-width: 100%;
  text-transform: uppercase;
  @include media-breakpoint-down(sm) {
    font-size: $font-size-xs;
  }
}

.label-regular {
  font-family: $font-family-base;
  letter-spacing: 0;
  text-transform: none;
}

// For use with horizontal and inline forms, when you need the label text to
// align with the form controls.
.col-form-label {
  padding-top: calc(#{$input-padding-y} - #{$input-border-width} * 2);
  padding-bottom: calc(#{$input-padding-y} - #{$input-border-width} * 2);
  margin-bottom: 0; // Override the `<label>` default
}

.col-form-label-lg {
  padding-top: calc(#{$input-padding-y-lg} - #{$input-border-width} * 2);
  padding-bottom: calc(#{$input-padding-y-lg} - #{$input-border-width} * 2);
  font-size: $font-size-lg;
}

.col-form-label-sm {
  padding-top: calc(#{$input-padding-y-sm} - #{$input-border-width} * 2);
  padding-bottom: calc(#{$input-padding-y-sm} - #{$input-border-width} * 2);
  font-size: $font-size-sm;
}


//
// Legends
//

// For use with horizontal and inline forms, when you need the legend text to
// be the same size as regular labels, and to align with the form controls.
.col-form-legend {
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
  margin-bottom: 0;
  font-size: $font-size-base;
}


// Static form control text
//
// Apply class to an element to make any string of text align with labels in a
// horizontal form layout.

.form-control-static {
  padding-top: $input-padding-y;
  padding-bottom: $input-padding-y;
  margin-bottom: 0; // match inputs if this class comes on inputs with default margins
  line-height: $input-line-height;
  border: solid transparent;
  border-width: $input-border-width 0;

  &.form-control-sm,
  &.form-control-lg {
    padding-right: 0;
    padding-left: 0;
  }
}


// Form control sizing
//
// Build on `.form-control` with modifier classes to decrease or increase the
// height and font-size of form controls.
//
// The `.form-group-* form-control` variations are sadly duplicated to avoid the
// issue documented in https://github.com/twbs/bootstrap/issues/15074.

.form-control-sm {
  padding: $input-padding-y-sm $input-padding-x-sm;
  font-size: $font-size-sm;
}

select.form-control-sm {
  &:not([size]):not([multiple]) {
    height: $input-height-sm;
  }
}

.form-control-lg {
  border-width: 2px;
  padding: $input-padding-y-lg $input-padding-x-lg;
  font-family: $font-family-secondary;
  letter-spacing: .1em;
  text-transform: uppercase;
}

select.form-control-lg {
  &:not([size]):not([multiple]) {
    height: $input-height-lg;
  }
}


// Form groups
//
// Designed to help with the organization and spacing of vertical forms. For
// horizontal forms, use the predefined grid classes.

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

.form-text {
  color: $gray;
  display: block;
  font-size: $font-size-sm;
  margin-top: $form-text-margin-top;
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.

.form-check {
  position: relative;
  display: block;
  margin-bottom: $form-check-margin-bottom;

  &.disabled {
    .form-check-label {
      color: $text-muted;
      cursor: not-allowed;
    }
  }
}

.form-check-label {
  padding-left: $form-check-input-gutter;
  margin-bottom: 0; // Override default `<label>` bottom margin
  cursor: pointer;
}

.form-check-input {
  position: absolute;
  margin-top: $form-check-input-margin-y;
  margin-left: -$form-check-input-gutter;

  &:only-child {
    position: static;
  }
}

// Radios and checkboxes on same line
.form-check-inline {
  display: inline-block;

  .form-check-label {
    vertical-align: middle;
  }

  + .form-check-inline {
    margin-left: $form-check-inline-margin-x;
  }
}

// Form validation
//
// Provide feedback to users when form field values are valid or invalid. Works
// primarily for client-side validation via scoped `:invalid` and `:valid`
// pseudo-classes but also includes `.is-invalid` and `.is-valid` classes for
// server side validation.

.invalid-feedback {
  font-size: $font-size-xs;
  color: $form-feedback-invalid-color;
}

.form-control,
.custom-select {
  .was-validated &:invalid,
  &.is-invalid,
  &.f3-form-error {
    border-color: $form-feedback-invalid-color;

    &:focus {
      box-shadow: 0 0 0 .2rem rgba($form-feedback-invalid-color,.25);
    }
  }
}


// Inline forms
//
// Make forms appear inline(-block) by adding the `.form-inline` class. Inline
// forms begin stacked on extra small (mobile) devices and then go inline when
// viewports reach <768px.
//
// Requires wrapping inputs and labels with `.form-group` for proper display of
// default HTML form controls and our custom form controls (e.g., input groups).

.form-inline {
  display: flex;
  flex-flow: row wrap;
  align-items: center; // Prevent shorter elements from growing to same height as others (e.g., small buttons growing to normal sized button height)

  // Because we use flex, the initial sizing of checkboxes is collapsed and
  // doesn't occupy the full-width (which is what we want for xs grid tier),
  // so we force that here.
  .form-check {
    width: 100%;
  }

  // Kick in the inline
  @include media-breakpoint-up(sm) {
    label {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 0;
    }

    // Inline-block all the things for "inline"
    .form-group {
      display: flex;
      flex: 0 0 auto;
      flex-flow: row wrap;
      align-items: center;
      margin-bottom: 0;
    }

    // Allow folks to *not* use `.form-group`
    .form-control {
      display: inline-block;
      width: auto; // Prevent labels from stacking above inputs in `.form-group`
      vertical-align: middle;
    }

    // Make static controls behave like regular ones
    .form-control-static {
      display: inline-block;
    }

    .input-group {
      width: auto;
    }

    .form-control-label {
      margin-bottom: 0;
      vertical-align: middle;
    }

    // Remove default margin on radios/checkboxes that were used for stacking, and
    // then undo the floating of radios and checkboxes to match.
    .form-check {
      display: flex;
      align-items: center;
      justify-content: center;
      width: auto;
      margin-top: 0;
      margin-bottom: 0;
    }
    .form-check-label {
      padding-left: 0;
    }
    .form-check-input {
      position: relative;
      margin-top: 0;
      margin-right: $form-check-input-margin-x;
      margin-left: 0;
    }

    // Custom form controls
    .custom-control {
      display: flex;
      align-items: center;
      justify-content: center;
      padding-left: 0;
    }
    .custom-control-indicator {
      position: static;
      display: inline-block;
      margin-right: $form-check-input-margin-x; // Flexbox alignment means we lose our HTML space here, so we compensate.
      vertical-align: text-bottom;
    }
  }
}

// Checkboxes and radios
//
// Base class takes care of all the key behavioral aspects.

.custom-control {
  align-items: center;
  position: relative;
  display: inline-flex;
  padding-left: $custom-control-gutter;
  margin-right: $custom-control-spacer-x;
  margin-bottom: $custom-control-spacer-y;
  min-height: $custom-control-indicator-size;
  cursor: pointer;
  @include media-breakpoint-down(xl) {
    padding-left: 2rem;
  }
  @include media-breakpoint-down(sm) {
    min-height: 1.5rem;
  }
}

.custom-control-input {
  position: absolute;
  z-index: -1; // Put the input behind the label so it doesn't overlay text
  opacity: 0;

  &:checked ~ .custom-control-indicator:before {
    opacity: 1;
  }

  &:focus ~ .custom-control-indicator {
    // the mixin is not used here to make sure there is feedback
    box-shadow: $custom-control-focus-indicator-box-shadow;
  }

  &:active ~ .custom-control-indicator:before {
    opacity: 1;
  }

  &:disabled {
    ~ .custom-control-indicator {
      cursor: $custom-control-disabled-cursor;
      background-color: $custom-control-disabled-indicator-bg;
    }

    ~ .custom-control-description {
      color: $custom-control-disabled-description-color;
      cursor: $custom-control-disabled-cursor;
    }
  }
}

.custom-control-description {
  font-family: $font-family-secondary;
  font-size: $font-size-sm;
  line-height: 1.3;
}

// Custom indicator
//
// Generates a shadow element to create our makeshift checkbox/radio background.

.custom-control-indicator {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  display: block;
  width: $custom-control-indicator-size;
  height: $custom-control-indicator-size;
  pointer-events: none;
  user-select: none;
  background-color: $custom-control-indicator-bg;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: $custom-control-indicator-bg-size;
  border: 1px solid $body-color;
  box-shadow: $custom-control-indicator-box-shadow;
  &:before {
    background: $brand-primary;
    content: "";
    height: .75rem;
    left: 50%;
    opacity: 0;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: opacity .2s;
    width: .75rem;
    @include media-breakpoint-down(sm) {
      height: .875rem;
      width: .875rem;
    }
  }
  @include media-breakpoint-down(sm) {
    width: 1.5rem;
    height: 1.5rem;
  }
}

// Checkboxes
//
// Tweak just a few things for checkboxes.

.custom-checkbox {
  .custom-control-indicator {
    border-radius: $custom-checkbox-radius;
  }
}

// Radios
//
// Tweak just a few things for radios.

.custom-radio {
  .custom-control-indicator {
    border-radius: $custom-radio-radius;
  }

  .custom-control-input:checked ~ .custom-control-indicator {
    background-image: $custom-radio-checked-icon;
  }
}


// Layout options
//
// By default radios and checkboxes are `inline-block` with no additional spacing
// set. Use these optional classes to tweak the layout.

.custom-controls-stacked {
  display: flex;
  flex-direction: column;

  .custom-control {
    margin-bottom: $custom-control-spacer-y;

    + .custom-control {
      margin-left: 0;
    }
  }
}


// Select
//
// Replaces the browser default select with a custom one, mostly pulled from
// http://primercss.io.
//

.custom-select {
  display: inline-block;
  max-width: 100%;
  $select-border-width: $border-width;
  height: calc(#{$input-height} + #{$select-border-width});
  padding: $custom-select-padding-y ($custom-select-padding-x + $custom-select-indicator-padding) $custom-select-padding-y $custom-select-padding-x;
  line-height: $custom-select-line-height;
  color: $custom-select-color;
  vertical-align: middle;
  background: $custom-select-bg $custom-select-indicator no-repeat right $custom-select-padding-x center;
  background-size: $custom-select-bg-size;
  border: $custom-select-border-width solid $custom-select-border-color;
  border-radius: $custom-select-border-radius;
  // Use vendor prefixes as `appearance` isn't part of the CSS spec.
  // sass-lint:disable no-vendor-prefixes
  -moz-appearance: none;
  -webkit-appearance: none;

  &:focus {
    border-color: $custom-select-focus-border-color;
    outline: none;
    box-shadow: $custom-select-focus-box-shadow;

    &::-ms-value {
      // For visual consistency with other platforms/browsers,
      // supress the default white text on blue background highlight given to
      // the selected option text when the (still closed) <select> receives focus
      // in IE and (under certain conditions) Edge.
      // See https://github.com/twbs/bootstrap/issues/19398.
      color: $input-color;
      background-color: $input-bg;
    }
  }

  &:disabled {
    color: $custom-select-disabled-color;
    cursor: not-allowed;
    background-color: $custom-select-disabled-bg;
  }

  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
  }
}

.custom-select-sm {
  padding-top: $custom-select-padding-y;
  padding-bottom: $custom-select-padding-y;
  font-size: $custom-select-sm-font-size;

  // &:not([multiple]) {
  //   height: 26px;
  //   min-height: 26px;
  // }
}

.custom-select-inline {
  border: none;
  display: inline-block;
  font-weight: bold;
  padding: 0 1.5rem .125rem 0;
  position: relative;
  max-width: 100%;
  vertical-align: middle;
  background: $custom-select-bg $custom-select-indicator no-repeat right .25rem center;
  background-size: $custom-select-bg-size;
  border-radius: $custom-select-border-radius;
  // Use vendor prefixes as `appearance` isn't part of the CSS spec.
  // sass-lint:disable no-vendor-prefixes
  -moz-appearance: none;
  -webkit-appearance: none;

  &:focus {
    border-color: $custom-select-focus-border-color;
    outline: none;
    box-shadow: $custom-select-focus-box-shadow;

    &::-ms-value {
      // For visual consistency with other platforms/browsers,
      // supress the default white text on blue background highlight given to
      // the selected option text when the (still closed) <select> receives focus
      // in IE and (under certain conditions) Edge.
      // See https://github.com/twbs/bootstrap/issues/19398.
      color: $input-color;
      background-color: $input-bg;
    }
  }

  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
  }
}

.custom-select-inline-wrapper {
  display: inline-block;
  max-width: 100%;
  position: relative;
  &:before {
    background: $black;
    bottom: 0;
    content: "";
    height: 1px;
    left: 0;
    position: absolute;
    right: 1.5rem;
    z-index: 2;
  }
}

// File
//
// Custom file input.

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

.custom-file-input {
  min-width: $custom-file-width;
  max-width: 100%;
  height: $custom-file-height;
  margin: 0;
  filter: alpha(opacity = 0);
  opacity: 0;

  &:focus ~ .custom-file-control {
    box-shadow: $custom-file-focus-box-shadow;
  }
}

.custom-file-control {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 5;
  height: $custom-file-height;
  padding: $custom-file-padding-x $custom-file-padding-y;
  line-height: $custom-file-line-height;
  color: $custom-file-color;
  pointer-events: none;
  user-select: none;
  background-color: $custom-file-bg;
  border: $custom-file-border-width solid $custom-file-border-color;
  border-radius: $custom-file-border-radius;
  box-shadow: $custom-file-box-shadow;

  &::before {
    position: absolute;
    top: -$custom-file-border-width;
    right: -$custom-file-border-width;
    bottom: -$custom-file-border-width;
    z-index: 6;
    display: block;
    height: $custom-file-height;
    padding: $custom-file-padding-x $custom-file-padding-y;
    line-height: $custom-file-line-height;
    color: $custom-file-button-color;
    background-color: $custom-file-button-bg;
    border: $custom-file-border-width solid $custom-file-border-color;
    border-radius: 0 $custom-file-border-radius $custom-file-border-radius 0;
  }
}

