:root {
	--bg: #f3f5f8;
	--surface: #ffffff;
	--surface-alt: #f8fafc;
	--header-bg: #22262a;
	--border: #dde3ea;
	--text: #1f2937;
	--text-muted: #5b6573;
	--accent: #f97316;
	--accent-dark: #ea580c;
	--accent-soft: #fff7ed;
	--green: #16a34a;
	--green-bright: #22c55e;
	--orange: #ea580c;
	--danger: #dc2626;
	--radius: 10px;
	--shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

*, *::before, *::after {
	box-sizing: border-box;
}

body {
	margin: 0;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--text);
	background: var(--bg);
	line-height: 1.45;
}

/* Header */
.site-header {
	background: var(--header-bg);
	border-bottom: 3px solid var(--accent);
	color: #fff;
}

.header-inner {
	max-width: 1440px;
	margin: 0 auto;
	padding: 0.65rem 1.25rem 0.45rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
}

.header-sub {
	max-width: 1440px;
	margin: 0 auto;
	padding: 0 1.25rem 0.65rem;
}

.site-subheading {
	margin: 0;
	font-size: 0.98rem;
	font-weight: 500;
	color: #e5e7eb;
}

.brand {
	display: flex;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
}

#imactivatelogo {
	height: 44px;
	width: auto;
	display: block;
}

.badge {
	display: inline-flex;
	align-items: center;
	padding: 0.25rem 0.65rem;
	border-radius: 999px;
	font-size: 0.78rem;
	font-weight: 600;
	background: rgba(249, 115, 22, 0.16);
	color: #fdba74;
	border: 1px solid rgba(249, 115, 22, 0.35);
}

.region-picker {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.region-picker label {
	font-size: 0.85rem;
	font-weight: 600;
	color: #d1d5db;
}

.region-picker select {
	background: #31373d;
	color: #fff;
	border: 1px solid #4b5563;
	border-radius: 7px;
	padding: 0.45rem 0.75rem;
	font-size: 0.9rem;
	font-weight: 600;
	cursor: pointer;
}

.region-picker select:focus {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
}

/* Main container */
.container {
	max-width: 1440px;
	margin: 1rem auto 3rem;
	padding: 0 1.25rem;
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

/* Toolbar */
.toolbar {
	padding: 0.9rem 1rem;
	display: flex;
	align-items: flex-end;
	gap: 0.85rem;
	flex-wrap: wrap;
}

.toolbar-group {
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
}

.toolbar-group label {
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
}

.route-search-group {
	flex: 1 1 360px;
	min-width: 260px;
}

.route-combobox {
	display: flex;
	gap: 0.45rem;
}

.route-combobox input {
	flex: 0 1 220px;
	min-width: 150px;
}

.route-combobox select {
	flex: 1 1 240px;
	min-width: 180px;
}

input[type="search"],
select {
	font: inherit;
	font-size: 0.88rem;
	padding: 0.45rem 0.65rem;
	border: 1px solid #cbd5e1;
	border-radius: 7px;
	background: #fff;
	color: var(--text);
}

input[type="search"]:focus,
select:focus {
	outline: 2px solid rgba(249, 115, 22, 0.35);
	border-color: var(--accent);
}

.toolbar-actions {
	display: flex;
	gap: 0.5rem;
	margin-left: auto;
}

.btn {
	font: inherit;
	font-size: 0.88rem;
	font-weight: 600;
	padding: 0.48rem 0.95rem;
	border-radius: 7px;
	border: 1px solid transparent;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
	white-space: nowrap;
}

.btn:active {
	transform: translateY(1px);
}

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

.btn-primary:hover {
	background: var(--accent-dark);
}

.btn-secondary {
	background: #fff;
	color: var(--text);
	border-color: #cbd5e1;
}

.btn-secondary:hover {
	background: var(--surface-alt);
	border-color: #94a3b8;
}

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

.btn-sm {
	padding: 0.32rem 0.7rem;
	font-size: 0.82rem;
}

/* Summary Strip / KPIs */
.hint-banner {
	background: var(--accent-soft);
	border: 1px solid #fed7aa;
	color: #7c2d12;
	padding: 0.65rem 1rem;
	border-radius: var(--radius);
	font-size: 0.9rem;
}

.kpi-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
	gap: 0.75rem;
}

.kpi-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 0.75rem 1rem;
	box-shadow: var(--shadow);
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}

.kpi-label {
	font-size: 0.74rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
}

.kpi-value {
	font-size: 1.45rem;
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
}

.kpi-title-val {
	font-size: 1.02rem;
	font-weight: 700;
	color: var(--text);
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.kpi-sub {
	font-size: 0.78rem;
	color: var(--text-muted);
}

.accent-green { color: var(--green); }
.accent-orange { color: var(--orange); }

/* Map Section */
.map-section {
	overflow: hidden;
}

#map {
	width: 100%;
	height: 620px;
	position: relative;
	background: #e5e7eb;
}

.overlay {
	position: absolute;
	inset: 0;
	z-index: 1000;
	background: rgba(17, 24, 39, 0.58);
	backdrop-filter: blur(2px);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.85rem;
	color: #fff;
	font-weight: 600;
	font-size: 1.05rem;
}

.spinner {
	width: 38px;
	height: 38px;
	border: 4px solid rgba(255, 255, 255, 0.25);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to { transform: rotate(360deg); }
}

.progress-card {
	background: #1f2937;
	border: 1px solid var(--accent);
	border-radius: 12px;
	padding: 1.25rem 1.5rem;
	width: min(460px, 90%);
	display: flex;
	flex-direction: column;
	gap: 0.8rem;
}

.progress-title {
	color: #fdba74;
	font-size: 1rem;
}

.progress-track {
	height: 12px;
	background: #374151;
	border-radius: 999px;
	overflow: hidden;
}

.progress-fill {
	height: 100%;
	width: 0%;
	background: var(--accent);
	transition: width 0.1s linear;
}

.progress-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 0.9rem;
	font-variant-numeric: tabular-nums;
}

.toast {
	position: absolute;
	bottom: 1.25rem;
	left: 50%;
	transform: translateX(-50%);
	z-index: 1001;
	background: #1f2937;
	color: #fff;
	border: 1px solid var(--accent);
	padding: 0.6rem 1.15rem;
	border-radius: 999px;
	font-size: 0.9rem;
	font-weight: 600;
	box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

/* Layer Bar */
.layer-bar {
	padding: 0.7rem 1rem;
	background: var(--surface-alt);
	border-top: 1px solid var(--border);
	display: flex;
	align-items: center;
	gap: 0.65rem 1rem;
	flex-wrap: wrap;
}

.toggle-chip {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	font-size: 0.85rem;
	font-weight: 500;
	cursor: pointer;
	user-select: none;
}

.toggle-chip input {
	accent-color: var(--accent);
	width: 15px;
	height: 15px;
	cursor: pointer;
}

.dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	display: inline-block;
}

.dot-work { background: #ea580c; }
.dot-res { background: #16a34a; }
.dot-stop { background: #6b7280; }

/* Map Legend */
.map-legend {
	background: rgba(255, 255, 255, 0.94);
	padding: 0.55rem 0.75rem;
	border-radius: 8px;
	border: 1px solid var(--border);
	box-shadow: var(--shadow);
	font-size: 0.78rem;
	line-height: 1.5;
	color: var(--text);
}

.map-legend-row {
	display: flex;
	align-items: center;
	gap: 0.45rem;
}

/* Tables */
.data-section {
	padding: 0.95rem 1rem;
}

.section-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
	margin-bottom: 0.75rem;
}

.section-header h2 {
	margin: 0;
	font-size: 1.15rem;
}

.section-sub {
	margin: 0.2rem 0 0;
	font-size: 0.84rem;
	color: var(--text-muted);
}

.section-actions {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.input-sm {
	padding: 0.3rem 0.6rem !important;
	font-size: 0.82rem !important;
}

.table-wrap {
	overflow-x: auto;
	border: 1px solid var(--border);
	border-radius: 8px;
}

.table-wrap-scroll {
	max-height: 440px;
	overflow-y: auto;
}

.data-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.83rem;
	font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
	padding: 0.48rem 0.6rem;
	border-bottom: 1px solid var(--border);
	text-align: left;
	white-space: nowrap;
}

.data-table thead th {
	background: #22262a;
	color: #fff;
	font-weight: 600;
	position: sticky;
	top: 0;
	z-index: 2;
}

.data-table thead tr.sub-header th {
	background: var(--accent-dark);
	top: 31px;
	font-size: 0.76rem;
}

.data-table thead th[data-sort] {
	cursor: pointer;
	user-select: none;
}

.data-table thead th[data-sort]:hover {
	filter: brightness(1.15);
}

.data-table thead th.sort-asc::after { content: " ▲"; font-size: 0.7rem; }
.data-table thead th.sort-desc::after { content: " ▼"; font-size: 0.7rem; }

.data-table th.group-people { background: #15803d; text-align: center; }
.data-table th.group-jobs { background: #c2410c; text-align: center; }
.data-table th.group-rate { background: #1d4ed8; text-align: center; }

.data-table th.num,
.data-table td.num {
	text-align: right;
}

.data-table td.score-cell {
	font-weight: 700;
	color: #1e3a8a;
}

.data-table tbody tr:nth-child(even) {
	background: var(--surface-alt);
}

.data-table tbody tr.clickable-row {
	cursor: pointer;
}

.data-table tbody tr.clickable-row:hover {
	background: #ffedd5;
}

.data-table tbody tr.group-row {
	background: #fef3c7 !important;
	font-weight: 700;
	border-bottom: 2px solid var(--accent);
}

.data-table tbody tr.empty-row td {
	text-align: center;
	padding: 1.5rem;
	color: var(--text-muted);
}

.data-table.hide-social-grades .sg-col {
	display: none;
}

/* Keep the default 13-column Connectivity Ratings table cleanly visible without horizontal scroll on desktop */
#connectivityTable.hide-social-grades {
	font-size: 0.8rem;
}

#connectivityTable.hide-social-grades th,
#connectivityTable.hide-social-grades td {
	padding: 0.42rem 0.4rem;
}

#connectivityTable.hide-social-grades thead th.num {
	white-space: normal;
	line-height: 1.15;
}

.route-cell {
	max-width: 88px;
	overflow: hidden;
	text-overflow: ellipsis;
}

.route-cell .route-pill {
	max-width: 78px;
	overflow: hidden;
	text-overflow: ellipsis;
	vertical-align: middle;
}

.route-pill {
	display: inline-block;
	min-width: 2.1rem;
	text-align: center;
	padding: 0.13rem 0.42rem;
	border-radius: 5px;
	color: #fff;
	font-weight: 700;
	font-size: 0.77rem;
}

.type-badge {
	display: inline-block;
	padding: 0.1rem 0.4rem;
	border-radius: 999px;
	font-size: 0.72rem;
	font-weight: 600;
	border: 1px solid transparent;
}

.type-bus {
	background: #f1f5f9;
	color: #334155;
	border-color: #cbd5e1;
}

.type-tram {
	background: #ecfdf5;
	color: #047857;
	border-color: #a7f3d0;
}

.type-tube {
	background: #eff6ff;
	color: #1d4ed8;
	border-color: #bfdbfe;
}

.desc-cell {
	max-width: 195px;
	overflow: hidden;
	text-overflow: ellipsis;
}

.op-cell {
	max-width: 130px;
	overflow: hidden;
	text-overflow: ellipsis;
}

.region-cell {
	max-width: 96px;
	overflow: hidden;
	text-overflow: ellipsis;
}

@media (max-width: 1200px) {
	#connectivityTable.hide-social-grades th,
	#connectivityTable.hide-social-grades td {
		padding: 0.38rem 0.32rem;
		font-size: 0.77rem;
	}
	.route-cell { max-width: 74px; }
	.route-cell .route-pill { max-width: 66px; }
	.desc-cell { max-width: 155px; }
	.op-cell { max-width: 105px; }
	.region-cell { max-width: 82px; }
}

/* Popup button */
.popup-btn {
	margin-top: 0.45rem;
	display: inline-block;
	background: var(--accent);
	color: #fff;
	border: none;
	border-radius: 5px;
	padding: 0.25rem 0.55rem;
	font-size: 0.78rem;
	font-weight: 600;
	cursor: pointer;
}

.popup-btn:hover {
	background: var(--accent-dark);
}

/* Footer / Sources */
.sources {
	padding: 1.1rem 1.25rem;
}

.sources h2 {
	margin: 0 0 0.5rem;
	font-size: 1.05rem;
}

.methodology-note {
	margin: 0 0 0.8rem;
	font-size: 0.85rem;
	color: var(--text-muted);
	max-width: 96ch;
}

.source-list {
	margin: 0;
	padding-left: 1.2rem;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
	gap: 0.35rem 1.5rem;
	font-size: 0.85rem;
}

.source-list a {
	color: var(--accent-dark);
	text-decoration: none;
}

.source-list a:hover {
	text-decoration: underline;
}

.hidden {
	display: none !important;
}

/* Desaturated light-map style for OSM tiles so routes and census dots pop */
#map.map-muted-tiles .leaflet-tile-pane {
	filter: grayscale(88%) brightness(1.06) contrast(0.92);
}

@media (max-width: 768px) {
	#map { height: 460px; }
	.toolbar-actions { margin-left: 0; width: 100%; }
	.toolbar-actions .btn { flex: 1; }
	.route-combobox { flex-direction: column; }
	.route-combobox input,
	.route-combobox select { flex: 0 0 auto; width: 100%; }
	.layer-stats { margin-left: 0; width: 100%; }
}
