/* A menu of actions: a manual popover that menu.js places in the top layer under its trigger, at a
   pointer, or docks at the bottom of a phone's window as a sheet.
   The look restates PowerLocal's .social-menu with shared tokens (SOURCE.md). */
/* Shipped in a cascade layer: unlayered host CSS wins without !important. */
@layer ds.tokens, ds.base, ds.components;
@layer ds.components {
.ds-menu {
  --_row: var(--ds-control-size-m);
  --_font: var(--ds-type-control-size);
  --_small: var(--ds-type-control-small);
  /* The check mark and the icons: the button's icon size for this density. */
  --_glyph: var(--ds-icon-size-m);
  --_gap: var(--ds-space-2);
  /* Item text lines up with the trigger's label: the trigger's inset less the menu's padding and edges. */
  --_inset: calc(var(--ds-space-4) - var(--ds-space-1) - var(--ds-control-border-width));
  /* A column exists only when an item uses it (PHP marks the menu), so the labels line up in every row. */
  --_check-column: 0px;
  --_icon-column: 0px;
  box-sizing: border-box;
  /* The UA popover sheet centres the panel (inset: 0; margin: auto); menu.js sets left and top.
     No display here: the UA's display: none keeps a closed popover hidden. */
  inset: auto;
  margin: 0;
  min-inline-size: 12rem;
  max-inline-size: min(20rem, calc(100vw - 2 * var(--ds-space-2)));
  max-block-size: calc(100dvh - 2 * var(--ds-space-2));
  overflow-y: auto;
  padding: var(--ds-space-1);
  border: var(--ds-control-border-width) solid var(--ds-color-border);
  border-radius: var(--ds-radius);
  background: var(--ds-color-surface);
  color: var(--ds-color-text);
  box-shadow: var(--ds-shadow-popup);
  /* The top layer still inherits from the DOM: state the type rather than take the trigger's context. */
  font: 400 var(--_font)/1.4 var(--ds-font);
  letter-spacing: normal;
  text-align: start;
  text-transform: none;
  white-space: normal;

  /* Dense triggers get dense rows, on touch too (professional tools need them); M and L rows are 44px. */
  &:is([data-size="2xs"], [data-size="xs"], [data-size="s"]) {
    --_row: var(--ds-control-size-s);
    --_font: var(--ds-type-control-small);
    --_small: var(--ds-type-control-xs);
    --_glyph: var(--ds-icon-size-s);
    --_inset: calc(var(--ds-space-3) - var(--ds-space-1) - var(--ds-control-border-width));
  }
  &[data-ds-check] { --_check-column: calc(var(--_glyph) + var(--_gap)); }
  &[data-ds-icons] { --_icon-column: calc(var(--_glyph) + var(--_gap)); }
}

/* One row: [check] [icon] label [keys], and the reason line under the label. */
.ds-menu-item {
  box-sizing: border-box;
  appearance: none;
  display: grid;
  grid-template-columns: var(--_check-column) var(--_icon-column) minmax(0, 1fr) auto;
  align-content: center;
  align-items: baseline;
  inline-size: 100%;
  min-block-size: var(--_row);
  margin: 0;
  padding: var(--ds-space-1) var(--_inset);
  /* Transparent until an unavailable item draws it dashed, so no item moves. */
  border: var(--ds-control-border-width) solid transparent;
  border-radius: var(--ds-radius-control);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;

  & > [data-ds-menu-label] { grid-area: 1 / 3; }
  /* Why an unavailable item cannot run here: a second, smaller line under its label, read as its description. */
  & > [data-ds-menu-reason] { grid-area: 2 / 3; font-size: var(--_small); line-height: 1.4; }
  /* Glyphs sit in their columns, centred on the label's first line, as the keys sit on its baseline. */
  & > :is([data-ds-menu-check], [data-ds-menu-icon]) {
    align-self: start;
    inline-size: var(--_glyph);
    block-size: var(--_glyph);
    margin-block: calc((1lh - var(--_glyph)) / 2);
  }
  & > [data-ds-menu-check] { grid-area: 1 / 1; }
  /* Icons are decoration: quieter than the words, like the keys at the other end; higher contrast lifts both. */
  & > [data-ds-menu-icon] { grid-area: 1 / 2; color: var(--ds-color-text-muted); }
  &:is([data-destructive="true"], [aria-disabled="true"]) > [data-ds-menu-icon] { color: inherit; }
  /* The gutter keeps its room while unchecked, so a row never moves when it is checked. */
  &[aria-checked="false"] > [data-ds-menu-check] { visibility: hidden; }

  /* One highlight: the focused item. A mouse or pen moves focus as it moves (menu.js), keys move it too. */
  &:not([aria-disabled="true"]):focus { background: var(--ds-color-neutral-hover); }
  &:not([aria-disabled="true"]):active { background: var(--ds-color-neutral-pressed); }
  /* Inside the item, so neighbours never cover the ring. */
  &:focus-visible {
    outline: var(--ds-focus-width) solid var(--ds-color-focus);
    outline-offset: calc(-1 * var(--ds-focus-width));
  }
  &[data-destructive="true"]:not([aria-disabled="true"]) { color: var(--ds-color-danger); }
  /* Unavailable items stay focusable (WAI-ARIA); menu.js never activates them. Like an unavailable
     button: readable muted text on the disabled surface with a dashed edge, a cue beyond colour. */
  &[aria-disabled="true"] {
    border-color: var(--ds-color-border);
    border-style: dashed;
    background: var(--ds-color-disabled-surface);
    color: var(--ds-color-disabled-text);
    cursor: not-allowed;
  }
  /* The ring sits inside the dashed edge, so both stay visible. */
  &[aria-disabled="true"]:focus-visible { outline-offset: calc(-1 * (var(--ds-focus-width) + var(--ds-control-border-width) + 1px)); }
  /* A shortcut sits at the row's end in muted text (Social Studio's key column). CSS writes it, left to
     right with tabular digits (button.css), once enhanceMenuButton has said which keyboard is in use; until
     then, and on touch screens, it takes no room. */
  & > [data-ds-keys] { grid-area: 1 / 4; }
  & > [data-ds-keys]:where([data-ds-platform] *) {
    padding-inline-start: var(--ds-space-4);
    color: var(--ds-color-text-muted);
  }
  &[aria-disabled="true"] > [data-ds-keys] { color: inherit; }
}
/* Phones and tablets without a keyboard have no use for the keys; aria-keyshortcuts stays. */
@media (hover: none) {
  .ds-menu-item > [data-ds-keys] { display: none; }
}

/* A split button's busy action keeps its width: the spinner takes room from the padding, so the arrow
   does not move while the action runs. An action with a leading icon swaps the icon instead. */
.ds-split-button > [aria-busy="true"]:not(:has(> [data-ds-button-icon="leading"])) {
  padding-inline: max(0px, calc(var(--_inset) - (var(--_icon) + var(--_gap)) / 2));
}

.ds-menu-separator {
  block-size: 0;
  margin: var(--ds-space-1) var(--ds-space-2);
  border: 0;
  border-block-start: var(--ds-control-border-width) solid var(--ds-color-divider);
}

/* A phone's sheet (menu.js, 768px or less): docked at the bottom of the window as visp-sibe's, as wide as
   the window up to 32rem, with a grip to drag it down, a scrim over the page beside it (.ds-menu-scrim) and Cancel last.
   Its rows keep the trigger's density. */
.ds-menu[data-ds-sheet] {
  inset: auto 0 0;
  margin-inline: auto;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 32rem;
  max-block-size: 80dvh;
  padding: var(--ds-space-5) var(--ds-space-2) calc(var(--ds-space-2) + env(safe-area-inset-bottom, 0px));
  border-block-end: 0;
  border-end-start-radius: 0;
  border-end-end-radius: 0;
  overscroll-behavior: contain;
  /* The grip: decoration, quiet in standard contrast and drawn strongly in higher contrast. */
  &::before {
    content: "";
    position: absolute;
    inset-block-start: var(--ds-space-3);
    inset-inline: 0;
    margin-inline: auto;
    inline-size: 2.5rem;
    block-size: .25rem;
    border-radius: .125rem;
    background: color-mix(in srgb, var(--ds-color-text) calc(25% + var(--ds-contrast-amount) * .75), transparent);
  }
}
/* The sheet's scrim (menu.js puts it before the panel, in the top layer under it): it dims the page and takes
   every press beside the sheet, so nothing under it is pressed, scrolled or dragged. */
.ds-menu-scrim {
  inset: 0;
  inline-size: auto;
  block-size: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: color-mix(in srgb, var(--ds-neutral-1000) 45%, transparent);
  touch-action: none;
}

@media (prefers-reduced-motion: no-preference) {
  .ds-menu-item { transition: background-color var(--ds-motion-duration-state) var(--ds-motion-ease-standard); }
  /* A sheet follows the finger one to one, then settles back or leaves on the shared state timing. */
  .ds-menu[data-ds-sheet]:not([data-ds-dragging]) { transition: translate var(--ds-motion-duration-state) var(--ds-motion-ease-standard); }
  /* It rises from the bottom while the page dims. */
  .ds-menu-scrim { transition: opacity var(--ds-motion-duration-state) var(--ds-motion-ease-standard); }
  @starting-style {
    .ds-menu[data-ds-sheet]:popover-open { translate: 0 100%; }
    .ds-menu-scrim:popover-open { opacity: 0; }
  }
}
/* The way out, on copies (pointer-gesture/leaving-copy.js): the way in, backwards and faster. */
.ds-menu[data-ds-sheet].is-leaving { animation: ds-menu-sheet-out .12s ease-in forwards; pointer-events: none; }
.ds-menu-scrim.is-leaving { animation: ds-menu-scrim-out .12s ease-in forwards; pointer-events: none; }
@keyframes ds-menu-sheet-out { to { translate: 0 100%; } }
@keyframes ds-menu-scrim-out { to { opacity: 0; } }
@media (forced-colors: active) {
  .ds-menu { border-color: CanvasText; }
  /* Rows are not boxes; only an unavailable row draws its (dashed) edge. */
  .ds-menu-item { border-color: Canvas; }
  /* Adjust none: otherwise Chrome paints a Canvas backplate behind the label, white on white. */
  .ds-menu-item:not([aria-disabled="true"]):focus { forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight; }
  .ds-menu-item:focus-visible { outline-color: CanvasText; }
  .ds-menu-item[aria-disabled="true"] { color: GrayText; border-color: GrayText; }
  /* The key, the icon and the check take the row's own colour, also HighlightText on the focused row. */
  .ds-menu-item > :is([data-ds-keys], [data-ds-menu-icon], [data-ds-menu-check]) { color: inherit; }
  .ds-menu-separator { border-color: CanvasText; }
  .ds-menu[data-ds-sheet] { border-block-end: 0; }
  .ds-menu[data-ds-sheet]::before { background: CanvasText; }
}
}
