/* data.css — the data table and the charts, new in 1.10.

   A page links this after its theme, and only a page that shows a
   table or a chart: it is not in fiesta.css, whose one-link promise
   had 412 bytes to spare when these arrived. Like tokens.css it is
   structure and declares no colour of its own but one, the chart's
   mark, which it reads from a theme's --rst-series-1 and falls back
   to a light-dark() pair when the theme declares none (no shipped
   theme does). check/data_contrast_test.go holds that pair to 3:1 on
   every theme's card and page.

   No script. A chart is server-rendered SVG that carries marks only:
   every word and number, the axes' included, is HTML, because text
   inside a viewBox scales with the chart and an 11px label drawn at
   640px wide is 6px at 390. The SVG stretches to its box
   (preserveAspectRatio="none") and its strokes do not
   (vector-effect: non-scaling-stroke, on every stroked shape, since
   the property is not inherited). The geometry is SVG attributes,
   never a style attribute, so a strict CSP that blocks inline styles
   draws it whole.

   Logical properties throughout. Where the chart runs right to left
   the HTML labels do so by themselves, so the plot is mirrored with
   them: the time axis reads with the chart. The mirror keys on the
   component's own direction, :dir(rtl), not on an ancestor's dir
   attribute, so a chart in an ltr section of an Arabic page stays
   unmirrored, as its labels do. */

/* ── The data table ──────────────────────────────────────────────────

   A native <table rst-table>, announced as a table, in a card that
   scrolls it sideways when it is wider than the screen, so a phone
   keeps every column: nothing is hidden, the page itself never
   scrolls sideways, and the row header column stays pinned at the
   inline start while the numbers move under it. The pinned column is
   bounded, at least min(9rem, 40cqi) and at most min(12rem, 40cqi) of
   the scrollport (on a phone the two meet at 40%), and a long name
   wraps inside it, an unbreakable word included (overflow-wrap:
   anywhere), so it never covers the numbers; a table that fits gives
   it more room, since nothing scrolls under it then. In a narrow card
   every cell's side padding halves, so an ordinary word fits the
   pinned column whole. The scroll region is
   focusable and named (tabindex="0", role="region"), so a keyboard
   can scroll it in a browser that does not make scrollers focusable,
   and it draws the focus ring. Its scroll padding, the pinned
   column's cap at the inline start, keeps a focused link from coming
   to rest under the pinned header or column.

   Head row on the sunken surface in the label step; hairline rules
   between rows, none between columns but the pinned column's edge; a
   footer row of totals under the strong rule. rst-num on a cell is a
   number: end-aligned (left in Arabic), tabular, never wrapped.

   Layers, lowest first: cells, the pinned row headers (1), the head
   row (2), the corner where the two meet (3). Each sticky cell paints
   an opaque ground, so nothing shows through it. */
[rst-table-scroll] { container-type: inline-size; overflow-x: auto; overscroll-behavior-inline: contain; scroll-padding-inline-start: min(12rem, 40%); }
[rst-table-scroll]:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: 2px; }
[rst-table-scroll~="bounded"] { max-block-size: min(70vh, 40rem); overflow-y: auto; scroll-padding-block-start: 2.5rem; }
[rst-table] { border-collapse: separate; border-spacing: 0; font-size: var(--rst-fs-sm); inline-size: 100%; }
[rst-table] > caption { color: var(--rst-text-muted); font-size: var(--rst-fs-xs); padding: var(--rst-sp-2) var(--rst-sp-4); text-align: start; }
[rst-table] th, [rst-table] td { border-block-end: 1px solid var(--rst-line); padding: var(--rst-sp-2) var(--rst-sp-4); text-align: start; vertical-align: baseline; }
[rst-table] thead th, [rst-table] thead td { background: var(--rst-surface-2); color: var(--rst-text-muted); font-size: var(--rst-fs-xs); font-weight: 650; white-space: nowrap; }
[rst-table] tbody th, [rst-table] tfoot th { background: var(--rst-surface); border-inline-end: 1px solid var(--rst-line); font-weight: 550; inset-inline-start: 0; position: sticky; z-index: 1; }
[rst-table] tbody th, [rst-table] tfoot th, [rst-table] thead th:first-child { box-sizing: border-box; max-inline-size: min(12rem, 40cqi); min-inline-size: min(9rem, 40cqi); overflow-wrap: anywhere; white-space: normal; }
[rst-table] thead th:first-child { border-inline-end: 1px solid var(--rst-line); inset-inline-start: 0; position: sticky; z-index: 3; }
@container (max-width: 30rem) {
  [rst-table] th, [rst-table] td { padding-inline: var(--rst-sp-2); }
}
[rst-table] tbody tr:last-child > th, [rst-table] tbody tr:last-child > td { border-block-end: 0; }
[rst-table] tfoot th, [rst-table] tfoot td { border-block-end: 0; border-block-start: 1px solid var(--rst-line-strong); font-weight: 650; }
[rst-table] [rst-num] { font-variant-numeric: tabular-nums; text-align: end; white-space: nowrap; }
[rst-table~="dense"] th, [rst-table~="dense"] td { padding-block: var(--rst-sp-1); }
[rst-table-scroll~="bounded"] thead th { inset-block-start: 0; position: sticky; z-index: 2; }
[rst-table-scroll~="bounded"] thead th:first-child { z-index: 3; }

/* A sortable column's head is a link to the same list sorted by it,
   so sorting is ordinary navigation. Only a column with that link
   looks sortable. The sorted one carries aria-sort and shows the
   chevron, turned up for ascending; the others show none. */
[rst-table] th > a { align-items: center; color: inherit; display: inline-flex; gap: var(--rst-sp-1); text-decoration: none; }
[rst-table] th > a:hover { color: var(--rst-text); text-decoration: underline; }
[rst-table] th > a .icon { block-size: 16px; display: none; flex: none; inline-size: 16px; }
[rst-table] th[aria-sort] > a .icon { display: block; }
[rst-table] th[aria-sort="ascending"] > a .icon { transform: rotate(180deg); }

/* No rows match the filters: the head row stays, so the shape of the
   table is still there, and one cell spanning every column says so.
   A table that has never had rows is the empty state, not a table. */
[rst-table-empty] > td { color: var(--rst-text-muted); padding-block: var(--rst-sp-5); text-align: center; }

/* ── The chart ───────────────────────────────────────────────────────

   <figure rst-chart>, named by the heading over its card and
   described by one visible sentence the caller writes (rst-chart-
   desc). The plot is aria-hidden: the figure's own table, in the
   "Show the numbers" disclosure (rst-chart-data), outside the hidden
   plot, carries every value once, and a bar chart is a table itself.
   A chart with no data says so in one sentence (rst-chart-empty) in
   place of the plot. */
[rst-chart] { --rst-chart-mark: var(--rst-series-1, light-dark(#2a78d6, #3987e5)); container-type: inline-size; display: grid; gap: var(--rst-sp-3); margin: 0; padding: var(--rst-sp-4); }
[rst-chart-desc] { color: var(--rst-text-muted); font-size: var(--rst-fs-xs); margin: 0; }
[rst-chart-empty] { color: var(--rst-text-muted); margin: 0; padding-block: var(--rst-sp-5); text-align: center; }
[rst-chart-data] > summary { color: var(--rst-text-muted); cursor: pointer; font-size: var(--rst-fs-xs); }
[rst-chart-data][open] > summary { margin-block-end: var(--rst-sp-2); }

/* A key under the plot names what is not the series: the goal's
   hairline, drawn as a short line beside its words. */
[rst-chart-key] { align-items: center; color: var(--rst-text-muted); display: flex; font-size: var(--rst-fs-xs); gap: var(--rst-sp-2); margin: 0; }
[rst-chart-key]::before { border-block-start: 1px solid var(--rst-text-muted); content: ""; inline-size: var(--rst-sp-4); }

/* ── Bars: a table with a bar in each row ────────────────────────────

   A horizontal bar chart of named categories is a <table
   rst-table="bars">: the name, the bar, the value. Being a table, it
   is its own complete text alternative and needs no second one; the
   bar column is decoration in an aria-hidden SVG, and its head is
   named in words only a screen reader hears (rst-sr-only), so the
   column is not announced as blank. The table's columns
   are shared by every row, so every bar has the same track and the
   lengths compare, and the values line up in their own column. 1.10
   draws one series of values at or above zero, each bar from the
   inline start: <rect width="value / max × 1000"> in a 1000-wide
   viewBox. */
[rst-table~="bars"] [rst-num] { inline-size: 1%; }
[rst-table~="bars"] [rst-table-bar] { inline-size: 100%; }
[rst-table-bar] { min-inline-size: 4rem; vertical-align: middle; }
[rst-table-bar] > svg { block-size: var(--rst-sp-2); display: block; inline-size: 100%; }
[rst-table-bar]:dir(rtl) > svg { transform: scaleX(-1); }
[rst-table-bar] rect { fill: var(--rst-chart-mark); }

/* ── The line ────────────────────────────────────────────────────────

   One series over evenly spaced points. A grid of the y labels and
   the plot, then the x labels under the plot. The plot's height is
   CSS (12rem, 9rem in a narrow container) and its width the
   container's; its viewBox is 0 0 1000 1000, stretched.

   The y labels are listed top to bottom, highest first, each a
   zero-height item spread with space-between, so each one centres on
   its gridline: the ticks are even from the axis's bottom to its top
   by construction. The x labels are zero-width items spread the same
   way, one per point, so each centres on its point, and every one
   keeps its place: a narrow chart hides the text of those not marked
   rst-chart-keep, never the item, or the rest would move. The first
   and last label sit inside the plot rather than centred over its
   edges.

   The dot is two coincident zero-length paths with round caps, which
   stay round however the plot stretches: the ring, a 12px stroke in
   the card's colour, then the 8px dot over it. The plot's gutters
   leave the ring room at the top and the inline end, and overflow
   stays visible so it is never clipped. A goal is one solid hairline,
   named in the key; no line here is dashed. */
[rst-chart-plot] { column-gap: var(--rst-sp-3); display: grid; grid-template-columns: auto 1fr; padding-block-start: var(--rst-sp-2); padding-inline-end: var(--rst-sp-2); }
[rst-chart-plot] > svg { block-size: 12rem; display: block; grid-area: 1 / 2; inline-size: 100%; overflow: visible; }
[rst-chart-plot]:dir(rtl) > svg { transform: scaleX(-1); }
[rst-chart-y] { color: var(--rst-text-faint); display: flex; flex-direction: column; grid-area: 1 / 1; font-size: var(--rst-fs-xs); font-variant-numeric: tabular-nums; justify-content: space-between; }
[rst-chart-y] > span { align-items: center; block-size: 0; display: flex; justify-content: flex-end; white-space: nowrap; }
[rst-chart-x] { color: var(--rst-text-faint); display: flex; font-size: var(--rst-fs-xs); grid-area: 2 / 2; justify-content: space-between; margin-block-start: var(--rst-sp-2); }
[rst-chart-x] > span { display: flex; inline-size: 0; justify-content: center; white-space: nowrap; }
[rst-chart-x] > span:first-child { justify-content: flex-start; }
[rst-chart-x] > span:last-child { justify-content: flex-end; }
[rst-chart-grid] { fill: none; stroke: var(--rst-line); stroke-width: 1px; vector-effect: non-scaling-stroke; }
[rst-chart-base] { fill: none; stroke: var(--rst-line-strong); stroke-width: 1px; vector-effect: non-scaling-stroke; }
[rst-chart-goal] { fill: none; stroke: var(--rst-text-muted); stroke-width: 1px; vector-effect: non-scaling-stroke; }
[rst-chart-line] { fill: none; stroke: var(--rst-chart-mark); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2px; vector-effect: non-scaling-stroke; }
[rst-chart-ring] { fill: none; stroke: var(--rst-surface); stroke-linecap: round; stroke-width: 12px; vector-effect: non-scaling-stroke; }
[rst-chart-dot] { fill: none; stroke: var(--rst-chart-mark); stroke-linecap: round; stroke-width: 8px; vector-effect: non-scaling-stroke; }

/* rst-chart-hits lies over the plot, one HTML slice per point, whose
   title is the point's label and value: a mouse gets the browser's
   own tooltip and a light band under the pointer. A slice runs from
   the midpoint before its point to the one after, so the first and
   last are half as wide as the rest (flex 1 against 2), and the row
   mirrors with the page as the plot does. HTML rather than an SVG
   <title>, so the words are in the page's language like any other
   attribute. A convenience: the table is where every value is. */
[rst-chart-hits] { display: flex; grid-area: 1 / 2; }
[rst-chart-hits] > span { flex: 2 1 0; }
[rst-chart-hits] > span:first-child, [rst-chart-hits] > span:last-child { flex-grow: 1; }
@media (hover: hover) {
  [rst-chart-hits] > span:hover { background: color-mix(in srgb, var(--rst-text) 6%, transparent); }
}

@container (max-width: 30rem) {
  [rst-chart-plot] > svg { block-size: 9rem; }
  [rst-chart-x] > span:not([rst-chart-keep]) { visibility: hidden; }
}

/* ── The sparkline ───────────────────────────────────────────────────

   A figure of its own: a small line, and a caption that says the
   period it covers and, in the caller's words, what the line does.
   The line is aria-hidden; the caption is what a reader gets, so it
   must say the shape (a spike, a dip, a flat run), not only where
   the line starts and ends. The line's margin is the gutter its end
   dot's ring needs at the top and bottom of its box. */
[rst-spark] { --rst-chart-mark: var(--rst-series-1, light-dark(#2a78d6, #3987e5)); align-items: center; display: flex; flex-wrap: wrap; gap: var(--rst-sp-1) var(--rst-sp-3); margin: 0; }
[rst-spark] > svg { block-size: 1.5rem; flex: none; inline-size: 6rem; margin-block: var(--rst-sp-2); overflow: visible; }
[rst-spark]:dir(rtl) > svg { transform: scaleX(-1); }
[rst-spark] > figcaption { color: var(--rst-text-muted); font-size: var(--rst-fs-xs); }

/* ── Forced colours ──────────────────────────────────────────────────

   The system's colours: the mark is text-coloured, the rules grey,
   the ring the canvas. One series, so the mark needs no second
   signal to say which series it is. */
@media (forced-colors: active) {
  [rst-chart], [rst-spark] { --rst-chart-mark: CanvasText; }
  [rst-chart-grid], [rst-chart-base], [rst-chart-goal] { stroke: GrayText; }
  [rst-chart-ring] { stroke: Canvas; }
}
