/* Desktop map canvas and results panel share the viewport in equal columns. */
main#home[aria-label="Mapa de eventos"] {
	min-height: calc(100dvh - 4.5rem);
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	grid-template-rows: minmax(calc(100dvh - 4.5rem - var(--space-16)), auto);
	padding-top: var(--space-16);
	padding-bottom: var(--space-16);
}

/* Size the Leaflet canvas independently from event-card media. */
main#home[aria-label="Mapa de eventos"] > .map-canvas {
	position: relative;
	width: 100%;
	height: 100%;
	aspect-ratio: auto;
	align-self: stretch;
	padding: 0;
	overflow: hidden;
	border-radius: var(--radius-card);
}

.leaflet-div-icon.map-event-marker {
	border: 0;
	background: transparent;
}

.leaflet-div-icon.map-user-location {
	border: 0;
	background: transparent;
}

@keyframes map-user-location-pulse {
	0% { opacity: 0.7; transform: scale(0.25); }
	100% { opacity: 0; transform: scale(1); }
}

.map-user-location__pulse {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: rgb(51 136 255 / 35%);
	animation: map-user-location-pulse 1.6s ease-out infinite;
}

.map-user-location__dot {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 14px;
	height: 14px;
	transform: translate(-50%, -50%);
	border: 2px solid #fff;
	border-radius: 50%;
	background: #3388ff;
	box-shadow: 0 1px 4px rgb(0 0 0 / 35%);
}

@keyframes map-event-card-appear {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes map-event-marker-appear {
	from { opacity: 0; transform: scale(0.2); }
	to { opacity: 1; transform: scale(1); }
}

main#home[aria-label="Mapa de eventos"] .events__grid .event-card:not([hidden]) {
	animation: map-event-card-appear 200ms ease-out;
}

.map-event-marker__pin {
	position: absolute;
	top: 0;
	left: 2px;
	width: 32px;
	height: 32px;
	border: 2px solid var(--color-text-primary);
	border-radius: 50%;
	background: var(--color-accent);
	box-shadow: 0 2px 5px rgb(0 0 0 / 30%);
	animation: map-event-marker-appear 200ms ease-out;
}

.map-event-marker__heart {
	position: absolute;
	inset: 0;
	width: 16px;
	height: 16px;
	margin: auto;
	color: var(--color-text-primary);
	fill: var(--color-surface-strong);
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
	pointer-events: none;
}

.map-event-marker__pin::after {
	position: absolute;
	bottom: -9px;
	left: 8px;
	width: 0;
	height: 0;
	border-top: 9px solid var(--color-text-primary);
	border-right: 6px solid transparent;
	border-left: 6px solid transparent;
	content: "";
}

.map-event-marker:hover .map-event-marker__pin {
	transform: translateY(-2px);
}

@media (prefers-reduced-motion: reduce) {
	main#home[aria-label="Mapa de eventos"] .events__grid .event-card:not([hidden]),
	.map-event-marker__pin,
	.map-user-location__pulse {
		animation: none;
	}
}

.leaflet-popup.map-event-popup {
	pointer-events: auto;
}

.leaflet-popup.map-event-popup .leaflet-popup-content-wrapper {
	padding: 0;
	overflow: hidden;
	border-radius: var(--radius-card);
	background: transparent;
	box-shadow: none;
}

.leaflet-popup.map-event-popup .leaflet-popup-tip {
	background: var(--color-surface-strong);
	box-shadow: none;
}

.leaflet-popup.map-event-popup .leaflet-popup-content {
	width: min(18.75rem, calc(100vw - var(--space-8))) !important;
	margin: 0;
}

.leaflet-popup.map-event-popup .event-card {
	width: 100%;
	margin: 0;
	cursor: pointer;
}

.leaflet-popup.map-event-popup .event-card__details {
	min-height: 0;
	gap: var(--space-2);
	padding: var(--space-3);
}

.leaflet-popup.map-event-popup .event-card__venue {
	margin: 0;
}

.leaflet-popup.map-event-popup .event-card__visual {
	height: auto;
	aspect-ratio: 2.1;
	padding: 0;
}

.leaflet-popup.map-event-popup .event-card__title a {
	color: var(--color-text-inverse);
}

.leaflet-popup.map-event-popup .map-event-popup__close {
	position: absolute;
	top: var(--space-2);
	left: calc(var(--space-2) + 2rem + var(--space-2));
	z-index: 2;
	display: grid;
	width: 2rem;
	height: 2rem;
	place-items: center;
	padding: 0;
	border: 0;
	border-radius: var(--radius-pill);
	background: var(--color-background);
	color: var(--color-text-primary);
	cursor: pointer;
	font-size: var(--font-size-l);
	line-height: 1;
}

.leaflet-popup.map-event-popup .map-event-popup__close span {
	transform: translateY(-2px);
}

/* Keep the results panel independently scrollable beside the map. */
main#home[aria-label="Mapa de eventos"] > .events {
	min-width: 0;
	width: 100%;
	height: auto;
	grid-template-rows: auto auto auto;
	gap: 0;
	overflow: visible;
	padding: 0;
}

/* Tighten the filter header to fit the map's results panel. */
main#home[aria-label="Mapa de eventos"] .explore-filters {
	min-width: 0;
	width: 100%;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--space-4);
	padding: 0 var(--space-6) var(--space-5);
	background: var(--color-background);
}

/* The map panel uses its own compact heading treatment. */
main#home[aria-label="Mapa de eventos"] .section__title {
	display: none;
}

/* Show two standard event cards per row on desktop. */
main#home[aria-label="Mapa de eventos"] .events__grid {
	min-width: 0;
	width: 100%;
	min-height: auto;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	align-content: start;
	gap: var(--space-3);
	overflow: visible;
	padding: var(--space-5);
}

/* Desktop uses standard cards; show the filter trigger only on mobile. */
.map-filter-trigger,
.map-filter-sheet {
	display: none;
}

/* Give map cards more room for their full event details on desktop. */
@media (min-width: 1024px) {
	.event-card-map .event-card__visual {
		height: auto;
		aspect-ratio: 2.1;
	}

	/* Map and filters stay pinned while the page scrolls through the full event grid. */
	main#home[aria-label="Mapa de eventos"] {
		grid-template-rows: auto;
		align-items: start;
	}

	main#home[aria-label="Mapa de eventos"] > .map-canvas {
		position: sticky;
		top: var(--space-16);
		height: calc(100dvh - 4.5rem - var(--space-16));
		max-height: calc(100dvh - 4.5rem - var(--space-16));
	}

	main#home[aria-label="Mapa de eventos"] > .events {
		display: flex;
		flex-direction: column;
		height: auto;
		min-height: 0;
		overflow: visible;
	}

	main#home[aria-label="Mapa de eventos"] .explore-filters {
		position: sticky;
		top: var(--space-16);
		z-index: 3;
		/* Reserve the map's height so filters unstick at the same scroll point as the map. */
		margin-bottom: calc(100dvh - 4.5rem - var(--space-16) - 6.25rem);
		/* Cover the top offset so cards don't show above the stuck filters. */
		box-shadow: 0 calc(-1 * var(--space-16)) 0 var(--color-background);
	}

	main#home[aria-label="Mapa de eventos"] .events__grid {
		margin-top: calc(-1 * (100dvh - 4.5rem - var(--space-16) - 6.25rem));
	}
}

/* Keep the tablet map panel readable with one desktop-style card per row. */
@media (max-width: 1023px) {
	.header {
		z-index: 1100;
	}

	/* Stack the map above the results on tablet. */
	main#home[aria-label="Mapa de eventos"] {
		height: auto;
		min-height: 0;
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: auto;
		row-gap: var(--space-4);
	}

	main#home[aria-label="Mapa de eventos"] > .map-canvas {
		height: min(60dvh, 36rem);
		aspect-ratio: auto;
	}

	main#home[aria-label="Mapa de eventos"] .events__grid {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* Tablet shows three cards per row. */
@media (min-width: 768px) and (max-width: 1023px) {
	main#home[aria-label="Mapa de eventos"] .events__grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.event-card-map .event-card__visual {
		height: 10rem;
	}

	.event-card-map .event-card__details {
		min-height: 7.5rem;
	}
}

/* Mobile stacks map and results, and repositions the map pins. */
@media (max-width: 767px) {
	/* Use compact horizontal cards only on phones. */
	.event-card-map {
		display: flex;
		min-height: 7.125rem;
	}

	.event-card-map .event-card__visual {
		width: 8.75rem;
		min-height: 7.125rem;
		flex: 0 0 8.75rem;
		padding: 0;
	}

	.event-card-map .event-card__category {
		top: auto;
		right: auto;
		bottom: var(--space-2);
		left: var(--space-2);
		max-width: calc(100% - var(--space-4));
	}

	.event-card-map .event-card__attending {
		top: auto;
		right: auto;
		bottom: calc(var(--space-2) + 1.75rem);
		left: var(--space-2);
		max-width: calc(100% - var(--space-4));
	}

	.event-card-map .event-card__attending + .event-card__category {
		top: auto;
		bottom: var(--space-2);
		left: var(--space-2);
	}

	.event-card-map .event-card__details {
		min-width: 0;
		flex: 1;
		align-content: center;
		gap: var(--space-2);
		padding: var(--space-4);
	}

	.event-card-map .event-card__meta {
		width: 100%;
		align-items: center;
		justify-content: space-between;
		gap: var(--space-2);
	}

	.event-card-map .event-card__title {
		overflow: hidden;
		font-size: var(--font-size-xs);
		line-height: 1.2;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}

	/* Let the map and results grow vertically on narrow screens. */
	main#home[aria-label="Mapa de eventos"] {
		height: auto;
		min-height: 0;
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: auto;
		row-gap: var(--space-4);
		padding-top: var(--section-space);
		padding-bottom: var(--section-space);
	}

	/* Preserve the map's proportions while capping its height. */
	main#home[aria-label="Mapa de eventos"] > .map-canvas {
		height: min(50dvh, 42rem);
		aspect-ratio: auto;
		max-height: none;
	}

	/* Allow the results panel to follow the map in the page flow. */
	main#home[aria-label="Mapa de eventos"] > .events {
		height: auto;
		grid-template-rows: auto auto auto;
		gap: var(--space-4);
		overflow: visible;
	}

	/* Remove desktop filter insets from the stacked mobile layout. */
	main#home[aria-label="Mapa de eventos"] .explore-filters {
		padding: 0;
		background: transparent;
	}

	/* Restore the map panel title on mobile. */
	main#home[aria-label="Mapa de eventos"] .section__title {
		display: block;
		font-size: var(--font-size-s);
	}

	/* Let event cards flow naturally below the mobile filter controls. */
	main#home[aria-label="Mapa de eventos"] .events__grid {
		overflow: visible;
		padding: 0 0 var(--space-8);
	}

	/* Overlay the filter launcher at the end of the discipline row. */
	.explore-filters__discipline-wrap {
		position: relative;
		min-width: 0;
		width: 100%;
	}

	/* End the scroll viewport before the overlaid button to clip chips at every scroll position. */
	.explore-filters__discipline-wrap .explore-filters__group {
		width: calc(100% - 2.25rem - var(--space-3));
		padding-right: 0;
	}

	.map-filter-trigger {
		position: absolute;
		top: 0;
		right: 0;
		z-index: 1;
		display: inline-flex;
	}

	.explore-filters__group--facets {
		justify-content: flex-end;
		overflow: visible;
	}

	/* Hide individual filter chips; the bottom sheet contains their controls. */
	.explore-filters__group--facets .explore-filters__facet {
		display: none;
	}

/* Native bottom sheet for selecting map filters on mobile. */
	/* Anchor the filter dialog to the viewport bottom as a sheet. */
	dialog.map-filter-sheet[open] {
		position: fixed;
		inset: auto 0 0;
		display: grid;
		width: 100%;
		max-width: none;
		max-height: min(80dvh, 42rem);
		gap: var(--space-6);
		margin: 0;
		padding: var(--space-6) var(--content-gutter) var(--space-8);
		overflow-y: auto;
		border: 0;
		border-radius: var(--radius-card) var(--radius-card) 0 0;
		background: var(--color-background);
		color: var(--color-text-primary);
		box-shadow: 0 -0.5rem 2rem rgb(0 0 0 / 16%);
	}

	/* Dim the page behind the open filter sheet. */
	.map-filter-sheet::backdrop {
		background: rgb(0 0 0 / 45%);
	}

	/* Separate the sheet title from its close control. */
	.map-filter-sheet__header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: var(--space-4);
	}

	.map-filter-sheet__header h2 {
		font-size: var(--font-size-m);
	}

	/* Stack filter fields and the completion action vertically. */
	.map-filter-sheet__form {
		display: grid;
		gap: var(--space-4);
	}

}