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


// GENERAL STYLES
// --------------

// Make all forms have space below them
form {
  margin: 0 0 @baseLineHeight;
}

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}

// Groups of fields with labels on top (legends)
legend {
  cursor: pointer;
  display: block;
  width: 100%;
  padding: 0;
  margin-bottom: @baseLineHeight;
  font-size: @baseFontSize * 1.5;
  line-height: @baseLineHeight * 2;
  color: @grayDark;
  border: 0;
  border-bottom: 1px solid #e5e5e5;
}

// Identify controls by their labels
label {
  display: block;
  font-size: @baseFontSize;
  font-weight: normal;
  line-height: @baseLineHeight;
  margin-bottom: 5px;
}

// Set font for forms
button,
input,
optgroup,
select,
textarea {
  font-family: inherit;
  font-size: @baseFontSize;
  line-height: @baseLineHeight;
  margin: 0;
  text-transform: none;
}

// Form controls
// -------------------------

// Shared size and type resets
select,
textarea,
input {
  box-sizing: border-box;
  display: inline-block;
  height: @baseLineHeight + 10;
  padding: 4px 6px;
  margin-bottom: 9px;
  color: @gray;
  border-radius: @inputBorderRadius;
}

// Reset appearance properties for textual inputs and textarea
// Declare width for legacy (can't be on input[type=*] selectors or it's too specific)
input,
textarea {
  width: 210px;
}
// Reset height since textareas have rows
textarea {
  height: auto;
  resize: none;
}
// Everything else
textarea,
input {
  background-color: @inputBackground;
  border: 1px solid @inputBorder;
  box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
  transition: border linear .2s, box-shadow linear .2s;

  // Focus state
  &:focus {
    background-color: #fff;
    border-color: darken(@inputBorder, 20%);
    box-shadow: none;
  }
}

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

// Reset width of input images, buttons, radios, checkboxes
input[type="file"],
input[type="radio"],
input[type="checkbox"] {
  width: auto; // Override of generic input selector
}

// Make select elements obey height by applying a border
select {
  appearance: none;
  background: @inputBackground url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' height='10px' width='15px'><text x='0' y='10' fill='rgb(85,85,85)'>▾</text></svg>") right center/1em no-repeat border-box;
  border: 1px solid @inputBorder;
  cursor: pointer;
  padding-right: 1.5em;
  width: 223px; // default input width + 10px of padding that doesn't get applied
}

// Focus for select, file, radio, and checkbox
select:focus,
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}


// Placeholder
// -------------------------

// Placeholder text gets special styles; can't be bundled together though for some reason
input::placeholder,
textarea::placeholder {
  color: @placeholderText;
}


// INPUT SIZES
// -----------

// General classes for quick sizes
.input-large      { width: 210px; }
.input-xlarge     { width: 270px; }
.input-xxlarge    { width: 530px; }

// Grid style input sizes
input[class*="span"],
select[class*="span"],
textarea[class*="span"] {
  margin-left: 0;
}
// Ensure input-prepend/append never wraps
.input-append input[class*="span"] {
  display: inline-block;
}



// DISABLED STATE
// --------------

// Disabled and read-only inputs
input[disabled],
select[disabled],
textarea[disabled],
input[readonly],
select[readonly],
textarea[readonly] {
  cursor: not-allowed;
  background-color: @inputDisabledBackground;
}
// Explicitly reset the colors here
input[type="radio"][disabled],
input[type="checkbox"][disabled],
input[type="radio"][readonly],
input[type="checkbox"][readonly] {
  background-color: transparent;
}




// FORM FIELD FEEDBACK STATES
// --------------------------

// Error
.control-group.error {
  .formFieldState(@errorText, @errorText, @errorBackground);
}

// INPUT GROUPS
// ------------

// Allow us to put symbols and text within the input field for a cleaner look
.input-append {
  margin-bottom: 5px;
  font-size: 0;
  white-space: nowrap; // Prevent span and input from separating
  position: relative;

  input,
  select {
    margin-bottom: 0; // prevent bottom margin from screwing up alignment in stacked forms
    font-size: @baseFontSize;
    vertical-align: top;
    border-radius: @inputBorderRadius;
  }
  .btn {
    margin-left: -1px;
    vertical-align: top;
    border-radius: 0;
  }
  .btn:last-child {
    border-radius: 0 @inputBorderRadius @inputBorderRadius 0;
  }
}



// HORIZONTAL & VERTICAL FORMS
// ---------------------------

// Common properties
// -----------------

.form-inline,
.form-horizontal {
  input,
  textarea,
  select,
  .input-append {
    display: inline-block;
    margin-bottom: 0;
    vertical-align: middle;
  }
  // Re-hide hidden elements due to specifity
  .hide {
    display: none;
  }
}
.form-inline label,
.form-inline .btn-group {
  display: inline-block;
}
// Remove margin for input-prepend/-append
.form-inline .input-append {
  margin-bottom: 0;
}


// Margin to space out fieldsets
.control-group {
  margin-bottom: @baseLineHeight / 2;
}

// Legend collapses margin, so next element is responsible for spacing
legend + .control-group {
  margin-top: @baseLineHeight;
  -webkit-margin-top-collapse: separate;
}

// Horizontal-specific styles
// --------------------------

.form-horizontal {
  // Increase spacing between groups
  .control-group {
    margin-bottom: @baseLineHeight;
  }
  // Float the labels left
  .control-label {
    display: inline-block;
    width: 140px;
    padding-top: 5px;
    text-align: right;
  }
  // Move over all input controls and content
  .controls {
    // Super jank IE7 fix to ensure the inputs in .input-append and input-prepend
    // don't inherit the margin of the parent, in this case .controls
    display: inline-block;
    margin-left: 20px;
    vertical-align: top;
  }
}
