//
// Forms
// --------------------------------------------------

// Normalize non-controls
// --------------------------------------------------

fieldset {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

legend {
  display: block;
  width: 100%;
  padding: 0;
  margin-bottom: $grid-unit-y * 2;
  padding-bottom: $grid-unit-y;
  font-size: $font-size-h4;
  line-height: $grid-unit-y * 3;
  border: 0;
  font-weight: $headings-font-weight;

  @include themes(color, legend-color);
  @include themes-border-bottom(legend-border-color);
}

label {
  display: block;
  max-width: 100%;
  font-size: $font-size-base;
  line-height: $grid-unit-y * 2;
  margin-bottom: $grid-unit-y;
  font-weight: $font-weight-regular;
  font-family: $font-family-proxima;

  @include themes(color, color-new-body-light);

  &.label-required {
    &:before {
      content: "* ";
      color: $brand-danger;
    }
  }
}

// Normalize form controls
// --------------------------------------------------

input[type="search"] {
  @include box-sizing(border-box);

  -webkit-appearance: none;
  appearance: none;
}

// Position radios and checkboxes better
input[type="radio"],
input[type="checkbox"] {
  margin: 4px 0 0;
  line-height: normal;

  &[disabled],
  &.disabled,
  fieldset[disabled] & {
    cursor: $cursor-disabled;
  }
}

input[type="file"] {
  display: block;
}

// Make range inputs behave like textual form controls
@include input-range();

// Make multiple select elements height not fixed
select[multiple],
select[size] {
  height: auto;
}

// Focus for file, radio, and checkbox
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  @include tab-focus;
}

// Adjust output element
output {
  display: block;
  padding-top: ($padding-base-vertical + 1);
  font-size: $font-size-base;
  line-height: $line-height-base;

  @include themes(color, input-color);
}

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

  option {
    @include themes-value(color, $color-new-heading);
  }
}

textarea {
  padding: $input-padding-base-x;
}

input[type="number"] {
  padding-top: 0;
  padding-bottom: 0;
  padding-right: 0;
  line-height: $grid-unit-y * 5 - 2;
}

// Common form controls
// --------------------------------------------------

.form-control {
  display: block;
  width: 100%;
  background-image: none;
  border-radius: $input-border-radius;
  font-size: $font-size-base;
  padding: $input-padding-base-y $input-padding-base-x;
  font-weight: $input-font-weight;
  line-height: $grid-unit-y * 3;
  height: auto;
  border-width: 1px;
  border-style: solid;

  @include themes(color, input-color);
  @include themes(background-color, input-bg);
  @include themes(border-color, input-border);

  @include transition(
    border-color ease-in-out 0.15s,
    box-shadow ease-in-out 0.15s
  );
  @include box-shadow(none);
  @include form-control-focus($input-border-focus);
  @include placeholder;

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

  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    opacity: 1;

    @include themes(background-color, input-bg-disabled);
  }

  &[disabled],
  fieldset[disabled] & {
    cursor: $cursor-disabled;
  }

  &-transparent {
    @include themes-value(background-color, transparent);
  }

  &.form-control-focused {
    @include form-control-focus-no-el($input-border-focus);
  }

  &-no-borders {
    border-width: 0;

    @include box-shadow-themes(box-shadow-new);
  }
}

.form-value {
  @include themes(color, color-new-heading);
}

textarea.form-control {
  height: auto;
}

// Special styles for iOS temporal inputs
// --------------------------------------------------

@media screen and (-webkit-min-device-pixel-ratio: 0) {
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  input[type="month"] {
    &.form-control {
      line-height: $input-height-base;
    }

    &.input-sm,
    .input-group-sm & {
      line-height: $input-height-small;
    }

    &.input-lg,
    .input-group-lg & {
      line-height: $input-height-large;
    }
  }
}

// Form groups
// --------------------------------------------------

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

// Static form control text
// --------------------------------------------------

.form-control-static {
  min-height: ($line-height-computed + $font-size-base);
  margin-bottom: 0;
  line-height: $input-line-height-base;
  padding: ($input-padding-base-y + 2) 0;

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

// Form control sizing
// --------------------------------------------------

@include input-size(
  ".input-sm",
  $input-height-small,
  $input-padding-sm-y - 1,
  $input-padding-sm-x,
  $font-size-small,
  $grid-unit-y * 2,
  $input-border-radius-small
);
.form-group-sm {
  input[type="number"] {
    padding-top: 0;
    padding-bottom: 0;
    padding-right: 0;
    line-height: $grid-unit-y * 2 + ($input-padding-sm-y - 1) * 2;
  }

  .form-control {
    padding: $input-padding-sm-y - 1 $input-padding-sm-x;
    font-size: $font-size-small;
    line-height: $grid-unit-y * 2;
    border-radius: $input-border-radius-small;
  }
  select.form-control {
    line-height: $grid-unit-y * 2;
  }
  textarea.form-control,
  select[multiple].form-control {
    height: auto;
  }
  .form-control-static {
    padding: $input-padding-sm-y $input-padding-sm-x;
    font-size: $font-size-small;
    line-height: $grid-unit-y * 2;
    min-height: 0;
  }
}

@include input-size(
  ".input-lg",
  $input-height-large,
  ($input-padding-lg-y - 1),
  $input-padding-lg-x,
  $font-size-large,
  ceil($grid-unit-y * 2.5),
  $input-border-radius-large
);
.form-group-lg {
  input[type="number"] {
    padding-top: 0;
    padding-bottom: 0;
    padding-right: 0;
    line-height: $grid-unit-y * 2 + ($input-padding-lg-y - 1) * 2;
  }

  .form-control {
    padding: ($input-padding-lg-y - 1) $input-padding-lg-x;
    font-size: $font-size-large;
    line-height: ceil($grid-unit-y * 2.5);
    border-radius: $input-border-radius-large;
  }
  select.form-control {
    line-height: ceil($grid-unit-y * 2.5);
  }
  textarea.form-control,
  select[multiple].form-control {
    height: auto;
  }
  .form-control-static {
    padding: $padding-base-vertical $padding-base-horizontal;
    font-size: $font-size-large;
    line-height: ceil($grid-unit-y * 2.5);
    min-height: 0;
  }
}

// Form control feedback states
// --------------------------------------------------

.has-feedback {
  position: relative;

  .form-control {
    padding-right: $input-height-base;
  }

  input[type="number"] {
    padding-right: 0;
  }

  label {
    & ~ .form-control-feedback {
      top: $grid-unit-y * 3.5;
    }

    &.sr-only ~ .form-control-feedback {
      top: 0;
    }
  }
}

.form-control-feedback {
  position: absolute;
  top: 0;
  right: 2px;
  z-index: 2;
  display: block;
  width: $input-height-base;
  height: $input-height-base;
  line-height: $input-height-base;
  text-align: center;
  pointer-events: none;

  @include themes(color, color-new-body-light);
}

.input-lg + .form-control-feedback,
.input-group-lg + .form-control-feedback,
.form-group-lg .form-control + .form-control-feedback {
  width: $input-height-large;
  height: $input-height-large;
  line-height: $input-height-large;
}

.input-sm + .form-control-feedback,
.input-group-sm + .form-control-feedback,
.form-group-sm .form-control + .form-control-feedback {
  width: $input-height-small;
  height: $input-height-small;
  line-height: $input-height-small;
}

.has-success {
  @include form-control-validation(
    form-control-success-text,
    form-control-success-icon,
    form-control-success-bg,
    form-control-success-border,
    form-control-success-border-focus
  );
}
.has-warning {
  @include form-control-validation(
    form-control-warning-text,
    form-control-warning-icon,
    form-control-warning-bg,
    form-control-warning-border,
    form-control-warning-border-focus
  );
}
.has-error {
  @include form-control-validation(
    form-control-danger-text,
    form-control-danger-icon,
    form-control-danger-bg,
    form-control-danger-border,
    form-control-danger-border-focus
  );
}

// Help text
// --------------------------------------------------

.help-block {
  display: block;
  margin-top: $form-help-block-margin-top;
  margin-bottom: $form-help-block-margin-bottom;
  line-height: $grid-unit-y * 2;
  font-size: $font-size-small;
  font-weight: $font-weight-regular;

  @include themes(color, color-new-body-light);
}

// Inline forms
// --------------------------------------------------

.form-inline {
  @include form-inline;
}

// Horizontal forms
// --------------------------------------------------

.form-horizontal {
  .form-group {
    @include make-row;
  }

  @media (min-width: $screen-sm-min) {
    .control-label {
      padding-top: ($padding-base-vertical - 3);
      margin-bottom: 0;
      text-align: right;
    }
  }

  // Validation states
  .has-feedback .form-control-feedback {
    right: floor(($grid-gutter-width * 0.5));
  }

  // Form group sizes
  .form-group-lg {
    @media (min-width: $screen-sm-min) {
      .control-label {
        padding-top: ($padding-large-vertical + 1);
        font-size: $font-size-large;
      }
    }
  }
  .form-group-sm {
    @media (min-width: $screen-sm-min) {
      .control-label {
        padding-top: ($padding-small-vertical + 1);
        font-size: $font-size-small;
      }
    }
  }
}

// Extra elements
// --------------------------------

// Wrapper for select to add an arrow icon
.form-select {
  $form-select-icon-size-y: 5px;

  position: relative;
  width: 100%;

  &:before {
    content: "\f078";
    font-family: $font-family-awesome;
    font-weight: $font-family-awesome-weight;
    position: absolute;
    height: $form-select-icon-size-y;
    line-height: $form-select-icon-size-y;
    text-align: center;
    font-size: $font-size-extra-small;
    right: 15px;
    top: 50%;
    margin-top: -(ceil($form-select-icon-size-y * 0.5));

    @include themes(color, form-select-icon-color);
  }

  .form-control {
    padding-right: $form-select-icon-size + $grid-unit-x * 2 - 2;

    @include text-overflow();
  }

  &-disabled {
    @include themes(color, color-new-grey);

    &:before {
      @include themes(color, color-new-grey);
    }
  }
}
