/* Dashboard 3-30-300 */

:root {
	--bg: #ffffff;
	--line: rgba(41, 88, 123, 0.16);
	--ink: #29587b;
	--ink-dim: rgba(41, 88, 123, 0.5);
	--blue: #29587b;
	--card: #ffffff;
	--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: var(--bg);
	color: var(--ink);
	font-family: var(--font);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

.app {
	display: flex;
	flex-direction: column;
	gap: 14px;
	height: 100vh;
	height: 100dvh;
	padding: 16px 20px 20px;
}


/* ---------- Testata ---------- */

.top {
	display: flex;
	align-items: center;
	min-height: 38px;
}

.city {
	position: relative;
	display: inline-flex;
	align-items: center;
}

.city-name {
	margin: 0;
	color: var(--ink);
	font-size: 26px;
	font-weight: 800;
	letter-spacing: 0.06em;
	line-height: 1.2;
	text-transform: uppercase;
}

/* Più città: il nome diventa un menu (select nativo trasparente sopra il titolo) */
.city.is-multi .city-name {
	margin-left: -8px;
	padding: 4px 34px 2px 8px;
	border-radius: 8px;
	background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 6l4.5 4.5L12.5 6' fill='none' stroke='%2329587b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
	transition: background-color 0.2s;
}

.city.is-multi:hover .city-name { background-color: rgba(41, 88, 123, 0.08); }

.city-select {
	position: absolute;
	inset: 0;
	width: 100%;
	opacity: 0;
	cursor: pointer;
	font-family: var(--font);
	font-size: 16px;
}

.city:has(.city-select:focus-visible) .city-name {
	outline: 2px solid var(--ink);
	outline-offset: 2px;
}


/* ---------- Layout ---------- */

.layout {
	flex: 1;
	min-height: 0;
	display: grid;
	grid-template-columns: minmax(0, 1fr) clamp(280px, 24vw, 360px);
	gap: var(--gap);
}

.panel {
	border: 1px solid var(--line);
	border-radius: var(--radius);
}


/* ---------- Mappa ---------- */

.map-panel {
	position: relative;
	min-height: 0;
	overflow: hidden;
	border: 2px solid rgba(41, 88, 123, 0.35);
	background: #ffffff;
}

.map {
	position: absolute;
	inset: 0;
	--ol-background-color: #ffffff;
	--ol-accent-background-color: #eef3f7;
	--ol-subtle-background-color: rgba(41, 88, 123, 0.12);
	--ol-partial-background-color: rgba(255, 255, 255, 0.85);
	--ol-foreground-color: #29587b;
	--ol-subtle-foreground-color: #29587b;
	--ol-brand-color: #29587b;
}

.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-zoom button,
.map .ol-home button {
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	margin: 0 0 6px;
	border-radius: 10px;
	color: var(--blue);
	font-family: var(--font);
	font-size: 22px;
	font-weight: 700;
	line-height: 1;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
	cursor: pointer;
}

.map .ol-zoom button:hover,
.map .ol-zoom button:focus-visible,
.map .ol-home button:hover,
.map .ol-home button:focus-visible {
	background: var(--ol-accent-background-color);
	outline: none;
}

.map .ol-attribution,
.map .ol-attribution.ol-uncollapsible {
	right: 10px;
	bottom: 10px;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.85);
}

.map .ol-attribution ul {
	padding: 3px 8px 2px;
	color: #3c3c3c;
	font-family: var(--font);
	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;
	color: var(--blue);
	font-family: var(--font);
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
	pointer-events: none;
}

.legend.is-abitanti { --legend-col: 25px; }

.legend:empty { display: none; }

.legend-item {
	display: grid;
	grid-template-columns: var(--legend-col) auto;
	align-items: center;
	column-gap: 10px;
	padding: 4px 0;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.1;
	white-space: nowrap;
}

.legend-item > :first-child { justify-self: center; }

.legend-swatch {
	width: 18px;
	height: 18px;
	border: 2px solid var(--blue);
	border-radius: 50%;
}

.legend-title {
	margin: 2px 0 4px;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.legend-item-size {
	font-size: 14px;
	font-weight: 600;
}

.legend-size circle {
	fill: none;
	stroke: var(--blue);
	stroke-width: 1.5;
}

.legend-group + .legend-group {
	margin-top: 8px;
	padding-top: 6px;
	border-top: 1px solid rgba(41, 88, 123, 0.18);
}


/* ---------- 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: 0 2px 10px rgba(0, 0, 0, 0.16);
	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 rgba(41, 88, 123, 0.15);
	border-top-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;
	margin-top: 60px;
	margin-bottom: 12px;
	padding: 8px;
	border: 2px solid rgba(41, 88, 123, 0.35);
	border-radius: 12px;
	background: var(--card);
}

.opt {
	position: relative;
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 12px 14px;
	border-radius: 10px;
	color: var(--ink-dim);
	font-family: var(--font);
	font-size: 21px;
	font-weight: 700;
	line-height: 1.1;
	cursor: pointer;
	user-select: none;
	transition: color 0.2s, background-color 0.2s;
}

.opt:hover { color: #3f7aa6; background: rgba(41, 88, 123, 0.06); }
.opt.is-active { color: var(--ink); }

.opt input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.opt-dot {
	flex: none;
	width: 14px;
	height: 14px;
	border: 2px solid currentColor;
	border-radius: 50%;
	transition: background-color 0.2s;
}

.opt.is-active .opt-dot { background: var(--ink); }

.opt input:focus-visible ~ .opt-dot {
	outline: 2px solid var(--ink);
	outline-offset: 3px;
}


/* ---------- Grafici ---------- */

.chart-card {
	flex: 1;
	min-height: 0;
	margin-top: -60px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px 6px;
	border-radius: var(--radius);
	background: var(--card);
	overflow: hidden;
}

.chart {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 560px;
	max-height: 560px;
	overflow: visible;
	font-family: var(--font);
}

.chart .mark {
	cursor: pointer;
	outline: none;
	transition: opacity 0.2s;
}

.chart.has-focus .mark:not(.is-active) { opacity: 0.35; }

.pie {
	transform-origin: 200px 200px;
	animation: pie-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.pie .mark {
	stroke: #fff;
	stroke-width: 2;
	stroke-linejoin: round;
}

.pie .mark:focus-visible { stroke: var(--blue); stroke-width: 3; }

.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:focus-visible circle { stroke: var(--blue); stroke-width: 3; }

.bubble-label {
	fill: #111;
	font-weight: 800;
	pointer-events: none;
}

.bubble-label.is-outside { font-weight: 700; }

.chart-error {
	max-width: 300px;
	color: var(--blue);
	font-size: 16px;
	font-weight: 600;
	text-align: center;
	overflow-wrap: anywhere;
}

@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; }
}


/* ---------- Tooltip ---------- */

.tooltip {
	position: fixed;
	z-index: 1000;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 12px;
	border-radius: 10px;
	background: #1d1d1d;
	color: #f6f6f6;
	font-family: var(--font);
	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 span:last-child { color: #c9c9c9; }

.tooltip-dot {
	flex: none;
	width: 10px;
	height: 10px;
	border-radius: 50%;
}


/* ---------- Schermi piccoli ---------- */

@media (max-width: 900px) {
	.app {
		height: auto;
		min-height: 100vh;
	}

	/* Selettore della vista sopra la mappa */
	.layout {
		display: flex;
		flex-direction: column;
	}

	.side { display: contents; }
	.switch { order: 1; }
	.map-panel { order: 2; }
	.chart-card { order: 3; }

	.map-panel {
		height: 62vh;
		min-height: 380px;
	}

	.chart-card {
		flex: none;
		height: 380px;
	}
}

@media (max-width: 560px) {
	.app { padding: 12px 16px 16px; }

	.city-name { font-size: 22px; }

	.opt {
		padding: 10px 12px;
		font-size: 18px;
	}

	.switch { padding: 4px; }

	.legend {
		left: 10px;
		bottom: 10px;
		padding: 8px 12px 8px 8px;
	}

	/* Legenda su due colonne */
	.legend.is-abitanti {
		display: flex;
		align-items: flex-end;
	}

	.legend.is-abitanti .legend-group + .legend-group {
		margin: 0 0 0 10px;
		padding: 0 0 0 10px;
		border-top: 0;
		border-left: 1px solid rgba(41, 88, 123, 0.18);
	}

	.legend-title { font-size: 10px; }
	.legend-item { font-size: 13px; padding: 3px 0; }
	.legend-item-size { font-size: 12px; }

	/* Attribuzione in alto, il basso resta alla legenda */
	.map .ol-attribution,
	.map .ol-attribution.ol-uncollapsible {
		top: 10px;
		bottom: auto;
		max-width: 60%;
	}

	.map .ol-attribution ul { font-size: 10px; }

	.map-loading {
		top: 14px;
		right: auto;
		left: 62px;
	}
}
