/* scverse repo-health dashboard.
 *
 * Colours come from the data-viz reference palette. The four status colours are the
 * reserved status slots (good / warning / serious / critical); they tint the cell
 * background while the glyph itself stays in primary ink, so status is never carried by
 * colour alone and every cell keeps text-grade contrast in both themes.
 */

:root {
	color-scheme: light;

	--surface-1: #fcfcfb;
	--plane: #f9f9f7;
	--text-primary: #0b0b0b;
	--text-secondary: #52514e;
	--muted: #898781;
	--gridline: #e1e0d9;
	--baseline: #c3c2b7;
	--border: rgba(11, 11, 11, 0.1);
	--accent: #2a78d6;

	--good: #0ca30c;
	--warning: #fab219;
	--serious: #ec835a;
	--critical: #d03b3b;

	--tint-pass: color-mix(in srgb, var(--good) 20%, var(--surface-1));
	--tint-fail: color-mix(in srgb, var(--critical) 24%, var(--surface-1));
	--tint-warn: color-mix(in srgb, var(--warning) 32%, var(--surface-1));
	--tint-unknown: color-mix(in srgb, var(--muted) 22%, var(--surface-1));
	--tint-na: var(--surface-1);

	--radius: 4px;
	--cell: 1.7rem;
	/* Column labels are set at 45°, so the header only needs sin(45°) ≈ 0.71 of the
	 * longest label's length — this fits half again as much text as the vertical labels
	 * it replaces, which is why nothing has to be truncated. It is still finite, though:
	 * `test_check_titles_fit_the_rotated_header` holds titles to what this clears. */
	--head-height: 13rem;
	--font: system-ui, -apple-system, "Segoe UI", sans-serif;
	--mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
	:root:where(:not([data-theme="light"])) {
		color-scheme: dark;
		--surface-1: #1a1a19;
		--plane: #0d0d0d;
		--text-primary: #ffffff;
		--text-secondary: #c3c2b7;
		--muted: #898781;
		--gridline: #2c2c2a;
		--baseline: #383835;
		--border: rgba(255, 255, 255, 0.1);
		--accent: #3987e5;
		--tint-pass: color-mix(in srgb, var(--good) 26%, var(--surface-1));
		--tint-fail: color-mix(in srgb, var(--critical) 30%, var(--surface-1));
		--tint-warn: color-mix(in srgb, var(--warning) 26%, var(--surface-1));
		--tint-unknown: color-mix(in srgb, var(--muted) 26%, var(--surface-1));
	}
}

:root[data-theme="dark"] {
	color-scheme: dark;
	--surface-1: #1a1a19;
	--plane: #0d0d0d;
	--text-primary: #ffffff;
	--text-secondary: #c3c2b7;
	--muted: #898781;
	--gridline: #2c2c2a;
	--baseline: #383835;
	--border: rgba(255, 255, 255, 0.1);
	--accent: #3987e5;
	--tint-pass: color-mix(in srgb, var(--good) 26%, var(--surface-1));
	--tint-fail: color-mix(in srgb, var(--critical) 30%, var(--surface-1));
	--tint-warn: color-mix(in srgb, var(--warning) 26%, var(--surface-1));
	--tint-unknown: color-mix(in srgb, var(--muted) 26%, var(--surface-1));
}

* {
	box-sizing: border-box;
}

/* The filters toggle `hidden` on rows and cells. Table elements carry a `display` from
 * their own rules, which would otherwise out-specify the UA `[hidden]` rule. */
[hidden] {
	display: none !important;
}

body {
	margin: 0;
	padding: 0 1.5rem 4rem;
	background: var(--plane);
	color: var(--text-primary);
	font-family: var(--font);
	font-size: 15px;
	line-height: 1.5;
}

a {
	color: var(--accent);
}
a:hover {
	text-decoration-thickness: 2px;
}
code {
	font-family: var(--mono);
	font-size: 0.9em;
}

.masthead {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	padding: 1.5rem 0 1rem;
}
.masthead h1 {
	margin: 0;
	font-size: 1.35rem;
	letter-spacing: -0.01em;
}
.masthead h1 a {
	color: inherit;
	text-decoration: none;
}
.subtitle {
	margin: 0.25rem 0 0;
	color: var(--text-secondary);
	max-width: 62ch;
}

.ghost {
	font: inherit;
	color: var(--text-secondary);
	background: var(--surface-1);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 0.3rem 0.7rem;
	cursor: pointer;
}
.ghost:hover {
	color: var(--text-primary);
	border-color: var(--baseline);
}

/* -- stat tiles ------------------------------------------------------------------ */

.tiles {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
	gap: 0.75rem;
	margin: 0 0 1.25rem;
}
.tile {
	background: var(--surface-1);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 0.75rem 0.9rem;
}
.tile-label {
	color: var(--text-secondary);
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.tile-value {
	font-size: 1.9rem;
	line-height: 1.15;
	font-weight: 600;
}
.tile.hero .tile-value {
	font-size: 2.6rem;
}
.tile-value .unit {
	font-size: 0.55em;
	color: var(--text-secondary);
	margin-left: 0.1em;
}
.tile-note {
	color: var(--muted);
	font-size: 0.82rem;
}

/* -- legend & controls ------------------------------------------------------------ */

.legend,
.controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 0.85rem;
	margin-bottom: 0.75rem;
	color: var(--text-secondary);
	font-size: 0.85rem;
}
.legend .sep,
.controls .sep {
	width: 1px;
	height: 1.1rem;
	background: var(--baseline);
}
.legend abbr {
	border-bottom: 1px dotted var(--baseline);
	cursor: help;
	text-decoration: none;
}

.controls input[type="search"],
.controls select {
	font: inherit;
	color: var(--text-primary);
	background: var(--surface-1);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 0.3rem 0.5rem;
	min-width: 12rem;
}
.controls .check {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	cursor: pointer;
}
.controls .count {
	margin-left: auto;
	color: var(--muted);
	font-variant-numeric: tabular-nums;
}

/* -- the matrix -------------------------------------------------------------------- */

.matrix-scroll {
	overflow: auto;
	max-height: 85vh;
	background: var(--surface-1);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

table.matrix {
	border-collapse: separate;
	border-spacing: 0;
	font-size: 0.85rem;
	/* A 45° label overhangs its own column to the right by as much as it rises, so the
	 * last few need that much gutter or `.matrix-scroll` clips them. Padding applies
	 * here only because the collapse mode is `separate`. */
	padding-right: var(--head-height);
}

table.matrix th,
table.matrix td {
	padding: 0;
}

.matrix thead th {
	position: sticky;
	top: 0;
	z-index: 3;
	background: var(--surface-1);
	border-bottom: 1px solid var(--gridline);
}
.matrix thead tr:nth-child(2) th {
	top: 1.9rem;
}

.matrix .corner {
	left: 0;
	/* Above every column header — labels and group titles both — so what slides underneath
	 * it during horizontal scroll is hidden rather than drawn across the repository names. */
	z-index: 200;
	min-width: 15rem;
	text-align: left;
	padding: 0 0.6rem;
	vertical-align: bottom;
	color: var(--text-secondary);
	/* Names from data: matched to the group dividers, since it is the boundary that matters
	 * most and should not read as the weaker of the two. */
	border-right: 2px solid var(--muted);
}

.matrix .colgroup {
	height: 1.9rem;
	/* Also above the labels: if one ever outgrows the header — bigger text, a longer
	 * title — it gets cut off cleanly at this band instead of running over the titles. */
	z-index: 100;
	/* Every band cell starts a group, so this is the `.group-start` rule by another name. */
	border-left: 2px solid var(--muted);
	font-size: 0.78rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-secondary);
}
.colgroup-toggle {
	font: inherit;
	color: inherit;
	background: none;
	border: 0;
	cursor: pointer;
	padding: 0.2rem 0.4rem;
	white-space: nowrap;
}
.colgroup-toggle:hover {
	color: var(--text-primary);
}
.colgroup-toggle .chevron {
	display: inline-block;
	transition: transform 0.15s;
}

.matrix .colhead {
	height: var(--head-height);
	width: var(--cell);
	min-width: var(--cell);
	/* Every header cell is opaque, so without an explicit order each one would paint over
	 * the label overhanging from its left-hand neighbour and only the last column's label
	 * would survive. The template counts `--z` down across the row, left to right. */
	z-index: var(--z, 3);
	vertical-align: bottom;
	font-weight: 400;
	color: var(--text-secondary);
}
/* Each label starts on its own column's centre line and ascends to the right at 45°.
 * Adjacent labels stay `--cell` × sin(45°) ≈ 19px apart measured across the diagonal,
 * which clears the 13px text, so they never collide however long they get. The header
 * cell is already `position: sticky`, which is what this is positioned against. */
.matrix .colhead .rot {
	position: absolute;
	bottom: 0.3rem;
	left: 50%;
	transform-origin: 0 100%;
	transform: rotate(-45deg);
	display: flex;
	align-items: center;
	gap: 0.4rem;
	white-space: nowrap;
	line-height: 1.2;
	cursor: help;
}
/* The tier is its own token, not the first letter of the title, so it gets a box and a
 * gap rather than sitting flush against the text. Weight ramps down with importance —
 * filled, outlined, bare — which reads before the letter does and, unlike a ramp of three
 * fills, holds up in both themes. The legend shows the same three badges. */
.tier {
	flex: none;
	display: inline-block;
	min-width: 1.2em;
	padding: 0 0.15em;
	border: 1px solid transparent;
	border-radius: 3px;
	font-family: var(--mono);
	font-size: 0.75rem;
	font-weight: 700;
	line-height: 1.35;
	text-align: center;
}
.tier[data-tier="required"] {
	background: color-mix(in srgb, var(--baseline) 55%, var(--surface-1));
	color: var(--text-primary);
}
.tier[data-tier="recommended"] {
	border-color: var(--baseline);
	color: var(--text-secondary);
}
.tier[data-tier="informational"] {
	color: var(--muted);
}

.matrix tr.section th {
	position: sticky;
	left: 0;
	text-align: left;
	padding: 0.45rem 0.6rem;
	background: var(--plane);
	border-top: 1px solid var(--gridline);
	border-bottom: 1px solid var(--gridline);
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.matrix .rowhead {
	position: sticky;
	left: 0;
	z-index: 2;
	background: var(--surface-1);
	text-align: left;
	font-weight: 400;
	padding: 0 0.6rem;
	border-right: 2px solid var(--muted);
	border-bottom: 1px solid var(--gridline);
	white-space: nowrap;
}
.matrix tbody tr:hover .rowhead {
	background: var(--plane);
}
.matrix .rowhead .score {
	color: var(--muted);
	font-variant-numeric: tabular-nums;
	font-size: 0.8em;
	margin-left: 0.4rem;
}

.matrix td.cell {
	width: var(--cell);
	min-width: var(--cell);
	height: var(--cell);
	text-align: center;
	border-bottom: 1px solid var(--gridline);
	border-left: 1px solid var(--gridline);
}

/* Where one check group ends and the next begins. The rotated labels can't carry this — a
 * full-height rule through the header would cut across the labels leaning over it — so the
 * group band draws it above and the cells draw it below, and the eye joins them up.
 *
 * `--muted` rather than the `--baseline` the other rules use: against the status tints a
 * baseline-weight line reads as just another gridline, and being the one grey that is the
 * same in both themes, it holds up on either surface. */
.matrix :is(th, td).group-start {
	border-left-width: 2px;
	border-left-color: var(--muted);
}

/* Glyph carries the meaning; the tint is the redundant channel. */
.glyph {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: var(--cell);
	color: var(--text-primary);
	text-decoration: none;
	font-weight: 600;
	cursor: help;
}
a.glyph {
	cursor: pointer;
}
a.glyph:hover,
.glyph:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: -2px;
}

.s-pass {
	background: var(--tint-pass);
}
.s-fail {
	background: var(--tint-fail);
}
.s-warn {
	background: var(--tint-warn);
}
.s-unknown {
	background: var(--tint-unknown);
	color: var(--text-secondary);
}
.s-na {
	background: var(--tint-na);
	color: var(--muted);
}

.legend .glyph {
	width: 1.6rem;
	border-radius: var(--radius);
}

/* Week-over-week movement, when a previous results.json was supplied. */
.changed-regressed {
	box-shadow: inset 0 0 0 2px var(--critical);
}
.changed-fixed {
	box-shadow: inset 0 0 0 2px var(--good);
}

/* Collapsing swaps a group's columns for a single summary column. These selectors have to
 * be pinned to cells: `data-group` is also on the toggle button *inside* each group
 * header, so the unqualified version hid the expander along with the columns, leaving a
 * collapsed group with no way back other than "Expand all groups". */
.matrix :is(th, td).collapsed-only {
	display: none;
}
.matrix.has-collapsed :is(th, td)[data-group].is-collapsed {
	display: none;
}
.matrix.has-collapsed :is(th, td).collapsed-only[data-group].is-collapsed {
	display: table-cell;
}

/* -- per-repo page -------------------------------------------------------------------- */

.lede {
	color: var(--text-secondary);
	max-width: 70ch;
}
.pill {
	background: var(--tint-unknown);
	border-radius: 999px;
	padding: 0.05rem 0.5rem;
	font-size: 0.8rem;
}

.facts {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem 2rem;
	margin: 0 0 1.5rem;
}
.facts div {
	display: flex;
	flex-direction: column;
}
.facts dt {
	color: var(--muted);
	font-size: 0.78rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.facts dd {
	margin: 0;
}

.checkgroup {
	margin-bottom: 2rem;
}
.checkgroup h2 {
	font-size: 0.85rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-secondary);
	margin-bottom: 0.4rem;
}

table.detail,
table.catalogue {
	width: 100%;
	border-collapse: collapse;
	background: var(--surface-1);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font-size: 0.88rem;
}
table.detail th,
table.detail td,
table.catalogue th,
table.catalogue td {
	text-align: left;
	padding: 0.45rem 0.6rem;
	border-bottom: 1px solid var(--gridline);
	vertical-align: top;
}
table.detail thead th,
table.catalogue thead th {
	color: var(--text-secondary);
	font-weight: 500;
	font-size: 0.8rem;
}
table.detail .st {
	width: 2rem;
	padding: 0;
}
table.detail .st .glyph {
	border-radius: 0;
}
table.detail .tier-col {
	color: var(--text-secondary);
	white-space: nowrap;
}
.muted {
	color: var(--muted);
	font-size: 0.85em;
}

/* -- footer ------------------------------------------------------------------------------ */

.footnotes {
	margin-top: 2rem;
}
.footnotes details {
	border-top: 1px solid var(--gridline);
	padding: 0.6rem 0;
}
.footnotes summary {
	cursor: pointer;
	color: var(--text-secondary);
}
.reasons {
	margin: 0.6rem 0 0;
	padding-left: 1.1rem;
	color: var(--text-secondary);
}
.reasons li {
	margin-bottom: 0.15rem;
}

.colophon {
	margin-top: 2.5rem;
	padding-top: 1rem;
	border-top: 1px solid var(--gridline);
	color: var(--muted);
	font-size: 0.82rem;
}
.colophon p {
	margin: 0.25rem 0;
}
.colophon .glyph {
	display: inline-flex;
	width: 1.4rem;
	height: 1.2rem;
	vertical-align: middle;
}

.empty {
	color: var(--text-secondary);
	padding: 1.5rem 0;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

@media print {
	.controls,
	.ghost,
	.matrix-scroll {
		max-height: none;
		overflow: visible;
	}
	body {
		background: #fff;
	}
}
