.@{button-prefix-cls} {
  &-rtl {
    direction: rtl;
  }

  &-primary {
    .@{button-prefix-cls}-group &:last-child:not(:first-child),
    .@{button-prefix-cls}-group & + & {
      .@{button-prefix-cls}-group-rtl& {
        border-right-color: @button-group-border;
        border-left-color: @button-default-border;
      }
      &[disabled] {
        .@{button-prefix-cls}-group-rtl& {
          border-right-color: @button-default-border;
          border-left-color: @button-group-border;
        }
      }
    }
  }

  & > &-loading-icon {
    .@{iconfont-css-prefix} {
      .@{button-prefix-cls}-rtl& {
        padding-right: 0;
        padding-left: @margin-xs;
      }
    }

    &:only-child {
      .@{iconfont-css-prefix} {
        padding-right: 0;
        padding-left: 0;
      }
    }
  }

  > .@{iconfont-css-prefix} + span,
  > span + .@{iconfont-css-prefix} {
    .@{button-prefix-cls}-rtl& {
      margin-right: 8px;
      margin-left: 0;
    }
  }
}

// mixin
.btn-group(@btnClassName: btn) {
  .@{btnClassName} + .@{btnClassName},
  .@{btnClassName} + &,
  span + .@{btnClassName},
  .@{btnClassName} + span,
  > span + span,
  & + .@{btnClassName},
  & + & {
    .@{btnClassName}-rtl&,
    .@{btnClassName}-group-rtl& {
      margin-right: -1px;
      margin-left: auto;
    }
  }

  &.@{btnClassName}-group-rtl {
    direction: rtl;
  }

  > .@{btnClassName}:first-child:not(:last-child),
  > span:first-child:not(:last-child) > .@{btnClassName} {
    .@{btnClassName}-group-rtl& {
      border-top-left-radius: 0;
      border-top-right-radius: @button-border-radius-base;
      border-bottom-right-radius: @button-border-radius-base;
      border-bottom-left-radius: 0;
    }
  }

  > .@{btnClassName}:last-child:not(:first-child),
  > span:last-child:not(:first-child) > .@{btnClassName} {
    .@{btnClassName}-group-rtl& {
      border-top-left-radius: @button-border-radius-base;
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
      border-bottom-left-radius: @button-border-radius-base;
    }
  }

  &-sm {
    > .@{btnClassName}:first-child:not(:last-child),
    > span:first-child:not(:last-child) > .@{btnClassName} {
      .@{btnClassName}-group-rtl& {
        border-top-left-radius: 0;
        border-top-right-radius: @button-border-radius-sm;
        border-bottom-right-radius: @button-border-radius-sm;
        border-bottom-left-radius: 0;
      }
    }

    > .@{btnClassName}:last-child:not(:first-child),
    > span:last-child:not(:first-child) > .@{btnClassName} {
      .@{btnClassName}-group-rtl& {
        border-top-left-radius: @button-border-radius-sm;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        border-bottom-left-radius: @button-border-radius-sm;
      }
    }
  }
}
