/* -----------------------------------------------
Form
----------------------------------------------- */

// Form Layout
.b-form-group {
  position: relative;
  margin-bottom: 1rem;
  flex-basis: 0;
  flex-grow: 1;
  width: 100%;
  max-width: 100%;
}

.b-form-group[class^='b-col'] {
  flex-grow: unset;
  flex-basis: unset;
  & > .b-form-label {
    display: unset;
    margin: unset;
  }
}

.b-form-row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

.b-form-label-outer {
  display: unset;
  margin: unset;
}

.b-form-label {
  display: inline-block;
  margin-bottom: 0.25rem;
}

.b-form-label ~ .b-form-check-inline {
  margin-left: 0.5rem;
}

// Input, TextArea, Select
.b-form-control {
  display: block;
  width: 100%;
  height: calc(1.5em + 0.75rem + 2px);
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #212529;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid rgba(33, 37, 41, 0.15);
  border-radius: 0.25rem;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  transition: all 0.15s ease-in-out;
  &:focus {
    color: #495057;
    background-color: #fff;
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 0, 0, 0.1);
  }
  &-sm {
    height: calc(1.4em + 0.4rem + 2px);
    padding: 0.25rem 0.4rem;
    font-size: 1rem;
    line-height: 1.4;
    border-radius: 0.2rem;
  }
  &-lg {
    height: calc(1.5em + 1rem + 2px);
    padding: 0.5rem 1rem;
    font-size: 1.25rem;
    line-height: 1.5;
    border-radius: 0.3rem;
  }
}

.b-form-control:disabled,
.b-form-control[readonly] {
  background-color: #e9ecef;
  opacity: 1;
}

.b-form-label.is-required:after {
  margin-left: 0.25rem;
  content: '*';
  color: #999;
}

.b-form-radio.is-required:after {
  content: none !important;
}

// Textarea
textarea.b-form-control {
  height: auto;
}

// Inline Forms
@media (min-width: 576px) {
  .b-form-inline .b-form-group,
  .b-form-inline.b-form-group,
  .b-form-inline > label,
  .b-form-inline .b-form-group > label {
    width: auto;
    display: inline-flex;
    flex: 0 0 auto;
    flex-flow: row wrap;
    align-items: center;
    margin-right: 0.5rem;
    margin-bottom: 0;
  }
  .b-form-inline .b-form-label {
    width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
    margin-right: 0.5rem;
  }
  .b-form-inline .b-form-control {
    display: inline-block;
    width: auto;
    vertical-align: middle;
  }
}

// Horizontal Form
.b-form-group.b-row .b-form-label {
  padding-top: calc(0.375rem + 1px);
  padding-bottom: calc(0.375rem + 1px);
  margin-bottom: 0;
  font-size: inherit;
  line-height: 1.5;
}

// Feedback
.b-form-was-validated .b-form-control:invalid,
.b-form-control.is-invalid {
  border-color: #dc3545;
  padding-right: calc(1.5em + 0.75rem);
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
  & + label {
    opacity: 0;
  }
}

.b-valid-feedback {
  display: none;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 80%;
  color: #28a745;
}

.b-invalid-feedback {
  display: none;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 80%;
  color: #dc3545;
}

.b-form-was-validated :invalid ~ .b-invalid-feedback,
.b-form-was-validated :valid ~ .b-valid-feedback {
  display: block !important;
}

// Check
.b-form-check {
  position: relative;
  display: block;
  min-height: 1.5rem;
  padding-left: 1.5rem;
  &.is-required:after {
    margin-left: 0.25rem;
    content: '*';
    color: #999;
  }
}

.b-form-check-inline {
  display: inline-flex;
  margin-right: 0.5rem;
}

.b-form-check-label {
  display: inline-block;
  position: relative;
  margin-bottom: 0;
  vertical-align: top;
  &:before {
    position: absolute;
    color: #fff;
    border-color: #00abf7;
    background-color: #00abf7;
    transition: all 0.15s ease-in-out;
    top: 0.25rem;
    left: -1.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    pointer-events: none;
    content: '';
    background-color: #fff;
    border: #adb5bd solid 1px;
    border-radius: 0.25rem;
  }
  &:after {
    position: absolute;
    top: 0.25rem;
    left: -1.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    content: '';
    background: no-repeat 50%/50% 50%;
  }
}

.b-form-check-input {
  position: absolute;
  left: 0;
  z-index: -1;
  width: 1rem;
  height: 1.25rem;
  opacity: 0;
  &:focus ~ .b-form-check-label:before {
    color: #495057;
    background-color: #fff;
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(128, 189, 255, 0.2);
  }
  &:checked ~ .b-form-check-label:before {
    color: #fff;
    border-color: #00abf7;
    background-color: #00abf7;
  }
}

.b-form-checkbox .b-form-check-label:after {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/%3e%3c/svg%3e");
}

.b-form-radio .b-form-check-label:before {
  border-radius: 100%;
}
.b-form-radio .b-form-check-label:after {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
}

.b-form-was-validated .b-form-check.is-required input:invalid ~ .b-form-check-label {
  &:before {
    border-color: #dc3545;
  }
  color: #dc3545;
}

// Switch
.b-form-switch {
  position: relative;
  z-index: 1;
  display: block;
  min-height: 1.5rem;
  padding-left: 2.25rem;
  margin-bottom: 0;
  cursor: pointer;
}

.b-form-switch .b-form-check-label:before {
  left: -2.25rem;
  width: 1.75rem;
  pointer-events: all;
  border-radius: 0.5rem;
  background-color: #fff;
  border: 1px solid #adb5bd;
  transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.b-form-switch .b-form-check-label:before {
  position: absolute;
  top: 0.25rem;
  left: -2.25rem;
  width: 1.75rem;
  height: 1rem;
  display: block;
  pointer-events: all;
  border-radius: 0.5rem;
  content: '';
}

.b-form-switch .b-form-check-label:after {
  top: calc(0.25rem + 2px);
  left: calc(-2.25rem + 2px);
  width: calc(1rem - 4px);
  height: calc(1rem - 4px);
  border-radius: 0.5rem;
  background-color: #adb5bd;
  transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.b-form-switch .b-form-check-input:checked ~ .b-form-check-label:after {
  background-color: #fff;
  transform: translateX(0.75rem);
}

.b-form-check-input:disabled ~ .b-form-check-label::before,
.b-form-check-input[disabled] ~ .b-form-check-label::before {
  background-color: #e9ecef;
}

// date/time
.b-form-control[type='date'],
.b-form-control[type='time'],
.b-form-control[type='date']:invalid,
.b-form-control[type='time']:invalid {
  padding-right: 0.25rem;
}

// file
.b-form-control[type='file'] {
  overflow: hidden; // prevent pseudo element button overlap
  &:not(:disabled):not([readonly]) {
    cursor: pointer;
  }
}

.b-form-control::file-selector-button {
  padding: .65rem .75rem;
  margin: -.375rem -.75rem;
  margin-inline-end: .75rem;
  color: #212529;
  pointer-events: none;
  border-color: inherit;
  border-style: solid;
  border-width: 0;
  border-inline-end-width: 1px;
  border-radius: 0;
  transition: all .2s ease-in-out;
}

.b-form-control:hover:not(:disabled):not([readonly])::file-selector-button {
  background-color: #e9ecef;
}