/**
 * Leaflet Map Manager — frontend styles (mobile-first).
 */

/* Wrapper -------------------------------------------------------------- */

.lmm-wrapper {
	position: relative;
	width: var(--lmm-width, 100%);
	height: auto;
	font-family: inherit;
	box-sizing: border-box;
}

.lmm-wrapper *,
.lmm-wrapper *::before,
.lmm-wrapper *::after {
	box-sizing: inherit;
}

/* Map canvas ----------------------------------------------------------- */

.lmm-map {
	width: 100%;
	height: var(--lmm-height, 420px);
	background: #e5e3df;
	border-radius: 6px;
	z-index: 1;
}

.lmm-map:focus-visible {
	outline: 3px solid #2271b1;
	outline-offset: 2px;
}

/* Legend panel --------------------------------------------------------- */

.lmm-panel {
	position: absolute;
	z-index: 1000; /* Above Leaflet panes (400) and controls. */
	/* max-height: calc(var(--lmm-height, 420px) - 150px); */
	max-width: min(280px, 70%);
	/* overflow-y: auto; */
	background: #fff;
	border-radius: 6px;
	box-shadow: 0 1px 6px rgb(0 0 0 / 25%);
	padding: 6px;
}

/* Corner placement, chosen by drag & drop in the map editor. */
.lmm-pos-top-right .lmm-panel {
	top: 10px;
	right: 10px;
}

.lmm-pos-top-left .lmm-panel {
	top: 10px;
	left: 10px;
}

.lmm-pos-bottom-right .lmm-panel {
	bottom: 10px;
	right: 10px;
}

.lmm-pos-bottom-left .lmm-panel {
	bottom: 10px;
	left: 10px;
}

/* Credits bar along the bottom edge of the map (providers). */
.lmm-credits-bar {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 900; /* Under legend (1000) and mobile sheet (1200). */
	background: rgb(255 255 255 / 85%);
	font-size: 10px;
	line-height: 1.5;
	color: #50575e;
	padding: 2px 8px;
	pointer-events: none;
	border-radius: 0 0 6px 6px;
}

.lmm-credits-bar a {
	color: inherit;
	pointer-events: auto;
}

/* Lift bottom-right controls (scale + layer list) above the credits bar. */
.lmm-wrapper .leaflet-bottom.leaflet-right {
	margin-bottom: 20px;
}

.lmm-panel-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
	max-height: calc(var(--lmm-height, 420px) - 215px);
	overflow-y: auto;
}

.lmm-panel-item {
	display: flex;
	align-items: center;
	gap: 6px;
	border-radius: 4px;
	padding: 4px 6px;
	transition: opacity 0.2s ease;
}

.lmm-panel-item.lmm-panel-family-item {
    margin-left: 25px;
}

.lmm-panel-item.is-hidden {
	opacity: 0.45;
}

.lmm-panel-label {
	display: flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
	flex: 1;
	min-width: 0;
	font-size: 14px;
	line-height: 1.3;
	color: #222;
	user-select: none;
}

.lmm-panel-checkbox {
	margin: 0;
	flex-shrink: 0;
	accent-color: #2271b1;
}

.lmm-panel-icon {
	width: 22px;
	height: 22px;
	object-fit: contain;
	flex-shrink: 0;
	border-radius: 3px;
}

.lmm-panel-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.lmm-panel-item:not(.lmm-panel-family-item) .lmm-panel-name {
	text-transform:uppercase;
	font-weight:700;
}

.lmm-panel-family-item {
	padding-left: 28px;
}

.lmm-panel-toggle-all {
	display: block;
	width: 100%;
	margin-top: 6px;
	padding: 5px 8px;
	border: 1px solid #dcdcde;
	border-radius: 4px;
	background: #f6f7f7;
	color: #1d2327;
	font-size: 12px;
	line-height: 1.4;
	cursor: pointer;
	text-align: center;
	transition: background 0.15s ease;
}

.lmm-panel-toggle-all:hover,
.lmm-panel-toggle-all:focus-visible {
	background: #eeefef;
	outline: none;
}

.lmm-panel-toggle-all:focus-visible {
	box-shadow: 0 0 0 2px #2271b1;
}

.lmm-eye {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	border: 0;
	border-radius: 4px;
	background: transparent;
	color: #444;
	cursor: pointer;
	flex-shrink: 0;
}

.lmm-eye:hover,
.lmm-eye:focus-visible {
	background: #f0f0f1;
	color: #111;
	outline: none;
}

.lmm-eye:focus-visible {
	box-shadow: 0 0 0 2px #2271b1;
}

/* Desktop popups (>768px) ---------------------------------------------- */

.lmm-popup .leaflet-popup-content-wrapper {
	border-radius: 8px;
}

.lmm-popup-content {
	display: flex;
	flex-direction: column;
	gap: 8px;
	min-width: 220px;
}

.lmm-popup-image {
	width: 100%;
	height: 150px;
	object-fit: cover;
	border-radius: 6px;
}

.lmm-popup-title {
	margin: 0;
	font-size: 16px;
	line-height: 1.25;
	color: #1d2327;
}

.lmm-popup-text {
	margin: 0;
	font-size: 13px;
	line-height: 1.45;
	color: #3c434a;
}

.lmm-popup-link {
	align-self: flex-start;
	font-size: 13px;
	font-weight: 600;
	color: #2271b1;
	text-decoration: none;
}

.lmm-popup-link:hover,
.lmm-popup-link:focus-visible {
	text-decoration: underline;
}

/* Mobile bottom-sheet popup (<768px) ----------------------------------- */

@media (max-width: 767px) {

	/* Legend collapses into a compact overlay strip. */
	.lmm-panel {
		top: 8px;
		right: 8px;
		left: 8px;
		bottom: auto;
		max-width: none;
		max-height: 96px;
	}

	.lmm-panel-list {
		flex-direction: row;
		flex-wrap: wrap;
	}

	.lmm-panel-name {
		max-width: 110px;
	}

	.lmm-mobile-popup {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 1200;
		background: #fff;
		border-top: 3px solid #2271b1; /* Visual separator over the map. */
		border-radius: 14px 14px 0 0;
		box-shadow: 0 -4px 18px rgb(0 0 0 / 30%);
		padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0));
		max-height: 52%;
		overflow-y: auto;
		transform: translateY(105%);
		transition: transform 0.25s ease-out;
	}

	.lmm-mobile-popup.is-open {
		transform: translateY(0);
	}

	.lmm-mobile-close {
		position: absolute;
		top: 6px;
		right: 8px;
		width: 32px;
		height: 32px;
		border: 0;
		border-radius: 50%;
		background: #f0f0f1;
		font-size: 18px;
		line-height: 1;
		cursor: pointer;
		color: #1d2327;
		z-index: 1;
	}

	.lmm-mobile-close:hover,
	.lmm-mobile-close:focus-visible {
		background: #dcdcde;
		outline: none;
	}

	.lmm-mobile-close:focus-visible {
		box-shadow: 0 0 0 2px #2271b1;
	}

	.lmm-mobile-inner .lmm-popup-content {
		padding-right: 36px;
	}

	.lmm-mobile-inner .lmm-popup-image {
		height: 120px;
	}
}

/* Hide the sheet entirely outside mobile widths. */
@media (min-width: 768px) {
	.lmm-mobile-popup {
		display: none !important;
	}
}

/* Cluster icons -------------------------------------------------------- */

.lmm-cluster-icon {
	background: transparent;
	border: 0;
}

/* Pictograms keep their original aspect ratio and transparency:
   no painted background, no border, contain instead of cover. */
.lmm-marker-picto {
	object-fit: contain;
	background: transparent !important;
}

.lmm-cluster-picto {
	display: block;
	width: 46px;
	height: 46px;
	object-fit: contain;
	background: transparent !important;
	border: 0;
	box-shadow: none;
}

.lmm-cluster-count {
	position: absolute;
	top: -7px;
	right: -9px;
	min-width: 20px;
	padding: 1px 5px;
	border-radius: 999px;
	background: #d63638;
	color: #fff;
	font: bold 11px/16px sans-serif;
	text-align: center;
	box-shadow: 0 1px 3px rgb(0 0 0 / 40%);
}

/* Reduced motion ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {

	.lmm-mobile-popup {
		transition: none;
	}
}
