/* Chart (docs/widgets/chart.md), Soft design (spec §3.7): the chart on a white card with a thin border,
   rounded corners and a soft shadow; bars with rounded ends and small gaps; filled points with a
   ring. The drawing is on a canvas, so the script reads its font, colours and shapes from here: the
   other designs change these tokens, never a property a Style control writes. */
.hafe-chart {
	/* The colours the Style tab leaves alone: the accent first, then hues checked to stay apart for
	   colour-blind readers next to each other, and against the card (docs/widgets/chart.md). */
	--hafe-chart-default-1: var(--hafe-accent);
	--hafe-chart-default-2: #c27a1c;
	--hafe-chart-default-3: #4f6bd8;
	--hafe-chart-default-4: #c4546b;
	--hafe-chart-default-5: #3594ae;
	--hafe-chart-default-6: #7a5bc0;
	--hafe-chart-default-7: #8a8f3a;
	--hafe-chart-default-8: #4b5563;
	/* What gaps between shapes and rings round points show: the card. */
	--hafe-chart-paper: var(--hafe-chart-bg, var(--hafe-surface));
	--hafe-chart-frame: var(--hafe-line);
	--hafe-chart-rule: color-mix(in srgb, var(--hafe-ink) 10%, transparent);
	--hafe-chart-base: color-mix(in srgb, var(--hafe-ink) 28%, transparent);
	--hafe-chart-pad: 1.25rem;
	/* Shapes, in pixels: bar ends, the outline of a bar, the gap between shapes, a line's width, an
	   area's fill, hollow points (1) or filled (0), and dashed grid lines. */
	--hafe-chart-corner: 4;
	--hafe-chart-stroke: 0;
	--hafe-chart-gap: 2;
	--hafe-chart-width: 2;
	--hafe-chart-area: 0.18;
	--hafe-chart-tint: 1;
	--hafe-chart-hollow: 0;
	--hafe-chart-dash: 0;
	--hafe-chart-tip: var(--hafe-surface);
	--hafe-chart-tip-ink: var(--hafe-ink);
	--hafe-chart-tip-line: var(--hafe-line);
	--hafe-chart-tip-round: 10;
	box-sizing: border-box;
	margin: 0;
	padding: var(--hafe-chart-padding, var(--hafe-chart-pad));
	border: 1px solid var(--hafe-chart-border, var(--hafe-chart-frame));
	border-radius: var(--hafe-chart-radius, var(--hafe-radius));
	background: var(--hafe-chart-paper);
	box-shadow: var(--hafe-shadow);
	color: var(--hafe-ink);
	overflow-wrap: break-word;
}

@media (max-width: 767px) {

	.hafe-chart {
		--hafe-chart-pad: 1rem 0.75rem;
	}
}

/* The dark scheme: lighter steps of the same hues, checked against the dark card. */
.hafe-scheme-dark .hafe-chart {
	--hafe-chart-default-1: color-mix(in oklab, var(--hafe-accent) 72%, #fff);
	--hafe-chart-default-2: #e0a04a;
	--hafe-chart-default-3: #7f97ec;
	--hafe-chart-default-4: #e0778c;
	--hafe-chart-default-5: #8dcfe0;
	--hafe-chart-default-6: #a58de4;
	--hafe-chart-default-7: #b2b55c;
	--hafe-chart-default-8: #c2c8d2;
	--hafe-chart-rule: rgb(255 255 255 / 9%);
	--hafe-chart-base: rgb(255 255 255 / 28%);
	color-scheme: dark;
}

.hafe-chart__plot {
	display: flex;
	flex-direction: column;
	gap: 0.75em;
	height: var(--hafe-chart-height, 400px);
	/* Axis text reads smaller than the page's, and a theme's large text stays in proportion. */
	font-size: max(0.75em, 12px);
	color: var(--hafe-chart-text, var(--hafe-ink-soft));
}

.hafe-chart__plot--start,
.hafe-chart__plot--end {
	flex-direction: row;
	align-items: center;
}

/* Chart.js sizes the canvas from this box, whatever the legend leaves it. */
.hafe-chart__box {
	position: relative;
	flex: 1 1 0;
	align-self: stretch;
	min-width: 0;
	min-height: 0;
}

.hafe-chart .hafe-chart__legend {
	display: flex;
	flex: none;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.25em 1em;
	max-height: 50%;
	margin: 0;
	padding: 2px;
	overflow-y: auto;
	color: var(--hafe-chart-text, var(--hafe-ink));
	list-style: none;
}

.hafe-chart .hafe-chart__plot--start .hafe-chart__legend,
.hafe-chart .hafe-chart__plot--end .hafe-chart__legend {
	flex-direction: column;
	flex-wrap: nowrap;
	max-width: 40%;
	max-height: 100%;
}

.hafe-chart__legend li {
	margin: 0;
	padding: 0;
}

/* Specific enough to beat a theme's or kit's button styles, hover included. */
.hafe-chart .hafe-chart__toggle,
.hafe-chart .hafe-chart__toggle:hover,
.hafe-chart .hafe-chart__toggle:focus {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	min-height: 24px;
	margin: 0;
	padding: 0.1em 0.3em;
	border: 0;
	border-radius: 4px;
	background: none;
	box-shadow: none;
	color: inherit;
	font: inherit;
	letter-spacing: inherit;
	text-align: start;
	text-transform: none;
	text-decoration: none;
	cursor: pointer;
}

.hafe-chart .hafe-chart__toggle:hover {
	text-decoration: underline;
}

.hafe-chart .hafe-chart__toggle:focus-visible {
	outline: 2px solid var(--hafe-accent);
	outline-offset: 1px;
}

.hafe-chart .hafe-chart__toggle[aria-pressed="false"] {
	color: var(--hafe-chart-text, var(--hafe-ink-soft));
	text-decoration: line-through;
}

.hafe-chart__swatch {
	box-sizing: border-box;
	flex: none;
	width: 0.75em;
	height: 0.75em;
	border: 2px solid var(--hafe-chart-swatch);
	border-radius: var(--hafe-chart-dot, 50%);
	background: var(--hafe-chart-swatch-fill, var(--hafe-chart-swatch));
}

[aria-pressed="false"] > .hafe-chart__swatch {
	background: none;
}

/* Until it's drawn (when it comes into view), a canvas is 300px wide: kept inside its box, so a chart
   lower down doesn't widen a phone's page. */
.hafe-chart__canvas {
	display: block;
	max-width: 100%;
}

.hafe-chart__data--visible {
	margin-block-start: 1.25em;
	overflow-x: auto;
}

.hafe-chart__table {
	width: 100%;
	margin: 0;
	border: 0;
	border-collapse: collapse;
	font-variant-numeric: tabular-nums;
}

.hafe-chart .hafe-chart__table th,
.hafe-chart .hafe-chart__table td {
	padding: 0.5em 0.75em;
	border: 0;
	border-block-start: 1px solid var(--hafe-chart-table-border, var(--hafe-line));
	background: none;
	color: inherit;
	text-align: end;
	text-transform: none;
}

.hafe-chart .hafe-chart__table thead > tr > * {
	border-block-start: 0;
	background: var(--hafe-chart-head, color-mix(in srgb, var(--hafe-ink) 4%, var(--hafe-chart-paper)));
	font-weight: 600;
}

.hafe-chart .hafe-chart__table th:first-child,
.hafe-chart .hafe-chart__table tbody th {
	text-align: start;
}

.hafe-chart__caption,
.hafe-chart__data--sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* The script couldn't draw: the numbers are what's left. */
.hafe-chart.is-failed .hafe-chart__plot {
	display: none;
}

.hafe-chart.is-failed .hafe-chart__data--sr {
	position: static;
	width: auto;
	height: auto;
	margin: 0;
	overflow-x: auto;
	clip-path: none;
	white-space: normal;
}

@media (scripting: none) {

	.hafe-chart__plot {
		display: none;
	}

	.hafe-chart__data--sr {
		position: static;
		width: auto;
		height: auto;
		margin: 0;
		overflow-x: auto;
		clip-path: none;
		white-space: normal;
	}
}

@media print {

	.hafe-chart {
		break-inside: avoid;
		box-shadow: none;
	}
}
