@use '../config' as *;

textarea {
  &[cols] {
    height: auto;
  }
}

/**
Form label
 */
.col-form-label,
.form-label {
  --form-label-required-gap: #{$form-label-required-gap};

  display: block;
  font-weight: var(--font-weight-medium);

  &.required {
    &::after {
      margin-inline-start: var(--form-label-required-gap);
      color: $red;
      content: '*';
    }
  }
}

.form-label-description {
  float: inline-end;
  font-weight: var(--font-weight-normal);
  color: $form-secondary-color;
}

/**
Form hint
 */
.form-hint {
  --form-hint-margin-top: #{$form-hint-margin-top};
  --form-hint-label-offset: #{$form-hint-label-offset};
  --form-hint-control-margin-top: #{$form-hint-control-margin-top};

  display: block;
  color: $form-secondary-color;

  &:last-child {
    margin-bottom: 0;
  }

  + .form-control {
    margin-top: var(--form-hint-margin-top);
  }

  .form-label + & {
    margin-top: var(--form-hint-label-offset);
  }

  .input-group + &,
  .form-control + &,
  .form-select + & {
    margin-top: var(--form-hint-control-margin-top);
    color: $form-secondary-color;
  }
}

/**
Form select
 */
.form-select {
  &:-moz-focusring {
    color: var(--body-color);
  }
}

/**
Form control
 */
.form-control {
  &:-webkit-autofill {
    color: var(--body-color);
    box-shadow: 0 0 0 1000px var(--bg-surface-secondary) inset;
    -webkit-text-fill-color: var(--body-color);
  }

  &:disabled,
  &.disabled {
    color: $form-secondary-color;
    user-select: none;
  }

  &[size] {
    width: auto;
  }
}

.form-control-light {
  background-color: var(--gray-100);
  border-color: transparent;
}

.form-control-dark {
  color: $white;
  background-color: rgba($black, 0.1);
  border-color: transparent;

  &:focus {
    background-color: rgba($black, 0.1);
    border-color: rgba($white, 0.24);
    box-shadow: none;
  }

  &::placeholder {
    color: rgba($white, 0.6);
  }
}

.form-control-rounded {
  @include border-radius(var(--border-radius-pill));
}

.form-control-flush {
  padding: 0;
  line-height: inherit;
  resize: none;
  background: none !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

.form-footer {
  --form-footer-margin-top: #{$form-footer-margin-top};

  margin-top: var(--form-footer-margin-top);
}

.form-fieldset {
  --form-fieldset-padding: #{$form-fieldset-padding};
  --form-fieldset-margin-bottom: #{$form-fieldset-margin-bottom};

  padding: var(--form-fieldset-padding);
  margin-bottom: var(--form-fieldset-margin-bottom);
  background: var(--bg-surface-secondary);
  border: var(--border-width) var(--border-style) var(--border-color);
  @include border-radius(var(--border-radius));
}

fieldset:empty {
  display: none;
}

/**
Form help
 */
.form-help {
  --form-help-size: #{$form-help-size};
  --form-help-font-size: #{$form-help-font-size};

  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--form-help-size);
  height: var(--form-help-size);
  font-size: var(--form-help-font-size);
  font-weight: var(--font-weight-semibold);
  color: $form-secondary-color;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  background: var(--gray-100);
  @include border-radius(var(--border-radius-pill));
  @include transition(background-color $transition-time, color $transition-time);

  &:hover,
  &[aria-describedby] {
    color: $white;
    background: var(--primary);
  }
}

/**
Input group
 */
.input-group {
  box-shadow: $input-box-shadow;
  @include border-radius($input-border-radius);

  .form-control,
  .form-select,
  .btn {
    box-shadow: none;
  }
}

.input-group-link {
  font-size: $h5-font-size;
}

.input-group-flat {
  &:focus-within {
    box-shadow: $input-focus-box-shadow;
    @include border-radius($input-border-radius);

    .form-control,
    .input-group-text {
      border-color: $input-focus-border-color !important;
    }
  }

  .form-control {
    &:focus {
      border-color: $input-border-color;
      box-shadow: none;
    }

    &:not(:last-child) {
      border-inline-end: 0;
    }

    &:not(:first-child) {
      border-inline-start: 0;
    }
  }

  .input-group-text {
    z-index: 10;
    background: $form-check-input-bg;
    @include transition($input-transition);

    &:first-child {
      padding-inline-end: 0;
      border-inline-end: 0;
    }

    &:last-child {
      padding-inline-start: 0;
      border-inline-start: 0;
    }
  }
}

/**
Upload files
 */
.form-file-button {
  margin-inline-start: 0;
  border-inline-start: 0;
}

/**
Floating inputs
 */
// Fix for the bug in twbs/bootstrap v5.3.3. Issue #39080. Should be fixed in v5.3.4
label[for='floating-input'] {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/**
Forms on mobile devices 
  */
.form-control,
.form-select {
  --form-control-mobile-font-size: #{$form-control-mobile-font-size};

  @include media-breakpoint-down(sm) {
    font-size: var(--form-control-mobile-font-size);
  }
}
