/* Dashboard 3-30-300 */

:root {
	--blue: #29587b;
	--hover: rgba(41, 88, 123, 0.08);
	--accent: #eef3f7;
	--shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
	--shadow-small: 0 2px 10px rgba(0, 0, 0, 0.16);
	--radius: 14px;
	--gap: 16px;
	--font: 'Overpass', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

[hidden] { display: none !important; }

html, body {
	height: 100%;
	margin: 0;
}

body {
	background: #fff;
	color: var(--blue);
	font-family: var(--font);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

button, input {
	color: inherit;
	font-family: inherit;
}

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

.back:hover,
.city-arrow:hover,
.legend-toggle:hover,
.legend-book:hover,
.legend-item:hover,
.box-close:hover,
.box-close:focus-visible { background: var(--hover); }

.back:focus-visible,
.city-link:focus-visible,
.city-arrow:focus-visible,
.citta-link:focus-visible {
	outline: 2px solid var(--blue);
	outline-offset: 2px;
}

.side-text a,
.map-info a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.side-text a:hover,
.side-text a:focus-visible,
.map-info a:hover,
.map-info a:focus-visible { text-decoration-thickness: 2px; }

.app {
	display: flex;
	flex-direction: column;
	gap: 14px;
	height: 100vh;
	height: 100dvh;
	padding: 16px 72px 20px;
}


/* ---------- Testata ---------- */

.top {
	display: flex;
	align-items: center;
	min-height: 38px;
}

.back {
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	margin: 0 8px 0 -6px;
	border-radius: 8px;
	color: var(--blue);
	transition: background-color 0.2s;
}

.cities {
	position: relative;
	display: flex;
	flex: 1;
	align-items: baseline;
	gap: clamp(8px, 1vw, 22px);
	min-width: 0;
	padding: 4px;
	overflow-x: auto;
	scrollbar-width: none;
	white-space: nowrap;
}

.cities::-webkit-scrollbar { display: none; }

.city-link {
	flex: none;
	color: var(--blue);
	font-size: clamp(11px, 0.9vw, 15px);
	font-weight: 700;
	letter-spacing: 0.06em;
	line-height: 1.2;
	text-decoration: none;
	text-transform: uppercase;
	opacity: 0.45;
	transition: opacity 0.2s;
}

.city-link:hover { opacity: 0.75; }

.city-link:focus-visible { border-radius: 4px; }

.city-link.is-active {
	font-size: 26px;
	font-weight: 800;
	opacity: 1;
}

.city-arrow {
	position: fixed;
	top: 50%;
	z-index: 5;
	display: grid;
	place-items: center;
	width: 44px;
	height: 64px;
	padding: 0;
	border: 0;
	border-radius: 12px;
	background: none;
	color: var(--blue);
	cursor: pointer;
	transform: translateY(-50%);
	transition: background-color 0.2s;
}

.city-prev { left: 14px; }
.city-next { right: 14px; }


/* ---------- Layout ---------- */

.layout {
	flex: 1;
	min-height: 0;
	display: grid;
	grid-template-columns: minmax(0, 1fr) clamp(280px, 24vw, 360px);
	gap: var(--gap);
}


/* ---------- Mappa ---------- */

.map-panel {
	position: relative;
	min-height: 0;
	overflow: hidden;
	border: 2px solid var(--blue);
	border-radius: var(--radius);
}

.map {
	position: absolute;
	inset: 0;
	--ol-background-color: #fff;
	--ol-accent-background-color: var(--accent);
	--ol-subtle-background-color: rgba(41, 88, 123, 0.12);
	--ol-partial-background-color: rgba(255, 255, 255, 0.85);
	--ol-foreground-color: var(--blue);
	--ol-subtle-foreground-color: var(--blue);
	--ol-brand-color: var(--blue);
}

.bw { filter: grayscale(100%); }

.map .ol-control {
	padding: 0;
	background: transparent;
	border-radius: 10px;
}

.map .ol-zoom { top: 14px; left: 14px; }
.map .ol-home { top: 98px; left: 14px; }
.map .ol-guida { top: 140px; left: 14px; }
.map .ol-info { top: 182px; left: 14px; }

.map .ol-zoom button,
.map .ol-home button,
.map .ol-info button,
.map .ol-guida button {
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	margin: 0 0 6px;
	border-radius: 10px;
	color: var(--blue);
	font-size: 22px;
	line-height: 1;
	box-shadow: var(--shadow-small);
	cursor: pointer;
}

.map .zoom-glyph { display: block; }
.map .zoom-glyph.is-in { transform: translateY(2.6px); }
.map .zoom-glyph.is-out { transform: translateY(1.25px); }

.map .ol-zoom button:hover,
.map .ol-zoom button:focus-visible,
.map .ol-home button:hover,
.map .ol-home button:focus-visible,
.map .ol-info button:hover,
.map .ol-info button:focus-visible,
.map .ol-info button[aria-expanded="true"],
.map .ol-guida button:hover,
.map .ol-guida button:focus-visible,
.map .ol-guida button[aria-expanded="true"] {
	background: var(--accent);
	outline: none;
}

.map .ol-attribution {
	right: 10px;
	bottom: 10px;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.85);
}

.map .ol-attribution ul {
	padding: 3px 8px 2px;
	color: var(--blue);
	font-size: 12px;
	text-shadow: none;
}

.map .ol-attribution a { color: var(--blue); }


/* ---------- Legenda ---------- */

.legend {
	--legend-col: 20px;
	position: absolute;
	left: 14px;
	bottom: 14px;
	z-index: 2;
	padding: 10px 18px 10px 12px;
	border-radius: 12px;
	background: #fff;
	box-shadow: var(--shadow);
	pointer-events: none;
}

.legend:empty { display: none; }

.legend.is-collapsed { padding: 4px; }

.legend .legend-group:first-of-type .legend-title { padding-right: 24px; }

.legend-toggle,
.legend-book {
	display: grid;
	place-items: center;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	pointer-events: auto;
	transition: background-color 0.2s;
}

.legend-toggle {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 26px;
	height: 26px;
	border-radius: 7px;
}

.legend-book {
	width: 40px;
	height: 40px;
	border-radius: 9px;
}

.legend-toggle:focus-visible,
.legend-book:focus-visible {
	outline: 2px solid var(--blue);
	outline-offset: 1px;
}

.legend-group + .legend-group {
	margin-top: 8px;
	padding-top: 6px;
	border-top: 1px solid var(--blue);
}

.legend-title {
	margin: 2px 0 4px;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.legend-item {
	display: grid;
	grid-template-columns: var(--legend-col) auto;
	align-items: center;
	column-gap: 10px;
	width: calc(100% + 12px);
	margin: 0 -6px;
	padding: 4px 6px;
	border: 0;
	border-radius: 7px;
	background: none;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.1;
	text-align: left;
	white-space: nowrap;
	cursor: pointer;
	pointer-events: auto;
	transition: background-color 0.2s, opacity 0.2s;
}

.legend-item > :first-child { justify-self: center; }

.legend-item:focus-visible {
	outline: 2px solid var(--blue);
	outline-offset: -1px;
}

.legend-item.is-active { background: rgba(41, 88, 123, 0.14); }

.legend-item.is-dimmed { opacity: 0.4; }

.legend-item.is-dimmed:hover { opacity: 0.75; }

.legend-item-size {
	font-size: 14px;
	font-weight: 600;
}

.legend-swatch {
	width: 18px;
	height: 18px;
	border: 2px solid;
	border-radius: 50%;
}

.legend-size circle {
	fill: none;
	stroke: var(--blue);
	stroke-width: 1.5;
}


/* ---------- Box sulla mappa: scheda al click, informazioni, guida ---------- */

.popup,
.map-info {
	background: #fff;
	box-shadow: var(--shadow);
}

.box-close {
	position: absolute;
	top: 8px;
	right: 8px;
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	cursor: pointer;
}


/* ---------- Scheda al click ---------- */

.popup {
	position: relative;
	width: max-content;
	min-width: 160px;
	max-width: min(320px, calc(100vw - 64px));
	padding: 12px 14px 8px;
	border: 2px solid var(--blue);
	border-radius: 12px;
}

.popup.is-edificio { min-width: min(240px, calc(100vw - 64px)); }

.popup::after {
	content: '';
	position: absolute;
	left: 50%;
	bottom: -9px;
	width: 14px;
	height: 14px;
	margin-left: -7px;
	border-right: 2px solid var(--blue);
	border-bottom: 2px solid var(--blue);
	background: #fff;
	transform: rotate(45deg);
}

.popup .box-close {
	top: 6px;
	right: 6px;
}

.popup-head {
	display: flex;
	align-items: center;
	gap: 10px;
}

.popup-head .legend-swatch { flex: none; }

.popup-head > div { flex: 1; }

.popup-title {
	padding-right: 26px;
	font-size: 18px;
	font-weight: 800;
	line-height: 1.1;
}

.popup-sub {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 4px;
	padding-right: 10px;
	font-size: 13px;
	font-weight: 500;
}

.popup-sub > :not(.popup-bar) { transform: translateY(2px); }

.popup-sub-valore { min-width: 24px; }

.popup-bar {
	flex: 1;
	min-width: 48px;
	height: 14px;
	overflow: hidden;
	border-radius: 7px;
	background: #cacaca;
}

.popup-bar span {
	display: block;
	height: 100%;
	border-radius: 7px;
	background: #e0e0e0;
}

.popup-list {
	margin: 10px 0 0;
	padding-top: 4px;
	border-top: 1px solid var(--blue);
}

.popup-list:first-child {
	margin-top: 0;
	padding: 0 30px 0 0;
	border-top: 0;
}

.popup-row {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 16px;
	padding: 5px 0;
	font-size: 14px;
	line-height: 1.2;
}

.popup-row dt { font-weight: 600; }

.popup-row dd {
	margin: 0;
	font-weight: 800;
	white-space: nowrap;
}


/* ---------- Informazioni (pulsante "i") e guida (pulsante "?") ---------- */

.map-info {
	position: absolute;
	top: 14px;
	left: 62px;
	z-index: 4;
	display: flex;
	flex-direction: column;
	width: min(640px, calc(100% - 76px));
	height: min(334px, calc(100% - 28px));
	padding: 14px 8px 6px 16px;
	border-radius: 12px;
	font-size: 14px;
	line-height: 1.5;
}

.map-info-title {
	margin: 0 28px 8px 0;
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.map-info-body {
	flex: 1;
	min-height: 0;
	overflow-y: scroll;
	padding-right: 8px;
}

.map-info p,
.map-info ul { margin: 0 0 10px; }

.map-info ul { padding-left: 20px; }

.map-info li { margin-bottom: 4px; }

.map-info-body::-webkit-scrollbar { width: 8px; }

.map-info-body::-webkit-scrollbar-track {
	border-radius: 4px;
	background: rgba(41, 88, 123, 0.1);
}

.map-info-body::-webkit-scrollbar-thumb {
	border-radius: 4px;
	background: rgba(41, 88, 123, 0.55);
}

.map-info-body::-webkit-scrollbar-thumb:hover { background: var(--blue); }

@supports not selector(::-webkit-scrollbar) {
	.map-info-body {
		scrollbar-width: thin;
		scrollbar-color: rgba(41, 88, 123, 0.55) rgba(41, 88, 123, 0.1);
	}
}

.map-guida {
	height: auto;
	max-height: calc(100% - 28px);
	overflow-y: auto;
	padding: 14px 16px 16px;
}

.guida-passo {
	display: grid;
	grid-template-columns: 80px 1fr;
	gap: 16px;
	align-items: center;
}

.guida-passo + .guida-passo { margin-top: 18px; }

.map-info .guida-passo p { margin: 0; }

.guida-passo img {
	justify-self: center;
	max-width: 100%;
	height: auto;
}

.guida-zoom { transform: translateX(12px); }
.guida-clic { transform: translateX(-8px); }


/* ---------- Caricamento ---------- */

.map-loading {
	position: absolute;
	top: 14px;
	right: 14px;
	z-index: 3;
	display: grid;
	place-items: center;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: #fff;
	box-shadow: var(--shadow-small);
	opacity: 0;
	transform: scale(0.8);
	transition: opacity 0.2s, transform 0.2s;
	pointer-events: none;
}

.map-loading.is-visible {
	opacity: 1;
	transform: none;
}

.spinner {
	width: 34px;
	height: 34px;
	border: 3px solid transparent;
	border-top-color: var(--blue);
	border-right-color: var(--blue);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

.spinner-small {
	width: 20px;
	height: 20px;
	border-width: 2.5px;
}

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


/* ---------- Pannello laterale ---------- */

.side {
	display: flex;
	flex-direction: column;
	gap: var(--gap);
	min-height: 0;
}

.switch {
	position: relative;
	z-index: 2;
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 6px;
	border: 2px solid var(--blue);
	border-radius: 12px;
	background: #fff;
}

.opt {
	position: relative;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 12px;
	border-radius: 10px;
	font-size: 18px;
	font-weight: 700;
	line-height: 1.1;
	cursor: pointer;
	user-select: none;
	opacity: 0.4;
	transition: color 0.2s, background-color 0.2s, opacity 0.2s;
}

.opt:hover { opacity: 0.7; background: rgba(41, 88, 123, 0.06); }

.opt.is-active,
.opt.is-active:hover {
	opacity: 1;
	color: #fff;
	background: var(--blue);
}

.opt input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.opt-dot {
	flex: none;
	width: 12px;
	height: 12px;
	border: 2px solid currentColor;
	border-radius: 50%;
	transition: background-color 0.2s;
}

.opt.is-active .opt-dot { background: #fff; }

.opt input:focus-visible ~ .opt-dot {
	outline: 2px solid var(--blue);
	outline-offset: 3px;
}

.side-text {
	flex: 1;
	min-height: 0;
	overflow: hidden;
	padding: 0 6px;
	font-size: 15px;
	line-height: 1.5;
	-webkit-mask-image: linear-gradient(to bottom, #000 85%, transparent);
	mask-image: linear-gradient(to bottom, #000 85%, transparent);
}

.side-text p { margin: 0 0 0.8em; }

.side-text strong { font-weight: 700; }


/* ---------- Grafici ---------- */

.chart-card {
	flex: none;
	aspect-ratio: 1 / 1;
	max-height: 60%;
	min-height: 0;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 0 6px 16px;
	border-radius: var(--radius);
	overflow: hidden;
}

.chart {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 560px;
	max-height: 560px;
	overflow: visible;
}

.chart .mark {
	cursor: pointer;
	outline: none;
	transition: opacity 0.2s;
}

.chart.has-focus .mark:not(.is-active) { opacity: 0.35; }

.chart.has-selection .mark:not(.is-selected),
.chart.has-selection .pie-label:not(.is-selected) { opacity: 0.35; }

.chart.has-selection .mark.is-active:not(.is-selected) { opacity: 0.7; }

.pie {
	transform-origin: 200px 200px;
	animation: pie-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.pie .mark {
	stroke: var(--blue);
	stroke-width: 1.5;
	vector-effect: non-scaling-stroke;
	stroke-linejoin: round;
}

.pie-label {
	fill: var(--blue);
	font-size: 18px;
	font-weight: 600;
	animation: fade-in 0.4s 0.25s backwards;
}

.bubble {
	transform-box: fill-box;
	transform-origin: center;
	animation: bubble-in 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.bubble circle {
	stroke-width: 2;
	vector-effect: non-scaling-stroke;
}

.pie .mark:focus-visible,
.bubble:focus-visible circle { stroke-width: 3; }

.bubble-label {
	fill: var(--blue);
	font-weight: 800;
	pointer-events: none;
}

.bubble-label.is-outside { font-weight: 700; }
.bubble-label.is-light { fill: #fff; }

.chart.is-morph .pie,
.chart.is-morph .pie-label,
.chart.is-morph .bubble { animation: none; }

@keyframes pie-in {
	from { opacity: 0; transform: scale(0.92) rotate(-10deg); }
	to { opacity: 1; transform: none; }
}

@keyframes bubble-in {
	from { opacity: 0; transform: scale(0.6); }
	to { opacity: 1; transform: none; }
}

@keyframes fade-in {
	from { opacity: 0; }
	to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
	.pie, .pie-label, .bubble { animation: none; }
}

@media (min-width: 901px) {
	.chart-card { margin-top: -12px; }
	.side-text { margin-top: -22px; }
}


/* ---------- Tooltip ---------- */

.tooltip {
	position: fixed;
	z-index: 1000;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 12px;
	border: 2px solid var(--blue);
	border-radius: 10px;
	background: #fff;
	font-size: 14px;
	line-height: 1.2;
	white-space: nowrap;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
	pointer-events: none;
}

.tooltip strong { font-weight: 800; }

.tooltip-dot {
	flex: none;
	width: 14px;
	height: 14px;
	border: 2px solid;
	border-radius: 50%;
}


/* ---------- Pulsante "vai ai grafici" (solo telefono e tablet) ---------- */

.chart-jump { display: none; }


/* ---------- Schermi piccoli ---------- */

@media (max-width: 900px) {
	.app {
		height: auto;
		min-height: 100vh;
		padding: 16px 20px 20px;
	}

	.city-arrow { display: none; }

	.layout {
		display: flex;
		flex-direction: column;
	}

	.side { display: contents; }
	.switch { order: 1; }
	.chart-card { order: 3; }

	.map-panel {
		order: 2;
		height: 62vh;
		min-height: 380px;
		overflow: visible;
	}

	.map {
		border-radius: 12px;
		overflow: hidden;
	}

	.side-text {
		order: 4;
		overflow: visible;
		-webkit-mask-image: none;
		mask-image: none;
	}

	.chart-jump {
		position: absolute;
		right: -8px;
		bottom: 10px;
		z-index: 3;
		display: grid;
		place-items: center;
		width: 40px;
		height: 40px;
		padding: 0;
		border: 0;
		border-radius: 10px;
		background: #fff;
		box-shadow: var(--shadow-small);
		cursor: pointer;
	}

	.chart-jump:hover,
	.chart-jump:focus-visible { background: var(--accent); outline: none; }

	.chart-card {
		aspect-ratio: auto;
		max-height: none;
		height: 380px;
	}
}

@media (max-width: 560px) {
	.app { padding: 12px 16px 16px; }

	.city-link.is-active { font-size: 22px; }

	.opt {
		padding: 8px 10px;
		font-size: 16px;
	}

	.switch { padding: 4px; }

	.legend {
		left: 10px;
		bottom: 10px;
		padding: 8px 12px 8px 8px;
	}

	.legend.is-popolazione {
		display: flex;
		align-items: flex-end;
	}

	.legend.is-popolazione .legend-group + .legend-group {
		margin: 0 0 0 10px;
		padding: 0 0 0 10px;
		border-top: 0;
		border-left: 1px solid var(--blue);
	}

	.legend-title { font-size: 10px; }
	.legend-item { font-size: 13px; }
	.legend-item-size { font-size: 12px; }

	.map .ol-attribution {
		top: 10px;
		right: 10px;
		bottom: auto;
		max-width: none;
	}

	.map .ol-attribution ul {
		padding: 2px 6px 1px;
		font-size: 9px;
		white-space: nowrap;
	}

	.map-loading {
		right: auto;
		left: 62px;
	}
}


/* ---------- Pagina iniziale (immagine dei risultati, posizioni in pixel dell'immagine 1414 x 2000) ---------- */

.home {
	display: flex;
	justify-content: center;
	padding: 24px 16px 40px;
}

.risultati {
	position: relative;
	width: 100%;
	max-width: 760px;
	container-type: inline-size;
}

.risultati img {
	display: block;
	width: 100%;
	height: auto;
}

.risultati-titolo {
	position: absolute;
	top: calc(var(--y) / 2000 * 100%);
	left: 0;
	width: 100%;
	height: calc(var(--h) / 2000 * 100%);
	margin: 0;
	background: #fff;
	font-size: calc(var(--fs) / 1414 * 100cqw);
	font-weight: 600;
	line-height: calc(var(--h) / 1414 * 100cqw);
	text-align: center;
	white-space: nowrap;
}

.citta-link {
	position: absolute;
	left: calc(var(--x) / 1414 * 100%);
	top: calc(var(--y) / 2000 * 100%);
	width: calc(var(--w) / 1414 * 100%);
	height: calc(var(--h) / 2000 * 100%);
	border-radius: 8px;
}

.citta-underline {
	position: absolute;
	left: calc((var(--ux) - var(--x)) / var(--w) * 100%);
	top: calc((var(--uy) - var(--y)) / var(--h) * 100%);
	width: calc(var(--uw) / var(--w) * 100%);
	height: max(1.5px, calc(4 / var(--h) * 100%));
	border-radius: 2px;
	background: var(--blue);
	opacity: 0;
	transition: opacity 0.15s;
}

.citta-link:hover .citta-underline,
.citta-link:focus-visible .citta-underline { opacity: 1; }
