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

// Overlay the dropdown button on top of the sticky header and main toolbar
html.js {
  .dropbutton-wrapper.open {
    .dropbutton-widget {
      z-index: 502; // Above toolbar and sticky header
    }

    .dropbutton {
      background: var(--gin-bg-layer3);
    }
  }
}

.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-inline-end: calc(var(--dropbutton-extrasmall-toggle-size) + var(--dropbutton-toggle-size-spacing) + -2px) !important;
    border-inline-end: 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 {
    position: relative;
    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 {
    inset-block-start: 2px;
    inset-inline-end: 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);
      }
    }
  }

  .dropbutton__items {
    position: absolute;
    inset-inline-end: 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 & {
      inset-inline-start: 0;
      inset-inline-end: auto;
    }

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

  > .dropbutton__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,
  .dropbutton__items > .dropbutton__item,
  .dropbutton__items > .dropbutton__item ~ .dropbutton__item {
    background-color: var(--gin-bg-app);
    border: 0 none;
    box-shadow: none;

    &:first-of-type {
      margin-inline-end: 0;
    }

    // Multiple 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: start;
      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);
      }
    }
  }

  .dropbutton__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),
  .dropbutton__items > .dropbutton__item,
  > .dropbutton__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 {
    visibility: hidden;
    opacity: 0;
  }

  .dropbutton-wrapper .dropbutton__items {
    visibility: visible;
    opacity: 1;
    max-height: 30vh;
    overflow: auto;
  }

  .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;
    height: auto;
  }
}

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

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

  .dropbutton--multiple.dropbutton--extrasmall > .dropbutton__item:first-of-type {
    margin-inline-end: 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-inline: var(--gin-spacing-s);
    }
  }

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