.input-group {
  position: relative; // For dropdowns
  display: flex;
  align-items: stretch;
  flex-wrap: nowrap;
  width: 100%;

  // Undo padding and float of grid classes
  &[class*='col-'] {
    float: none;
    padding-right: 0;
    padding-left: 0;
  }

  .form-control + .form-control{
    margin-left: -1px;
  }
  > .form-control,
  > .c8y-select-wrapper,
  > .form-group,
  > div[c8y-device-group-selector] {
    position: relative;
    z-index: 2;
    flex: 1 1 auto;
    margin-bottom: 0;
    height: @form-control-height-base !important;
    min-width: 0;
    &:not(:first-child) {
      margin-left: -1px;
    }
  }
  > .color-input {
    flex-grow: 0;
    flex-basis: 39px;
  }
  .form-control.inner-scroll{
    box-shadow: none;
    border: 1px solid @form-control-border-color-default;
    padding-top: 0;
    padding-bottom: 0;
    align-items: center;
  }

  c8y-software-type {
    flex-grow: 1 !important;

    c8y-typeahead .input-group input {
      flex-grow: 1 !important;
    }
  }

  &.typeahead > div:not(.input-group-btn) {
    flex: 1;

    .form-control {
      width: 100%;
    }
  }
}

.input-group-addon {
  display: flex;
  align-items: center;
  padding: @form-control-padding-base-vertical @form-control-padding-base-horizontal;
  border-radius: @form-control-border-radius;
  background-color: @form-control-border-color-default;
  color: @form-control-color-default;
  font-weight: @form-control-font-weight;
  font-size: @font-size-base;
  font-family: @form-control-font-family;
  line-height: @form-control-line-height;
  height: @form-control-height-base;

  &.inner-scroll {
    max-width: 230px;
    height: 32px;
    margin-left: -1px;
  }

  .form-group-sm &,
  .input-group-sm &,
  &.input-sm {
    padding: @form-control-padding-small-vertical @form-control-padding-small-horizontal;
    font-size: @font-size-small;
    height: @form-control-height-sm;
  }

  label.c8y-checkbox,
  label.c8y-radio {
    margin: 0;
    line-height: 1;

    input[type='checkbox'] + span::before,
    input[type='radio'] + span::before {
      margin: 0;
    }
  }
}

.input-group-btn {
  display: flex;
  align-items: stretch;
  max-height: @form-control-height-base;
  &:not(:first-child) {
    margin-left: -1px;
  }
  &--last {
    margin-left: -1px;
  }
  .input-group-sm &{
    max-height: @form-control-height-sm;
  }
}

.input-group-addon,
.input-group-btn,
.form-control {
  &:not(:first-child):not(:last-child) {
    border-radius: 0;
  }
}

// search with round corners
.input-group.input-group-search {
  display: flex !important;

  .form-control {
    &,
    &:first-child,
    &:last-child {
      padding-right: calc(@form-control-height-base + @form-control-padding-base-horizontal);
      padding-left: calc(@form-control-padding-base-horizontal * 2);
      border-radius: calc(@form-control-height-base * 0.5);
    }
  }

  .input-group-btn,
  .input-group-addon {
    position: absolute;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    min-width: @form-control-height-base;
    height: @form-control-height-base;
    border: 0;
    background-color: transparent;

    .btn {
      width: 100%;
      height: 100%;
      line-height: 1;
      border-radius: calc(@form-control-height-base * 0.5) !important;
      &:hover {
        box-shadow: inset 0 0 0 2px @component-brand-primary;
      }
    }
  }

  &.input-group-sm {
    .form-control:not(.c8y-radio):not(.c8y-checkbox) {
      padding-left: 12px;
    }

    .input-group-btn,
    .input-group-addon, .form-group {
      height: @form-control-height-sm;
    }
  }
}

.input-group.input-group-password {
  display: flex !important;

  .form-control {
    &,
    &:first-child,
    &:last-child {
      padding-right: calc(@form-control-height-base + @form-control-padding-base-horizontal);
      padding-left: @form-control-padding-base-horizontal;
    }
  }

  .input-group-btn,
  .input-group-addon {
    position: absolute;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    min-width: @form-control-height-base;
    height: @form-control-height-base;
    border: 0;
    background-color: transparent;

    .btn {
      width: 100%;
      height: 100%;
    }
  }

  &.input-group-sm {
    .form-control:not(.c8y-radio):not(.c8y-checkbox) {
      padding-left: 12px;
    }

    .input-group-btn,
    .input-group-addon {
      height: @form-control-height-sm;
    }
  }
}

// dropdown without round corners
.input-group.input-group-dropdown {
  .input-group-btn,
  .input-group-addon {
    position: absolute;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    min-width: @form-control-height-base;
    height: @form-control-height-base;
    border: 0;
    background-color: transparent;

    .btn {
      width: 100%;
      height: 100%;
      border: 0;
    }
  }
  &.input-group-sm{
    .input-group-btn,
    .input-group-addon {
      height: @form-control-height-sm;
    }
  }
}

// Reset rounded corners
.input-group .form-control:first-child,
.input-group-addon:first-child,
.input-group-btn:first-child > .btn,
.input-group-btn:first-child > .btn-group > .btn,
.input-group-btn:first-child > .dropdown-toggle,
.input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle),
.input-group-btn:last-child > .btn-group:not(:last-child) > .btn {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-group .form-control:last-child,
.input-group-addon:last-child,
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .btn-group > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child),
.input-group-btn:first-child > .btn-group:not(:first-child) > .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

//Input group editable
// supports a save button and a cancel button inside a input-group
.input-group-editable {
  .input-group-btn {
    .btn-clean {
      position: relative;
      padding: 6px;

      &::after {
        position: absolute;
        top: 50%;
        right: 0;
        display: block;
        margin-top: -10px;
        width: 1px;
        height: 20px;
        background-color: fade(@black, 10%);
        content: '';
      }
    }

    &:last-child {
      .btn-clean::after {
        display: none;
      }
    }
  }
}

.input-group-editable {
  textarea.form-control {
    max-height: unset !important;
    height: @form-control-height-base;
  }

  input[type='number']:not(:focus) {
    -moz-appearance: textfield;

    &::-webkit-inner-spin-button {
      margin: 0;

      -webkit-appearance: none;
    }
  }

  .form-control:not(.ng-dirty) {
    transition: all 0.25s ease;

    &[disabled] {
      padding-left: 0;
      box-shadow: none;
      opacity: @component-disabled-opacity;
      transition: none;
    }

    ~ .input-group-btn {
      display: none;
    }
  }

  &:not(:hover) {
    textarea.form-control {
      resize: none;
    }

    .form-control:not(:focus):not(.ng-dirty) {
      z-index: 2;
      overflow: hidden;
      flex: 0 1 auto;
      margin-right: 12px;
      padding-left: 0;
      min-width: 3ch;
      max-width: 100%;
      width: fit-content;
      background-color: transparent;
      box-shadow: none;
      text-overflow: ellipsis;

      &[disabled],
      &[read-only] {
        width: 100%;
      }

      + span:after {
        z-index: 5;
        display: inline-block;
        margin-left: -16px;
        color: @component-brand-primary;
        content: @dlt-c8y-icon-pencil;
        font: normal normal normal 14px/1 @icon-font-family;
        font-size: 12px;
        line-height: 32px;
        opacity: 0.5;

        text-rendering: auto;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;

        .form-group-lg & {
          line-height: 40px;
        }
      }

      &[disabled] {
        + span:after {
          display: none;
        }
      }
    }
  }

  &:hover {
    .form-control:not(:focus):not(.ng-dirty) {
      flex: 0 1 auto;
      max-width: 100%;
      width: fit-content;
    }
  }
}

// Sizing options
// Remix the default form control sizing classes into new ones for easier manipulation.
.input-group-lg > .form-control,
.input-group-lg > .input-group-addon,
.input-group-lg > .input-group-btn > .btn {
  .input-lg();
}
.input-group-lg > .form-group{
  height: @form-control-height-lg!important;
}
.input-group-sm > .form-control,
.input-group-sm > .input-group-addon,
.input-group-sm > .input-group-btn > .btn {
  .input-sm();
}
.input-group-sm > .form-group{
  height: @form-control-height-sm!important;
}

// Text input groups
.input-group-addon {
  padding: @form-control-padding-base-vertical @form-control-padding-base-horizontal;
  border: 1px solid @input-group-addon-border-color;
  border-radius: @form-control-border-radius;
  background-color: @input-group-addon-background-default;
  color: @form-control-color-default;
  text-align: center;
  font-weight: normal;
  font-size: @font-size-base;
  line-height: 1;

  &.input-sm {
    padding: @form-control-padding-small-vertical @form-control-padding-small-horizontal;
    border-radius: @form-control-border-radius;
    font-size: @font-size-small;
  }

  &.input-lg {
    padding: @form-control-padding-large-vertical @form-control-padding-large-horizontal;
    border-radius: @form-control-border-radius;
    font-size: @font-size-large;
  }

  input[type='radio'],
  input[type='checkbox'] {
    margin-top: 0;
  }
}

// Button input groups
.input-group-btn {
  position: relative; // Jankily prevent input button groups from wrapping with `white-space` and
  white-space: nowrap; // Negative margin for spacing, position for bringing hovered/focused/actived
  // `font-size` in combination with `inline-block` on buttons.
  font-size: 0;

  // element above the siblings.
  > .btn {
    position: relative;
    padding: 5px 12px;
    height: 100%;

    + .btn {
      margin-left: -1px;
      border-left-color: fade(@black, 15%);
    }

    // Bring the "active" button to the front
    &:hover,
    &:focus,
    &:active {
      z-index: 2;
    }

    &.btn-default:not(:focus) {
      border-color: @form-control-border-color-default;
    }

    &.btn-link[disabled] {
      color: @component-color-disabled !important;
      opacity: @form-control-disabled-opacity !important;
      cursor: @cursor-disabled !important;
      pointer-events: auto !important;
    }
  }

  // No negative margins to show the complet input border
  &:first-child {
    > .btn,
    > .btn-group {
      margin-right: 0;
      border-right-color: fade(@black, 15%);
    }

    > .btn:last-child {
      // border-right: 0;
    }
  }

  &:last-child {
    > .btn:not(:focus),
    > .btn-group {
      z-index: 2;
      border-left-color: fade(@black, 15%);
    }
    > .btn:focus {
      margin-left: -1px;
    }
  }
  &:not(:first-child) {
    > .btn:first-child:not(:focus) {
      // border-left: 0;
    }
  }
}

// input-group-array for formly array.type.component
.input-group-array {
  @media screen and (min-width: @screen-sm-min) {
    display: flex;
  }

  .form-group {
    position: relative;
  }

  .form-group,
  .input-group-btn {
    margin-bottom: 4px;
  }

  // @TODO: JAWI validate
  > .input-group-btn.delete-row {
    margin-top: 24px;
  }

  formly-field {
    flex-grow: 1;
  }

  + .input-group-array {
    .input-group-btn {
      margin-top: 0;
    }

    .form-group > label {
      display: none;
    }
  }
}

// modifier classes for formly
.formly-group-array-cols {
  .input-group-array {
    gap: @margin-base;

    > formly-field {
      display: contents;

      > formly-group {
        display: contents;
      }
    }

    formly-field {
      flex-basis: 50%;
    }
  }
}

formly-field label.c8y-checkbox {
  margin: @margin-base 0;
}

c8y-lwm2m-legend-wrapper formly-field {
  > c8y-field-checkbox {
    display: flex;
    align-items: center;
    margin: 0 0 @margin-8 0;
    & label.c8y-switch {
      display: flex !important;
      overflow: visible;
      align-items: center;
    }
  }
}

// EXTENDABLE INPUT LIST
[c8yinputgrouplistcontainer] > li:not(:last-child) .input-group-btn > .btn.text-primary {
  display: none;
}
