/* The user dashboard: a two-column grid of sections whose spans come from
 * User#dashboard_positions, plus the watchlist, dividends and portfolio blocks. */
@layer components {
  .dashboard__owner {
    color: var(--color-ink-medium);
    display: flex;
    gap: var(--inline-space-half);
  }

  .dashboard__sections {
    display: flex;
    flex-direction: column;
    gap: var(--block-space-double);
    margin-block-end: var(--block-space-double);

    /* Landscape gets the grid; portrait stacks. Section spans are set inline. */
    @media (min-width: 640px) {
      display: grid;
      gap: calc(var(--block-space) * 2.5);
      grid-template-columns: repeat(2, minmax(0, 1fr));
      margin-block-end: calc(var(--block-space) * 2.5);
    }
  }

  /* Each section leads with a heading and one or more quiet stats */
  .dashboard__sections nav {
    h2 {
      font-size: var(--text-large);
      font-weight: 700;

      /* The whole heading is a link, but it reads as a heading, not a link */
      a { color: inherit; }
    }

    small {
      color: var(--color-ink-medium);
    }
  }

  /* Networth chart
  /* ------------------------------------------------------------------------ */

  .networth-chart {
    block-size: 25vh;
    position: relative;
  }

  .networth-readout {
    align-items: center;
    display: flex;
    justify-content: space-between;
  }

  /* Made visible by the chart controller once a point is hovered */
  .networth-readout__past {
    color: var(--color-ink-medium);
    visibility: hidden;

    p:first-child { font-size: var(--text-small); }
    p:last-child { font-size: var(--text-x-small); }
  }

  /* Watchlist
  /* ------------------------------------------------------------------------ */

  /* overflow: flexbox won't shrink past min-content, which is the width of the
     content while it's whitespace-nowrap */
  .watchlist {
    overflow: hidden;
  }

  /* As many 24ch columns as fit, stretched to share the width, so tracks run
     wider than 24ch whenever there is room and 24ch only decides when another
     one forms. A row cannot compress below about 14ch: ticker and price never
     ellipsize, only the description does.
     auto-fit measures this element, so the count follows the tile with no query
     to keep in step, and min() stops a tile narrower than one column from
     overflowing.
     24 rather than anything smaller because the root font-size steps up at
     100ch, which grows ch while the tile stays put: the tile measured in ch
     drops from 74 to 62 as the viewport crosses 800. A minimum of 20 to 23ch
     reaches a third column below that step and loses it again above, so the
     layout goes backwards as the window widens. 24ch clears the step; 26ch and
     up never reach three at all, since .dashboard caps a section at 952px. */
  .watchlist__items {
    display: grid;
    gap: var(--block-space);
    grid-template-columns: repeat(auto-fit, minmax(min(24ch, 100%), 1fr));
  }

  /* Boxed, so two columns of rows read as rows rather than as a block of text
     with a gutter through it. */
  /* min-inline-size: 0 so the row can shrink under its own content - a grid
     item's automatic minimum is its min-content width, which a long
     description would otherwise hold open past the ellipsis. */
  .watchlist__item {
    border: var(--border);
    border-radius: 0.5ch;
    min-inline-size: 0;
    padding: var(--block-space-half) var(--inline-space);
  }

  /* Portfolio allocation
  /* ------------------------------------------------------------------------ */

  .allocation-bar {
    display: flex;
    inline-size: 100%;
    margin-block-end: var(--block-space);
  }

  .allocation-bar__segment {
    background-color: var(--asset-color);
    block-size: 0.5rem;
  }

  .allocation-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--inline-space-half);
  }

  .allocation-legend__link {
    align-items: center;
    color: var(--color-ink-medium);
    display: flex;
    font-size: var(--text-small);
    gap: var(--inline-space-half);

    /* A colour swatch, not an icon. It was a pasted 16px <svg> holding an 8px
       circle; a disc needs no glyph file and no mask. */
    .allocation-legend__dot {
      background-color: var(--asset-color);
      block-size: 0.5rem;
      border-radius: 50%;
      flex: none;
      inline-size: 0.5rem;
    }
  }

  /* FI progress
  /* ------------------------------------------------------------------------ */

  .fi-split {
    display: flex;
    flex-direction: column;
    gap: var(--block-space-half);
    margin-block-end: var(--block-space);
  }

  .fi-split__bar {
    display: flex;
    inline-size: 100%;
  }

  .fi-split__contributions,
  .fi-split__gains {
    block-size: 0.5rem;
  }

  .fi-split__contributions { background-color: oklch(var(--lch-blue-dark)); }
  .fi-split__gains { background-color: oklch(var(--lch-pink-medium)); }

  .fi-split__labels {
    display: flex;
    font-size: var(--text-small);
    justify-content: space-between;
  }

  .fi-split__caption {
    color: var(--color-ink-medium);
    display: block;
    font-size: var(--text-x-small);
  }

  .fi-quote {
    color: var(--color-ink-medium);
    font-style: italic;
  }

  /* Achievements
  /* ------------------------------------------------------------------------ */

  .achievements {
    color: var(--color-ink-medium);
    display: flex;
    flex-direction: column;
    gap: var(--block-space-half);

    li {
      align-items: center;
      display: flex;
      font-size: var(--text-small);
      gap: var(--inline-space-half);
    }
  }

  /* Footer nav
  /* ------------------------------------------------------------------------ */

  .dashboard__footer-links {
    display: flex;
    flex-direction: column;
    gap: var(--block-space-half);
  }

  .dashboard__logo {
    align-items: center;
    display: flex;
    gap: var(--inline-space-half);
    margin-block-start: var(--block-space-double);

    img {
      block-size: 2rem;
      inline-size: 2rem;
    }
  }
}
