/* ============================================================================
   TOM SHAW — Data visualisation
   Workstream C. Loads at position 8, after ts-data.css.

   Contains: chart frame, plot, axes, marks, legend, sparkline, gauge,
   geography.

   Charts are first-party inline SVG (contract §7.8). No ApexCharts, no Morris,
   no third-party runtime. Geometry is written as SVG attributes by
   js/ts-chart.js; colour is only ever a class in this file. That split is what
   keeps a chart CSP-clean: nothing here needs an inline style, and the classic
   "fill:#9137FF" attribute never appears in the markup.

   Every series colour is a token. The categorical sets were validated with the
   dataviz validator before this file was written — see docs/11-dataviz.md.
   ========================================================================= */

/* ============================================================================
   1. CHART FRAME — .ts-chart
   A <figure>. The caption is the title, the plot is the picture, the legend
   names the series, and <details> carries the same numbers as a table.
   The surface matches .ts-tablewrap and .ts-stat exactly.
   ========================================================================= */
/**
 * 16px of padding, not 20px, and a ruled head.
 *
 * "The surface matches .ts-tablewrap and .ts-stat exactly" was true of the
 * border and the radius and false of everything inside: a chart inset its
 * content 20px while the .ts-card beside it in the same grid inset 16px and
 * ruled its header. On dashboard.html the two sat side by side and read as two
 * different components. A chart is a card whose body happens to be a picture.
 */
.ts-chart {
  display: flex;
  flex-direction: column;
  gap: calc(var(--ts-space) * 2);
  margin: 0 0 calc(var(--ts-space) * 3);
  padding: calc(var(--ts-space) * 2);
  background: var(--ts-white);
  border: 1px solid var(--ts-grey-light);
  border-radius: var(--ts-radius-card);
  min-width: 0;
}

/* Bleeds to the card edge so the rule is the full width of the surface, like
   .ts-card__head. The negative margin is exactly the padding above it. */
.ts-chart__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--ts-space);
  flex-wrap: wrap;
  margin: 0 calc(var(--ts-space) * -2);
  padding: 0 calc(var(--ts-space) * 2) calc(var(--ts-space) * 2);
  border-bottom: 1px solid var(--ts-grey-light);
}
.ts-chart--dark .ts-chart__head { border-bottom-color: var(--ts-hairline-dark); }
.ts-chart__title {
  margin: 0;
  font-size: var(--ts-fs-section);
  font-weight: var(--ts-fw-bold);
  color: var(--ts-ink);
}
.ts-chart__meta {
  margin: 0;
  font-size: var(--ts-fs-ui-sm);
  color: var(--ts-grey-text);
  font-variant-numeric: tabular-nums;
}

/* --- Plot ----------------------------------------------------------------
   The SVG fills the plot box; the box carries the height so a chart cannot
   collapse before its data arrives. */
.ts-chart__plot { height: var(--ts-chart-h); }
.ts-chart__plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.ts-chart--sm .ts-chart__plot { height: var(--ts-chart-h-sm); }
.ts-chart--lg .ts-chart__plot { height: var(--ts-chart-h-lg); }

/* A row of figures. minmax(320px) rather than the tile grid's 220px, because a
   chart narrower than that stops being readable and should become a stat. */
.ts-statgrid--charts { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.ts-statgrid .ts-chart { margin-bottom: 0; }
.ts-chart--wide { grid-column: 1 / -1; }

/* ============================================================================
   2. AXES AND GRID
   Grid lines are subordinate to the axis, and the axis is subordinate to the
   data. Grid lines are decorative aids and are exempt from 1.4.11; the marks
   are not.
   ========================================================================= */
.ts-chart__grid { stroke: var(--ts-chart-grid); stroke-width: 1; fill: none; }
.ts-chart__axis { stroke: var(--ts-grey-light); stroke-width: 1; fill: none; }
.ts-chart__tick {
  font-family: var(--ts-mono);
  font-size: var(--ts-fs-ui-label);
  fill: var(--ts-grey-text);
}
.ts-chart__tick--y { text-anchor: end; }
.ts-chart__tick--x { text-anchor: middle; }
.ts-chart__axistitle {
  font-family: var(--ts-mono);
  font-size: var(--ts-fs-ui-label);
  letter-spacing: var(--ts-tracking-label);
  text-transform: uppercase;
  fill: var(--ts-grey-text);
}

/* ============================================================================
   3. MARKS
   One class per slot, assigned in fixed order and never cycled. A fifth series
   is a texture in slot 4's ink or is folded into "Other" — never a new hue.
   ========================================================================= */
.ts-chart__mark--1 { fill: var(--ts-series-1); }
.ts-chart__mark--2 { fill: var(--ts-series-2); }
.ts-chart__mark--3 { fill: var(--ts-series-3); }
.ts-chart__mark--4 { fill: var(--ts-series-4); }

/* "Other" / unclassified is deliberately NOT a series colour. It is the
   secondary ink, so an aggregate bucket never competes with a real category. */
.ts-chart__mark--other { fill: var(--ts-grey-text); }

.ts-chart__stroke--1 { stroke: var(--ts-series-1); }
.ts-chart__stroke--2 { stroke: var(--ts-series-2); }
.ts-chart__stroke--3 { stroke: var(--ts-series-3); }
.ts-chart__stroke--4 { stroke: var(--ts-series-4); }
.ts-chart__line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Area fill under a line is context, not the value — the line is the value. */
.ts-chart__area { stroke: none; fill-opacity: .14; }

/* A 2px surface ring keeps overlapping dots readable where series cross. */
.ts-chart__dot { stroke: var(--ts-white); stroke-width: 2; }

/* Selective direct labels. Never a number on every point. */
.ts-chart__label {
  font-family: var(--ts-mono);
  font-size: var(--ts-fs-ui-label);
  font-variant-numeric: tabular-nums;
  fill: var(--ts-ink);
}
.ts-chart__label--onmark { fill: var(--ts-white); }
.ts-chart__label--muted  { fill: var(--ts-grey-text); }

/**
 * The VALUE printed at the end of a mark — a different thing from the category
 * label beside it, which is why it is its own element and not a modifier.
 *
 * This arrived in a compatibility shim on 14 Aug 2026 covering a name clash
 * between two workstreams. The clash is resolved (marks are .ts-chart__mark--N
 * everywhere) and the shim is gone, but this element was never the mistake —
 * a chart that carries its numbers is how it passes AA, so it is promoted here
 * rather than deleted with the rest.
 *
 * Bold and tabular, so a column of values reads as a column.
 */
.ts-chart__value {
  font-family: var(--ts-mono);
  font-size: var(--ts-fs-ui-sm);
  font-weight: var(--ts-fw-bold);
  font-variant-numeric: tabular-nums;
  fill: var(--ts-ink);
  dominant-baseline: middle;
}
.ts-chart--dark .ts-chart__value { fill: var(--ts-on-dark-1); }

/* --- Texture -------------------------------------------------------------
   Required whenever the categories are SEVERITY bands, so severity is never
   colour alone — the same rule that makes .ts-chip encode shape as well as
   colour. Patterns live in the #ts-chart-defs sprite; ts-chart.js injects it
   if the page has not shipped it as markup. */
.ts-chart--textured .ts-chart__mark--2 { fill: url(#ts-tex-2); }
.ts-chart--textured .ts-chart__mark--3 { fill: url(#ts-tex-3); }
.ts-chart--textured .ts-chart__mark--4 { fill: url(#ts-tex-4); stroke: var(--ts-series-4); stroke-width: 1.5; }
.ts-chart--dark.ts-chart--textured .ts-chart__mark--2 { fill: url(#ts-tex-2-dark); }
.ts-chart--dark.ts-chart--textured .ts-chart__mark--3 { fill: url(#ts-tex-3-dark); }
.ts-chart--dark.ts-chart--textured .ts-chart__mark--4 { fill: url(#ts-tex-4-dark); stroke: var(--ts-series-4-dark); }

/* Inks used inside the pattern sprite, which sits outside any .ts-chart. */
.ts-chart__ink--2 { fill: var(--ts-series-2); }
.ts-chart__ink--3 { fill: var(--ts-series-3); }
.ts-chart__ink--4 { fill: var(--ts-series-4); }
.ts-chart__ink--2-dark { fill: var(--ts-series-2-dark); }
.ts-chart__ink--3-dark { fill: var(--ts-series-3-dark); }
.ts-chart__ink--4-dark { fill: var(--ts-series-4-dark); }
.ts-chart__defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ============================================================================
   4. LEGEND — .ts-legend
   Always present for two or more series; a single-series chart has no legend
   because the title already names it. The key repeats the mark's texture, so
   the legend stays true in greyscale and in print.
   ========================================================================= */
.ts-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ts-space) calc(var(--ts-space) * 2);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--ts-fs-ui-sm);
  color: var(--ts-grey-text);
}
.ts-legend__item { display: inline-flex; align-items: center; gap: calc(var(--ts-space) * .75); }
.ts-legend__key {
  width: 12px; height: 12px;
  flex: 0 0 12px;
  border-radius: 2px;
  background: var(--ts-grey-text);
}
.ts-legend__value {
  margin-left: calc(var(--ts-space) * .5);
  font-family: var(--ts-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ts-ink);
}

.ts-legend__key--1 { background: var(--ts-series-1); }
.ts-legend__key--2 { background: var(--ts-series-2); }
.ts-legend__key--3 { background: var(--ts-series-3); }
.ts-legend__key--4 { background: var(--ts-series-4); }
.ts-legend__key--other { background: var(--ts-grey-text); }

/* Textured keys mirror the SVG patterns: hatch, dot, open. */
.ts-legend--textured .ts-legend__key--2 {
  background: repeating-linear-gradient(45deg,
    var(--ts-series-2) 0 3px, var(--ts-white) 3px 6px);
}
.ts-legend--textured .ts-legend__key--3 {
  background: radial-gradient(var(--ts-series-3) 42%, var(--ts-white) 44%) 0 0 / 6px 6px;
}
.ts-legend--textured .ts-legend__key--4 {
  background: var(--ts-white);
  box-shadow: inset 0 0 0 2px var(--ts-series-4);
}

/* A banded scale rather than separate keys — used by the choropleth. */
.ts-legend--steps { gap: 0 2px; align-items: center; }
.ts-legend--steps .ts-legend__item { gap: 4px; }
/* flex-basis, not width: .ts-legend__key sets `flex: 0 0 12px`, so a bare
   width is ignored and the band never widens. */
.ts-legend--steps .ts-legend__key { flex: 0 0 28px; width: 28px; border-radius: 0; }

/* ============================================================================
   5. DATA VIEW — .ts-chart__data
   The table that carries the same numbers as the picture. This is how a chart
   passes AA, and it is also how it survives print, greyscale and 200% zoom.
   It is never optional, so it is styled as a real control rather than hidden
   behind an icon.
   ========================================================================= */
.ts-chart__data { font-size: var(--ts-fs-ui-sm); }
.ts-chart__data > summary {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--ts-space) * .75);
  padding: 4px 0;
  color: var(--ts-purple);
  font-weight: var(--ts-fw-bold);
  cursor: pointer;
  border-radius: 3px;
}
.ts-chart__data > summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.ts-chart__data > summary:focus-visible {
  outline: var(--ts-focus-width) solid var(--ts-focus-light);
  outline-offset: var(--ts-focus-offset);
}
/* A data view is a small table of labels and numbers, so it wraps to its card
   rather than keeping the list table's 720px floor. Without this the widest
   row header — "Australian Capital Territory" — pushes the page sideways at
   320px, which rule 11 does not allow. */
.ts-chart__data .ts-table {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
  margin-top: var(--ts-space);
}
.ts-chart__data .ts-table th { position: static; white-space: normal; }
.ts-chart__data .ts-table td { overflow-wrap: anywhere; }

/* --- Extensions to .ts-table (home: ts-app-shell.css) ---------------------
   A data view inside a chart that sits on black. The table keeps its shape
   and swaps its inks; it never keeps a light ground on a dark surface. */
.ts-chart--dark .ts-table { color: var(--ts-on-dark-1); }
.ts-chart--dark .ts-table th { background: var(--ts-surface-3); color: var(--ts-on-dark-2); }
/* Row headers are cells here too — see the note on .ts-table tbody th
   (home: ts-app-shell.css). Without this the first column of every chart's
   data table is a solid band. */
.ts-chart--dark .ts-table tbody th { background: transparent; color: var(--ts-on-dark-1); }
.ts-chart--dark .ts-table td { border-top-color: var(--ts-hairline-dark); }
.ts-chart--dark .ts-table tbody tr:hover { background: var(--ts-wash-dark); }
.ts-chart--dark .ts-table a { color: var(--ts-violet-300); }

/* ============================================================================
   6. ON BLACK — .ts-chart--dark
   A chart switches the WHOLE series set by ground and never mixes the two.
   Inside .ts-hero it also drops its own surface: the hero supplies the black,
   and one glow surface per screen means the chart must not add a second.
   ========================================================================= */
.ts-chart--dark {
  background: var(--ts-surface-1);
  border-color: var(--ts-hairline-dark);
  color: var(--ts-on-dark-1);
}
.ts-chart--dark .ts-chart__title { color: var(--ts-on-dark-1); }
.ts-chart--dark .ts-chart__meta,
.ts-chart--dark .ts-legend { color: var(--ts-on-dark-3); }
.ts-chart--dark .ts-chart__grid { stroke: var(--ts-chart-grid-dark); }
.ts-chart--dark .ts-chart__axis { stroke: var(--ts-hairline-dark); }
.ts-chart--dark .ts-chart__tick,
.ts-chart--dark .ts-chart__axistitle { fill: var(--ts-on-dark-3); }
.ts-chart--dark .ts-chart__label { fill: var(--ts-on-dark-1); }
.ts-chart--dark .ts-chart__label--muted { fill: var(--ts-on-dark-3); }
.ts-chart--dark .ts-chart__label--onmark { fill: var(--ts-black); }
.ts-chart--dark .ts-chart__dot { stroke: var(--ts-black); }
.ts-chart--dark .ts-legend__value { color: var(--ts-on-dark-1); }
.ts-chart--dark :focus-visible { outline-color: var(--ts-focus-dark); }
.ts-chart--dark .ts-chart__data > summary { color: var(--ts-violet-300); }

.ts-chart--dark .ts-chart__mark--1 { fill: var(--ts-series-1-dark); }
.ts-chart--dark .ts-chart__mark--2 { fill: var(--ts-series-2-dark); }
.ts-chart--dark .ts-chart__mark--3 { fill: var(--ts-series-3-dark); }
.ts-chart--dark .ts-chart__mark--4 { fill: var(--ts-series-4-dark); }
.ts-chart--dark .ts-chart__mark--other { fill: var(--ts-on-dark-3); }
.ts-chart--dark .ts-chart__stroke--1 { stroke: var(--ts-series-1-dark); }
.ts-chart--dark .ts-chart__stroke--2 { stroke: var(--ts-series-2-dark); }
.ts-chart--dark .ts-chart__stroke--3 { stroke: var(--ts-series-3-dark); }
.ts-chart--dark .ts-chart__stroke--4 { stroke: var(--ts-series-4-dark); }
.ts-chart--dark .ts-legend__key--1 { background: var(--ts-series-1-dark); }
.ts-chart--dark .ts-legend__key--2 { background: var(--ts-series-2-dark); }
.ts-chart--dark .ts-legend__key--3 { background: var(--ts-series-3-dark); }
.ts-chart--dark .ts-legend__key--4 { background: var(--ts-series-4-dark); }
.ts-chart--dark .ts-legend__key--other { background: var(--ts-on-dark-3); }
.ts-chart--dark.ts-legend--textured .ts-legend__key--4,
.ts-chart--dark .ts-legend--textured .ts-legend__key--4 {
  background: var(--ts-black);
  box-shadow: inset 0 0 0 2px var(--ts-series-4-dark);
}

.ts-hero .ts-chart--dark { background: transparent; border: 0; padding: 0; margin: 0; }

/* ============================================================================
   7. SPARKLINE — .ts-spark
   Shape, not value. It carries no axis and no labels, so it never appears
   without a figure beside it that states the number.
   ========================================================================= */
.ts-spark { display: block; width: 100%; height: var(--ts-spark-h); overflow: visible; }
.ts-spark__line { fill: none; stroke: var(--ts-series-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ts-spark__area { fill: var(--ts-series-1); fill-opacity: .12; stroke: none; }
.ts-spark__last { fill: var(--ts-series-1); stroke: var(--ts-white); stroke-width: 2; }
.ts-spark__base { stroke: var(--ts-grey-light); stroke-width: 1; }

.ts-stat--dark .ts-spark__line { stroke: var(--ts-series-1-dark); }
.ts-stat--dark .ts-spark__area { fill: var(--ts-series-1-dark); }
.ts-stat--dark .ts-spark__last { fill: var(--ts-series-1-dark); stroke: var(--ts-black); }
.ts-stat--dark .ts-spark__base { stroke: var(--ts-hairline-dark); }

/* ============================================================================
   8. GAUGE — .ts-gauge
   One bounded score against its scale. An arc alone is unreadable, so the
   number is always drawn inside it and the range is always stated.
   ========================================================================= */
.ts-gauge { display: block; width: 100%; height: var(--ts-chart-h-sm); overflow: visible; }
.ts-gauge--lg { height: var(--ts-chart-h); }
.ts-gauge__track { fill: none; stroke: var(--ts-track); stroke-width: 12; stroke-linecap: round; }
.ts-gauge__fill  { fill: none; stroke: var(--ts-series-1); stroke-width: 12; stroke-linecap: round; }
.ts-gauge__value {
  text-anchor: middle;
  font-size: var(--ts-fs-h2);
  font-weight: var(--ts-fw-bold);
  font-variant-numeric: tabular-nums;
  fill: var(--ts-ink);
}
.ts-gauge__scale {
  text-anchor: middle;
  font-family: var(--ts-mono);
  font-size: var(--ts-fs-ui-label);
  fill: var(--ts-grey-text);
}
.ts-chart--dark .ts-gauge__track { stroke: var(--ts-track-dark); }
.ts-chart--dark .ts-gauge__fill  { stroke: var(--ts-series-1-dark); }
.ts-chart--dark .ts-gauge__value { fill: var(--ts-on-dark-1); }
.ts-chart--dark .ts-gauge__scale { fill: var(--ts-on-dark-3); }

/* ============================================================================
   9. GEOGRAPHY — .ts-geo
   Not a map (contract §7.4). A self-hosted simplified region SVG rendered as a
   choropleth, with the numbers in a table beneath. No pan, no zoom, no tile
   server: a tile request leaks which part of a customer's estate an operator
   is looking at.

   The bands are a SEQUENTIAL ramp — one hue, light to dark — because the
   quantity is magnitude, not identity. Every step clears 3:1 on its ground.
   ========================================================================= */
.ts-geo { display: flex; flex-direction: column; gap: calc(var(--ts-space) * 2); }
/* The diagram is capped and centred rather than filling the card. Regions are
   schematic, so scaling them to 800px adds size without adding information —
   and the card is wide for the sake of the table beneath, not the picture. */
.ts-geo__svg {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  align-self: center;
}
.ts-geo__region { stroke: var(--ts-white); stroke-width: 1; fill: var(--ts-grey-card); }
.ts-geo__region--1 { fill: var(--ts-violet-400); }
.ts-geo__region--2 { fill: var(--ts-violet-600); }
.ts-geo__region--3 { fill: var(--ts-violet-800); }
.ts-geo__region--4 { fill: var(--ts-violet-900); }
/* No data is a state, not a zero. It says so in the table too. */
.ts-geo__region--none { fill: var(--ts-grey-card); stroke: var(--ts-grey-light); }
/* A region label sits on whichever band it lands on, and the bands span the
   whole ramp — so no single ink clears 4.5:1 on all four. The label is drawn
   with a surface-coloured halo behind it (paint-order: stroke) and its
   contrast is judged against that halo, which is the same trick a printed map
   uses and the only one that holds as the data re-bands. */
.ts-geo__label {
  font-family: var(--ts-mono);
  font-size: var(--ts-fs-ui-label);
  text-anchor: middle;
  fill: var(--ts-ink);
  stroke: var(--ts-white);
  stroke-width: 3;
  stroke-linejoin: round;
  paint-order: stroke;
  font-variant-numeric: tabular-nums;
}
.ts-geo__label--dim { fill: var(--ts-grey-text); }

.ts-chart--dark .ts-geo__region { stroke: var(--ts-black); fill: var(--ts-surface-3); }
.ts-chart--dark .ts-geo__region--1 { fill: var(--ts-violet-300); }
.ts-chart--dark .ts-geo__region--2 { fill: var(--ts-violet-400); }
.ts-chart--dark .ts-geo__region--3 { fill: var(--ts-violet-500); }
.ts-chart--dark .ts-geo__region--4 { fill: var(--ts-violet-600); }
.ts-chart--dark .ts-geo__region--none { fill: var(--ts-surface-3); stroke: var(--ts-hairline-dark); }
.ts-chart--dark .ts-geo__label { fill: var(--ts-on-dark-1); stroke: var(--ts-black); }
.ts-chart--dark .ts-geo__label--dim { fill: var(--ts-on-dark-3); }

.ts-geo__legend .ts-legend__key--1 { background: var(--ts-violet-400); }
.ts-geo__legend .ts-legend__key--2 { background: var(--ts-violet-600); }
.ts-geo__legend .ts-legend__key--3 { background: var(--ts-violet-800); }
.ts-geo__legend .ts-legend__key--4 { background: var(--ts-violet-900); }
.ts-chart--dark .ts-geo__legend .ts-legend__key--1 { background: var(--ts-violet-300); }
.ts-chart--dark .ts-geo__legend .ts-legend__key--2 { background: var(--ts-violet-400); }
.ts-chart--dark .ts-geo__legend .ts-legend__key--3 { background: var(--ts-violet-500); }
.ts-chart--dark .ts-geo__legend .ts-legend__key--4 { background: var(--ts-violet-600); }

/* ============================================================================
   10. RESPONSIVE
   At 320px a chart keeps its frame and loses its density, never its data view.
   ========================================================================= */
@media (max-width: 620px) {
  .ts-chart { padding: calc(var(--ts-space) * 2); }
  .ts-chart--lg .ts-chart__plot { height: var(--ts-chart-h); }
}
