/* ─────────────────────────────────────────────────────────────────────────
   STAGE MENU — the status selector (METIS-pub#826)

     .stage-menu                 a <details>: the chip is its summary
     .stage-menu__chip           the stage, in its step's own colours
                                 (--stage-bg / --stage-fg, set inline from
                                 the step's config, as list chips are); a
                                 plain <span> for who may not move it
     .stage-menu__chip--kind     the kind and the status as one pill
                                 (METIS-pub#826): .stage-menu__kind, muted
                                 on the neutral ground, then
                                 .stage-menu__status in the step's colours;
                                 the kind alone when there is no status
     .stage-menu__caret          the chip's ▾, only where it opens
     .stage-menu__menu           the journey's steps, under the chip
     .stage-menu__option         one step: its title, then what it means
     .stage-menu__option.is-current   the step it is on, ticked

   Drawn by crm/partials/_stage_menu.html (the Stage field's "chip" variant);
   crm/js/stage_menu.js closes it on Escape and on a click elsewhere.
   Graduated from Audax's .au-stage (audax/css/quest_outline.css), the same
   chip and menu; Audax moving onto this one leaves one copy.
   Extend with a modifier; never fork. docs/dev/web/design-system.md §3.4
   ───────────────────────────────────────────────────────────────────────── */

@layer components {
  .stage-menu {
    position: relative;
    display: inline-block;
  }

  /* One look for every header (the owner, #826): the chip in its step's own
     colours, like the stage chips in lists ("the public indicator with the
     red color"), so a status reads alike on a place and on a quest. No step
     set: the neutral chip. One line high exactly (--space-6, border
     included): the place header's meta line is that high and fixed, and a
     taller chip spilled onto the tabs under it. */
  .stage-menu__chip {
    display: inline-flex;
    box-sizing: border-box;
    align-items: center;
    gap: var(--space-1);
    height: var(--space-6);
    padding: 0 var(--space-3);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    background: var(--stage-bg, var(--color-surface-2));
    color: var(--stage-fg, var(--color-text-muted));
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    list-style: none;
  }

  summary.stage-menu__chip { cursor: pointer; }
  summary.stage-menu__chip::-webkit-details-marker { display: none; }

  summary.stage-menu__chip:hover,
  summary.stage-menu__chip:focus-visible,
  .stage-menu[open] > summary.stage-menu__chip {
    outline: 2px solid color-mix(in oklab, var(--color-text) 30%, transparent);
    outline-offset: 1px;
  }

  /* Kind and status as one chip (METIS-pub#826, the owner: "the same way
     we have it on a journey chip"): one pill, two parts — the kind muted on
     the calm ground the to-do rows' journey chip wears, then the status in
     its step's own pair, so its colour reads as it does on its own. */
  .stage-menu__chip--kind {
    gap: 0;
    padding: 0;
    overflow: hidden;
    border-color: var(--color-border);
    background: var(--color-surface-2);
  }

  /* Where the line is short (a phone header), the kind gives way first,
     ellipsed; the status never does. */
  .stage-menu,
  .stage-menu__chip--kind { max-width: 100%; }

  .stage-menu__kind {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 var(--space-3);
    color: var(--color-text-muted);
    font-weight: 500;
  }

  .stage-menu__status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    flex: none;
    align-self: stretch;
    padding: 0 var(--space-3) 0 var(--space-2);
    background: var(--stage-bg, var(--color-surface-2));
    color: var(--stage-fg, var(--color-text-muted));
  }

  /* A chip with no kind keeps its own padding: the status is the pill. */
  .stage-menu__chip:not(.stage-menu__chip--kind) .stage-menu__status { display: contents; }

  .stage-menu__caret {
    flex: none;
    opacity: 0.75;
  }

  .stage-menu__menu {
    position: absolute;
    z-index: 300;
    top: calc(100% + var(--space-1));
    left: 0;
    min-width: 16rem;
    max-width: min(22rem, calc(100vw - var(--space-8)));
    margin: 0;
    padding: var(--space-1);
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-2);
  }

  .stage-menu__option {
    display: grid;
    width: 100%;
    gap: var(--space-1);
    padding: var(--space-2);
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
  }

  .stage-menu__option:hover,
  .stage-menu__option:focus-visible { background: var(--color-surface-2); }

  .stage-menu__option-title { font-size: var(--text-md); }
  .stage-menu__option.is-current .stage-menu__option-title { font-weight: 700; }
  /* The step it is on: ticked (an inline mark; the UI font has no ✓). */
  .stage-menu__option-title {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
  }
  .stage-menu__check { flex: none; color: var(--color-accent); }

  .stage-menu__option-meaning {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    white-space: normal;
  }

  /* "Another journey…": the last line, under a rule. */
  .stage-menu__other {
    border-top: 1px solid var(--color-border-light);
    border-radius: 0;
    color: var(--color-accent);
  }
}
