/* ============================================================
   Baker Donelson - Autonomous Vehicle State Guide (v2, second revision)
   Built to fill the height of its iframe exactly. No vh units
   are used inside this file - inside a frame, vh resolves
   against the frame, not the device.

   Recommended embed:
   <iframe src="av-state-guide-v2.html" width="95%" height="760"
           scrolling="no" frameborder="0"
           style="width:95%;height:clamp(560px,88vh,900px);border:0"></iframe>
   ============================================================ */

html,
body {
	height: 100%;
	margin: 0;
	padding: 0;
	overflow: hidden; /* the panel is the only scroll context */
	background: #ffffff;
}

.av-guide {
	--av-teal: #006983;
	--av-tier-1: #00485a;
	--av-tier-2: #5aa0b3;
	--av-tier-3: #cdd9dd;
	--av-tier-3-edge: #7d9199;
	--av-teal-dark: #00566b;
	--av-red: #d51b1e;
	--av-ink: #22272b;
	--av-muted: #5c6670;
	--av-rule: #d6dbdf;
	--av-panel-bg: #ffffff;
	--av-stroke: #ffffff;
	--av-font: Arial, Helvetica, "Helvetica Neue", sans-serif;

	font-family: var(--av-font);
	color: var(--av-ink);
	line-height: 1.5;
	box-sizing: border-box;
	height: 100%;
	max-width: 1180px;
	margin: 0 auto;
	padding: 10px;
	display: flex;
	flex-direction: column;
	position: relative; /* anchor for the mobile sheet */
}

.av-guide *,
.av-guide *::before,
.av-guide *::after {
	box-sizing: inherit;
}

/* ---------- Two-column shell ---------- */

.av-layout {
	flex: 1 1 auto;
	min-height: 0; /* lets children shrink instead of overflowing */
	display: grid;
	grid-template-columns: minmax(0, 1.75fr) minmax(330px, 1fr);
	grid-template-rows: auto minmax(0, 1fr);
	/* Explicit areas. The picker is a direct child of the grid so it
	   can move above the map on small screens, which means placement
	   must be stated - auto-placement would push the panel to row 2. */
	grid-template-areas:
		"map picker"
		"map panel";
	column-gap: 22px;
	row-gap: 10px;
	/* The panel's height is set in script to match the map column. */
	align-items: start;
}

/* ---------- Left column: map ---------- */

.av-map-col {
	grid-area: map;
	min-width: 0;
	min-height: 0;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
}

.av-map-wrap {
	flex: 0 1 auto;
	min-height: 0;
	display: flex;
	justify-content: center;
	overflow: hidden;
}

/* The SVG scales to whatever box it is given, in both axes. */
.av-map-wrap svg {
	width: 100%;
	height: auto;
	max-height: 100%;
	object-fit: contain;
	display: block;
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
	touch-action: manipulation;
}

.av-state {
	fill: var(--av-teal);
	stroke: var(--av-stroke);
	stroke-width: 0.8;
	stroke-linejoin: round;
	cursor: pointer;
	outline: none;
	transition: filter 120ms ease-in-out;
}

/* Tier fills. Edit the variables above to retheme; edit
   av-tiers-v2.js to move a state between tiers. */
.av-state.av-tier-1 {
	fill: var(--av-tier-1);
}

.av-state.av-tier-2 {
	fill: var(--av-tier-2);
}

.av-state.av-tier-3 {
	fill: var(--av-tier-3);
	/* The pale fill would otherwise vanish into the white page at the
	   outer edge of the map, so this tier carries its own outline. */
	stroke: var(--av-tier-3-edge);
	stroke-width: 0.7;
}

.av-state:hover {
	filter: brightness(1.12);
}

/* The selected state keeps its tier colour - recolouring it would
   destroy the information the map exists to show - so selection is
   marked with a halo instead. */
.av-state.is-selected {
	stroke: #ffffff;
	stroke-width: 2.2;
	filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.85));
}

.av-state:focus-visible {
	stroke: #ffd400;
	stroke-width: 2.2;
}

.av-label {
	fill: var(--av-ink);
	font-family: var(--av-font);
	font-size: 10px;
	font-weight: bold;
	text-anchor: middle;
	dominant-baseline: middle;
	pointer-events: none;
}

/* Dark tier takes white labels; the two lighter tiers take dark
   labels. Every combination clears 4.5:1. */
.av-label-1 {
	fill: #ffffff;
}

.av-label-2,
.av-label-3 {
	fill: var(--av-ink);
}

.av-legend {
	flex: 0 0 auto;
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 14px;
	margin: 12px 2px 0;
	padding-top: 12px;
	border-top: 1px solid var(--av-rule);
}

.av-legend-item {
	min-width: 0;
	font-size: 12px;
	color: var(--av-muted);
	line-height: 1.45;
}

.av-legend-head {
	display: flex;
	align-items: center;
	gap: 7px;
	font-weight: bold;
	color: var(--av-ink);
	margin-bottom: 3px;
}

.av-legend-desc {
	display: block;
}

.av-legend-key {
	display: inline-block;
	width: 14px;
	height: 14px;
	flex: 0 0 auto;
	border: 1px solid rgba(0, 0, 0, 0.25);
}

.av-legend-key.av-tier-1 {
	background: var(--av-tier-1);
}

.av-legend-key.av-tier-2 {
	background: var(--av-tier-2);
}

.av-legend-key.av-tier-3 {
	background: var(--av-tier-3);
}

.av-map-hint {
	flex: 0 0 auto;
	color: var(--av-muted);
	font-size: 12px;
	margin: 8px 2px 0;
}

/* ---------- Right column: detail panel ---------- */

.av-panel-col {
	grid-area: panel;
	min-width: 0;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.av-picker {
	grid-area: picker;
	flex: 0 0 auto;
	align-self: end;
}

.av-picker label {
	display: block;
	font-size: 12px;
	font-weight: bold;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--av-muted);
	margin-bottom: 4px;
}

.av-picker-row {
	display: flex;
	gap: 8px;
}

.av-picker-row select {
	flex: 1 1 auto;
	min-width: 0;
}

/* Desktop shows the key in the resting panel, so the control is
   only needed where the panel is off-screen until it is opened. */
.av-key-btn {
	display: none;
	flex: 0 0 auto;
	font-family: var(--av-font);
	font-size: 15px;
	white-space: nowrap;
	color: var(--av-teal-dark);
	background: #fff;
	border: 1px solid var(--av-rule);
	padding: 0 12px;
	cursor: pointer;
	border-radius: 0;
}

.av-key-btn:focus-visible {
	outline: 2px solid var(--av-teal);
	outline-offset: 1px;
}

.av-picker select {
	width: 100%;
	font-family: var(--av-font);
	font-size: 14px;
	color: var(--av-ink);
	padding: 7px 9px;
	border: 1px solid var(--av-rule);
	background: #fff;
	border-radius: 0;
}

.av-picker select:focus-visible {
	outline: 2px solid var(--av-teal);
	outline-offset: 1px;
}

.av-panel {
	flex: 1 1 auto;
	min-height: 0;
	border: 1px solid var(--av-rule);
	background: var(--av-panel-bg);
	display: flex;
	flex-direction: column;
}

.av-panel-head {
	flex: 0 0 auto;
	background: var(--av-teal);
	color: #fff;
	padding: 11px 14px;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	column-gap: 10px;
	row-gap: 9px;
}

.av-panel-heading {
	order: 1;
}

.av-panel-close {
	order: 2;
}

.av-panel-break[hidden] {
	display: none;
}

.av-panel-break {
	order: 3;
	flex: 0 0 100%;
	height: 0;
	margin: 0;
}

.av-panel-tier {
	order: 4;
}

.av-reset-btn {
	order: 5;
	margin-left: auto;
}

.av-panel-heading {
	flex: 1 1 auto;
	min-width: 0;
	flex-wrap: wrap;
	display: flex;
	align-items: baseline;
	gap: 9px;
}

.av-panel-abbr {
	flex: 0 0 auto;
	font-size: 12px;
	font-weight: bold;
	letter-spacing: 0.08em;
	opacity: 0.75;
}

.av-panel-title {
	font-size: 19px;
	font-weight: bold;
	margin: 0;
	line-height: 1.2;
	color: #fff;
	overflow-wrap: break-word;
}

.av-panel-tier {
	flex: 0 0 auto;
	font-size: 11px;
	font-weight: bold;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	padding: 4px 8px;
	border-radius: 2px;
	white-space: nowrap;
}

.av-panel-tier[hidden] {
	display: none;
}



.av-panel-tier.av-tier-1 {
	background: #ffffff;
	color: var(--av-tier-1);
}

.av-panel-tier.av-tier-2 {
	background: var(--av-tier-2);
	color: var(--av-ink);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.av-panel-tier.av-tier-3 {
	background: var(--av-tier-3);
	color: var(--av-ink);
}

.av-panel-btn {
	flex: 0 0 auto;
	font-family: var(--av-font);
	font-size: 12px;
	line-height: 1;
	color: #fff;
	background: transparent;
	border: 1px solid rgba(255, 255, 255, 0.5);
	padding: 7px 9px;
	cursor: pointer;
	border-radius: 2px;
}

.av-panel-btn:hover {
	background: rgba(255, 255, 255, 0.15);
}

.av-panel-btn:focus-visible {
	outline: 2px solid #ffd400;
	outline-offset: 1px;
}

.av-panel-btn[hidden] {
	display: none;
}

.av-reset-btn {
	font-weight: bold;
}

.av-panel-close {
	display: none; /* mobile sheet only */
}

.av-panel-body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	padding: 15px 17px 20px;
	font-size: 14px;
	scrollbar-gutter: stable;
	scrollbar-color: #a8b4bb #eef1f2;
	scrollbar-width: thin;
}

.av-panel-body::-webkit-scrollbar {
	width: 12px;
}

.av-panel-body::-webkit-scrollbar-track {
	background: #eef1f2;
}

.av-panel-body::-webkit-scrollbar-thumb {
	background: #a8b4bb;
	border: 3px solid #eef1f2;
	border-radius: 6px;
}

.av-panel-body::-webkit-scrollbar-thumb:hover {
	background: var(--av-teal);
}

.av-panel-body p {
	margin: 0 0 14px;
}

.av-panel-body p:last-child {
	margin-bottom: 0;
}

.av-panel-body strong {
	color: var(--av-teal-dark);
}

.av-panel-body p + p {
	border-top: 1px solid var(--av-rule);
	padding-top: 14px;
}

.av-panel-empty {
	color: var(--av-muted);
	font-size: 14px;
}

.av-panel-empty p {
	margin: 0 0 10px;
}

.av-key-onmobile {
	display: none;
}

.av-tier-key {
	margin: 0;
	border-top: 1px solid var(--av-rule);
}

.av-tier-key dt {
	display: flex;
	align-items: center;
	gap: 7px;
	font-weight: bold;
	color: var(--av-ink);
	font-size: 13px;
	margin-top: 10px;
}

.av-tier-key dd {
	margin: 3px 0 10px 21px;
	font-size: 12.5px;
	color: var(--av-muted);
}

.av-tier-group {
	margin-top: 16px;
	padding-top: 12px;
	border-top: 1px solid var(--av-rule);
}

.av-tier-group-head {
	display: flex;
	align-items: center;
	gap: 7px;
	margin: 0 0 7px;
	font-size: 13px;
	font-weight: bold;
	color: var(--av-ink);
}

.av-tier-count {
	margin-left: auto;
	font-size: 11px;
	font-weight: normal;
	color: var(--av-muted);
}

.av-goto-list {
	display: flex;
	flex-wrap: wrap;
	gap: 5px 6px;
}

.av-goto {
	font-family: var(--av-font);
	font-size: 12.5px;
	line-height: 1;
	color: var(--av-teal-dark);
	background: #f2f6f7;
	border: 1px solid var(--av-rule);
	border-radius: 2px;
	padding: 5px 7px;
	cursor: pointer;
}

.av-goto:hover {
	background: var(--av-teal);
	border-color: var(--av-teal);
	color: #fff;
}

.av-goto:focus-visible {
	outline: 2px solid var(--av-teal);
	outline-offset: 1px;
}

.av-panel-empty strong {
	display: block;
	color: var(--av-ink);
	font-size: 16px;
	margin-bottom: 6px;
}

.av-sr-status {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

/* ---------- Mobile: panel becomes a sheet over the map ---------- */

@media (max-width: 860px) {
	.av-guide {
		padding: 8px;
	}

	.av-layout {
		grid-template-columns: 1fr;
		grid-template-rows: auto minmax(0, 1fr);
		grid-template-areas:
			"picker"
			"map";
		column-gap: 0;
		row-gap: 10px;
	}

	/* The dropdown is the real interface at this width, so it
	   sits above the map rather than beside it. */
	.av-picker {
		align-self: auto;
	}

	.av-map-col {
		min-height: 0;
	}

	.av-map-hint {
		display: none;
	}

	/* Not enough width for three columns of prose beside a phone-sized
	   map, so the definitions collapse to chips here and move into the
	   panel, which the Map key button opens. */
	.av-legend {
		display: flex;
		flex-wrap: wrap;
		gap: 6px 16px;
		margin-top: 10px;
		padding-top: 10px;
	}

	.av-legend-desc {
		display: none;
	}

	.av-legend-head {
		margin-bottom: 0;
	}

	.av-key-onmobile {
		display: block;
	}

	.av-goto {
		font-size: 14px;
		padding: 8px 10px;
	}

	.av-panel-col {
		position: absolute;
		inset: 0;
		z-index: 5;
		background: #fff;
		padding: 8px;
		transform: translateY(101%);
		visibility: hidden;
		transition: transform 220ms ease-out, visibility 0s linear 220ms;
	}

	.av-panel-col.is-open {
		transform: translateY(0);
		visibility: visible;
		transition: transform 220ms ease-out, visibility 0s;
	}

	.av-key-btn {
		display: block;
	}

	.av-panel-close {
		display: block;
	}

	/* Touch targets, and both header buttons at a matching size. */
	.av-panel-btn {
		font-size: 14px;
		padding: 9px 12px;
	}

	.av-panel-title {
		font-size: 18px;
	}

	.av-panel-body {
		font-size: 16px;
		line-height: 1.6;
		padding: 16px 16px 24px;
	}

	/* 16px stops iOS Safari zooming the frame on focus */
	.av-picker select {
		font-size: 16px;
		padding: 10px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.av-state {
		transition: none;
	}

	.av-panel-col {
		transition: none;
	}
}

/* ---------- Print ---------- */

@media print {
	html,
	body {
		height: auto;
		overflow: visible;
	}

	.av-guide {
		height: auto;
	}

	.av-layout {
		grid-template-columns: 1fr;
	}

	.av-panel-col {
		position: static;
		transform: none;
		visibility: visible;
	}

	.av-panel-body {
		overflow: visible;
	}

	.av-picker,
	.av-map-hint,
	.av-panel-tier {
	flex: 0 0 auto;
	font-size: 11px;
	font-weight: bold;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	padding: 4px 8px;
	border-radius: 2px;
	white-space: nowrap;
}

.av-panel-tier[hidden] {
	display: none;
}



.av-panel-tier.av-tier-1 {
	background: #ffffff;
	color: var(--av-tier-1);
}

.av-panel-tier.av-tier-2 {
	background: var(--av-tier-2);
	color: var(--av-ink);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.av-panel-tier.av-tier-3 {
	background: var(--av-tier-3);
	color: var(--av-ink);
}

.av-panel-btn {
		display: none;
	}
}
