/*
 * /watchlist (watchlists/show, _map, _table): every company a reader
 * follows, as the strip's heat tiles by sector or as tables that sort. The
 * heading and the serif standfirst, a hairline-ruled row of choices — view,
 * grouping, the export — then one `.card` per group.
 *
 * In the table view a group folds on its own <details>; its summary is the
 * card's header row, so the fold reads as the section heading it is, with a
 * chevron at the far end that turns when it is shut. "All together" draws
 * one table and no fold. The tables are one form: a checkbox beside each
 * ticker, a "select all" over each group once the `selection` controller is
 * there, and a bar that stays at the foot of the window while the tables
 * scroll past, with the count and the one button that unfollows.
 */
@layer pages {
  .watchlist {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
  }

  .watchlist__head {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);

    & > .heading {
      margin-block-end: 0;
    }
  }

  .watchlist__standfirst {
    max-inline-size: var(--measure);
    margin: 0;
    color: var(--color-ink-soft);
    font-family: var(--font-prose);
    font-size: var(--text-lead);
    line-height: var(--leading-lead);
    font-variant-numeric: tabular-nums lining-nums;
  }

  .watchlist__empty {
    margin: 0;
    color: var(--color-ink-muted);
    font-size: var(--text-ui);
  }

  .watchlist__controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 var(--space-2xl);
    border-block: var(--rule-hairline);
  }

  /* A choice whose options do not say what they choose: the map's colour. */
  .watchlist__choice {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
  }

  /* The export sits at the row's far end: the dashed link, as the strip has
     it, or the words and the lock. */
  .watchlist__export {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2xs);
    margin-inline-start: auto;
    font-size: var(--text-ui-sm);
    white-space: nowrap;

    &:is(a) {
      text-decoration-style: dashed;
    }

    &:is(span) {
      color: var(--color-ink-muted);
    }
  }

  .watchlist__tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
  }

  .watchlist__fold-summary {
    list-style: none;

    &:is(summary) {
      cursor: pointer;
    }

    &::-webkit-details-marker {
      display: none;
    }
  }

  .watchlist__chevron {
    flex: none;
    align-self: center;
    margin-inline-start: auto;
    transition: rotate 150ms ease;

    .watchlist__fold:not([open]) & {
      rotate: -90deg;
    }
  }

  .watchlist__followed {
    color: var(--color-ink-muted);
  }

  .watchlist__selection-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
  }

  .watchlist__select-all {
    font-size: var(--text-ui-sm);
  }

  /* The checkbox and the ticker share the pinned first cell, so ticking a
     row never scrolls away from the name it ticks. */
  .watchlist__pick {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);

    & input {
      inline-size: 1rem;
      block-size: 1rem;
      margin: 0;
      accent-color: var(--color-accent);
      cursor: pointer;

      @media (pointer: coarse) {
        inline-size: 1.5rem;
        block-size: 1.5rem;
      }
    }
  }

  .watchlist__selection {
    position: sticky;
    inset-block-end: 0;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-xs) var(--space-md);
    padding-block: var(--space-xs);
    border-block-start: var(--rule-heavy);
    background-color: var(--color-surface);
  }

  .watchlist__selection-count {
    color: var(--color-ink-muted);
    font-size: var(--text-ui-sm);
  }
}
