.form-group {
  position: relative;

  &__action-link {
    @include font-style('body--m');
    @include text-ellipsis(
      $form-group-action-link-max-width--m-inversed,
      block
    );
    position: absolute;
    right: 0;
    top: 0;
  }

  &__label {
    @include font-style('body--m');
    @include form-field--primary-text-color;
    display: block;
    margin-bottom: $spacing--xxs;
  }

  &__optional,
  &__message {
    @include form-field--secondary-text-color;
  }

  &__optional {
    @include font-style('body--xs');
    margin-left: 1px;
    text-decoration: none;
  }

  &__message {
    @include font-style('body--m');
    display: block;
    margin-top: $spacing--xs;
  }

  // form group: inputs
  &__input {
    position: relative;
    display: flex;
    flex-direction: column;
  }

  &__input--button {
    input[type],
    input[type]:focus,
    input[type]:read-only {
      padding-right: 50px;
    }
  }

  &__input--icon-left {
    .icon {
      left: 20px;
      top: $spacing--s;

      svg {
        fill: $color-brand--one;
      }
    }

    input {
      padding-left: 50px;
    }

    input[type]:read-only {
      padding-left: 50px;
    }

    //IE fix
    input[readonly] {
      padding-left: 50px;
    }

    input[type]:focus {
      padding-left: 49px;
    }

    input[type]:read-only + .icon svg {
      @include color-dark-shade-alternative;
    }

    //IE fix
    input[readonly] + .icon svg {
      @include color-dark-shade-alternative;
    }
  }

  &__input.clearable-input {
    button {
      height: $icon-size;
      opacity: 0;
      pointer-events: none;
      position: absolute;
      right: 20px;
      top: $spacing--s;
      transition: opacity $transition-duration ease;
      width: $icon-size;

      .icon {
        left: initial;
        top: 0;
      }

      .icon svg {
        @include color-dark-shade-main;
        transition: fill $transition-duration--fast ease;
      }

      &:hover .icon svg {
        @include color-dark-shade-alternative;
      }
    }

    input::-ms-clear {
      display: none;
    }

    &--active button {
      opacity: 1;
      pointer-events: auto;
    }
  }

  // form group: error
  &--error {
    .form-group__feedback {
      opacity: 1;
    }

    input,
    .icon svg {
      @include form-field--invalid-text-icon;
    }

    input[type='text']:read-only + .icon svg {
      @include color-dark-shade-alternative;
    }
  }

  // form group: feedback
  &__feedback {
    @include font-style('body--m');
    @include form-field--feedback-color;
    display: block;
    margin-top: $spacing--xs;
    opacity: 0.5;
  }

  // form group: character count
  &__characters {
    @include font-style('body--xs');
    bottom: $baseline * 1.8;
    margin-top: $spacing--xs;
    pointer-events: none;

    &:not(.text--negative) {
      @include form-field--secondary-text-color;
    }
  }

  // form group: spacing
  & + & {
    margin-top: $spacing--m;
  }

  /// currency specific styling:

  &.currency-format {
    .form-group__input {
      @include form-field--currency-color;
      background: #fff;
      border-radius: $border-radius;
      display: block;
      height: 60px;
      overflow: hidden;

      &.readonly {
        background: $color--grey-10; // needs to be adjusted when Spherion has color mapping too.
      }

      &:focus-within {
        @include form-field--focus;
      }

      input,
      input:focus {
        border-color: transparent;
        border-radius: 0;
      }

      input {
        position: absolute;
        width: 70%;
        padding: 12px 18px 14px; //mimics focus so content does not jump
      }

      span {
        @include text-ellipsis;
        background: #f4f8fd;
        border-right: 1px solid #d7d7d7;
        color: $color-brand--one;
        display: inline-block;
        line-height: 58px; //mimics input field height.
        max-width: 132px; // alows for maximun 5 wide characters + ellipsis dots
        padding: 0 15px;
        pointer-events: auto;

        &.icon svg {
          height: 20px;
          padding-top: 20px;
          width: 20px;
        }
      }
    }

    &.form-group--error {
      .form-group__input,
      &.currency-format .form-group__input {
        @include form-field--invalid;

        &:focus-within {
          @include form-field--invalid;
          @include form-field--invalid-box-shadow;
        }

        span {
          @include form-field--invalid;
        }
      }
    }

    input[type='text']:read-only:not(select):not(.flatpickr),
    input[type='number']:read-only:not(select):not(.flatpickr) {
      border: none;

      .form-group__input:focus-within {
        border: none;
      }
    }
  }
}

// viewport l
@include viewport--l {
  .block__content .form-group {
    width: grid-columns(8, 9);
  }
}

// form groups
@include viewport--l('inversed') {
  .form-groups--row {
    .form-group + .button,
    .form-group + .form-group {
      margin-top: $spacing--xs;
    }
  }
}

@include viewport--l {
  .form-groups--row {
    display: flex;
    justify-content: space-between;

    .form-group {
      flex: 1;
      margin-top: 0;

      & + .button--icon.button--m,
      & + .button--filled.button--m,
      & + .form-group {
        margin-left: 5px;
      }
    }

    .button {
      margin-top: 0;
    }
  }
}

@include viewport--m('inversed') {
  .form-group__action-link {
    @include text-ellipsis($form-group-action-link-max-width, block);
  }
}
