// Form

.form-control {
  max-inline-size: $input-max-width;
  background: $form-control-bg;
  border: $form-control-border;

  &:disabled,
  &[readonly] {
    background-color: $form-control-bg-disabled;
    opacity: 1;
    &:hover,
    &:active,
    &:focus {
      cursor: not-allowed;
    }
  }

  &:focus:not(:disabled):not([readonly]) {
    border: 1px solid var(--template-link-color) !important;
  }

  &:hover:not(:disabled):not([readonly])::-webkit-file-upload-button,
  &:hover:not(:disabled):not([readonly])::file-selector-button {
    background-color: $file-selector-btn-bg-hvr;
  }

  &.invalid {
    border-color: var(--danger);
  }

  &.valid {
    border-color: var(--success);
  }

  &::placeholder {
    font-style: italic;
    opacity: .9;
  }

  &::-webkit-file-upload-button,
  &::file-selector-button {
    background-color: $file-selector-btn-bg;
  }
}

.control-group {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  margin: 0 0 1rem;

  > .form-check {
    display: inline-block;
  }

  &::after {
    display: table;
    clear: both;
    content: "";
  }

  .control-label {
    inline-size: 240px;
    padding: .3rem 1rem .3rem 0;
  }

  .controls {
    position: relative;
    flex: 1;
    min-inline-size: 210px;
    max-inline-size: 100%;

    + div {
      inline-size: 100%;
      margin: 5px 0 10px;
    }
  }

  .form-vertical & {
    flex-direction: column;
  }
}

.stack .control-label {
  inline-size: 100%;
}

.spacer {
  hr {
    inline-size: 380px;
  }
}

td .form-control {
  display: inline-block;
  inline-size: auto;
}

.checkboxes {
  padding-block-start: 5px;

  .checkbox input {
    position: static;
    margin-inline-start: 0;
  }
}

.form-check {
  padding-block-start: 5px;
  margin-block-end: 0;
}

.modal label {
  inline-size: 100%;
}

// Validation
.invalid {
  border-color: var(--danger);
}

label.invalid {
  color: var(--danger-text);
}

.valid {
  border-color: var(--success);
}

label.valid {
  color: var(--success-text);
}

.form-control-feedback {
  display: block;
}

[aria-grabbed="true"] {
  box-shadow: $input-box-shadow;
}

.sortable-handler.inactive {
  opacity: .3;
}

// set up hidden tooltip
[role="tooltip"]:not(.show) {
  z-index: $zindex-tooltip;
  display: none;
  padding: .5em;
  margin: .25em;
  color: $white;
  text-align: start;
  background: $black;
  border-radius: .2rem !important;
}

// reveal associated tooltip on focus
:focus + [role="tooltip"],
:hover + [role="tooltip"] {
  position: absolute;
  display: block;
  max-inline-size: 100%;
  overflow-wrap: break-word;
  white-space: normal;
}

.filter-search-bar__description {
  inset-block-start: 100%;
  inset-block-end: auto;
}

.container-popup .filter-search-bar__description {
  inset-block-start: 100%;
  inset-block-end: auto;
}

.input-group > .form-control[readonly] {
  margin-inline-end: 1px;
}

.form-group {
  @extend .mb-3;
}

// Subform - non table layout
div.subform-repeatable-group {
  position: relative;
  padding: 32px 32px 16px 28px;
  margin-block-start: 20px;
  border: $input-border-width solid $input-border-color;
  @include border-radius($border-radius);

  > .btn-toolbar {

    .btn-group {
      position: static;
    }

    .btn {
      position: absolute;

      &.group-add {
        inset-inline-end: -1px;
        inset-block-end: -1px;
        border-radius: $border-radius 0 $border-radius 0;
      }
      &.group-remove {
        inset-block-start: -1px;
        inset-inline-end: -1px;
        border-radius: 0 $border-radius;
      }
      &.group-move {
        inset-block-start: 50%;
        inset-inline-end: 100%;
        padding: 0;
        border-radius: $border-radius 0 0 $border-radius;
        transform: translateY(-50%);

        span {
          padding: 1.5rem .5rem;
        }
      }
      &.group-move-up {
        inset-block-start: 50%;
        inset-inline-end: 100%;
        margin-block-start: -45px;
        border-radius: 0;
        transform: translateY(-50%);
      }
      &.group-move-down {
        inset-block-start: 50%;
        inset-inline-end: 100%;
        margin-block-start: 45px;
        border-radius: 0;
        transform: translateY(-50%);
      }
    }
  }
}

// Highlight draggable section
.subform-repeatable-group[draggable="true"] {
  // For non table layout
  background-color: $teal;

  // For table layout
  > td {
    background-color: $teal;
  }
}
