/*
 * Year bars: a bar a fiscal year, oldest first, each as tall as its share of
 * the tallest (`--share`), its figure over it and its year — and a change,
 * where the chart has one — under it. Plain HTML, so the figures are in
 * view-source and on paper with no JavaScript; the bars are `aria-hidden`.
 * The Dividends card (companies/keystats/_dividends) draws what was paid in
 * the series colour, a forecast outlined on the forecast tint and filled
 * from the foot as it is paid (`--paid`); the Cash conversion and returns
 * card (companies/keystats/_cash_returns) a share a year.
 *
 *   .year-bars--reference  a dashed line across the bars at `--reference`,
 *                          its share of the tallest: 100% of net income. The
 *                          figures sit on the paper so the line passes
 *                          behind them.
 *   .year-bars--sparse     under 640px only the years marked
 *                          `.year-bars__year--keep` (first, last, lowest,
 *                          highest) keep their figure, so ten of them fit a
 *                          phone without running into each other.
 */
@layer components {
  .year-bars {
    --year-bars-height: 7rem;

    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    align-items: end;
    gap: var(--space-2xs);
    margin: var(--space-sm) 0 0;
    padding: 0;
    list-style: none;
    font-family: var(--font-data);
    font-variant-numeric: tabular-nums lining-nums;
  }

  /* One column, held to the year's width: an auto column grew to a label's,
     and took the bar with it. */
  .year-bars__year {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: var(--space-3xs);
    min-inline-size: 0;
  }

  .year-bars__total,
  .year-bars__change {
    color: var(--color-ink-subtle);
    font-size: var(--text-meta-xs);
    white-space: nowrap;
  }

  /* A line even with no change to show, or that year's foot drops below the
     others': the first year, and the year after one of no dividend. */
  .year-bars__change {
    min-block-size: 1lh;
  }

  .year-bars__bar {
    inline-size: 100%;
    block-size: calc(var(--share) * var(--year-bars-height));
    background: linear-gradient(to top, var(--color-series-1) calc(var(--paid) * 100%), transparent 0);
  }

  .is-forecast .year-bars__bar {
    border: var(--rule-width) dashed var(--color-rule-control);
    background-color: var(--color-forecast);
  }

  .year-bars__label {
    padding-block-start: var(--space-3xs);
    border-block-start: var(--rule-hairline);
    inline-size: 100%;
    color: var(--color-ink-muted);
    font-size: var(--text-meta-xs);
    text-align: center;
  }

  .year-bars--reference .year-bars__bar {
    position: relative;

    &::after {
      position: absolute;
      inset-inline: 0;
      inset-block-end: calc(var(--reference) * var(--year-bars-height));
      border-block-start: var(--rule-width) dashed var(--color-ink);
      content: "";
    }
  }

  /* The line runs on across the gap to the next year. */
  .year-bars--reference .year-bars__year:not(:last-child) .year-bars__bar::after {
    inset-inline-end: calc(-1 * var(--space-2xs));
  }

  .year-bars--reference .year-bars__total {
    position: relative;
    z-index: 1;
    padding-inline: var(--space-3xs);
    background: var(--color-surface);
  }

  @media (width < 640px) {
    .year-bars--sparse .year-bars__year:not(.year-bars__year--keep) .year-bars__total {
      visibility: hidden;
    }
  }
}
