/**
 * mappa.css - Stili per la mappa interattiva
 */

body {
	margin: 0;
	padding: 0;
	height: 100vh;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background-color: var(--background);
	/* Lascia gesture standard fuori dalla mappa; il container SVG usa touch-action:none + pinch JS */
	touch-action: auto;
	-webkit-text-size-adjust: 100%;
}

header {
	width: 100%;
	background: var(--primary-blue);
	box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header .logo, 
header .nav-links a {
	color: var(--text-light);
}

header .logo i,
header .nav-links a i {
	color: var(--accent-orange);
}

header .search-form {
	background: rgba(255, 255, 255, 0.15);
	border-color: rgba(255, 255, 255, 0.2);
}

header .search-form input,
header .search-form button {
	color: var(--text-light);
}

header .search-form input::placeholder {
	color: rgba(255, 255, 255, 0.6);
}

.map-container {
	flex: 0 0 auto;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 0;
	overflow: hidden;
	background-color: #d0e8f8;
	position: relative;
	margin-top: 72px;
	height: calc(100vh - 72px);
	touch-action: none;
	overscroll-behavior: none;
}

#world-map {
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	-webkit-tap-highlight-color: transparent;
	touch-action: none;
	will-change: transform;
	cursor: grab;
}

#world-map:active {
	cursor: grabbing;
}

/* Nessuna transition sul transform: svg-pan-zoom aggiorna il viewport ogni frame;
   una transition qui rende il pan/zoom “in ritardo” rispetto al dito/cursore. */
#world-map .svg-pan-zoom_viewport,
#world-map g.svg-pan-zoom_viewport {
	transition: none;
}

svg path {
	touch-action: none;
	transition: fill 0.3s ease, stroke 0.3s ease;
	fill: #e0e0e0;
	stroke: #b8b8b8;
	stroke-width: 0.3;
	-webkit-tap-highlight-color: transparent;
	tap-highlight-color: transparent;
	-webkit-user-select: none;
	-moz-user-select: none;
	user-select: none;
	pointer-events: painted;
	shape-rendering: geometricPrecision;
}

svg path.has-content {
	fill: #ffa85c;
	stroke: #ff8c2e;
	stroke-width: 0.5;
	cursor: pointer;
	transition: fill 0.25s ease, stroke 0.25s ease, filter 0.25s ease, stroke-width 0.25s ease;
}

svg path.has-content:hover {
	fill: #ff9944;
	stroke: #f37021;
}

svg path.has-content:active {
	fill: var(--accent-orange);
	stroke: #d9621c;
	stroke-width: 0.6;
}

svg path.has-content.highlighted {
	fill: var(--accent-orange) !important;
	filter: drop-shadow(0 0 8px rgba(243, 112, 33, 0.6));
	stroke: #d9621c;
	stroke-width: 0.7;
}

svg path.no-content {
	fill: #d4d4d4;
	stroke: #a8a8a8;
	stroke-width: 0.3;
	cursor: help;
}

svg path.no-content:hover {
	fill: #c8c8c8;
}

.tooltip {
	position: absolute;
	background: var(--primary-blue);
	color: white;
	padding: 8px 16px;
	border-radius: 8px;
	font-size: 0.85rem;
	pointer-events: none;
	display: none;
	z-index: 1001;
	box-shadow: 0 4px 15px rgba(0,0,0,0.2);
	font-weight: 600;
	transition: background 0.3s ease;
	-webkit-tap-highlight-color: transparent;
	-webkit-user-select: none;
	-moz-user-select: none;
	user-select: none;
	touch-action: none;
}

/* Hint istruzioni per mobile */
.map-hint {
	position: absolute;
	bottom: 120px;
	left: 50%;
	transform: translateX(-50%);
	background: rgba(0, 51, 102, 0.95);
	color: white;
	padding: 14px 24px;
	border-radius: 30px;
	font-size: 0.9rem;
	font-weight: 600;
	z-index: 1003;
	box-shadow: 0 6px 24px rgba(0,0,0,0.25);
	display: flex;
	align-items: center;
	gap: 10px;
	animation: fadeInUp 0.5s ease, fadeOutDown 0.5s ease 3.5s forwards;
	pointer-events: none;
}

.map-hint i {
	color: var(--accent-orange);
	font-size: 1.1rem;
}

@keyframes fadeInUp {
	from {
		opacity: 0;
		transform: translateX(-50%) translateY(20px);
	}
	to {
		opacity: 1;
		transform: translateX(-50%) translateY(0);
	}
}

@keyframes fadeOutDown {
	from {
		opacity: 1;
		transform: translateX(-50%) translateY(0);
	}
	to {
		opacity: 0;
		transform: translateX(-50%) translateY(20px);
	}
}

.map-legend {
	position: absolute;
	top: 90px;
	left: max(1.15rem, env(safe-area-inset-left, 0px));
	background: var(--surface);
	padding: 16px 20px;
	border-radius: 12px;
	box-shadow: 0 4px 16px rgba(0,0,0,0.1);
	z-index: 1002;
	font-size: 0.85rem;
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
}

.map-legend h4 {
	margin: 0 0 12px 0;
	font-size: 0.9rem;
	color: var(--primary-blue);
	font-weight: 700;
}

.legend-item {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 8px;
}

.legend-item:last-child {
	margin-bottom: 0;
}

.legend-color {
	width: 24px;
	height: 16px;
	border-radius: 4px;
	border: 1px solid #ddd;
}

.legend-color.has-content {
	background: #ffa85c;
	border-color: #ff8c2e;
}

.legend-color.no-content {
	background: #d4d4d4;
	border-color: #a8a8a8;
}

.legend-text {
	font-size: 0.8rem;
	color: var(--text-dark);
}

.map-controls {
	position: absolute; 
	bottom: max(2.5rem, env(safe-area-inset-bottom, 0px));
	right: max(2.5rem, env(safe-area-inset-right, 0px));
	display: flex;
	flex-direction: column;
	gap: 12px;
	z-index: 1002;
}

.zoom-btn {
	width: 50px;
	height: 50px;
	background: var(--surface);
	color: var(--primary-blue);
	border: 1px solid #e2e8f0;
	border-radius: 12px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.3rem;
	box-shadow: 0 4px 12px rgba(0,0,0,0.1);
	transition: var(--transition);
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
	-webkit-user-select: none;
	user-select: none;
}

.zoom-btn:hover {
	background: var(--accent-orange);
	color: white;
	border-color: var(--accent-orange);
	transform: translateY(-3px);
	box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

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

@media (max-width: 768px) {
	.map-container {
		margin-top: 68px;
		height: calc(100vh - 68px);
		/* Migliora scroll e gesture touch */
		overflow: hidden;
		position: relative;
	}

	/* Solo reset visibile: pinch per zoom (+/- nascosti per evitare overlap con gesture) */
	#zoom-in,
	#zoom-out {
		display: none !important;
	}
	
	/* Controlli zoom più grandi e accessibili */
	.map-controls {
		bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
		right: max(1.15rem, env(safe-area-inset-right, 0px));
		gap: 0;
		/* Sfondo per migliore visibilità */
		background: color-mix(in srgb, var(--surface-raised) 55%, transparent);
		padding: 12px;
		border-radius: 16px;
		backdrop-filter: blur(8px);
	}
	
	.zoom-btn {
		width: 56px;
		height: 56px;
		font-size: 1.3rem;
		border-radius: 14px;
		box-shadow: 0 4px 20px rgba(0,0,0,0.2);
		/* Touch più preciso */
		-webkit-tap-highlight-color: transparent;
		touch-action: manipulation;
	}
	
	.zoom-btn:active {
		transform: translateY(0) scale(0.92);
		box-shadow: 0 2px 12px rgba(0,0,0,0.15);
		background: var(--accent-orange);
		color: white;
		border-color: var(--accent-orange);
	}
	
	/* Legenda compatta e posizionata meglio */
	.map-legend {
		top: 82px;
		left: max(0.85rem, env(safe-area-inset-left, 0px));
		padding: 14px 16px;
		font-size: 0.8rem;
		background: color-mix(in srgb, var(--surface-raised) 94%, transparent);
		backdrop-filter: blur(8px);
		box-shadow: var(--shadow-md);
		border: 1px solid var(--border-subtle);
		color: var(--text-primary);
	}
	
	.map-legend h4 {
		font-size: 0.85rem;
		margin-bottom: 10px;
	}
	
	.legend-item {
		gap: 10px;
		margin-bottom: 8px;
	}
	
	.legend-color {
		width: 22px;
		height: 15px;
	}
	
	.legend-text {
		font-size: 0.8rem;
	}
	
	header .nav-links {
		width: 85%;
	}
	
	.logo span {
		font-size: 1.2rem;
	}
	
	/* Tooltip più grande e visibile su mobile */
	.tooltip {
		font-size: 0.85rem;
		padding: 10px 14px;
		border-radius: 10px;
		max-width: 240px;
		white-space: normal;
		line-height: 1.4;
		box-shadow: 0 6px 24px rgba(0,0,0,0.25);
	}
	
	/* Paesi più visibili su mobile: bordi più spessi */
	svg path {
		stroke-width: 0.4;
	}
	
	svg path.has-content {
		stroke-width: 0.6;
		/* Colore più intenso per migliore visibilità */
		fill: #ff9f52;
	}
	
	svg path.has-content:active {
		stroke-width: 0.8;
		/* Feedback visivo più forte al tap */
		filter: drop-shadow(0 0 12px rgba(243, 112, 33, 0.7));
	}
	
	svg path.no-content {
		stroke-width: 0.35;
	}
}

@media (max-width: 576px) {
	/* Controlli zoom ancora più grandi per pollici */
	.map-controls {
		bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
		right: max(0.85rem, env(safe-area-inset-right, 0px));
		gap: 0;
		padding: 10px;
		border-radius: 14px;
	}
	
	.zoom-btn {
		width: 52px;
		height: 52px;
		font-size: 1.15rem;
		border-radius: 12px;
		/* Assicura touch target minimo di 48px */
		min-width: 48px;
		min-height: 48px;
	}
	
	/* Legenda ancora più compatta */
	.map-legend {
		top: 78px;
		left: max(0.75rem, env(safe-area-inset-left, 0px));
		padding: 10px 12px;
		font-size: 0.75rem;
	}
	
	.map-legend h4 {
		font-size: 0.78rem;
		margin-bottom: 8px;
	}
	
	.legend-item {
		margin-bottom: 6px;
		gap: 8px;
	}
	
	.legend-color {
		width: 18px;
		height: 13px;
	}
	
	.legend-text {
		font-size: 0.72rem;
	}
	
	/* Tooltip ottimizzato per schermi piccoli */
	.tooltip {
		font-size: 0.8rem;
		padding: 8px 12px;
		max-width: 200px;
		border-radius: 8px;
	}
	
	/* Container mappa con gesture migliorate */
	.map-container {
		-webkit-overflow-scrolling: touch;
		overscroll-behavior: contain;
	}
	
	/* Paesi ancora più spessi su schermi piccoli */
	svg path.has-content {
		stroke-width: 0.7;
	}
	
	svg path.has-content:active {
		stroke-width: 0.9;
	}
}

/* ============================================
   MOBILE MOLTO PICCOLO (<420px)
   ============================================ */
@media (max-width: 420px) {
	/* Controlli zoom occupano meno spazio */
	.map-controls {
		bottom: max(1rem, env(safe-area-inset-bottom, 0px));
		right: max(0.65rem, env(safe-area-inset-right, 0px));
		gap: 0;
		padding: 8px;
		border-radius: 12px;
	}
	
	.zoom-btn {
		width: 50px;
		height: 50px;
		font-size: 1.1rem;
		border-radius: 11px;
	}
	
	/* Legenda ancora più compatta */
	.map-legend {
		top: 76px;
		left: max(0.65rem, env(safe-area-inset-left, 0px));
		padding: 8px 10px;
		font-size: 0.7rem;
	}
	
	.map-legend h4 {
		font-size: 0.75rem;
		margin-bottom: 6px;
	}
	
	.legend-item {
		gap: 6px;
		margin-bottom: 5px;
	}
	
	.legend-color {
		width: 16px;
		height: 12px;
	}
	
	.legend-text {
		font-size: 0.68rem;
	}
	
	/* Paesi massima visibilità su schermi molto piccoli */
	svg path.has-content {
		stroke-width: 0.8;
		fill: #ff9440;
	}
}
