/*
 * Mappa del paesaggio culturale di Ferruzzano (versione 1.4.0)
 * Tutti i selettori sono confinati sotto .fm-mappa per non interferire con il tema.
 * Colori: testo e controlli con contrasto >= 4.5:1, icone e bordi >= 3:1 (WCAG 1.4.3, 1.4.11).
 *
 * Impostazione mobile-first. Il layout si adatta alla larghezza del blocco in cui
 * la mappa e inserita (container query), non a quella dello schermo: funziona
 * anche in un tema con colonna stretta o barra laterale.
 */
.fm-mappa {
	--fm-testo: #1a1a1a;
	--fm-sfondo: #ffffff;
	--fm-tenue: #f3f1ec;
	--fm-bordo: #6b6b6b;
	--fm-accento: #1a1a1a;
	--fm-focus: #1a1a1a;
	container-type: inline-size;
	width: 100%;
	max-width: 75rem;
	margin-inline: auto;
	color: var(--fm-testo);
	font-size: 1rem;
	line-height: 1.5;
	box-sizing: border-box;
}
.fm-mappa *, .fm-mappa *::before, .fm-mappa *::after { box-sizing: inherit; }

.fm-mappa .fm-sr {
	position: absolute !important;
	width: 1px; height: 1px;
	padding: 0; margin: -1px;
	overflow: hidden; clip: rect(0, 0, 0, 0);
	white-space: nowrap; border: 0;
}

.fm-mappa .fm-titolo {
	margin: 0 0 .5rem;
	font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
	line-height: 1.25;
}

/* Pulsanti di base ------------------------------------------------------- */
.fm-mappa .fm-btn,
.fm-mappa .fm-voce,
.fm-mappa [role="tab"] {
	font: inherit;
	color: var(--fm-testo);
	background: var(--fm-sfondo);
	border: 2px solid var(--fm-bordo);
	border-radius: 4px;
	min-height: 44px;
	padding: .4rem .9rem;
	cursor: pointer;
	text-align: left;
}
.fm-mappa .fm-btn:hover, .fm-mappa [role="tab"]:hover { background: var(--fm-tenue); }
.fm-mappa .fm-btn--testo {
	border-color: transparent;
	background: transparent;
	text-decoration: underline;
	text-underline-offset: 3px;
	padding: .15rem .25rem;
	min-height: 32px;
}
.fm-mappa .fm-btn[aria-disabled="true"] {
	cursor: default;
	text-decoration: none;
	color: #5a5a5a;
	opacity: .7;
}
.fm-mappa .fm-btn[aria-disabled="true"]:hover { background: transparent; }
.fm-mappa .fm-voce {
	border-color: transparent;
	background: transparent;
	text-decoration: none;
	padding: .35rem .25rem;
	min-height: 32px;
}
.fm-mappa .fm-voce-nome { text-decoration: underline; text-underline-offset: 3px; }
.fm-mappa .fm-voce[aria-current="true"] { font-weight: 700; }
.fm-mappa .fm-voce[aria-current="true"] .fm-voce-nome { text-decoration-thickness: 3px; }
.fm-mappa .fm-sub { display: block; font-size: .875rem; font-weight: 400; color: #4a4a4a; }

/* Focus visibile ovunque (WCAG 2.4.7, 2.4.11 in 2.2) */
.fm-mappa :focus-visible,
.fm-mappa .leaflet-marker-icon:focus {
	outline: 3px solid var(--fm-focus) !important;
	outline-offset: 2px;
	box-shadow: 0 0 0 5px #ffffff;
}

/* Controlli: ricerca, contatore, legenda --------------------------------- */
.fm-mappa .fm-controlli { display: grid; gap: .5rem; margin-bottom: .5rem; }
.fm-mappa .fm-ricerca label { display: block; font-weight: 600; margin-bottom: .125rem; }
.fm-mappa .fm-ricerca input {
	width: 100%;
	min-height: 44px;
	padding: .5rem .75rem;
	border: 2px solid var(--fm-bordo);
	border-radius: 4px;
	font: inherit;
	color: var(--fm-testo);
	background: var(--fm-sfondo);
}
.fm-mappa .fm-riepilogo {
	display: flex; flex-wrap: wrap; align-items: center;
	gap: .125rem .75rem;
	margin-top: .25rem;
	min-height: 2rem;
}
.fm-mappa .fm-contatore { font-weight: 600; }
.fm-mappa .fm-contatore--vuoto { color: #7a1414; }

/* Legenda: su spazi stretti e un pannello che si apre con un pulsante */
.fm-mappa .fm-legenda-toggle {
	display: flex; align-items: center; justify-content: space-between;
	gap: .5rem; width: 100%;
}
.fm-mappa .fm-freccia {
	flex: none;
	width: .6rem; height: .6rem;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg) translateY(-2px);
}
.fm-mappa.fm-legenda-aperta .fm-freccia { transform: rotate(225deg) translateY(-2px); }
.fm-mappa .fm-legenda {
	display: none;
	margin-top: .25rem;
	padding: .5rem .75rem;
	border: 2px solid var(--fm-bordo);
	border-radius: 4px;
	background: var(--fm-sfondo);
}
.fm-mappa.fm-legenda-aperta .fm-legenda { display: block; }
.fm-mappa .fm-legenda-testa {
	display: flex; flex-wrap: wrap; align-items: center;
	gap: 0 1rem; margin-bottom: .125rem;
}
.fm-mappa .fm-legenda-titolo { font-weight: 600; }
.fm-mappa .fm-legenda ul {
	list-style: none; margin: 0; padding: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr));
	gap: 0 .75rem;
}
.fm-mappa .fm-filtro {
	display: flex; align-items: center; gap: .4rem;
	min-height: 44px; padding: 0 .25rem; cursor: pointer;
}
.fm-mappa .fm-filtro input { flex: none; width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--fm-accento); }
.fm-mappa .fm-conta { color: #4a4a4a; white-space: nowrap; }
.fm-mappa .fm-icona { flex: none; filter: drop-shadow(0 0 1px rgba(0, 0, 0, .9)); }

/* Schede Mappa / Elenco -------------------------------------------------- */
.fm-mappa .fm-schede { display: flex; gap: .5rem; margin: .5rem 0; }
.fm-mappa [role="tab"][aria-selected="true"] {
	background: var(--fm-testo);
	color: #ffffff;
	border-color: var(--fm-testo);
}
.fm-mappa [role="tab"][aria-disabled="true"] { opacity: .6; }

/* Corpo: viste e pannello della scheda ---------------------------------- */
.fm-mappa .fm-corpo { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.fm-mappa .fm-vista { position: relative; }
.fm-mappa .fm-vista:focus { outline: none; }
.fm-mappa .fm-mappa-area {
	height: 62vh;
	min-height: 360px;
	max-height: 720px;
	border: 2px solid var(--fm-bordo);
	border-radius: 4px;
	background: var(--fm-tenue);
	isolation: isolate; /* i livelli interni di Leaflet non passano sopra menu e intestazioni del tema */
}

/* Collegamento "Salta la mappa": nascosto finche non riceve il focus da tastiera,
   poi in alto al centro della mappa (a sinistra ci sono i pulsanti dello zoom). */
.fm-mappa .fm-salta {
	position: absolute;
	width: 1px; height: 1px;
	margin: -1px; padding: 0; border: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	white-space: nowrap;
}
.fm-mappa .fm-salta:focus {
	width: auto; height: auto;
	margin: 0; padding: .5rem .75rem;
	overflow: visible;
	clip: auto; clip-path: none;
	white-space: normal;
	max-width: calc(100% - 7rem);
	text-align: center;
	left: 50%; top: .75rem;
	transform: translateX(-50%);
	z-index: 1100;
	background: var(--fm-sfondo);
	color: var(--fm-testo);
	border: 2px solid var(--fm-testo);
}
.fm-mappa .fm-avviso, .fm-mappa .fm-errore {
	border-left: 4px solid #a14000; background: #fff4ec; padding: .75rem 1rem; margin: 0;
}

/* Controlli di zoom di Leaflet: 44 px per il tocco */
.fm-mappa .leaflet-bar a.leaflet-control-zoom-in,
.fm-mappa .leaflet-bar a.leaflet-control-zoom-out {
	width: 44px; height: 44px; line-height: 42px; font-size: 26px;
}

/* Marker e gruppi --------------------------------------------------------- */
.fm-mappa .fm-marker { background: none; border: 0; }
.fm-mappa .fm-marker svg { display: block; }
.fm-mappa .fm-marker--attivo svg { transform: scale(1.35); transform-origin: center; }
.fm-mappa .fm-marker--attivo::after {
	content: ""; position: absolute; inset: -6px;
	border: 3px solid var(--fm-testo); border-radius: 50%;
	box-shadow: 0 0 0 2px #ffffff;
}
.fm-mappa .fm-marker--membro::after {
	content: ""; position: absolute; inset: -5px;
	border: 3px dashed var(--fm-testo); border-radius: 50%;
	box-shadow: 0 0 0 2px #ffffff;
}
.fm-mappa .fm-cluster {
	display: flex; align-items: center; justify-content: center;
	width: 44px; height: 44px;
	background: #ffffff;
	color: var(--fm-testo);
	border: 3px solid var(--fm-testo);
	border-radius: 50%;
	font-size: 1.0625rem;
	font-weight: 700;
	line-height: 1;
	box-shadow: 0 0 0 2px #ffffff, 0 1px 4px rgba(0, 0, 0, .5);
}

/* Elenco ---------------------------------------------------------------- */
.fm-mappa .fm-tabella-wrap { overflow-x: auto; }
.fm-mappa .fm-tabella { width: 100%; border-collapse: collapse; }
.fm-mappa .fm-tabella caption { text-align: left; font-weight: 600; padding: .25rem 0 .5rem; }
.fm-mappa .fm-tabella th, .fm-mappa .fm-tabella td {
	text-align: left; padding: .35rem .5rem; border-bottom: 1px solid #c8c8c8; vertical-align: middle;
}
.fm-mappa .fm-tabella th { border-bottom: 2px solid var(--fm-bordo); }
.fm-mappa .fm-tabella td:first-child { width: 3.5rem; font-variant-numeric: tabular-nums; }
.fm-mappa .fm-cat { display: inline-flex; align-items: center; gap: .4rem; }

/* Pannello della scheda ---------------------------------------------------- */
.fm-mappa .fm-pannello {
	border: 2px solid var(--fm-bordo);
	border-radius: 4px;
	padding: 1rem;
	background: var(--fm-sfondo);
	align-self: start;
}
.fm-mappa .fm-pannello-testa { display: flex; justify-content: space-between; align-items: start; gap: .5rem; }
.fm-mappa .fm-pannello-testa > :first-child { margin: 0; }
.fm-mappa .fm-pannello-testa > :first-child:focus { outline: 3px solid var(--fm-focus); outline-offset: 2px; }
.fm-mappa .fm-chiudi { flex: none; font-size: 1.5rem; line-height: 1; padding: .25rem .6rem; }
.fm-mappa .fm-badge { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; margin: .5rem 0 1rem; }
.fm-mappa .fm-num { color: #4a4a4a; }
.fm-mappa .fm-figura { margin: 0 0 1rem; }
.fm-mappa .fm-figura img { max-width: 100%; height: auto; display: block; }
.fm-mappa .fm-segnaposto { font-style: italic; color: #4a4a4a; }
.fm-mappa .fm-azioni { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.fm-mappa .fm-link { width: 100%; margin: 0; }
.fm-mappa .fm-link input { width: 100%; min-height: 40px; font: inherit; padding: .25rem .5rem; }

/* Scheda di un complesso: elenco dei punti con didascalia e foto ------------ */
.fm-mappa .fm-punti-complesso { margin-top: 1rem; padding-top: .75rem; border-top: 2px solid var(--fm-bordo); }
.fm-mappa .fm-punti-titolo { margin: 0 0 .5rem; font-size: 1.0625rem; line-height: 1.3; }
.fm-mappa .fm-punti-lista { list-style: none; margin: 0; padding: 0; }
.fm-mappa .fm-punto {
	padding: .75rem .5rem .75rem .75rem;
	border-left: 4px solid transparent;
	border-bottom: 1px solid #c8c8c8;
}
.fm-mappa .fm-punto--attivo { border-left-color: var(--fm-testo); background: var(--fm-tenue); }
.fm-mappa .fm-punto-testa { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem; margin: 0 0 .35rem; }
.fm-mappa .fm-punto-num { font-weight: 700; }
.fm-mappa .fm-punto-nome { color: #333333; }
.fm-mappa .fm-punto-sel {
	font-size: .875rem; font-weight: 700; line-height: 1.4;
	border: 2px solid var(--fm-testo); border-radius: 4px; padding: 0 .35rem;
}
.fm-mappa .fm-punto-sel[hidden] { display: none; }
.fm-mappa .fm-punto-fig { margin: .25rem 0 .5rem; }
.fm-mappa .fm-punto-fig img { display: block; width: auto; height: auto; max-width: 100%; max-height: 20rem; }
.fm-mappa .fm-punto-fig figcaption, .fm-mappa .fm-didascalia { margin: .35rem 0 .5rem; }
.fm-mappa .fm-punto .fm-btn--testo { margin-top: .15rem; }

/* Blocco largo almeno 30rem: la legenda aperta usa due colonne */
@container (min-width: 30rem) {
	.fm-mappa .fm-legenda ul { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Blocco largo almeno 60rem (circa 960 px): ricerca e contatore su una riga,
   legenda sempre visibile a tutta larghezza in quattro colonne (4 + 3 voci) */
@container (min-width: 60rem) {
	.fm-mappa .fm-controlli { gap: .25rem; }
	.fm-mappa .fm-ricerca { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
	.fm-mappa .fm-ricerca label { margin: 0; }
	.fm-mappa .fm-ricerca input { width: 17rem; max-width: 100%; }
	.fm-mappa .fm-riepilogo { margin: 0; min-height: 0; }
	.fm-mappa .fm-legenda-toggle { display: none; }
	.fm-mappa .fm-legenda { display: block; margin: 0; padding: 0; border: 0; }
	.fm-mappa .fm-legenda ul { grid-template-columns: repeat(4, auto); column-gap: 1.25rem; }
	.fm-mappa .fm-filtro { min-height: 32px; }
}

/* Blocco largo almeno 56rem: scheda affiancata alla mappa */
@container (min-width: 56rem) {
	.fm-mappa.fm-con-pannello .fm-corpo { grid-template-columns: minmax(0, 1fr) 22rem; }
	.fm-mappa .fm-pannello { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
}

/* Dispositivi touch: bersagli di almeno 44 px anche nei comandi secondari */
@media (pointer: coarse) {
	.fm-mappa .fm-filtro { min-height: 44px; }
	.fm-mappa .fm-btn--testo, .fm-mappa .fm-voce { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
	.fm-mappa *, .fm-mappa *::before, .fm-mappa *::after { transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
	.fm-mappa .fm-cluster, .fm-mappa .fm-pannello, .fm-mappa .fm-btn, .fm-mappa .fm-legenda { border-color: CanvasText; }
	.fm-mappa .fm-icona g { forced-color-adjust: none; }
}
