/*
 * A trend of a few lines over the periods a statement shows
 * (TrendChartHelper#trend_chart_tag): the margins under the
 * income statement's bridge, cash against debt under the balance sheet.
 * SVG drawn on the server, scaled with its box, so its text scales too; the
 * same figures are a table for screen readers. Colours are classes, because
 * an SVG attribute cannot read a custom property and a CSS rule can.
 */
@layer components {
  .trend-chart {
    position: relative;
    display: grid;
    gap: var(--space-xs);
    margin: 0;
  }

  /* The tooltip, behind `chart_tooltips` (the trend-tooltip controller):
     a hairline down the drawing at the hovered period, and that period's
     box beside it, over the page. Both are placed by the controller. */
  .trend-chart__tips {
    position: absolute;
    inset: 0;
    pointer-events: none;
  }

  .trend-chart__marker {
    position: absolute;
    border-inline-start: var(--rule-width) solid var(--color-ink-muted);
  }

  .trend-chart__tip {
    position: absolute;
    z-index: 10;
    display: grid;
    gap: var(--space-2xs);
    padding: var(--space-xs) var(--space-sm);
    border: var(--rule-width) solid var(--color-ink);
    background-color: var(--color-field);
    box-shadow: var(--shadow-overlay);
    white-space: nowrap;
  }

  .trend-chart__tip-rows {
    display: grid;
    grid-template-columns: auto auto;
    gap: var(--space-3xs) var(--space-md);
    font-size: var(--text-meta);
    line-height: var(--leading-meta);
  }

  .trend-chart__tip-value {
    color: var(--color-ink);
    font-weight: var(--weight-semibold);
    text-align: end;
  }

  /* A statement's, drawn three times for the room it has: the wide box
     across a wide card (TrendChartHelper::WIDE_BOX), the half-card one
     beside its partner, and a phone's below 30rem (SMALL_BOX). */
  .trend-chart--wide {
    container: trend-chart / inline-size;
  }

  .trend-chart__view.trend-chart__view--wide,
  .trend-chart__view.trend-chart__view--narrow {
    display: none;
  }

  @container trend-chart (width >= 30rem) {
    .trend-chart__view.trend-chart__view--narrow {
      display: grid;
    }

    .trend-chart__view.trend-chart__view--small {
      display: none;
    }
  }

  @container trend-chart (width >= 48rem) {
    .trend-chart__view.trend-chart__view--wide {
      display: grid;
    }

    .trend-chart__view.trend-chart__view--narrow {
      display: none;
    }
  }

  /* A drawing and its period labels; the drawing's foot is its x axis.
     `--aspect` is the drawing's width over its height. */
  .trend-chart__view {
    display: grid;
  }

  .trend-chart__ticks {
    position: relative;
    min-block-size: 1lh;
    color: var(--color-ink-muted);
    font-family: var(--font-data);
    font-size: var(--text-meta);
    line-height: var(--leading-meta);
    font-variant-numeric: tabular-nums lining-nums;
  }

  .trend-chart__tick {
    position: absolute;
    inset-inline-start: var(--x);
    translate: -50% 0;
    white-space: nowrap;
  }

  .trend-chart__caption {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2xs) var(--space-lg);
  }

  /* Centred under the drawing (owner, 2026-11-19). */
  .trend-chart__keys {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2xs) var(--space-md);
    color: var(--color-ink-muted);
    font-size: var(--text-meta);
  }

  .trend-chart__key::before {
    content: "";
    display: inline-block;
    inline-size: 1rem;
    margin-inline-end: var(--space-2xs);
    vertical-align: middle;
    border-block-start: 2px solid var(--key);
  }

  .trend-chart__key--dashed::before {
    border-block-start-style: dashed;
  }

  .trend-chart__key--bar::before {
    inline-size: 0.75rem;
    block-size: 0.75rem;
    border: 0;
    background: var(--key);
  }

  .trend-chart__key--accent { --key: var(--color-accent); }
  .trend-chart__key--soft { --key: var(--color-ramp-gain-2); }
  .trend-chart__key--neutral { --key: var(--color-median); }
  .trend-chart__key--debt { --key: var(--color-bar-loss); }
  .trend-chart__key--over { --key: var(--color-series-3); }
  .trend-chart__key--mid { --key: var(--color-bar-gain); }
  .trend-chart__key--dark { --key: var(--color-accent-strong); }

  .trend-chart__plot {
    display: block;
    inline-size: 100%;
    block-size: auto;
    overflow: visible;
  }

  .trend-chart__grid {
    stroke: var(--color-axis);
    stroke-width: 1;
  }

  .trend-chart__grid--zero {
    stroke: var(--color-ink-muted);
  }

  .trend-chart__axis {
    fill: var(--color-ink-muted);
    font-family: var(--font-data);
    font-size: 12px;
    font-variant-numeric: tabular-nums lining-nums;
  }

  /* Outlined in paper, so a value reads where it lands on a bar. */
  .trend-chart__value {
    paint-order: stroke;
    stroke: var(--color-ground);
    stroke-width: 4;
    stroke-linejoin: round;
    fill: var(--color-ink);
    font-family: var(--font-data);
    font-size: 12px;
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums lining-nums;
  }

  .trend-chart__line {
    fill: none;
    stroke-width: 2.25;
    stroke-linejoin: round;
    stroke-linecap: round;
  }

  /* The paper under a line drawn over bars. */
  .trend-chart__halo {
    fill: none;
    stroke: var(--color-ground);
    stroke-width: 6;
    stroke-linejoin: round;
    stroke-linecap: round;
  }

  .trend-chart__line--dashed {
    stroke-dasharray: 5 4;
  }

  .trend-chart__end {
    stroke: none;
  }

  .trend-chart__line--accent { stroke: var(--color-accent); fill: var(--color-accent); }
  .trend-chart__line--soft { stroke: var(--color-ramp-gain-2); fill: var(--color-ramp-gain-2); }
  .trend-chart__line--neutral { stroke: var(--color-median); fill: var(--color-median); }
  .trend-chart__line--debt { stroke: var(--color-bar-loss); fill: var(--color-bar-loss); }
  /* A line over bars — net margin, net debt's share, free cash flow — in
     the series ochre, which reads over the greens where ink was lost on the
     darkest (owner, 2026-11-19), and says nothing of gain or loss. */
  .trend-chart__line--over { stroke: var(--color-series-3); fill: var(--color-series-3); }

  .trend-chart__bar {
    stroke: none;
  }

  .trend-chart__bar--accent { fill: var(--color-ramp-gain-2); }
  .trend-chart__bar--soft { fill: var(--color-ramp-gain-1); }
  .trend-chart__bar--neutral { fill: var(--color-mask); }
  .trend-chart__bar--debt { fill: var(--color-loss-tint); }
  .trend-chart__bar--mid { fill: var(--color-bar-gain); }
  .trend-chart__bar--dark { fill: var(--color-accent-strong); }

  /* The newest bar, darker. */
  .trend-chart__bar--latest.trend-chart__bar--accent { fill: var(--color-accent); }
  .trend-chart__bar--latest.trend-chart__bar--soft { fill: var(--color-ramp-gain-2); }
  .trend-chart__bar--latest.trend-chart__bar--neutral { fill: var(--color-volume); }
  .trend-chart__bar--latest.trend-chart__bar--debt { fill: var(--color-bar-loss); }

  /* A polyline takes the line's colour as its stroke only. */
  .trend-chart__line.trend-chart__line--accent,
  .trend-chart__line.trend-chart__line--soft,
  .trend-chart__line.trend-chart__line--neutral,
  .trend-chart__line.trend-chart__line--debt,
  .trend-chart__line.trend-chart__line--over {
    fill: none;
  }
}
