/**
 * Election results (ADR-136 §7, TMS-1146): the hub, contest pages and the homepage strip.
 * Enqueued only on those pages (`tms_news_elections_enqueue_assets()`). Tokens with light fallbacks;
 * the two literal pairs are the Live chip (the `.tms-flag--breaking` red, 4.8:1 in both schemes) and
 * the Certified chip's dark values. Party is a bordered letter, never a colour fill: the series colours follow
 * ballot order, and red is not one of them, so no two candidates read as Democrat and Republican. Nothing animates.
 */

.tms-elections {
	--tms-elections-share: 0;
}

/* ── Status line and chips ───────────────────────────────────────────────── */

.tms-elections__status {
	align-items: baseline;
	color: var(--tms-color-muted, #6b7280);
	display: flex;
	flex-wrap: wrap;
	font-size: 0.875rem;
	gap: 0.35rem 0.75rem;
	margin: 0.75rem 0 0;
}

.tms-elections__live {
	background: #dc2626;
	border: 1px solid #dc2626;
	border-radius: 3px;
	color: #fff;
	font-size: 0.6875rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	padding: 0.15rem 0.45rem;
	text-transform: uppercase;
}

.tms-elections__live--paused,
.tms-elections__live--counting,
.tms-elections__live--upcoming {
	background: var(--tms-color-surface, #f7f7f7);
	border-color: var(--tms-color-border, #e5e7eb);
	color: var(--tms-color-text, #111);
}

.tms-elections__live--certified {
	background: var(--tms-color-text, #111);
	border-color: var(--tms-color-text, #111);
	color: var(--tms-color-background, #fff);
}

@media (prefers-color-scheme: dark) {
	.tms-elections__live--certified {
		background: #f9fafb;
		border-color: #f9fafb;
		color: #0b1120;
	}
}

.tms-elections__updated,
.tms-elections__quiet,
.tms-elections__cadence {
	font-family: var(--tms-font-list, inherit);
}

.tms-elections__notice {
	background: var(--tms-color-surface, #f7f7f7);
	border-left: 3px solid var(--tms-color-border, #e5e7eb);
	color: var(--tms-color-text, #111);
	flex-basis: 100%;
	margin: 0.25rem 0 0;
	padding: 0.5rem 0.75rem;
}

.tms-elections__notice--no-local {
	margin: 1.5rem 0 0;
}

.tms-elections__explainer {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.9375rem;
	margin: 0.5rem 0 0;
	max-width: 60ch;
}

.tms-elections__unofficial {
	font-style: normal;
	font-weight: 700;
	text-decoration: underline;
}

/* ── Sections and grids ──────────────────────────────────────────────────── */

.tms-elections__jump {
	margin-top: 1.25rem;
}

.tms-elections__section {
	margin-top: 2.5rem;
	scroll-margin-top: 5rem;
}

.tms-elections__section-header {
	align-items: baseline;
	display: flex;
	gap: 1rem;
	justify-content: space-between;
}

.tms-elections__count {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.8125rem;
	margin: 0;
}

.tms-elections__grid {
	display: grid;
	gap: 1.5rem 2rem;
	margin-top: 1rem;
}

.tms-elections__grid--2 {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tms-elections__grid--3,
.tms-elections__grid--dense {
	grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tms-elections__group {
	margin-top: 1.75rem;
}

.tms-elections__group-title {
	font-size: 1.125rem;
	margin: 0;
}

.tms-elections__group-site {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.8125rem;
	font-weight: 400;
}

.tms-elections__more {
	margin-top: 1rem;
}

.tms-elections__more-summary {
	align-items: center;
	cursor: pointer;
	display: flex;
	font-weight: 600;
	min-height: 44px;
}

/* ── Race card ───────────────────────────────────────────────────────────── */

.tms-elections__race {
	border-top: 2px solid var(--tms-color-border, #e5e7eb);
	min-width: 0;
	padding-top: 1rem;
}

.tms-elections__race--full {
	border-top-color: var(--tms-color-accent, #b91c1c);
}

.tms-elections__race--called,
.tms-elections__race--certified {
	border-top-color: var(--tms-color-text, #111);
}

.tms-elections__race-kicker {
	color: var(--tms-color-accent, #b91c1c);
	font-size: 0.75rem;
	font-weight: var(--tms-weight-label, 600);
	letter-spacing: 0.08em;
	margin: 0;
	text-transform: uppercase;
}

.tms-elections__threshold {
	color: var(--tms-color-text, #111);
	letter-spacing: 0;
	margin-left: 0.35rem;
	text-transform: none;
}

.tms-elections__race-title {
	font-family: var(--tms-font-headline, inherit);
	font-size: 1.3rem;
	line-height: 1.2;
	margin: 0.25rem 0 0.75rem;
}

.tms-elections__race--full .tms-elections__race-title,
.tms-elections__race--page .tms-elections__race-title {
	font-size: clamp(1.35rem, 2vw, 1.6rem);
}

.tms-elections__race-title a {
	color: inherit;
	text-decoration: none;
}

.tms-elections__race-title a:hover,
.tms-elections__race-title a:focus-visible {
	text-decoration: underline;
}

.tms-elections__call {
	font-weight: 700;
	margin: -0.5rem 0 0.75rem;
}

.tms-elections__cands {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tms-elections__cand {
	align-items: baseline;
	column-gap: 0.75rem;
	display: grid;
	font-family: var(--tms-font-list, inherit);
	font-variant-numeric: tabular-nums;
	grid-template-areas:
		"name party votes pct"
		"mark mark mark mark";
	grid-template-columns: minmax(0, 1fr) auto auto auto;
	padding: 0.4rem 0;
}

.tms-elections__cand-name {
	grid-area: name;
	overflow-wrap: anywhere;
}

.tms-elections__cand--leading .tms-elections__cand-name,
.tms-elections__cand--winner .tms-elections__cand-name {
	font-weight: 700;
}

.tms-elections__inc {
	border: 1px solid var(--tms-color-border, #e5e7eb);
	border-radius: 50%;
	color: var(--tms-color-muted, #6b7280);
	display: inline-block;
	font-size: 0.625rem;
	line-height: 1rem;
	text-align: center;
	width: 1rem;
}

.tms-elections__party {
	border: 1px solid currentColor;
	border-radius: 3px;
	font-size: 0.6875rem;
	font-weight: 700;
	grid-area: party;
	padding: 0 0.3rem;
}

.tms-elections__votes {
	grid-area: votes;
	text-align: right;
}

.tms-elections__pct {
	font-weight: 700;
	grid-area: pct;
	min-width: 3.5rem;
	text-align: right;
}

.tms-elections__mark {
	color: var(--tms-color-accent, #b91c1c);
	font-size: 0.75rem;
	font-weight: 700;
	grid-area: mark;
}

.tms-elections__mark:empty {
	display: none;
}

/* The precinct bar is a quiet progress line, not a fourth vote bar: thin, and half-strength in both schemes. */
.tms-elections__precincts-bar {
	background: var(--tms-color-surface-alt, #f1f5f9);
	display: block;
	height: 3px;
	margin-top: 0.3rem;
}

.tms-elections__bar-fill {
	background: var(--tms-color-muted, #6b7280);
	display: block;
	height: 100%;
	opacity: 0.55;
	width: calc(var(--tms-elections-share) * 100%);
}

/* ── Head-to-head bar and measure meter (TMS-1261) ─────────────────────────
 * One bar per race: every candidate's share side by side, adding to 100%, in the swatch colour beside their
 * name; a measure's Yes and No with the passing line drawn on it. The sentence under it carries the number. */

.tms-elections__swatch {
	border-radius: 2px;
	display: inline-block;
	height: 0.6rem;
	margin-right: 0.4rem;
	vertical-align: 0.05em;
	width: 0.6rem;
}

.tms-elections__swatch--s1 { background: var(--tms-elections-s1); }
.tms-elections__swatch--s2 { background: var(--tms-elections-s2); }
.tms-elections__swatch--s3 { background: var(--tms-elections-s3); }
.tms-elections__swatch--s4 { background: var(--tms-elections-s4); }
.tms-elections__swatch--s5 { background: var(--tms-elections-s5); }
.tms-elections__swatch--s6 { background: var(--tms-elections-s6); }

.tms-elections__swatch--other {
	background: var(--tms-color-border, #d1d5db);
}

.tms-elections__bar-box {
	margin-top: 0.6rem;
}

.tms-elections__bars {
	display: flex;
	gap: 2px;
	height: 12px;
	position: relative;
}

.tms-elections__seg {
	display: block;
	flex: var(--tms-elections-share) 1 0;
	min-width: 2px;
}

.tms-elections__seg--s1 { background: var(--tms-elections-s1); }
.tms-elections__seg--s2 { background: var(--tms-elections-s2); }
.tms-elections__seg--s3 { background: var(--tms-elections-s3); }
.tms-elections__seg--s4 { background: var(--tms-elections-s4); }
.tms-elections__seg--s5 { background: var(--tms-elections-s5); }
.tms-elections__seg--s6 { background: var(--tms-elections-s6); }

.tms-elections__seg--other {
	background: var(--tms-color-border, #d1d5db);
}

.tms-elections__meter-line {
	background: var(--tms-color-text, #111);
	bottom: -4px;
	left: calc(var(--tms-elections-share) * 100% - 1px);
	position: absolute;
	top: -4px;
	width: 2px;
}

.tms-elections__margin {
	font-family: var(--tms-font-list, inherit);
	font-size: 0.875rem;
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	margin: 0.45rem 0 0;
}

.tms-elections__race--compact .tms-elections__cand {
	grid-template-areas: "name party pct" "mark mark mark";
	grid-template-columns: minmax(0, 1fr) auto auto;
}

.tms-elections__race--compact .tms-elections__votes {
	display: none;
}

.tms-elections__race-footer {
	color: var(--tms-color-muted, #6b7280);
	font-family: var(--tms-font-list, inherit);
	font-size: 0.8125rem;
	margin-top: 0.75rem;
}

.tms-elections__precincts,
.tms-elections__credit {
	margin: 0.3rem 0 0;
}

.tms-elections__precincts-bar {
	margin: 0 0 0.3rem;
}

.tms-elections__lag {
	font-style: italic;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */

.tms-elections__table-wrap {
	margin-top: 1rem;
	overflow-x: auto;
}

.tms-elections__table {
	border-collapse: collapse;
	font-size: 0.9375rem;
	font-variant-numeric: tabular-nums;
	width: 100%;
}

.tms-elections__table th,
.tms-elections__table td {
	border-bottom: 1px solid var(--tms-color-border, #e5e7eb);
	padding: 0.55rem 0.75rem;
	text-align: left;
}

.tms-elections__table thead th {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.6875rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.tms-elections__table .tms-elections__num {
	text-align: right;
}

.tms-elections__table-pct {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.8125rem;
}

.tms-elections__row--total th,
.tms-elections__row--total td {
	border-top: 2px solid var(--tms-color-text, #111);
	font-weight: 700;
}

/* ── Local sites links ───────────────────────────────────────────────────── */

.tms-elections__links {
	display: grid;
	gap: 1.5rem 2rem;
	grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
	margin-top: 1rem;
}

.tms-elections__links-heading {
	font-size: 1rem;
	margin: 0 0 0.5rem;
}

.tms-elections__links-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tms-elections__links-list li {
	padding: 0.2rem 0;
}

/* ── Homepage strip ──────────────────────────────────────────────────────── */

.tms-elections--strip {
	background: var(--tms-color-surface, #f7f7f7);
	border-top: 3px solid var(--tms-color-accent, #b91c1c);
	margin: 1.5rem 0;
	padding: 18px 22px 20px;
}

.tms-elections__strip-header {
	align-items: baseline;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1rem;
}

.tms-elections__strip-title {
	align-items: center;
	display: flex;
	font-size: 1.25rem;
	gap: 0.5rem;
	margin: 0;
}

.tms-elections--strip .tms-elections__status {
	margin: 0;
}

.tms-elections__strip-more {
	font-weight: 600;
	margin-left: auto;
}

.tms-elections__credit--strip {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.8125rem;
	margin-top: 1rem;
}

/* ── The race timeline, "How the count came in" (TMS-1260) ────────────────
 * A plain SVG drawn by inc/elections-timeline.php (and rebuilt by elections-refresh.js). Line colours follow
 * ballot order among the drawn leaders, never party (two Democrats can meet in a top-two race); the rest are
 * muted. The viewBox scales with the column; text keeps its size through the SVG's font-size. */

.tms-elections {
	/* Validated as a set for colour-blind separation (TMS-1261). Some sit under 3:1 on white, so every series
	 * is named in text beside it (the swatch's candidate, the chart's label); the labels themselves stay ink. */
	--tms-elections-s1: #2a78d6;
	--tms-elections-s2: #eb6834;
	--tms-elections-s3: #1baf7a;
	--tms-elections-s4: #eda100;
	--tms-elections-s5: #e87ba4;
	--tms-elections-s6: #008300;
}

@media (prefers-color-scheme: dark) {
	.tms-elections {
		--tms-elections-s1: #3987e5;
		--tms-elections-s2: #d95926;
		--tms-elections-s3: #199e70;
		--tms-elections-s4: #c98500;
		--tms-elections-s5: #d55181;
		--tms-elections-s6: #008300;
	}
}

.tms-elections__timeline {
	border-top: 2px solid var(--tms-color-border, #e5e7eb);
	margin: 1.5rem 0 0;
	padding-top: 0.75rem;
}

.tms-elections__timeline-head {
	margin-bottom: 0.5rem;
}

.tms-elections__timeline-title {
	display: block;
	font-family: var(--tms-font-headline, inherit);
	font-size: 1.125rem;
	font-weight: 700;
}

.tms-elections__timeline-lede {
	color: var(--tms-color-text, #111);
	font-size: 0.9375rem;
}

.tms-elections__timeline-svg {
	display: block;
	height: auto;
	overflow: visible;
	width: 100%;
}

.tms-elections__timeline-svg--page {
	font-family: var(--tms-font-list, inherit);
	font-size: 11px;
	max-width: 760px;
}

.tms-elections__timeline-svg text {
	fill: var(--tms-color-muted, #6b7280);
	font-variant-numeric: tabular-nums;
}

.tms-elections__timeline-grid {
	stroke: var(--tms-color-border, #e5e7eb);
	stroke-width: 1;
}

.tms-elections__timeline-break {
	stroke: var(--tms-color-muted, #6b7280);
	stroke-dasharray: 2 3;
	stroke-width: 1;
}

.tms-elections__timeline-threshold {
	stroke: var(--tms-color-text, #111);
	stroke-dasharray: 5 4;
	stroke-width: 1;
}

.tms-elections__timeline-line {
	fill: none;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-width: 2.5;
	vector-effect: non-scaling-stroke;
}

.tms-elections__timeline-line--other {
	stroke: var(--tms-color-border, #d1d5db);
	stroke-width: 1.5;
}

.tms-elections__timeline-line--s1 { stroke: var(--tms-elections-s1); }
.tms-elections__timeline-line--s2 { stroke: var(--tms-elections-s2); }
.tms-elections__timeline-line--s3 { stroke: var(--tms-elections-s3); }
.tms-elections__timeline-line--s4 { stroke: var(--tms-elections-s4); }
.tms-elections__timeline-line--s5 { stroke: var(--tms-elections-s5); }
.tms-elections__timeline-line--s6 { stroke: var(--tms-elections-s6); }

.tms-elections__timeline-mark {
	fill: var(--tms-color-background, #fff);
	stroke-width: 2.5;
}

.tms-elections__timeline-mark--s1 { stroke: var(--tms-elections-s1); }
.tms-elections__timeline-mark--s2 { stroke: var(--tms-elections-s2); }
.tms-elections__timeline-mark--s3 { stroke: var(--tms-elections-s3); }
.tms-elections__timeline-mark--s4 { stroke: var(--tms-elections-s4); }
.tms-elections__timeline-mark--s5 { stroke: var(--tms-elections-s5); }
.tms-elections__timeline-mark--s6 { stroke: var(--tms-elections-s6); }

.tms-elections__timeline-svg .tms-elections__timeline-label {
	font-weight: 600;
}

/* Labels wear the text colour; the line ending beside each one carries the series colour. */
.tms-elections__timeline-svg .tms-elections__timeline-label {
	fill: var(--tms-color-text, #111);
}

.tms-elections__timeline-svg .tms-elections__timeline-note {
	fill: var(--tms-color-text, #111);
}

.tms-elections__timeline-band-track {
	fill: var(--tms-color-surface-alt, #f1f5f9);
}

.tms-elections__timeline-band {
	fill: var(--tms-color-muted, #6b7280);
	fill-opacity: 0.45;
}

.tms-elections__spark {
	margin: 0.5rem 0 0;
}

.tms-elections__spark .tms-elections__timeline-svg {
	height: 36px;
	max-width: 160px;
}

.tms-elections__spark .tms-elections__timeline-line {
	stroke-width: 1.75;
}

.tms-elections__spark .tms-elections__timeline-line--other {
	stroke-width: 1;
}

/* ── Lead tracker, "Who's ahead, report by report" (TMS-1261) ──────────────── */

.tms-elections__lead-zero {
	stroke: var(--tms-color-text, #111);
	stroke-width: 1;
}

.tms-elections__lead-line {
	fill: none;
	stroke: var(--tms-color-text, #111);
	stroke-linejoin: round;
	stroke-width: 2;
	vector-effect: non-scaling-stroke;
}

.tms-elections__lead-dot {
	fill: var(--tms-color-text, #111);
}

.tms-elections__lead-dot--change {
	fill: var(--tms-color-background, #fff);
	stroke: var(--tms-color-accent, #b91c1c);
	stroke-width: 2.5;
}

.tms-elections__timeline-svg .tms-elections__lead-end {
	fill: var(--tms-color-text, #111);
	font-weight: 700;
}

/* ── Closest races (TMS-1261) ─────────────────────────────────────────────
 * Each row joins the runner-up's share (hollow) to the leader's (solid) on a 0–100% track with a 50% tick. */

.tms-elections__closest-note {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.8125rem;
	margin: 0 0 0.5rem;
}

.tms-elections__closest {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tms-elections__closest-row {
	align-items: center;
	border-top: 1px solid var(--tms-color-border, #e5e7eb);
	column-gap: 1rem;
	display: grid;
	font-family: var(--tms-font-list, inherit);
	font-variant-numeric: tabular-nums;
	grid-template-areas: "name track margin";
	grid-template-columns: minmax(0, 1.3fr) minmax(8rem, 1fr) minmax(0, 0.9fr);
	padding: 0.55rem 0;
}

.tms-elections__closest-name {
	color: inherit;
	font-weight: 600;
	grid-area: name;
	overflow-wrap: anywhere;
}

.tms-elections__closest-track {
	background: linear-gradient(var(--tms-color-border, #e5e7eb), var(--tms-color-border, #e5e7eb)) center / 100% 1px no-repeat;
	display: block;
	grid-area: track;
	height: 14px;
	position: relative;
}

.tms-elections__closest-track::after {
	background: var(--tms-color-border, #d1d5db);
	content: "";
	height: 10px;
	left: 50%;
	position: absolute;
	top: 2px;
	width: 1px;
}

.tms-elections__closest-gap {
	background: var(--tms-color-text, #111);
	height: 3px;
	left: calc(var(--tms-elections-from) * 100%);
	position: absolute;
	top: 5.5px;
	width: calc((var(--tms-elections-share) - var(--tms-elections-from)) * 100%);
	z-index: 1;
}

.tms-elections__closest-gap::before,
.tms-elections__closest-gap::after {
	border: 2px solid var(--tms-color-text, #111);
	border-radius: 50%;
	box-sizing: border-box;
	content: "";
	height: 11px;
	position: absolute;
	top: -4px;
	width: 11px;
}

.tms-elections__closest-gap::before {
	background: var(--tms-color-background, #fff);
	left: -5.5px;
}

.tms-elections__closest-gap::after {
	background: var(--tms-color-text, #111);
	right: -5.5px;
}

.tms-elections__closest-margin {
	font-size: 0.875rem;
	grid-area: margin;
}

/* ── Turnout so far (TMS-1261) ────────────────────────────────────────────
 * One bar from 0 to every registered voter, filled to the ballots counted. Ink, not a series colour: turnout is not a
 * candidate. */

.tms-elections__turnout {
	font-family: var(--tms-font-list, inherit);
	font-variant-numeric: tabular-nums;
	max-width: 40rem;
}

.tms-elections__turnout-figure {
	margin: 0 0 0.4rem;
}

.tms-elections__turnout-figure strong {
	font-size: 1.75rem;
	font-weight: 700;
	line-height: 1;
	margin-right: 0.25rem;
}

.tms-elections__turnout-track {
	background: var(--tms-color-surface-alt, #f1f5f9);
	border-radius: 3px;
	display: block;
	height: 10px;
	overflow: hidden;
}

.tms-elections__turnout-fill {
	background: var(--tms-color-text, #111);
	display: block;
	height: 100%;
	width: calc(var(--tms-elections-share) * 100%);
}

.tms-elections__turnout-line {
	font-size: 0.875rem;
	margin: 0.45rem 0 0;
}

.tms-elections__turnout-note {
	color: var(--tms-color-muted, #6b7280);
	font-size: 0.8125rem;
	margin: 0.35rem 0 0;
}

/* ── Breakpoints: 960, 800, 640 ──────────────────────────────────────────── */

@media (max-width: 960px) {
	.tms-elections__grid--3,
	.tms-elections__grid--dense {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 800px) {
	.tms-elections__grid--2,
	.tms-elections__grid--3 {
		grid-template-columns: minmax(0, 1fr);
	}

	.tms-elections__jump {
		overflow-x: auto;
	}

	.tms-elections__strip-header {
		flex-direction: column;
	}

	.tms-elections__strip-more {
		margin-left: 0;
	}

	.tms-elections__table th:first-child {
		background: var(--tms-color-background, #fff);
		left: 0;
		position: sticky;
	}
}

@media (max-width: 640px) {
	.tms-elections__grid--dense {
		grid-template-columns: minmax(0, 1fr);
	}

	.tms-elections__closest-row {
		grid-template-areas: "name name" "track margin";
		grid-template-columns: minmax(6rem, 1fr) auto;
		row-gap: 0.35rem;
	}
}
