/*
 * Menu: a portalled popup (`.dx-popup` supplies size, level and radius) of block-tall item rows.
 */

@layer dx-components {
  /* The frame of `PopupScroll`; a long menu scrolls in it (`.dx-popup` with a viewport, `control.css`). */
  .dx-menu {
    min-width: 10rem;
    border-radius: var(--radius-md, 0.375rem);
  }
  /*
   * A submenu's frame overhangs its positioner by the viewport's block padding, so the first item (or, flipped, the
   * last) lines up with the SubTrigger row that floating-ui aligns the positioner to.
   */
  .dx-submenu:has(> [data-placement$='-start']) {
    margin-block-start: calc(-3 * var(--dx-control-inset));
  }
  .dx-submenu:has(> [data-placement$='-end']) {
    margin-block-end: calc(-3 * var(--dx-control-inset));
  }

  /* A palette: square cells, `columns` to a row; the frame shrinks to the grid rather than a menu's minimum width. */
  .dx-menu:has([data-columns]) {
    min-width: 0;
  }
  [data-scope='menu'][data-part='content'][data-columns] {
    display: grid;
  }
  [data-columns] > .dx-menu-item {
    justify-content: center;
    padding-inline: 0;
  }

  /* A menu insets its rows a little more than other popups, equally on every side, so a highlight reads as a rounded
     row within the menu rather than a band across it. */
  .dx-scroll-root.dx-popup.dx-menu > .dx-scroll-viewport {
    padding: calc(var(--dx-control-inset) * 3);
    scroll-padding-block: calc(var(--dx-control-inset) * 3);
  }
  .dx-menu-item {
    display: flex;
    align-items: center;
    gap: var(--dx-gap-size);
    height: var(--dx-block-size);
    padding-inline: calc(var(--dx-gap-size) * 1.5);
    border-radius: var(--radius-sm, 0.25rem);
    cursor: pointer;
  }
  /* Once any item in a menu leads with an icon, the rest keep an icon-wide space so every label starts in line. */
  [data-scope='menu'][data-part='content']:has(.dx-menu-item > .dx-icon:first-child)
    .dx-menu-item:not(:has(> :is(.dx-icon, .dx-menu-indicator):first-child)) {
    padding-inline-start: calc(var(--dx-gap-size) * 2.5 + var(--dx-icon-size));
  }
  .dx-menu-item[data-highlighted] {
    background: var(--color-hover-surface);
  }
  .dx-menu-item[data-disabled] {
    opacity: 0.5;
    cursor: default;
  }
  .dx-menu-item-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .dx-menu-shortcut {
    padding-inline-start: var(--dx-gap-size);
    font-family: inherit;
    font-size: var(--dx-label-font-size);
    line-height: var(--dx-label-line-height);
    color: var(--color-fg-muted);
  }

  /* An icon-sized leading cell that keeps its place while unchecked, so option labels stay aligned. */
  .dx-menu-indicator {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: var(--dx-icon-size);
    height: var(--dx-icon-size);
  }
  .dx-menu-indicator[data-state='unchecked'] {
    visibility: hidden;
  }
  .dx-menu-item[data-state='open'] {
    background: var(--color-hover-surface);
  }
}
