.form-group {
  // reset line-height to keep consistent vertical rhythm
  line-height: 0;
  position: relative;

  &__action-link {
    @include font-style('body--m');
    @include text-ellipsis($action-link-max-width, 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--s');
    margin-left: 1px;
    text-decoration: none;
  }

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

  // form group: inputs
  &__input {
    position: relative;
  }

  &__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 {
      fill: $color--two-50;
    }

    //IE fix
    input[readonly] + .icon svg {
      fill: $color--two-50;
    }
  }

  &__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 {
        fill: $color--two-50;
        transition: fill $transition-duration--fast ease;
      }

      &:hover .icon svg {
        fill: $color-brand--two;
      }
    }

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

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

  // form group: error
  &--error {
    .form-group__feedback {
      @include form-field--feedback-color;
      opacity: 1;
    }

    .form-group__input--icon-left .icon svg {
      @include form-field--feedback-color;
    }

    input[type="text"]:read-only + .icon svg {
      fill: $color--two-50;
    }
  }

  // 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--s');
    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;
  }
}

// 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--black.button--m,
      & + .form-group {
        margin-left: 5px;
      }
    }

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

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

