@layer components {
  /* Base: the sidebar's top row, opening a list of catalogues below it
  /* -------------------------------------------------------------------------- */

  .catalogue-picker {
    flex: 1;
    min-inline-size: 0;
    position: relative;
  }

  /* Elements
  /* -------------------------------------------------------------------------- */

  /* The catalogue reads as the sidebar's title, in full ink */
  .sidebar .catalogue-picker__trigger {
    color: var(--color-ink);
  }

  .catalogue-picker__label {
    font-weight: 500;
  }

  .catalogue-picker__caret {
    .catalogue-picker:has(.catalogue-picker__popup[open]) & {
      rotate: 180deg;
    }
  }

  /* Scoped to beat .popup in popup.css, which loads later at equal
     specificity. Left-aligned and the expanded sidebar's width, so it reads
     the same opened from the rail. */
  .catalogue-picker .catalogue-picker__popup {
    inline-size: calc(var(--sidebar-width) - var(--window-inset) * 2);
    inset: calc(100% + 4px) auto auto 0;
    max-inline-size: calc(100vw - var(--window-inset) * 2);
    transform-origin: top left;
    translate: none;

    /* Only the list scrolls, so "All catalogues" stays pinned below it */
    &[open] {
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
  }

  .catalogue-picker__list {
    min-block-size: 0;
    overflow-y: auto;
  }

  .catalogue-picker__footer {
    flex-shrink: 0;
  }

  .catalogue-picker__heading {
    color: var(--color-ink-muted);
    font-size: var(--text-xx-small);
    font-weight: 500;
    margin: 0;
    padding: 4px 8px;
  }

  @media print {
    .catalogue-picker { display: none; }
  }
}
