/* Closeable areas: a head that stays, a body that folds out beneath it.
 *
 * The problem this replaces (METIS-pub#416): a journey group's head was a grey
 * band and its rows were separate bordered cards at the same x and width, so
 * nothing said the cards belonged to the band or would fold away with it. The
 * parent was also quieter than its children — a 12px chevron and an 11px badge
 * against white cards with 36px avatars.
 *
 * Here the children hang off a thin rail drawn down from the fold arrow, and
 * the rows inside give up their own borders. The rail is the statement of
 * ownership; the box was.
 *
 * State is `data-open` on the root, mirrored in `aria-expanded` on the toggle.
 * It is server-rendered, so a group arrives folded or unfolded without JS
 * running first, and it is an attribute rather than a class because the server
 * sets it and `crm/js/disclosure.js` flips it — one name, two writers.
 */
@layer components {
  .disclosure__head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    position: relative;
    min-height: 40px;
    padding: 0 var(--space-2) 0 var(--space-1);
    border-radius: var(--radius-sm);
  }

  .disclosure__head:hover {
    background: var(--color-surface-2);
  }

  /* One button, stretched over the whole head, rather than the two that used
   * to flank the kanban link. An <a> may not sit inside a <button>, so the
   * link stays a sibling and is lifted above the overlay below. */
  .disclosure__toggle {
    appearance: none;
    border: 0;
    background: none;
    padding: 0;
    margin: 0;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    cursor: pointer;
  }

  .disclosure__toggle::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
  }

  /* Everything else interactive in the head has to sit above that overlay, or
   * the toggle eats it — the kanban link most of all, which must navigate
   * rather than fold. */
  .disclosure__head a,
  .disclosure__head button:not(.disclosure__toggle) {
    position: relative;
    z-index: 1;
  }

  /* The ring belongs on the head: the toggle's own outline would be drawn
   * around a 24px square while the click target is the whole row. */
  .disclosure__head:has(.disclosure__toggle:focus-visible) {
    outline: var(--focus-ring-width) solid var(--focus-ring);
    outline-offset: 2px;
  }

  .disclosure__chevron {
    transition: transform var(--dur-base) var(--ease-out);
  }

  .disclosure:not([data-open]) > .disclosure__head .disclosure__chevron {
    transform: rotate(-90deg);
  }

  /* Beside the name, not pushed to the far edge: the count is part of what the
   * group is called, and margin-left:auto put it an inch of whitespace away. */
  .disclosure__count {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  /* What a closed group says instead of nothing. Hidden while open, where the
   * rows themselves are the better answer. */
  .disclosure__summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    padding-left: var(--space-2);
    border-left: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  .disclosure__summary > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .disclosure[data-open] > .disclosure__head .disclosure__summary {
    display: none;
  }

  .disclosure__avatars {
    display: inline-flex;
    flex-shrink: 0;
  }

  .disclosure__avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--color-border-light);
    /* A ring in the page background, so overlapping circles read as separate.
     * A border rather than a box-shadow: the shadow scales are tokenised for
     * elevation, and a hairline ring is not elevation. */
    border: 2px solid var(--color-bg);
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-text-muted);
  }

  .disclosure__avatar + .disclosure__avatar {
    margin-left: -6px;
  }

  /* The rail. Its left edge sits under the chevron's centre: the head's left
   * padding plus half the 24px toggle. */
  .disclosure__body {
    border-left: 1.5px solid var(--color-border);
    margin-left: calc(var(--space-1) + 12px);
    padding-left: var(--space-4);
    margin-bottom: var(--space-3);
  }

  .disclosure:not([data-open]) > .disclosure__body {
    display: none;
  }
}
