/* Choropleth maps (js/choropleth.js). Colours for areas come from the script;
   everything else follows the app's theme tokens. */

.cp {
	--cp-hatch: #c3cad4;
	--cp-outside: #d4d8de;
	display: flex;
	flex-direction: column;
	height: 100%;
	min-height: 0;
	font-family: var(--font-body, 'Lato', Arial, Helvetica, sans-serif);
	color: var(--text);
}

[data-theme="dark"] .cp {
	--cp-hatch: #3a4753;
	--cp-outside: #262e38;
}

@media (prefers-color-scheme: dark) {
	[data-theme="system"] .cp {
		--cp-hatch: #3a4753;
		--cp-outside: #262e38;
	}
}

.cp-stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 140px;
}

.cp-map {
	position: absolute;
	inset: 0;
}

.cp .leaflet-container {
	background: var(--surface);
	font-family: inherit;
	outline-offset: -2px;
}

.cp-table-wrap {
	position: absolute;
	inset: 0;
	overflow: auto;
	background: var(--surface);
	z-index: 500;
}

/* Loading / empty / error */
.cp-status {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 16px;
	text-align: center;
	color: var(--text-muted);
	font-size: 13px;
	z-index: 600;
	pointer-events: none;
}

.cp-status[data-kind="loading"],
.cp-status[data-kind="error"] {
	background: var(--surface);
}

.cp-status[data-kind="empty"] span {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 8px 12px;
}

.cp-status button {
	pointer-events: auto;
}

.cp-spinner {
	width: 16px;
	height: 16px;
	border: 2px solid var(--border);
	border-top-color: var(--brand, #30afff);
	border-radius: 50%;
	animation: cp-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
	.cp-spinner { animation: none; }
}

/* Ctrl + scroll hint */
.cp-hint {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(15, 20, 26, 0.45);
	color: #fff;
	font-size: 15px;
	font-weight: 700;
	pointer-events: none;
	z-index: 700;
}

.cp-hint[hidden] {
	display: none;
}

/* Labels */
.cp-anchor {
	position: absolute;
	width: 0;
	height: 0;
}

.cp-label {
	position: absolute;
	left: 0;
	top: 0;
	transform: translate(-50%, -50%);
	white-space: nowrap;
	font-size: 11px;
	font-weight: 600;
	line-height: 1;
	pointer-events: none;
}

.cp-label--on-light {
	text-shadow: 0 0 2px rgba(255, 255, 255, 0.95), 0 0 3px rgba(255, 255, 255, 0.8);
}

.cp-label--on-dark {
	text-shadow: 0 0 2px rgba(0, 0, 0, 0.55);
}

.cp-label--you {
	background: var(--text-strong, #111);
	color: var(--surface);
	padding: 3px 7px;
	border-radius: 9px;
	font-weight: 700;
	box-shadow: 0 0 0 2px var(--surface);
}

/* Tooltip */
.leaflet-tooltip.cp-tip {
	background: var(--surface);
	color: var(--text);
	border: 1px solid var(--border);
	border-radius: 6px;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
	padding: 8px 10px;
	font-family: inherit;
	font-size: 12px;
	line-height: 1.35;
	white-space: nowrap;
}

.leaflet-tooltip-top.cp-tip::before {
	border-top-color: var(--surface);
}

.cp-tip-name {
	font-weight: 700;
	font-size: 13px;
	color: var(--text-strong, var(--text));
}

.cp-tip-value {
	font-weight: 700;
	font-size: 16px;
	margin: 2px 0;
	font-variant-numeric: tabular-nums;
}

.cp-tip-meta {
	color: var(--text-muted);
}

.cp-tip-you {
	display: inline-block;
	margin-left: 4px;
	padding: 1px 6px;
	border-radius: 8px;
	background: var(--text-strong, #111);
	color: var(--surface);
	font-size: 10px;
	font-weight: 700;
	vertical-align: 1px;
}

/* Controls */
.cp .leaflet-bar.cp-zoom {
	border: 1px solid var(--border);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
	border-radius: 6px;
	overflow: hidden;
}

.cp-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	background: var(--surface);
	color: var(--text);
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
}

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

.cp-zoom .cp-btn + .cp-btn {
	border-top: 1px solid var(--border);
}

.cp-zoom .cp-btn .fas {
	font-size: 12px;
}

.cp-btn:hover,
.cp-seg-btn:hover {
	background: var(--surface-2);
}

.cp-btn:focus-visible,
.cp-seg-btn:focus-visible,
.cp-link:focus-visible,
.cp-search-input:focus-visible {
	outline: 2px solid var(--brand-strong, #008aff);
	outline-offset: 1px;
}

.cp-tools {
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	align-items: center;
	gap: 6px;
}

.cp-seg {
	display: inline-flex;
	border: 1px solid var(--border);
	border-radius: 6px;
	overflow: hidden;
	background: var(--surface);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.cp-seg-btn {
	border: 0;
	background: var(--surface);
	color: var(--text-muted);
	font: inherit;
	font-size: 12px;
	font-weight: 600;
	padding: 6px 10px;
	cursor: pointer;
}

.cp-seg-btn + .cp-seg-btn {
	border-left: 1px solid var(--border);
}

.cp-seg-btn.is-active {
	background: var(--text-strong, #111);
	color: var(--surface);
}

.cp-search {
	display: inline-flex;
	align-items: center;
	border: 1px solid var(--border);
	border-radius: 6px;
	overflow: hidden;
	background: var(--surface);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.cp-search-input {
	display: none;
	width: 170px;
	border: 0;
	border-left: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	font: inherit;
	font-size: 12px;
	padding: 6px 8px;
}

.cp-search.is-open .cp-search-input {
	display: block;
}

/* Legend */
.cp-legend {
	flex: 0 0 auto;
	padding: 8px 2px 0;
	font-size: 12px;
	color: var(--text-muted);
}

.cp-legend-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 4px 10px;
	margin-bottom: 6px;
}

.cp-legend-title {
	font-weight: 700;
	color: var(--text);
}

.cp-legend-sub {
	font-size: 11px;
}

.cp-scale {
	max-width: 520px;
}

.cp-scale-bar {
	position: relative;
	display: flex;
	gap: 2px;
	height: 10px;
}

.cp-scale-step {
	position: relative;
	flex: 1 1 0;
}

.cp-scale-step:first-child {
	border-radius: 3px 0 0 3px;
}

.cp-scale-step:last-child {
	border-radius: 0 3px 3px 0;
}

.cp-scale-step--median {
	flex: 0 0 10px;
}

.cp-scale-you {
	position: absolute;
	left: 50%;
	bottom: 12px;
	transform: translateX(-50%);
	padding: 0 5px;
	border-radius: 7px;
	background: var(--text-strong, #111);
	color: var(--surface);
	font-size: 9px;
	font-weight: 700;
	line-height: 14px;
	white-space: nowrap;
}

.cp-scale-you::after {
	content: '';
	position: absolute;
	left: 50%;
	top: 100%;
	transform: translateX(-50%);
	border: 3px solid transparent;
	border-top-color: var(--text-strong, #111);
}

.cp-legend:has(.cp-scale-you) .cp-legend-head {
	margin-bottom: 20px;
}

.cp-scale-ticks {
	display: flex;
	gap: 2px;
	margin-top: 3px;
	font-size: 11px;
	font-variant-numeric: tabular-nums;
}

.cp-scale-tick {
	flex: 1 1 0;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	text-align: center;
}

.cp-scale-ticks.is-compact .cp-scale-tick {
	visibility: hidden;
}

.cp-scale-ticks.is-compact .cp-scale-tick--end {
	visibility: visible;
	overflow: visible;
}

.cp-scale-ticks.is-compact .cp-scale-tick--end:first-child {
	text-align: left;
}

.cp-scale-ticks.is-compact .cp-scale-tick--end:last-child {
	text-align: right;
}

.cp-scale-poles {
	display: flex;
	justify-content: space-between;
	margin-top: 2px;
	font-size: 11px;
}

.cp-keys {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px 14px;
	margin-top: 6px;
}

.cp-key {
	display: inline-flex;
	align-items: center;
	gap: 5px;
}

.cp-sw {
	display: inline-block;
	width: 12px;
	height: 12px;
	border-radius: 2px;
	flex: 0 0 auto;
}

.cp-sw--nodata {
	background: repeating-linear-gradient(135deg, var(--surface) 0 2px, var(--cp-hatch) 2px 3.5px);
	box-shadow: inset 0 0 0 1px var(--border);
}

.cp-sw--you {
	border: 2px solid var(--text-strong, #111);
	background: transparent;
}

.cp-sw--ring {
	border: 2px solid;
	background: transparent;
}

.cp-note {
	color: var(--text-muted);
}

.cp-attrib {
	margin-top: 4px;
	font-size: 10px;
	color: var(--text-subtle, #94a3b8);
}

.cp-link {
	border: 0;
	background: none;
	padding: 0;
	font: inherit;
	color: var(--brand-strong, #008aff);
	cursor: pointer;
}

.cp-link:hover {
	text-decoration: underline;
}

.cp--static .cp-link {
	display: none;
}

/* Table view */
.cp-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}

.cp-table caption {
	text-align: left;
	font-weight: 700;
	padding: 8px 10px;
	color: var(--text);
}

.cp-table th,
.cp-table td {
	padding: 6px 10px;
	border-bottom: 1px solid var(--border);
	text-align: left;
}

.cp-table th {
	position: sticky;
	top: 0;
	background: var(--surface-2);
	font-size: 12px;
	color: var(--text-muted);
}

.cp-table .num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.cp-table tr.is-own td {
	font-weight: 700;
	background: var(--surface-3);
}

.cp-muted {
	color: var(--text-muted);
	font-weight: 400;
}

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

.cp-message {
	padding: 16px;
	color: var(--text-muted);
}

/* Narrow maps (phones, small dashboard widgets): smaller controls. */
.cp {
	container: cp / inline-size;
}

@container cp (max-width: 520px) {
	.cp-seg-btn {
		padding: 4px 7px;
		font-size: 11px;
	}

	.cp-btn {
		width: 26px;
		height: 26px;
		font-size: 14px;
	}

	.cp-search-input {
		width: 130px;
	}
}
