.pf-c-select {
  @include pf-t-light; // force the container follow the light theme

  // Toggle
  --pf-c-select__toggle--PaddingTop: var(--pf-global--spacer--form-element);
  --pf-c-select__toggle--PaddingRight: var(--pf-global--spacer--sm);
  --pf-c-select__toggle--PaddingBottom: var(--pf-global--spacer--form-element);
  --pf-c-select__toggle--PaddingLeft: var(--pf-global--spacer--sm);
  --pf-c-select__toggle--MinWidth: var(--pf-global--target-size--MinWidth);
  --pf-c-select__toggle--FontSize: var(--pf-global--FontSize--md);
  --pf-c-select__toggle--FontWeight: var(--pf-global--FontWeight--normal);
  --pf-c-select__toggle--LineHeight: var(--pf-global--LineHeight--md);
  --pf-c-select__toggle--BackgroundColor: var(--pf-global--BackgroundColor--100);
  --pf-c-select__toggle--BorderWidth: var(--pf-global--BorderWidth--sm);
  --pf-c-select__toggle--BorderTopColor: var(--pf-global--BorderColor--300);
  --pf-c-select__toggle--BorderRightColor: var(--pf-global--BorderColor--300);
  --pf-c-select__toggle--BorderBottomColor: var(--pf-global--BorderColor--200);
  --pf-c-select__toggle--BorderLeftColor: var(--pf-global--BorderColor--300);
  --pf-c-select__toggle--Color: var(--pf-global--Color--100);
  --pf-c-select__toggle--hover--BorderBottomColor: var(--pf-global--active-color--100);
  --pf-c-select__toggle--active--BorderBottomWidth: var(--pf-global--BorderWidth--md);
  --pf-c-select__toggle--active--BorderBottomColor: var(--pf-global--active-color--100);
  --pf-c-select__toggle--expanded--BorderBottomWidth: var(--pf-global--BorderWidth--md);
  --pf-c-select__toggle--expanded--BorderBottomColor: var(--pf-global--active-color--100);
  --pf-c-select__toggle--disabled--BackgroundColor: var(--pf-global--disabled-color--300);
  --pf-c-select__toggle--m-plain--BorderColor: transparent;
  --pf-c-select__toggle--m-plain--Color: var(--pf-global--Color--100);
  --pf-c-select__toggle--m-plain--hover--Color: var(--pf-global--Color--100);

  // Remove during breaking change
  // When there is a typeahead (input box) adjust the top padding of the wrapper in case it wraps to the second line
  --pf-c-select__toggle-wrapper--m-typeahead--PaddingTop: 0;

  // Space for the children of the toggle
  --pf-c-select__toggle-wrapper--not-last-child--MarginRight: var(--pf-global--spacer--xs);

  // Max-width is needed for ellipsing the text. This leaves enough space for the toggle caret.
  // However, for cases where the clear icon button or a badge are added, the correct width will need to be calculated in script
  --pf-c-select__toggle-wrapper--MaxWidth: calc(100% - var(--pf-global--spacer--lg));

  // Chip group within a toggle-wrapper needs a margin-bottom in case it wraps
  --pf-c-select__toggle-wrapper--c-chip-group--MarginTop: var(--pf-global--spacer--sm);
  --pf-c-select__toggle-wrapper--c-chip-group--MarginBottom: var(--pf-global--spacer--xs);

  // The button inside a chip must be adjusted to reduce the padding, which is driving the height of the chip, so it fits within the toggle
  --pf-c-select__toggle-wrapper--c-chip--c-button--PaddingTop: var(--pf-global--spacer--xs);
  --pf-c-select__toggle-wrapper--c-chip--c-button--PaddingBottom: var(--pf-global--spacer--xs);

  // Select input for typeahead
  --pf-c-select__toggle-typeahead--FlexBasis: 10em;
  --pf-c-select__toggle-typeahead--BackgroundColor: transparent;
  --pf-c-select__toggle-typeahead--BorderTop: none;
  --pf-c-select__toggle-typeahead--BorderRight: none;
  --pf-c-select__toggle-typeahead--BorderLeft: none;

  // Typeahead form
  --pf-c-select__toggle-typeahead-form--MinWidth: #{pf-size-prem(120px)};

  // This is really var(--pf-c-form-control--PaddingBottom) but has to be recalculated instead of reusing another component's variable
  --pf-c-select__toggle-typeahead--active--PaddingBottom: calc(var(--pf-global--spacer--form-element) - var(--pf-global--BorderWidth--sm));

  //  Select toggle icon + toggle text
  --pf-c-select__toggle-icon--toggle-text--MarginLeft: var(--pf-global--spacer--xs);

  // Select toggle badge
  --pf-c-select__toggle-badge--PaddingLeft: var(--pf-global--spacer--sm);

  // Toggle arrow
  --pf-c-select__toggle-arrow--MarginLeft: var(--pf-global--spacer--md);
  --pf-c-select__toggle-arrow--MarginRight: var(--pf-global--spacer--sm);
  --pf-c-select__toggle-arrow--with-clear--MarginLeft: var(--pf-global--spacer--sm);
  --pf-c-select__toggle-arrow--m-top--m-expanded__toggle-arrow--Transform: rotate(180deg);

  // Toggle button
  --pf-c-select__toggle-clear--PaddingRight: var(--pf-global--spacer--sm);
  --pf-c-select__toggle-clear--PaddingLeft: var(--pf-global--spacer--md);
  --pf-c-select__toggle-button--PaddingLeft: var(--pf-global--spacer--sm);
  --pf-c-select__toggle-button--Color: var(--pf-global--Color--100);

  // Menu
  --pf-c-select__menu--BackgroundColor: var(--pf-global--BackgroundColor--light-100);
  --pf-c-select__menu--BorderWidth: var(--pf-global--BorderWidth--sm);
  --pf-c-select__menu--BoxShadow: var(--pf-global--BoxShadow--md);
  --pf-c-select__menu--PaddingTop: var(--pf-global--spacer--sm);
  --pf-c-select__menu--PaddingBottom: var(--pf-global--spacer--sm);
  --pf-c-select__menu--Top: calc(100% + var(--pf-global--spacer--xs)); // The top of the menu must be pushed down to create space between the toggle and menu
  --pf-c-select__menu--ZIndex: var(--pf-global--ZIndex--sm);
  --pf-c-select__menu--m-top--Transform: translateY(calc(-100% - var(--pf-global--spacer--xs))); // The "dropup" menu must be transformed up and this calculates how much to create space between the toggle and menu

  // Menu item
  --pf-c-select__menu-item--PaddingTop: var(--pf-global--spacer--sm);
  --pf-c-select__menu-item--PaddingRight: var(--pf-global--spacer--md);
  --pf-c-select__menu-item--m-selected--PaddingRight: var(--pf-global--spacer--2xl);
  --pf-c-select__menu-item--PaddingBottom: var(--pf-global--spacer--sm);
  --pf-c-select__menu-item--PaddingLeft: var(--pf-global--spacer--md);
  --pf-c-select__menu-item--FontSize: var(--pf-global--FontSize--md);
  --pf-c-select__menu-item--FontWeight: var(--pf-global--FontWeight--normal);
  --pf-c-select__menu-item--LineHeight: var(--pf-global--LineHeight--md);
  --pf-c-select__menu-item--Color: var(--pf-global--Color--dark-100);
  --pf-c-select__menu-item--disabled--Color: var(--pf-global--Color--dark-200);
  --pf-c-select__menu-item--hover--BackgroundColor: var(--pf-global--BackgroundColor--light-300);
  --pf-c-select__menu-item--disabled--BackgroundColor: transparent;

  // Menu item icon
  --pf-c-select__menu-item-icon--Color: var(--pf-global--active-color--100);
  --pf-c-select__menu-item-icon--FontSize: var(--pf-global--icon--FontSize--sm);
  --pf-c-select__menu-item-icon--Right: var(--pf-global--spacer--md);
  --pf-c-select__menu-item-icon--Top: 50%;
  --pf-c-select__menu-item-icon--Transform: translateY(-50%);

  // Match within a menu item when using typeahead
  --pf-c-select__menu-item--match--FontWeight: var(--pf-global--FontWeight--bold);

  // Menu group padding
  --pf-c-select__menu-input--PaddingTop: var(--pf-global--spacer--sm);
  --pf-c-select__menu-input--PaddingRight: var(--pf-c-select__menu-item--PaddingRight);
  --pf-c-select__menu-input--PaddingBottom: var(--pf-global--spacer--md);
  --pf-c-select__menu-input--PaddingLeft: var(--pf-c-select__menu-item--PaddingLeft);

  // Menu Item separator
  --pf-c-select__separator--Height: var(--pf-global--BorderWidth--sm);
  --pf-c-select__separator--BackgroundColor: var(--pf-global--BackgroundColor--light-300);
  --pf-c-select__separator--MarginTop: var(--pf-global--spacer--sm);
  --pf-c-select__separator--MarginBottom: var(--pf-global--spacer--sm);

  // Menu group
  // add a little space if it's not the first group because the first one also has the menu padding
  --pf-c-select__menu-group--not--first-of-type--PaddingTop: var(--pf-global--spacer--sm);

  // Menu section heading
  // Paddings are set to always line up with the other menu items
  --pf-c-select__menu-group-title--PaddingTop: var(--pf-c-select__menu-item--PaddingTop);
  --pf-c-select__menu-group-title--PaddingRight: var(--pf-c-select__menu-item--PaddingRight);
  --pf-c-select__menu-group-title--PaddingBottom: var(--pf-c-select__menu-item--PaddingBottom);
  --pf-c-select__menu-group-title--PaddingLeft: var(--pf-c-select__menu-item--PaddingLeft);
  --pf-c-select__menu-group-title--FontSize: var(--pf-global--FontSize--sm);
  --pf-c-select__menu-group-title--FontWeight: var(--pf-global--FontWeight--semi-bold);
  --pf-c-select__menu-group-title--Color: var(--pf-global--Color--dark-200);

  position: relative;
  display: inline-block;
  width: 100%;
}

.pf-c-select__toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-width: var(--pf-c-select__toggle--MinWidth);
  padding: var(--pf-c-select__toggle--PaddingTop) var(--pf-c-select__toggle--PaddingRight) var(--pf-c-select__toggle--PaddingBottom) var(--pf-c-select__toggle--PaddingLeft);
  font-size: var(--pf-c-select__toggle--FontSize);
  font-weight: var(--pf-c-select__toggle--FontWeight);
  line-height: var(--pf-c-select__toggle--LineHeight);
  color: var(--pf-c-select__toggle--Color);
  white-space: nowrap;
  cursor: pointer;
  background-color: var(--pf-c-select__toggle--BackgroundColor);
  border: none;

  &.pf-m-disabled,
  &:disabled {
    --pf-c-select__toggle--BackgroundColor: var(--pf-c-select__toggle--disabled--BackgroundColor);

    pointer-events: none;

    &::before {
      border: 0;
    }
  }

  & > * {
    color: var(--pf-c-select__toggle--Color);
  }

  &::before {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    content: "";
    border: var(--pf-c-select__toggle--BorderWidth) solid;
    border-color: var(--pf-c-select__toggle--BorderTopColor) var(--pf-c-select__toggle--BorderRightColor) var(--pf-c-select__toggle--BorderBottomColor) var(--pf-c-select__toggle--BorderLeftColor);
  }

  &:hover,
  &.pf-m-hover {
    &::before {
      --pf-c-select__toggle--BorderBottomColor: var(--pf-c-select__toggle--hover--BorderBottomColor);
    }
  }

  &:active,
  &.pf-m-active,
  &:focus-within {
    &::before {
      --pf-c-select__toggle--BorderBottomColor: var(--pf-c-select__toggle--active--BorderBottomColor);

      border-bottom-width: var(--pf-c-select__toggle--active--BorderBottomWidth);
    }
  }

  .pf-m-expanded > & {
    &::before {
      --pf-c-select__toggle--BorderBottomColor: var(--pf-c-select__toggle--expanded--BorderBottomColor);

      border-bottom-width: var(--pf-c-select__toggle--expanded--BorderBottomWidth);
    }
  }

  &.pf-m-plain {
    --pf-c-select__toggle--Color: var(--pf-c-select__toggle--m-plain--Color);

    &::before {
      border-color: var(--pf-c-select__toggle--m-plain--BorderColor);
    }

    &:hover,
    &.pf-m-hover,
    &:active,
    &.pf-m-active,
    .pf-m-expanded > & {
      --pf-c-select__toggle--Color: var(--pf-c-select__toggle--m-plain--hover--Color);

      &::before {
        border-color: var(--pf-c-select__toggle--m-plain--BorderColor);
      }
    }
  }

  &.pf-m-typeahead {
    --pf-c-select__toggle--PaddingTop: 0;
    --pf-c-select__toggle--PaddingRight: 0;
    --pf-c-select__toggle--PaddingBottom: 0;

    padding-top: var(--pf-c-select__toggle-wrapper--m-typeahead--PaddingTop);

    .pf-c-form-control {
      @include pf-text-overflow;

      position: relative;
      height: auto;
    }
  }

  .pf-c-select__toggle-clear {
    padding-right: var(--pf-c-select__toggle-clear--PaddingRight);
    padding-left: var(--pf-c-select__toggle-clear--PaddingLeft);
    margin-left: auto;
  }

  .pf-c-select__toggle-button {
    color: var(--pf-c-select__toggle-button--Color);
  }

  .pf-c-select__toggle-clear + .pf-c-select__toggle-button {
    padding-left: var(--pf-c-select__toggle-button--PaddingLeft);
  }
}


.pf-c-select__toggle-arrow {
  * + & {
    margin-right: var(--pf-c-select__toggle-arrow--MarginRight);
    margin-left: var(--pf-c-select__toggle-arrow--MarginLeft);
  }
  // stylelint-disable-next-line
  .pf-c-select.pf-m-top.pf-m-expanded & {
    transform: var(--pf-c-select__toggle-arrow--m-top--m-expanded__toggle-arrow--Transform);
  }
}

.pf-c-select__toggle-text {
  @include pf-text-overflow;
}

.pf-c-select__toggle-wrapper {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;

  // Max-width is needed for ellipsing the text. This leaves enough space for the toggle caret.
  // However, for cases where the clear icon button or a badge are added, the correct width will need to be calculated in script
  min-width: 0;
  max-width: var(--pf-c-select__toggle-wrapper--MaxWidth);
  white-space: normal;

  // Add space between children
  > :not(:last-child) {
    margin-right: var(--pf-c-select__toggle-wrapper--not-last-child--MarginRight);
  }

  // need to reduce the padding, which is driving the height of the chip, so it fits within the toggle
  .pf-c-chip .pf-c-button {
    padding-top: var(--pf-c-select__toggle-wrapper--c-chip--c-button--PaddingTop);
    padding-bottom: var(--pf-c-select__toggle-wrapper--c-chip--c-button--PaddingBottom);
  }

  // Remove during breaking change
  // if there is an input in the toggle-wrapper, then give it a negative top margin to match the typeahead top padding
  > .pf-c-form-control {
    margin-top: calc(-1 * var(--pf-c-select__toggle-wrapper--m-typeahead--PaddingTop));
  }

  // a chip group needs a bottom margin to make some space between the chip group and typeahead input box if it wraps
  .pf-c-chip-group {
    margin-top: var(--pf-c-select__toggle-wrapper--c-chip-group--MarginTop);
    margin-bottom: var(--pf-c-select__toggle-wrapper--c-chip-group--MarginBottom);
  }

  // Remove 'form:first-child' and '.pf-c-select__toggle-typeahead-form:first-child,' during breaking change - <form> shouldn't exist in this component
  // When the input or form is the first thing then use a negative left padding so it matches the toggle container
  > form:first-child,
  > .pf-c-select__toggle-typeahead-form:first-child,
  > .pf-c-select__toggle-typeahead:first-child {
    margin-left: calc(-1 * var(--pf-c-select__toggle--PaddingLeft));
  }
}

.pf-c-select__toggle-icon + .pf-c-select__toggle-text {
  margin-left: var(--pf-c-select__toggle-icon--toggle-text--MarginLeft);
}

.pf-c-select__toggle-badge {
  display: flex;
  padding-left: var(--pf-c-select__toggle-badge--PaddingLeft);
}

.pf-c-select__toggle-typeahead {
  flex-basis: var(--pf-c-select__toggle-typeahead--FlexBasis);
  flex-grow: 1;
  flex-shrink: 0;
  background-color: var(--pf-c-select__toggle-typeahead--BackgroundColor);
  border-top: var(--pf-c-select__toggle-typeahead--BorderTop);
  border-right: var(--pf-c-select__toggle-typeahead--BorderRight);
  border-bottom-color: inherit;
  border-bottom-style: inherit;
  border-bottom-width: inherit;
  border-left: var(--pf-c-select__toggle-typeahead--BorderLeft);

  &:focus,
  &.pf-m-focus {
    // Set the bottom padding to allow for the bottom border width of the containing toggle
    // This is really var(--pf-c-form-control--PaddingBottom) but has to be recalculated instead of reusing another component's variable
    padding-bottom: var(--pf-c-select__toggle-typeahead--active--PaddingBottom);
  }
}

// remove '.pf-c-select__toggle-typeahead-form' and '.pf-c-select__toggle-wrapper > form' at breaking change release - <form> shouldn't exist in this component
// Support form with input and input alone
.pf-c-select__toggle-typeahead-form,
.pf-c-select__toggle-typeahead,
.pf-c-select__toggle-wrapper > form {
  flex: 1;
  min-width: var(--pf-c-select__toggle-typeahead-form--MinWidth);
}

.pf-c-select__menu {
  position: absolute;
  top: var(--pf-c-select__menu--Top);
  z-index: var(--pf-c-select__menu--ZIndex);
  min-width: 100%;
  padding-top: var(--pf-c-select__menu--PaddingTop);
  padding-bottom: var(--pf-c-select__menu--PaddingBottom);
  background-color: var(--pf-c-select__menu--BackgroundColor);
  background-clip: padding-box;
  border: var(--pf-c-select__menu--BorderWidth) solid transparent;
  box-shadow: var(--pf-c-select__menu--BoxShadow);

  &.pf-m-align-right {
    right: 0;
  }

  .pf-c-select.pf-m-top & {
    top: 0;
    transform: var(--pf-c-select__menu--m-top--Transform);
  }
}

.pf-c-select__menu-fieldset {
  border: 0;
}

.pf-c-select__menu-item {
  position: relative;
  width: 100%;
  padding: var(--pf-c-select__menu-item--PaddingTop) var(--pf-c-select__menu-item--PaddingRight) var(--pf-c-select__menu-item--PaddingBottom) var(--pf-c-select__menu-item--PaddingLeft);
  font-size: var(--pf-c-select__menu-item--FontSize);
  font-weight: var(--pf-c-select__menu-item--FontWeight);
  line-height: var(--pf-c-select__menu-item--LineHeight);
  color: var(--pf-c-select__menu-item--Color);
  text-align: left;
  white-space: nowrap;
  background-color: transparent; // this can be removed if the shield in _base.css works for FF
  border: none;

  &:hover,
  &.pf-m-hover,
  &:focus,
  &.pf-m-focus {
    color: var(--pf-c-select__menu-item--Color);
    text-decoration: none;
    background-color: var(--pf-c-select__menu-item--hover--BackgroundColor);
  }

  &:focus,
  &.pf-m-focus {
    position: relative;
  }

  &:disabled,
  &.pf-m-disabled {
    color: var(--pf-c-select__menu-item--disabled--Color);
    pointer-events: none;
    background-color: var(--pf-c-select__menu-item--disabled--BackgroundColor);
  }

  &.pf-m-selected {
    --pf-c-select__menu-item--PaddingRight: var(--pf-c-select__menu-item--m-selected--PaddingRight);
  }
}

.pf-c-select__menu-item-icon {
  position: absolute;
  top: var(--pf-c-select__menu-item-icon--Top);
  right: var(--pf-c-select__menu-item-icon--Right);
  font-size: var(--pf-c-select__menu-item-icon--FontSize);
  color: var(--pf-c-select__menu-item-icon--Color);
  transform: var(--pf-c-select__menu-item-icon--Transform);
}

.pf-c-select__menu-item--match {
  font-weight: var(--pf-c-select__menu-item--match--FontWeight);
  background-color: inherit;
}

.pf-c-select__separator {
  height: var(--pf-c-select__separator--Height);
  margin-top: var(--pf-c-select__separator--MarginTop);
  margin-bottom: var(--pf-c-select__separator--MarginBottom);
  background-color: var(--pf-c-select__separator--BackgroundColor);
}

.pf-c-select__menu-group:not(:first-of-type) {
  padding-top: var(--pf-c-select__menu-group--not--first-of-type--PaddingTop);
}

.pf-c-select__menu-input {
  padding: var(--pf-c-select__menu-input--PaddingTop) var(--pf-c-select__menu-input--PaddingRight) var(--pf-c-select__menu-input--PaddingBottom) var(--pf-c-select__menu-input--PaddingLeft);
}

.pf-c-select__menu-group-title {
  padding-top: var(--pf-c-select__menu-group-title--PaddingTop);
  padding-right: var(--pf-c-select__menu-group-title--PaddingRight);
  padding-bottom: var(--pf-c-select__menu-group-title--PaddingBottom);
  padding-left: var(--pf-c-select__menu-group-title--PaddingLeft);
  font-size: var(--pf-c-select__menu-group-title--FontSize);
  font-weight: var(--pf-c-select__menu-group-title--FontWeight);
  color: var(--pf-c-select__menu-group-title--Color);
}
