/* * @bitbaum/chartkit — the look of the one chart. * * Every colour and face is a --ck-* variable. By default they read * @bitbaum/design-tokens' HSL-triplet variables, so apps on those tokens match * without doing anything; an app whose variables are full colours maps them * once on :root. The prefix is shared with chatkit on purpose: --ck-line, * --ck-accent, --ck-bg, --ck-font and --ck-mono mean the same thing in both, * so an app that has themed its chat has themed its charts. * * Non-negotiable, and why: * - Text is in rem, never in SVG units: the drawing is an SVG stretched to * its box (preserveAspectRatio="none", non-scaling strokes) and every * label is HTML laid over it, so a 320px plot has the same type as a * 1440px one. A label that scaled with the plot shrank to nothing on a * phone (Substrata's first chart). * - No label is set under 0.75rem (12px): the fleet's floor. * - Long labels truncate with an ellipsis and carry the full text in * `title`; bar labels have a least column; timeline events that would * collide take a second lane. The audit (src/audit.ts) measures all three. * - Light and dark both by token: nothing here is a literal colour except * the fallback for an app with no tokens at all. */ :where(:root) { /* Defaults at ZERO specificity on the root: an app's own :root rule setting a --ck-* variable always wins. */ --ck-ink: hsl(var(--text-primary, 0 0% 10%)); --ck-ink-muted: hsl(var(--text-tertiary, 0 0% 50%)); --ck-line: hsl(var(--border-subtle, 0 0% 90%)); --ck-bg: hsl(var(--surface-base, 0 0% 100%)); --ck-accent: var(--accent-primary, #ff5c00); --ck-up: hsl(var(--status-positive, 145 60% 35%)); --ck-down: hsl(var(--status-negative, 0 65% 50%)); --ck-warning: hsl(var(--status-warning, 38 80% 40%)); /* Series by index, never cycled: the first is the ink, and each later one differs from the ink by a dash as well as a colour, so the set survives a monochrome theme (Substrata's accent IS its ink) and a greyscale print. */ --ck-series-1: var(--ck-ink); --ck-series-2: var(--ck-accent); --ck-series-3: color-mix(in srgb, var(--ck-ink) 55%, transparent); --ck-series-4: var(--ck-up); --ck-series-5: var(--ck-down); --ck-series-6: color-mix(in srgb, var(--ck-accent) 55%, transparent); --ck-font: var(--font-sans, system-ui, -apple-system, "Segoe UI", sans-serif); --ck-mono: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace); /* The one label size, and the floor. */ --ck-label: 0.75rem; } /* ---- The frame ------------------------------------------------------- */ .ck-chart { margin: 0; min-width: 0; font-family: var(--ck-font); color: var(--ck-ink); } .ck-chart-caption { margin-top: 0.75rem; font-size: var(--ck-label); line-height: 1.45; color: var(--ck-ink-muted); } .ck-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; } .ck-chart a { color: inherit; } /* Labels: one size, one face, tabular figures, never under the floor. */ .ck-line-tick, .ck-line-xtick, .ck-line-unit, .ck-bar-value, .ck-legend, .ck-tl-month, .ck-meter-value, .ck-tile-label, .ck-tile-note { font-family: var(--ck-mono); font-size: var(--ck-label); line-height: 1; font-variant-numeric: tabular-nums; } /* Legend: a row of swatch + name (+ value), wrapping as a list does. */ .ck-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin: 0.6rem 0 0; padding: 0; list-style: none; color: var(--ck-ink-muted); } .ck-legend-item { display: inline-flex; align-items: center; gap: 0.4rem; min-width: 0; max-width: 100%; } .ck-legend-swatch { flex: none; width: 0.75rem; height: 0.75rem; border-radius: 2px; background: var(--ck-series-1); } .ck-legend-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--ck-ink); } .ck-legend-value { color: var(--ck-ink-muted); } [data-series="1"] { --ck-series: var(--ck-series-1); } [data-series="2"] { --ck-series: var(--ck-series-2); } [data-series="3"] { --ck-series: var(--ck-series-3); } [data-series="4"] { --ck-series: var(--ck-series-4); } [data-series="5"] { --ck-series: var(--ck-series-5); } [data-series="6"] { --ck-series: var(--ck-series-6); } .ck-legend-swatch[data-series], .ck-share-seg[data-series] { background: var(--ck-series); } /* ---- LineChart --------------------------------------------------------- */ .ck-chart-line { --ck-gutter: 3rem; --ck-plot-height: 13rem; /* Room for the top tick label and the tooltip arrow; the first tick sits on the plot's top edge. */ padding: 1.25rem 0.5rem 0 var(--ck-gutter); } .ck-line-plot { position: relative; height: var(--ck-plot-height); } .ck-line-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--ck-line); } .ck-line-tick { position: absolute; right: calc(100% + 0.5rem); top: -0.4rem; color: var(--ck-ink-muted); white-space: nowrap; } .ck-line-unit { position: absolute; right: 0; bottom: calc(100% + 0.25rem); color: var(--ck-ink-muted); } .ck-line-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; } .ck-line-path { fill: none; stroke: var(--ck-series, var(--ck-ink)); stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; } .ck-line-path[data-series="2"], .ck-line-path[data-series="6"] { stroke-dasharray: 6 4; } .ck-line-path[data-series="3"], .ck-line-path[data-series="5"] { stroke-dasharray: 2 4; } .ck-line-path[data-series="4"] { stroke-dasharray: 8 3 2 3; } /* A point: a target the size of a fingertip around an 8px mark, ringed in the surface colour so it reads where lines cross. */ .ck-pt { position: absolute; width: 1.5rem; height: 1.5rem; margin: -0.75rem 0 0 -0.75rem; border-radius: 50%; z-index: 1; outline: none; } .ck-pt::before { content: ""; position: absolute; inset: 0.5rem; border-radius: 50%; background: var(--ck-series, var(--ck-ink)); box-shadow: 0 0 0 2px var(--ck-bg); } .ck-pt-dense::before { inset: 0.6rem; } .ck-pt:hover::before, .ck-pt:focus-visible::before { inset: 0.3rem; } .ck-pt:focus-visible::before { box-shadow: 0 0 0 2px var(--ck-bg), 0 0 0 4px var(--ck-ink); } /* The fill under a line (`area`): the series' own colour, faint, so the grid still reads through it in light and dark. */ .ck-line-area { fill: color-mix(in srgb, var(--ck-series, var(--ck-ink)) 9%, transparent); stroke: none; } /* A value whose dot is hidden (`markers` none / ends / auto on dense data): the target is a full-height strip of the plot — the strips tile it, so a pointer or a finger anywhere over the line finds the nearest value and the target is never smaller than the plot is tall. The dot, a hairline cursor and the value appear on hover and keyboard focus. */ .ck-pt-col { top: 0; bottom: 0; height: auto; margin: 0; border-radius: 0; } .ck-pt-col::before, .ck-pt-col:hover::before, .ck-pt-col:focus-visible::before { inset: auto; left: calc(var(--ck-mx) - 0.3rem); top: calc(var(--ck-y) - 0.3rem); width: 0.6rem; height: 0.6rem; } .ck-pt-col::before { opacity: 0; /* The dot overhangs its strip; only the strip answers the pointer, so a neighbour's hidden dot never steals it. */ pointer-events: none; } .ck-pt-col.ck-pt-marked::before, .ck-pt-col:hover::before, .ck-pt-col:focus-visible::before { opacity: 1; } .ck-pt-col::after { content: ""; position: absolute; top: 0; bottom: 0; left: var(--ck-mx); border-left: 1px solid var(--ck-ink-muted); z-index: -1; display: none; pointer-events: none; } .ck-pt-col:hover, .ck-pt-col:focus-visible { z-index: 3; } .ck-pt-col:hover::after, .ck-pt-col:focus-visible::after { display: block; } .ck-pt-col .ck-tip { bottom: auto; top: var(--ck-y); left: var(--ck-mx); transform: translate(-50%, calc(-100% - 0.75rem)); } .ck-pt-col.ck-pt-start .ck-tip { transform: translate(0, calc(-100% - 0.75rem)); } .ck-pt-col.ck-pt-end .ck-tip { left: auto; right: calc(100% - var(--ck-mx)); transform: translate(0, calc(-100% - 0.75rem)); } .ck-tip { display: none; position: absolute; bottom: calc(100% + 0.25rem); left: 50%; transform: translateX(-50%); min-width: 11rem; max-width: 16rem; padding: 0.5rem 0.65rem; border: 1px solid var(--ck-line); background: var(--ck-bg); font-size: var(--ck-label); line-height: 1.4; color: var(--ck-ink-muted); z-index: 2; pointer-events: none; } .ck-pt-end .ck-tip { left: auto; right: 0; transform: none; } .ck-pt:hover .ck-tip, .ck-pt:focus-visible .ck-tip { display: flex; flex-direction: column; } .ck-tip strong { color: var(--ck-ink); font-size: 0.85rem; } .ck-line-axis { position: relative; height: 1.25rem; margin-top: 0.5rem; color: var(--ck-ink-muted); } .ck-line-xtick { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; } .ck-line-xtick.ck-at-start { transform: none; } .ck-line-xtick.ck-at-end { transform: translateX(-100%); } /* Five labels do not fit a phone's plot; every second one steps back. */ @media (max-width: 479px) { .ck-line-xtick:nth-child(even) { display: none; } } /* ---- ColumnChart ------------------------------------------------------- */ .ck-chart-columns { --ck-gutter: 3rem; --ck-plot-height: 11rem; padding: 1.25rem 0.5rem 0 var(--ck-gutter); } .ck-col-plot { position: relative; height: var(--ck-plot-height); } .ck-col-zero { border-top-color: var(--ck-ink-muted); } .ck-col-groups, .ck-col-axis { display: grid; grid-template-columns: repeat(var(--ck-periods, 1), minmax(0, 1fr)); gap: 0 0.5rem; } .ck-col-groups { position: absolute; inset: 0; } .ck-col-group { display: flex; justify-content: center; gap: 2px; min-width: 0; height: 100%; } .ck-col-slot, .ck-col-gap { position: relative; flex: 1 1 0; min-width: 0; max-width: 2.5rem; height: 100%; } .ck-col { position: absolute; left: 0; right: 0; display: block; min-height: 2px; border-radius: 2px 2px 0 0; background: var(--ck-series, var(--ck-ink)); outline: none; z-index: 1; } .ck-col-neg { border-radius: 0 0 2px 2px; } .ck-col:hover, .ck-col:focus-visible { box-shadow: 0 0 0 2px var(--ck-bg), 0 0 0 4px var(--ck-ink); } .ck-col:hover .ck-tip, .ck-col:focus-visible .ck-tip { display: flex; flex-direction: column; } .ck-col-axis { margin-top: 0.5rem; color: var(--ck-ink-muted); /* The axis is the plot's width; its labels ask it how wide it is. */ container: ck-col-axis / inline-size; } /* A period's cell. Its label is printed whole, centred on the column, and runs over its neighbours when they have stepped back; the first is held at the left edge and the last at the right (`safe` keeps an overflowing label on the side it starts from, and row-reverse makes that the right). */ .ck-col-xtick { display: flex; justify-content: center; min-width: 0; font-family: var(--ck-mono); font-size: var(--ck-label); line-height: 1.25rem; white-space: nowrap; font-variant-numeric: tabular-nums; } .ck-col-xtick:first-child { justify-content: safe center; } .ck-col-xtick:last-child { flex-direction: row-reverse; justify-content: safe center; } .ck-col-xlabel { flex: none; /* Only a label wider than the whole plot is ever shortened. */ max-width: 100cqw; overflow: hidden; text-overflow: ellipsis; } /* Too many periods for the width: every n-th label steps back so the rest are whole — thinned, never cut. The server plans which, per band of plot width (COLUMN_AXIS_WIDTHS in src/index.ts; keep the two in step). */ @container ck-col-axis (width < 160px) { .ck-col-xtick[data-hide~="0"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (160px <= width < 200px) { .ck-col-xtick[data-hide~="160"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (200px <= width < 240px) { .ck-col-xtick[data-hide~="200"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (240px <= width < 280px) { .ck-col-xtick[data-hide~="240"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (280px <= width < 320px) { .ck-col-xtick[data-hide~="280"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (320px <= width < 360px) { .ck-col-xtick[data-hide~="320"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (360px <= width < 400px) { .ck-col-xtick[data-hide~="360"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (400px <= width < 480px) { .ck-col-xtick[data-hide~="400"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (480px <= width < 560px) { .ck-col-xtick[data-hide~="480"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (560px <= width < 640px) { .ck-col-xtick[data-hide~="560"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (640px <= width < 720px) { .ck-col-xtick[data-hide~="640"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (720px <= width < 800px) { .ck-col-xtick[data-hide~="720"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (800px <= width < 880px) { .ck-col-xtick[data-hide~="800"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (880px <= width < 960px) { .ck-col-xtick[data-hide~="880"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (960px <= width < 1080px) { .ck-col-xtick[data-hide~="960"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (1080px <= width < 1200px) { .ck-col-xtick[data-hide~="1080"] > .ck-col-xlabel { display: none; } } @container ck-col-axis (width >= 1200px) { .ck-col-xtick[data-hide~="1200"] > .ck-col-xlabel { display: none; } } /* ---- BarChart ---------------------------------------------------------- */ .ck-bars { display: grid; /* The label has a least column — a bar whose name was squeezed to one letter is a bar nobody can read — and the value column is as wide as its widest number. */ grid-template-columns: minmax(6rem, 30%) minmax(0, 1fr) auto; gap: 0.5rem 0.75rem; margin: 0; padding: 0; list-style: none; } .ck-bar-row { display: contents; } .ck-bar-label { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 0.875rem; line-height: 1.25rem; } .ck-bar-row-hi .ck-bar-label { font-weight: 600; } .ck-bar-track { display: flex; align-items: center; min-width: 0; height: 1.25rem; } .ck-bar-fill { display: block; height: 0.75rem; min-width: 2px; border-radius: 0 2px 2px 0; background: var(--ck-ink); } .ck-bar-row-hi .ck-bar-fill { background: var(--ck-accent); } .ck-bar-row[data-tone="positive"] .ck-bar-fill { background: var(--ck-up); } .ck-bar-row[data-tone="warning"] .ck-bar-fill { background: var(--ck-warning); } .ck-bar-row[data-tone="negative"] .ck-bar-fill { background: var(--ck-down); } .ck-bar-value { display: inline-flex; align-items: baseline; gap: 0.5rem; justify-self: end; line-height: 1.25rem; white-space: nowrap; } .ck-bar-share, .ck-bar-none, .ck-bar-est { color: var(--ck-ink-muted); } /* ---- ShareBars --------------------------------------------------------- */ .ck-share { display: flex; height: 1.5rem; overflow: hidden; border-radius: 2px; } .ck-share-seg { position: relative; display: block; min-width: 0; height: 100%; /* The 2px of surface between fills, carried by the segment itself so the widths still sum to 100%. */ box-shadow: inset -2px 0 0 var(--ck-bg); background: var(--ck-series-1); container-type: inline-size; } .ck-share-seg:last-child { box-shadow: none; } .ck-share-other { background: var(--ck-line) !important; } .ck-share-inside { display: none; position: absolute; inset: 0 0.5rem; align-items: center; overflow: hidden; white-space: nowrap; font-family: var(--ck-mono); font-size: var(--ck-label); color: var(--ck-bg); } /* Inside only when the segment has room for the words. */ @container (min-width: 9rem) { .ck-share-inside { display: flex; } } /* ---- Sparkline --------------------------------------------------------- */ .ck-spark { flex: none; overflow: visible; vertical-align: middle; } .ck-spark path { fill: none; stroke: var(--ck-ink); stroke-width: 1.5px; stroke-linejoin: round; stroke-linecap: round; } /* The last value, a value standing alone between two gaps, and a point with a tone: each a round dot (a stroke of no length with a round cap). The end is the largest, so it still reads as the end. */ .ck-spark .ck-spark-end { stroke-width: 5px; } .ck-spark .ck-spark-solo, .ck-spark .ck-spark-dot { stroke-width: 4px; } .ck-spark [data-tone="positive"] { stroke: var(--ck-up); } .ck-spark [data-tone="warning"] { stroke: var(--ck-warning); } .ck-spark [data-tone="negative"] { stroke: var(--ck-down); } /* ---- Meter ------------------------------------------------------------- */ .ck-meter { display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; } .ck-meter-value { color: var(--ck-ink); } .ck-meter-track { display: flex; flex: none; width: 3rem; height: 0.375rem; overflow: hidden; border-radius: 9999px; background: var(--ck-line); } .ck-meter-fill { width: var(--ck-meter, 0%); background: var(--ck-accent); } .ck-meter-track[data-tone="neutral"] .ck-meter-fill { background: var(--ck-ink); } .ck-meter-track[data-tone="positive"] .ck-meter-fill { background: var(--ck-up); } .ck-meter-track[data-tone="warning"] .ck-meter-fill { background: var(--ck-warning); } .ck-meter-track[data-tone="negative"] .ck-meter-fill { background: var(--ck-down); } /* ---- StatTiles --------------------------------------------------------- */ .ck-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin: 0; padding: 0; overflow: hidden; list-style: none; border: 1px solid var(--ck-line); border-radius: 0.5rem; background: var(--ck-line); } @media (min-width: 640px) { .ck-tiles { grid-template-columns: repeat(var(--ck-n, 4), minmax(0, 1fr)); } } .ck-tiles > li { display: flex; min-width: 0; } .ck-tile { display: flex; flex: 1; flex-direction: column; gap: 0.35rem; min-width: 0; min-height: 2.75rem; padding: 1rem; background: var(--ck-bg); text-decoration: none; } .ck-tile-value { font-size: 1.5rem; font-weight: 500; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; } .ck-tile-label, .ck-tile-note { line-height: 1.35; color: var(--ck-ink-muted); } a.ck-tile:hover .ck-tile-label, a.ck-tile:focus-visible .ck-tile-label { color: var(--ck-ink); text-decoration: underline; text-underline-offset: 0.2em; } /* ---- Timeline ---------------------------------------------------------- */ .ck-tl { --ck-lane: 1.75rem; position: relative; padding: 0.25rem 0 0; } .ck-tl-lane { position: relative; height: var(--ck-lane); } .ck-tl-event { position: absolute; top: 0; display: inline-flex; align-items: center; gap: 0.35rem; height: var(--ck-lane); /* As wide as the room to the neighbour in this lane, never more. */ max-width: var(--ck-room, 30%); margin-left: -0.25rem; text-decoration: none; } .ck-tl-left { flex-direction: row-reverse; margin-left: 0.25rem; transform: translateX(-100%); } .ck-tl-dot { flex: none; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--ck-ink); box-shadow: 0 0 0 2px var(--ck-bg); } .ck-tl-dot[data-tone="up"] { background: var(--ck-up); } .ck-tl-dot[data-tone="down"] { background: var(--ck-down); } .ck-tl-label { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: var(--ck-label); line-height: 1; } a.ck-tl-event:hover .ck-tl-label, a.ck-tl-event:focus-visible .ck-tl-label { text-decoration: underline; text-underline-offset: 0.2em; } .ck-tl-axis { position: relative; height: 1.5rem; border-top: 1px solid var(--ck-line); } .ck-tl-tick { position: absolute; top: -1px; width: 1px; height: 0.3rem; background: var(--ck-line); } .ck-tl-major { height: 0.5rem; } .ck-tl-month { position: absolute; top: 0.7rem; left: 0; transform: translateX(-50%); white-space: nowrap; color: var(--ck-ink-muted); } .ck-tl-tick.ck-at-start .ck-tl-month { transform: none; } .ck-tl-tick.ck-at-end .ck-tl-month { transform: translateX(-100%); } /* Six month labels do not fit a phone; every second one steps back. */ @media (max-width: 479px) { .ck-tl-tick[data-alt] .ck-tl-month { display: none; } } /* Reference intervals are data supplied by the product, never clinical advice. */ .ck-reference-band { fill: color-mix(in srgb, var(--ck-ink-muted) 12%, transparent); } .ck-band-labels { margin: 0.5rem 0; padding-left: 1.25rem; color: var(--ck-ink-muted); font-size: var(--ck-label); } .ck-col-stacked { position: relative; } .ck-col-stacked .ck-col-slot, .ck-col-stacked .ck-col-gap { position: absolute; inset: 0; width: 70%; margin-inline: auto; } .ck-col-stacked .ck-col { min-height: 0; border-radius: 0; } .ck-ring-layout { display: grid; grid-template-columns: minmax(5rem, 35%) minmax(0, 1fr); gap: 1rem; align-items: center; } .ck-ring { width: 100%; max-width: 15rem; } .ck-ring circle { fill: none; stroke-width: 14; } .ck-ring-track { stroke: var(--ck-line); } .ck-ring-segment { stroke: var(--ck-series); transform: rotate(-90deg); transform-origin: center; } .ck-ring-legend { margin: 0; padding: 0; list-style: none; min-width: 0; } .ck-ring-legend li { display: grid; grid-template-columns: 0.75rem minmax(0, 1fr) auto; gap: 0.5rem; align-items: center; font-size: var(--ck-label); min-height: 2.75rem; } .ck-ring-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; } a.ck-ring-label { display: flex; align-items: center; min-height: 2.75rem; color: inherit; } .ck-col-stacked .ck-col-slot { pointer-events: none; } .ck-col-stacked .ck-col { pointer-events: auto; }