/* ===== GOV.UK colourway + typography ===== */
:root {
	--bg: #f3f2f1;
	--panel: #ffffff;
	--text: #0b0c0c;
	--muted: #505a5f;
	--border: #b1b4b6;
	--accent: #1d70b8;
	--good: #00703c;
	--warn: #ffbf47;
	--bad: #d4351c;
	--mono: #0b0c0c;
	--focus-ring: rgba(29, 112, 184, .35);
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 19px/1.5 "GDS Transport", Arial, "Helvetica Neue", Helvetica, sans-serif;
}

h1 {
	font-weight: 700;
	font-size: 48px;
	line-height: 1.1;
	margin: 0 0 16px;
}

h2 {
	font-weight: 700;
	font-size: 36px;
	line-height: 1.2;
	margin: 0;
}

h3 {
	font-weight: 700;
	font-size: 24px;
	line-height: 1.25;
	margin: 0 0 8px;
}

h4 {
	font-weight: 700;
	font-size: 19px;
	line-height: 1.3;
	margin: 0 0 8px;
}

a {
	color: var(--accent);
}

a:hover {
	text-decoration: underline;
}

a:focus {
	outline: 3px solid var(--focus-ring);
}

.wrap {
	max-width: 1280px;
	margin: 0 auto;
	padding: 16px;
}

header.status {
	display: flex;
	gap: 12px;
	align-items: center;
	flex-wrap: wrap;
	border: 1px solid var(--border);
	padding: 10px 12px;
	background: var(--panel);
}

.sticky {
	position: sticky;
	top: 0;
	z-index: 100;
	background: rgba(243, 242, 241, .9);
	backdrop-filter: saturate(120%) blur(3px);
}

header.status h1 {
	font-size: 24px;
}

.tag {
	padding: 2px 8px;
	border-radius: 0;
	font-size: 16px;
	border: 1px solid var(--border);
	color: var(--text);
	background: #fff;
}

nav.toolbar {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	margin: 12px 0;
}

.btn {
	border: 2px solid var(--accent);
	background: var(--accent);
	color: #fff;
	padding: 8px 12px;
	border-radius: 0;
	cursor: pointer;
}

.btn.secondary {
	background: #fff;
	color: var(--accent);
}

.btn[disabled] {
	opacity: .45;
	cursor: not-allowed;
}

main {
	display: grid;
	grid-template-columns: 1.1fr .9fr;
	gap: 16px;
}

main>section {
	min-width: 0;
}

section {
	background: var(--panel);
	border: 1px solid var(--border);
	overflow: hidden;
}

section>header {
	padding: 12px 14px;
	border-bottom: 1px solid var(--border);
	background: #f8f8f8;
}

.content {
	padding: 14px;
}

.row {
	display: grid;
	grid-template-columns: 220px 1fr;
	gap: 10px;
	margin-bottom: 10px;
	align-items: center;
}

input,
textarea,
select {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--border);
	background: #fff;
	color: var(--text);
	font: inherit;
}

input:focus,
textarea:focus,
select:focus {
	outline: 3px solid var(--focus-ring);
	box-shadow: none;
	border-color: var(--accent);
}

.inline {
	display: flex;
	gap: 10px;
	align-items: center;
	flex-wrap: wrap;
}

.maxw-220 {
	max-width: 220px;
}

.mt-10 {
	margin-top: 10px;
}

.mb-6 {
	margin-bottom: 6px;
}

.bold {
	font-weight: 700;
}

.mono {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 16px;
	color: var(--mono);
}

.muted {
	color: var(--muted);
}

.small {
	font-size: 16px;
}

/* Fieldset & legend accessibility (visual hide) */
fieldset {
	border: 0;
	margin: 0;
	padding: 0;
}

.visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Score cards */
.score-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 8px;
	margin-top: 8px;
}

.score-card {
	background: #fff;
	border: 1px solid var(--border);
	padding: 8px 10px;
	display: grid;
	grid-template-rows: auto auto auto 1fr;
	gap: 6px;
	position: relative;
	min-width: 0;
}

.score-head {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 8px;
	min-width: 0;
}

.pill {
	border: 1px solid var(--border);
	padding: 2px 6px;
	color: var(--text);
	font-size: 14px;
	margin-left: 6px;
}

/* Meters */
meter {
	width: 100%;
	height: 12px;
}

meter::-webkit-meter-bar {
	background: #e5e6e7;
}

meter::-webkit-meter-optimum-value {
	background: var(--accent);
}

meter::-webkit-meter-suboptimum-value {
	background: var(--warn);
}

meter::-webkit-meter-even-less-good-value {
	background: var(--bad);
}

.spark {
	width: 100%;
	height: 34px;
	display: block;
}

/* Log */
.scroll {
	max-height: 360px;
	overflow: auto;
	border: 1px solid var(--border);
	background: #fff;
	padding: 10px;
}

pre {
	margin: 0;
	white-space: pre-wrap;
	word-break: break-word;
}

.ev {
	margin: 10px 0 14px 0;
}

.ev .hdr {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	background: #f3f2f1;
	border-left: 4px solid var(--accent);
	padding: 6px 8px;
	color: var(--text);
	font-size: 14px;
	font-weight: 700;
}

.code {
	margin-top: 6px;
	padding: 10px;
	background: #fff;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 13px;
	line-height: 1.45;
	white-space: pre;
	overflow-x: auto;
	border: 1px solid var(--border);
}

/* Motor map + legends */
/* The row that holds the two KPI cards */
.flex.gap-6 {
	display: flex;
	flex-wrap: nowrap;
	/* donâ€™t drop to next line */
	gap: 1.5rem;
}

/* Each KPI card shares space and can shrink */
.kpi {
	background: #fff;
	border: 1px solid var(--border);
	padding: 8px 10px;
	flex: 1 1 0;
	min-width: 0;
	/* allow shrinking without overflow */
}

/* Canvases canâ€™t overflow their boxes */
.kpi canvas,
#path-preview,
#nd-scatter {
	display: block;
	max-width: 100%;
	height: auto;
	/* maintain aspect unless you set a fixed height */
	box-sizing: border-box;
}

/* Two-column layout: motor map (fluid) + live debug (fixed) */
.kpi-row{
  display:grid;
  grid-template-columns:minmax(0,1fr) 320px; /* left grows, right fixed */
  gap:24px;
  align-items:start;
}

/* Stack on smaller screens */
@media (max-width: 1100px){
  .kpi-row{ grid-template-columns:1fr; }
}

/* Prevent overflow: canvases fill card but don't stretch the row */
.kpi, .motor-map, figure { min-width:0; }
.motor-map canvas,
.kpi canvas,
#nd-scatter,
#path-preview{
  display:block;
  width:100%;      /* obey the cardâ€™s width */
  height:auto;     /* keep aspect ratio; JS will set DPR transform */
  max-width:100%;
}

/* Optional: keep the right card from growing */
.kpi-row > .kpi:last-child{ width:100%; max-width: 320px; }

.flex {
	display: flex;
}

.items-center {
	align-items: center;
}

.justify-between {
	justify-content: space-between;
}

.gap-6 {
	gap: 12px;
}

.motor-map {
	display: block;
}

.motor-figure {
	width: 100%;
}

.fullwidth-canvas {
	width: 100%;
	display: block;
	height: 260px;
}

/* optional: tighten the thresholds block spacing under the canvas */
.nd-thresholds {
	margin-top: 10px;
}

.legend {
	font-size: 14px;
	color: var(--muted);
}

.sw {
	display: inline-block;
	width: 10px;
	height: 10px;
	margin-right: 6px;
	border-radius: 2px;
	vertical-align: middle;
}

.good {
	background: var(--good);
}

.warn {
	background: var(--warn);
}

.bad {
	background: var(--bad);
}

.dob-fieldset {
	border: 0;
	padding: 0;
	margin: 0;
}

.dob-inputs {
	display: flex;
	gap: 12px;
	align-items: flex-end;
	flex-wrap: wrap;
}

.dob-item {
	display: grid;
	gap: 6px;
}

.dob__input--dd {
	width: 3.5rem;
}

/* 2 chars */
.dob__input--mm {
	width: 3.5rem;
}

/* 2 chars */
.dob__input--yyyy {
	width: 5.5rem;
}

/* 4 chars */
.dob__input.invalid {
	outline: 2px solid #d92c2c;
}

/* Address results */
.address-results {
	margin-top: 6px;
	border: 1px solid var(--border);
	overflow: hidden;
	background: #fff;
}

.address-results[hidden] {
	display: none;
}

.address-results li {
	padding: 8px 10px;
	border-top: 1px solid var(--border);
	cursor: pointer;
}

.address-results li:hover {
	background: #f3f2f1;
}

/* Responsiveness & overflow safety */
canvas {
	max-width: 100%;
	height: auto;
}

figure {
	margin: 0;
}

@media (max-width:1024px) {
	main {
		grid-template-columns: 1fr;
	}

	.row {
		grid-template-columns: 1fr;
	}

	.motor-map {
		grid-template-columns: 1fr;
	}
}
