/* Front page: map + feed.
   Mobile-first — the map sits above the feed until the viewport is wide enough to
   put them side by side. */

.sl-home {
	display: grid;
	grid-template-columns: 1fr;
	gap: 0;
}

/* ---------- Map panel ---------- */

.sl-home__map {
	position: relative;
	background: var(--sl-surface-hover);
}

.sl-map {
	height: 45vh;
	min-height: 300px;
	width: 100%;
	z-index: 1; /* Stay under the sticky header. */
}

.sl-map__fallback {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	height: 100%;
	padding: 2rem;
	text-align: center;
	color: var(--sl-text-muted);
}

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

.sl-legend {
	position: absolute;
	left: 1rem;
	bottom: 1rem;
	z-index: 2; /* Above the Leaflet pane. */
	max-width: 320px;
	padding: 0.875rem 1rem;
	background: var(--sl-surface);
	border: 1px solid var(--sl-border);
	border-radius: var(--sl-radius-lg);
	box-shadow: var(--sl-shadow-lg);
	font-size: 0.8125rem;
}

.sl-legend__title { font-size: 0.9375rem; margin-bottom: 0.25rem; }

.sl-legend__hint {
	margin: 0 0 0.75rem;
	color: var(--sl-text-muted);
	font-size: 0.75rem;
	line-height: 1.45;
}

.sl-legend__list {
	list-style: none;
	margin: 0 0 0.75rem;
	padding: 0;
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.375rem 0.75rem;
}

.sl-legend__item {
	display: flex;
	align-items: center;
	gap: 0.4375rem;
	color: var(--sl-text-muted);
	font-size: 0.75rem;
	white-space: nowrap;
}

.sl-legend__dot {
	width: 10px;
	height: 10px;
	flex: none;
	border-radius: 999px;
	background: var(--swatch);
}

/* "No reports yet" is an absence, so it gets an outline rather than a colour. */
.sl-legend__dot--none {
	background: transparent;
	border: 1px dashed var(--sl-border-strong);
}

.sl-legend__foot {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin: 0;
	padding-top: 0.625rem;
	border-top: 1px solid var(--sl-border);
	color: var(--sl-text-muted);
	font-size: 0.75rem;
}

.sl-legend__badge {
	display: grid;
	place-items: center;
	width: 22px;
	height: 22px;
	flex: none;
	border-radius: 999px;
	background: var(--sl-red);
	color: var(--sl-red-contrast);
	font-size: 0.6875rem;
	font-weight: 700;
}

/*
 * On a phone the map is only ~360px tall, and a floating legend covers the whole
 * south of the country — Valais, Ticino and Geneva vanish under it. Now that the
 * cantons themselves carry the data, hiding a third of them is not a trade worth
 * making, so on small screens the legend stops floating and sits under the map.
 */
@media (max-width: 560px) {
	.sl-legend {
		position: static;
		max-width: none;
		padding: 0.75rem 1rem;
		border-width: 1px 0 0;
		border-radius: 0;
		box-shadow: none;
	}
	.sl-legend__hint { display: none; }
}

/* ---------- Canton boundaries ---------- */

/*
 * Shape and behaviour only. The *fill* of each bracket is generated from
 * sl_cost_brackets() in inc/enqueue.php, so the pins, the legend swatches and these
 * polygons all read their colour from one array — and, through it, from tokens.css.
 */
.sl-canton {
	fill-opacity: 0.42;
	stroke: #fff;
	stroke-opacity: 0.75;
	stroke-width: 1;
	transition: fill-opacity 0.15s ease;
}

.sl-canton:hover,
.sl-canton:focus {
	fill-opacity: 0.62;
	stroke-opacity: 1;
	outline: none;
}

/* A canton nobody has reported from: hold the border, drop the fill to a whisper so
   the map underneath still reads. It is "no data", not a sixth cost bracket. */
.sl-canton--none {
	fill: var(--sl-text-faint);
	fill-opacity: 0.08;
}

.sl-canton--none:hover,
.sl-canton--none:focus { fill-opacity: 0.18; }

/* Dark mode: the tiles are darker, so the same fills need less opacity to read, and
   a white hairline border is too loud. */
@media (prefers-color-scheme: dark) {
	.sl-canton { fill-opacity: 0.38; stroke: #0d0f13; stroke-opacity: 0.55; }
	.sl-canton:hover, .sl-canton:focus { fill-opacity: 0.58; }
}

:root[data-theme='dark'] .sl-canton { fill-opacity: 0.38; stroke: #0d0f13; stroke-opacity: 0.55; }
:root[data-theme='dark'] .sl-canton:hover,
:root[data-theme='dark'] .sl-canton:focus { fill-opacity: 0.58; }

:root[data-theme='light'] .sl-canton { stroke: #fff; stroke-opacity: 0.75; }

/* Canton tooltip. Leaflet's default is a white chip that ignores dark mode. */
.leaflet-tooltip.sl-tip {
	padding: 0.4rem 0.55rem;
	border: 1px solid var(--sl-border);
	border-radius: 6px;
	background: var(--sl-surface);
	color: var(--sl-text);
	box-shadow: 0 2px 10px rgb(0 0 0 / 18%);
	font-size: 0.75rem;
	line-height: 1.4;
	white-space: nowrap;
}

.leaflet-tooltip.sl-tip .sl-tip__none { color: var(--sl-text-faint); }

/* Re-point the little arrow at our surface colour, whichever side it lands on. */
.leaflet-tooltip-left.sl-tip::before  { border-left-color: var(--sl-surface); }
.leaflet-tooltip-right.sl-tip::before { border-right-color: var(--sl-surface); }
.leaflet-tooltip-top.sl-tip::before    { border-top-color: var(--sl-surface); }
.leaflet-tooltip-bottom.sl-tip::before { border-bottom-color: var(--sl-surface); }

/* ---------- Map pins ---------- */

/* Leaflet gives divIcon a default background/border; clear it. */
.sl-pin-wrap { background: none; border: 0; }

.sl-pin {
	position: relative;
	display: block;
	width: 44px;
	height: 44px;
	border-radius: 999px;
	background: var(--pin, var(--sl-red));
	box-shadow: 0 2px 8px rgb(0 0 0 / 30%);
}

/* The teardrop tail. */
.sl-pin::after {
	content: "";
	position: absolute;
	left: 50%;
	bottom: -6px;
	width: 12px;
	height: 12px;
	background: var(--pin, var(--sl-red));
	transform: translateX(-50%) rotate(45deg);
	border-radius: 0 0 3px 0;
}

.sl-pin__avatar {
	position: absolute;
	inset: 3px;
	width: calc(100% - 6px);
	height: calc(100% - 6px);
	border-radius: 999px;
	object-fit: cover;
	z-index: 1;
}

.sl-pin__badge {
	position: absolute;
	right: -4px;
	bottom: -2px;
	z-index: 2;
	display: grid;
	place-items: center;
	min-width: 20px;
	height: 20px;
	padding: 0 4px;
	border-radius: 999px;
	background: var(--pin, var(--sl-red));
	border: 2px solid var(--sl-surface);
	color: #fff;
	font-size: 0.6875rem;
	font-weight: 700;
	line-height: 1;
}

.leaflet-marker-icon:focus-visible .sl-pin {
	outline: 2px solid var(--sl-focus);
	outline-offset: 2px;
}

/* ---------- Map popup ---------- */

.leaflet-popup-content-wrapper {
	background: var(--sl-surface);
	color: var(--sl-text);
	border-radius: var(--sl-radius);
	box-shadow: var(--sl-shadow-lg);
}
.leaflet-popup-tip { background: var(--sl-surface); }
.leaflet-popup-content { margin: 0.75rem; }

.sl-pop__head {
	margin: 0 0 0.5rem;
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--sl-text-faint);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.sl-pop__list { list-style: none; margin: 0; padding: 0; }
.sl-pop__item + .sl-pop__item {
	margin-top: 0.5rem;
	padding-top: 0.5rem;
	border-top: 1px solid var(--sl-border);
}

.sl-pop__link { display: block; text-decoration: none; }

.sl-pop__title {
	display: block;
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.35;
	color: var(--sl-text);
}
.sl-pop__link:hover .sl-pop__title { color: var(--sl-red); }

.sl-pop__meta {
	display: block;
	font-size: 0.75rem;
	color: var(--sl-text-faint);
	margin-top: 0.125rem;
}

.sl-pop__cost {
	display: inline-block;
	margin-top: 0.375rem;
	font-size: 0.8125rem;
	font-weight: 700;
	color: var(--sl-red);
	font-variant-numeric: tabular-nums;
}

/* Leaflet's own chrome, themed. */
.leaflet-control-zoom a {
	background: var(--sl-surface);
	color: var(--sl-text);
	border-color: var(--sl-border);
}
.leaflet-control-zoom a:hover { background: var(--sl-surface-hover); color: var(--sl-text); }
.leaflet-control-attribution {
	background: color-mix(in srgb, var(--sl-surface) 85%, transparent);
	color: var(--sl-text-muted);
}
.leaflet-control-attribution a { color: var(--sl-text-muted); }

/* OSM tiles are photographic-light; in dark mode, knock them back so the pins and
   the surrounding UI still read as one page. */
:root[data-theme="dark"] .leaflet-tile-pane {
	filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.86) saturate(0.25) grayscale(0.25);
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .leaflet-tile-pane {
		filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.86) saturate(0.25) grayscale(0.25);
	}
}

/* ---------- Right rail ---------- */

.sl-home__rail {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	padding: 1.25rem 1rem 2.5rem;
	background: var(--sl-bg);
	min-width: 0;
}

/* ---------- Filters ---------- */

.sl-filters {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
}

.sl-filter {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex: 1 1 160px;
	min-width: 0;
	padding: 0.4375rem 0.625rem;
	background: var(--sl-surface);
	border: 1px solid var(--sl-border);
	border-radius: var(--sl-radius);
}

.sl-filter__icon {
	display: grid;
	place-items: center;
	width: 30px;
	height: 30px;
	flex: none;
	border-radius: 7px;
	background: var(--sl-surface-hover);
	color: var(--sl-text-muted);
}

.sl-filter__body {
	display: flex;
	flex-direction: column;
	min-width: 0;
	flex: 1;
}

.sl-filter__label {
	font-size: 0.6875rem;
	color: var(--sl-text-faint);
	line-height: 1.2;
}

.sl-filter__select {
	width: 100%;
	border: 0;
	padding: 0;
	background: transparent;
	color: var(--sl-text);
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	line-height: 1.3;
	cursor: pointer;
}
.sl-filter__select:focus-visible { outline-offset: 1px; }

.sl-filters__submit { flex: none; }

.sl-filters__reset {
	font-size: 0.8125rem;
	color: var(--sl-text-muted);
	text-decoration: none;
}
.sl-filters__reset:hover { color: var(--sl-red); }

/* ---------- Feed ---------- */

.sl-feed__title {
	font-size: 1.125rem;
	margin-bottom: 0.5rem;
}

.sl-tabs {
	display: flex;
	gap: 1.25rem;
	margin-bottom: 0.25rem;
	border-bottom: 1px solid var(--sl-border);
}

.sl-tabs__tab {
	position: relative;
	padding: 0.5rem 0;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--sl-text-muted);
	text-decoration: none;
}
.sl-tabs__tab:hover { color: var(--sl-text); }

.sl-tabs__tab.is-current { color: var(--sl-red); }
.sl-tabs__tab.is-current::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: -1px;
	height: 2px;
	background: var(--sl-red);
	border-radius: 2px 2px 0 0;
}

.sl-feed__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

/* ---------- Report card ---------- */

.sl-rcard {
	background: var(--sl-surface);
	border: 1px solid var(--sl-border);
	border-radius: var(--sl-radius-lg);
	box-shadow: var(--sl-shadow);
	transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.sl-rcard:hover {
	box-shadow: var(--sl-shadow-lg);
	transform: translateY(-1px);
}

.sl-rcard__link {
	display: flex;
	gap: 0.875rem;
	padding: 1rem;
	text-decoration: none;
	color: inherit;
}

.sl-rcard__avatar {
	width: 52px;
	height: 52px;
	flex: none;
}

.sl-rcard__body { min-width: 0; flex: 1; }

.sl-rcard__title {
	font-size: 0.9375rem;
	margin-bottom: 0.1875rem;
	color: var(--sl-text);
}
.sl-rcard__link:hover .sl-rcard__title { color: var(--sl-red); }

.sl-rcard__meta {
	margin: 0 0 0.5rem;
	font-size: 0.75rem;
	color: var(--sl-text-faint);
}

.sl-rcard__excerpt {
	margin: 0 0 0.625rem;
	font-size: 0.8125rem;
	line-height: 1.5;
	color: var(--sl-text-muted);

	/* Two lines, then ellipsis — cards must stay the same height in a scannable list. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.sl-rcard__cost {
	display: inline-block;
	margin: 0 0 0.625rem;
	padding: 0.25rem 0.5rem;
	border-radius: 6px;
	background: color-mix(in srgb, var(--swatch) 15%, transparent);
	color: var(--swatch);
	font-size: 0.8125rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.sl-rcard__stats {
	display: flex;
	align-items: center;
	gap: 0.875rem;
	margin: 0;
	font-size: 0.75rem;
	color: var(--sl-text-faint);
}

.sl-rcard__stat {
	display: inline-flex;
	align-items: center;
	gap: 0.3125rem;
}
.sl-rcard__stat .sl-ico { width: 14px; height: 14px; }

.sl-rcard__time { margin-left: auto; }

.sl-feed__more { margin-top: 0.25rem; }

/* ---------- Desktop: map beside the feed ---------- */

@media (min-width: 1000px) {
	.sl-home {
		grid-template-columns: minmax(0, 1fr) 520px;
		align-items: start;
	}

	/*
	 * The map sticks to the viewport while the feed scrolls past it. Deliberately
	 * NOT a 100vh app shell with an internally-scrolling rail: that traps the page
	 * footer permanently off-screen. This keeps one normal page scroll.
	 */
	.sl-home__map {
		position: sticky;
		top: var(--sl-header-h);
		height: calc(100vh - var(--sl-header-h));
	}
	.sl-map { height: 100%; }

	.sl-home__rail {
		padding: 1.5rem;
		border-left: 1px solid var(--sl-border);
		background: var(--sl-surface-2);
		min-height: calc(100vh - var(--sl-header-h));
	}
}

@media (min-width: 1400px) {
	.sl-home { grid-template-columns: minmax(0, 1fr) 600px; }
}
