/* 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 */
  /* The query container: this tile's width is a user preference - wide or thin
     in Edit dashboard - so the rows should answer to the tile, not the
     viewport. */
  .watchlist {
    container-type: inline-size;
    overflow: hidden;
  }

  /* Grid, not columns: multicol has no row-gap, so the axes end up set by
     different mechanisms and drift apart. One gap here does both. */
  .watchlist__items {
    display: grid;
    gap: var(--block-space);
  }

  /* A row cannot compress below about 14ch - ticker and price never ellipsize,
     only the description does - and wants about 26ch for the description to
     read. Two of those plus the gap is 54ch. */
  @container (min-width: 54ch) {
    .watchlist__items {
      grid-template-columns: repeat(2, minmax(0, 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;
    }
  }
}
