// scss-lint:disable QualifyingElement

// Make the div behave like a button
.btn-group {
  position: relative;
  display: inline-block;
  vertical-align: middle; // match .btn alignment given font-size hack above

  > .btn {
    position: relative;
    float: left;

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

    &:hover {
      z-index: 2;
    }

    + .dropdown-toggle {
      padding-right: $split-btn-dropdown-toggle-padding-x;
      padding-left: $split-btn-dropdown-toggle-padding-x;
    }
  }

  .btn + .btn,
  .btn + .btn-group,
  .btn-group + .btn,
  .btn-group + .btn-group {
    margin-left: -$input-border-width;
  }

  > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
    border-radius: 0;
  }

  > .btn:first-child {
    margin-left: 0;

    &:not(:last-child):not(.dropdown-toggle) {
      @include border-right-radius(0);
    }
  }

  > .btn-group {
    float: left;
  }

  > .btn-group:not(:first-child):not(:last-child) > .btn {
    border-radius: 0;
  }

  > .btn-group:first-child:not(:last-child) {
    > .btn:last-child,
    > .dropdown-toggle {
      @include border-right-radius(0);
    }
  }

  > .btn:last-child:not(:first-child),
  > .dropdown-toggle:not(:first-child) {
    @include border-left-radius(0);
  }

  > .btn-group:last-child:not(:first-child) > .btn:first-child {
    @include border-left-radius(0);
  }

  > .btn-lg + .dropdown-toggle {
    padding-right: $split-btn-lg-dropdown-toggle-padding-x;
    padding-left: $split-btn-lg-dropdown-toggle-padding-x;
  }
}

// Optional: Group multiple button groups together for a toolbar
.btn-toolbar {
  margin-left: -$btn-toolbar-margin; // Offset the first child's margin
  @include clearfix();

  .btn-group,
  .input-group {
    float: left;
  }

  > .btn,
  > .btn-group,
  > .input-group {
    margin-left: $btn-toolbar-margin;
  }
}

// On active and open, don't show outline
.btn-group .dropdown-toggle:active,
.btn-group.open .dropdown-toggle {
  outline: 0;
}

// Sizing
//
// Remix the default button sizing classes into new ones for easier manipulation.

.btn-group-sm > .btn {
  @extend .btn-sm;
  padding: $btn-group-padding-y-sm $btn-group-padding-x-sm;
}
.btn-group-lg > .btn {
  @extend .btn-lg;
}

// Reposition the caret
.btn .caret {
  margin-left: 0;
}

// Carets in other button sizes
.btn-lg .caret {
  border-width: $caret-width-lg $caret-width-lg 0;
  border-bottom-width: 0;
}

// Upside down carets for .dropup
.dropup .btn-lg .caret {
  border-width: 0 $caret-width-lg $caret-width-lg;
}

// Checkbox and radio options
//
// In order to support the browser's form validation feedback, powered by the
// `required` attribute, we have to "hide" the inputs via `clip`. We cannot use
// `display: none;` or `visibility: hidden;` as that also hides the popover.
// Simply visually hiding the inputs via `opacity` would leave them clickable in
// certain cases which is prevented by using `clip` and `pointer-events`.
// This way, we ensure a DOM element is visible to position the popover from.
//
// See https://github.com/twbs/bootstrap/pull/12794 and
// https://github.com/twbs/bootstrap/pull/14559 for more information.

[data-toggle='buttons'] {
  > .btn,
  > .btn-group > .btn {
    input[type='radio'],
    input[type='checkbox'] {
      position: absolute;
      // clip: rect(0, 0, 0, 0);
      pointer-events: none;
    }
  }
}
