/**
 * Drupal dropbuttons (operations: Edit ▾, New issue ▾): a split button whose
 * secondary actions open in a menu, like the submenus of the app bar.
 *
 * Markup and toggling come from core/drupal.dropbutton, which leaves every
 * action in its own <li> next to the toggle, with no element around the
 * secondary ones. So the list is a grid: its first row is the button, the
 * rows below it overflow the widget and ::before draws the menu behind them.
 * Selectors start at the wrapper to outweigh core's dropbutton.css.
 *
 * Custom properties, set on .dropbutton-wrapper or on an ancestor:
 * --dropbutton-height      Height of the button (control-sm).
 * --dropbutton-menu-width  Minimum width of the menu (200px).
 * --dropbutton-menu-align  Edge of the button the menu hangs from: start | end.
 * --dropbutton-menu-inset  inset-inline of the menu frame: "-1px auto" for
 *                          start, "auto -1px" for end.
 */

.dropbutton-wrapper {
  --_height: var(--dropbutton-height, var(--control-sm));
  --_inner-radius: calc(var(--radius-md) - 1px);
  --_menu-gap: 6px;
  --_menu-padding: 6px;
  --_menu-width: max(100% + 2px, var(--dropbutton-menu-width, 200px));
  position: relative;
  vertical-align: middle;
}
/* Above the page, below the sticky app bar. */
.dropbutton-wrapper.dropbutton-multiple.open { z-index: 10; }

.dropbutton-wrapper .dropbutton-widget {
  position: relative;
  display: block;
  width: fit-content;
  height: var(--_height);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
}
/* Core reserves room for its absolutely positioned toggle and, in tables,
   takes the widget out of the flow. */
.dropbutton-wrapper.dropbutton-multiple .dropbutton-widget { padding: 0; }
td .dropbutton-wrapper.dropbutton-multiple { margin-inline: 0; padding-inline: 0; }
td .dropbutton-wrapper.dropbutton-multiple .dropbutton-widget { position: relative; }
/* Operations are the last column: their menu opens towards the table. */
td:last-child .dropbutton-wrapper {
  --dropbutton-menu-align: end;
  --dropbutton-menu-inset: auto -1px;
}

.dropbutton-wrapper .dropbutton-widget .dropbutton {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: calc(var(--_height) - 2px);
  overflow: visible;
  margin: 0;
  padding: 0;
  list-style: none;
}
.dropbutton-wrapper .dropbutton > li { min-width: 0; margin: 0; }

/* The button: primary action and toggle. */
.dropbutton-wrapper .dropbutton-action > a {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 var(--space-3);
  border-radius: var(--_inner-radius) 0 0 var(--_inner-radius);
  color: var(--text);
  font: 500 13px/20px var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
}
.dropbutton-wrapper.dropbutton-single .dropbutton-action > a { border-radius: var(--_inner-radius); }
.dropbutton-wrapper .dropbutton-action > a:hover { background: var(--surface-sunken); color: var(--text); }

.dropbutton-wrapper .dropbutton-toggle {
  position: static;
  width: auto;
  border-left: 1px solid var(--border);
  text-indent: 0;
}
.dropbutton-wrapper .dropbutton-toggle button {
  display: grid;
  place-items: center;
  width: var(--_height);
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0 var(--_inner-radius) var(--_inner-radius) 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.dropbutton-wrapper .dropbutton-toggle button:hover,
.dropbutton-wrapper.open .dropbutton-toggle button { background: var(--surface-sunken); color: var(--text); }

/* Chevron (Lucide chevron-down) in place of core's border triangle. */
.dropbutton-wrapper .dropbutton .dropbutton-arrow {
  position: static;
  display: block;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 0;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform 0.15s;
}
.dropbutton-wrapper.open .dropbutton .dropbutton-arrow { border: 0; transform: rotate(180deg); }

/* Core removes the outline of the links. */
.dropbutton-wrapper .dropbutton :is(a, button):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

/* The menu: secondary actions, one per row, over a frame as wide as the
   button or wider. */
.dropbutton-wrapper:not(.open) .dropbutton .secondary-action { display: none; }
.dropbutton-wrapper.open .dropbutton::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset-block: calc(var(--_height) - 1px + var(--_menu-gap)) 0;
  inset-inline: var(--dropbutton-menu-inset, -1px auto);
  width: var(--_menu-width);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
}
.dropbutton-wrapper .dropbutton .secondary-action {
  grid-column: 1 / -1;
  justify-self: var(--dropbutton-menu-align, start);
  /* Keeps long labels from widening the button: they wrap in the menu. */
  contain: inline-size;
  width: var(--_menu-width);
  margin-inline: -1px;
  padding-inline: calc(var(--_menu-padding) + 1px);
}
.dropbutton-wrapper .dropbutton-toggle + .secondary-action { margin-top: calc(var(--_menu-gap) + var(--_menu-padding) + 2px); }
.dropbutton-wrapper .dropbutton .secondary-action:last-child { margin-bottom: calc(var(--_menu-padding) + 1px); }
.dropbutton-wrapper .dropbutton .secondary-action > a {
  display: block;
  height: auto;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text);
  white-space: normal;
  overflow-wrap: anywhere;
}
.dropbutton-wrapper .dropbutton .secondary-action > a:is(:hover, :focus-visible) {
  background: var(--primary-soft);
  color: var(--on-primary-soft);
}
