.dropbutton-widget,
html.js .dropbutton-widget {
  background-color: transparent;
}

.dropbutton {
  border: 2px solid var(--gin-color-primary);
  border-radius: var(--gin-border-m);
  box-shadow: 0 1px 2px var(--gin-color-primary-light);

  // Offset for select button on first item
  &--multiple > .dropbutton__item:first-of-type {
    height: 100%;
    margin-right: var(--gin-spacing-xxl);
    border-right: 1px solid var(--gin-color-primary-light-active);

    input {
      color: var(--gin-color-primary);
      height: 100%;
      background-color: transparent;
      border: 0 none !important;
      border-radius: 0 !important;
    }
  }

  .gin--dark-mode & {
    box-shadow: 0 4px 18px var(--gin-shadow-button);
  }

  &:hover {
    border-color: var(--gin-color-primary);
  }

  &:active, &:focus {
    border-color: var(--gin-color-primary-active);
  }

  &-wrapper {
    box-shadow: none;
  }

  &__item:first-of-type > *,
  &__toggle {
    background: none;
    white-space: nowrap;

    @media (forced-colors: active) {
      border-width: 0 !important;
    }
  }

  &__item:first-of-type > * {
    padding: calc(.875rem - 1px) calc(var(--gin-spacing-l) - 1px);
  }

  &__toggle {
    top: 2px;
    right: 2px;
    width: calc(var(--gin-spacing-xxl) + 1px);
    height: 2.75rem;
    border-inline-start: var(--dropbutton-border-size, 1px) solid var(--gin-color-primary) !important;

    &:hover {
      background-color: var(--gin-color-primary);
    }

    @media not (forced-colors: active) {
      &::before {
        background-image: none;
        background-color: var(--gin-color-primary);
        mask-image: icon('drop');
        mask-repeat: no-repeat;
        mask-position: center center;
        mask-size: 12px 12px;
      }

      &:hover::before,
      &:active::before,
      &:focus::before {
        background-color: var(--gin-color-button-text);
      }
    }
  }

  & &__items {
    position: absolute;
    right: 0;
    list-style: none;
    padding: .5em;
    margin: 0;
    min-width: 120px;
    background: var(--gin-bg-layer3);
    border-radius: var(--gin-border-l);
    box-shadow: var(--gin-shadow-l2);

    .node-form & {
      left: 0;
      right: auto;
    }

    @media (forced-colors: active) {
      border: 1px solid linktext;
    }
  }

  & > &__items > .dropbutton__item:first-of-type {
    > a,
    > input,
    > .button {
      border-radius: var(--gin-border-s) var(--gin-border-s) 0 0;
    }
  }

  // Drupal 10.2.x fix
  &.dropbutton--gin .dropbutton-action > .button {
    border: var(--dropbutton-border-size) solid transparent !important;
  }

  // The ugly part: make it work for all different dropbutton versions out there
  &:not(.dropbutton--gin) > .dropbutton__item ~ .dropbutton__item,
  & &__items > .dropbutton__item,
  & &__items > .dropbutton__item ~ .dropbutton__item {
    background-color: var(--gin-bg-app);
    border: 0 none;
    box-shadow: none;

    &:first-of-type {
      margin-right: 0;
    }

    // Mutiple Dropbutton only has one item
    &:first-of-type:last-of-type > * {
      .js .dropbutton--multiple & {
        border-radius: var(--gin-border-s);
      }
    }

    > a,
    > input,
    > .button {
      font-weight: var(--gin-font-weight-heavy);
      text-align: left;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      color: var(--gin-color-primary);
      display: block;
      width: 100%;
      max-width: 320px;
      margin: 0;
      border: 0 none !important;
      border-radius: 0;
      background: var(--gin-bg-layer3);
      box-shadow: none;
      box-sizing: border-box;

      &:hover, &:active, &:focus {
        color: var(--gin-color-button-text);
        background: var(--gin-color-primary);
        border-radius: var(--gin-border-s);

        @media (forced-colors: active) {
          outline: 2px solid transparent;
          outline-offset: -2px;
        }
      }

      &:focus {
        @media (forced-colors: active) {
          outline-style: dotted;
        }
      }
    }
  }

  & > .dropbutton__item:first-of-type {
    > a,
    > input,
    > .button {
      &:hover, &:active, &:focus {
        color: var(--gin-color-button-text);
        background: var(--gin-color-primary);
      }
    }
  }

  & &__items > .dropbutton__item {
    border-radius: var(--gin-border-s);
  }

  // Shadow for pseudo dropdown on views page
  &:not(.dropbutton--gin) > .dropbutton__item.secondary-action {
    box-shadow: var(--gin-shadow-l2);
  }

  &:not(.dropbutton--gin) > .dropbutton__item:not(:first-of-type),
  & &__items > .dropbutton__item,
  & > &__items > .dropbutton__item ~ .dropbutton__item {
    > a,
    > input,
    > .button {
      font-size: var(--gin-font-size-s) !important;
      padding: .75em 1em !important;
    }
  }

  &__item:first-of-type ~ .dropbutton__item {
    max-width: unset;
    border-color: var(--gin-color-primary);

    & > *:hover {
      background-color: var(--gin-bg-layer3);
    }

    &__item ~ .dropbutton__item:last-child {
      border-color: var(--gin-color-primary);
    }
  }
}

html.js {
  .dropbutton {
    height: 3rem;
    min-height: 3rem;
    box-sizing: border-box;
  }

  .dropbutton-wrapper:not(.open) .dropbutton__items {
    display: none;
  }

  .dropbutton-wrapper .dropbutton__items {
    display: block;
  }

  .dropbutton-wrapper:not(.open) .dropbutton__item:first-of-type ~ .dropbutton__items {
    display: none;
  }

  .dropbutton-wrapper:not(.open) .dropbutton__items .dropbutton__item:first-of-type ~ .dropbutton__item {
    display: block;
  }
}

html.js.no-touchevents {
  .dropbutton--multiple.dropbutton--small .dropbutton__item:first-of-type {
    margin-right: 0;
  }

  .dropbutton--multiple.dropbutton--small > .dropbutton__item:first-of-type {
    margin-right: var(--gin-spacing-xl);
  }

  .dropbutton--multiple.dropbutton--extrasmall > .dropbutton__item:first-of-type {
    margin-right: var(--gin-spacing-l);
  }

  .dropbutton--small {
    min-width: 0;
    height: 2.25rem;
    min-height: 2.25rem;
    border-radius: var(--gin-border-s);

    .dropbutton__toggle {
      width: calc(var(--dropbutton-small-toggle-size, 2rem) + 1px);
    }
  }

  .dropbutton--extrasmall {
    min-width: 0;
    height: 1.75rem;
    min-height: 1.75rem;
    border-radius: var(--gin-border-s);

    .dropbutton__toggle {
      width: calc(var(--dropbutton-extrasmall-toggle-size, 1.5rem) + 1px);
    }

    .dropbutton__item:first-of-type > * {
      padding-left: var(--gin-spacing-s);
      padding-right: var(--gin-spacing-s);
    }
  }

  .dropbutton--multiple.dropbutton--extrasmall .dropbutton__items .dropbutton__item {
    margin-right: 0;
  }
}

// Last item in table
table tr:not(:first-of-type):nth-last-child(2) td .dropbutton__items,
table tr:not(:first-of-type):last-of-type td .dropbutton__items {
  bottom: 100%;
}
