/* ============================================================
   Service Finder (layout "service_finder") - Nearby Help
   Design ref: designs/Nearby Help.png + nearby help mobile.png.

   BOTH design files are unfinished wireframes: Emma left the
   layout in default greys/blues with a note that "it needs
   Littledale's branding applied to it". So the STRUCTURE here
   follows the mockup exactly (filter chips + area dropdown, list
   left / sticky map right, mobile List-Map toggle, legend), while
   every colour, radius, type and pin comes from the theme tokens.

   Desktop: list ~45% / map ~55%, map sticky, list scrolls.
   Mobile:  List/Map toggle - stacking a long list under a
            full-width map buries everything (Emma's brief).
   ============================================================ */

.service-finder {
	background: var(--color-light-grey);
	padding-block: var(--section-padding);
}

.service-finder__intro {
	max-width: 48rem;
	margin: 0 auto var(--space-lg);
	text-align: center;
}

.service-finder__heading {
	margin-bottom: 0;
}

/* ---- Panel ---- */

.service-finder__panel {
	background: var(--color-cream-light);
	border: 1px solid var(--color-footer-line);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-card);
	overflow: hidden;
}

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

.service-finder__filters {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-sm);
	padding: var(--space-sm);
	border-bottom: 1px solid var(--color-footer-line);
}

.service-finder__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	flex: 1 1 auto;
}

.service-finder__chip {
	padding: 0.5rem 0.9375rem;
	font-family: var(--font-body);
	font-size: 0.875rem;
	font-weight: 500;
	line-height: 1.2;
	color: var(--color-teal-dark);
	background: transparent;
	border: 1px solid var(--color-input-border);
	border-radius: 999px;
	cursor: pointer;
	transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

.service-finder__chip:hover {
	border-color: var(--color-teal);
	color: var(--color-teal);
}

.service-finder__chip.is-active {
	background: var(--color-teal-dark);
	border-color: var(--color-teal-dark);
	color: var(--color-text-on-dark);
}

.service-finder__chip:focus-visible {
	outline: 2px solid var(--color-caramel);
	outline-offset: 2px;
}

/* Search box - the primary control now the directory covers the whole UK.
   Same pill language as the chips beside it. */

.service-finder__search {
	position: relative;
	flex: 1 1 100%;
	min-width: 0;
}

.service-finder__search-icon {
	position: absolute;
	top: 50%;
	left: 0.9375rem;
	width: 15px;
	height: 15px;
	transform: translateY(-50%);
	color: var(--color-text-muted);
	pointer-events: none;
}

.service-finder__search-icon svg {
	display: block;
	width: 100%;
	height: 100%;
}

.service-finder__search-input {
	width: 100%;
	padding: 0.5625rem 2.5rem 0.5625rem 2.5rem;
	font-family: var(--font-body);
	font-size: 0.9375rem;
	color: var(--color-text);
	background: transparent;
	border: 1px solid var(--color-input-border);
	border-radius: 999px;
}

.service-finder__search-input::placeholder {
	color: var(--color-placeholder);
}

.service-finder__search-input:focus-visible {
	outline: 2px solid var(--color-caramel);
	outline-offset: 2px;
}

/* The theme renders its own clear button; hide WebKit's built-in one. */
.service-finder__search-input::-webkit-search-cancel-button {
	-webkit-appearance: none;
	appearance: none;
}

.service-finder__search-clear {
	position: absolute;
	top: 50%;
	right: 0.5rem;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	transform: translateY(-50%);
	color: var(--color-text-muted);
	background: none;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	transition: background-color var(--transition), color var(--transition);
}

.service-finder__search-clear:hover {
	background: var(--color-light-grey);
	color: var(--color-teal-dark);
}

.service-finder__search-clear:focus-visible {
	outline: 2px solid var(--color-caramel);
	outline-offset: 1px;
}

.service-finder__search-clear svg {
	width: 12px;
	height: 12px;
}

/* ---- Mobile List/Map toggle ---- */

.service-finder__views {
	display: flex;
	margin: var(--space-sm) var(--space-sm) 0;
	padding: 4px;
	background: var(--color-light-grey);
	border-radius: 999px;
}

.service-finder__view {
	flex: 1;
	padding: 0.5rem 1rem;
	font-family: var(--font-body);
	font-size: 0.9375rem;
	font-weight: 600;
	color: var(--color-teal-dark);
	background: transparent;
	border: 0;
	border-radius: 999px;
	cursor: pointer;
	transition: background-color var(--transition), color var(--transition);
}

.service-finder__view.is-active {
	background: var(--color-teal-dark);
	color: var(--color-text-on-dark);
}

.service-finder__view:focus-visible {
	outline: 2px solid var(--color-caramel);
	outline-offset: -2px;
}

/* ---- Body ---- */

.service-finder__count {
	margin: 0 0 var(--space-xs);
	font-size: 0.875rem;
	color: var(--color-text-muted);
}

/* Group sections: "National support" then "Local services A-Z". The heads
   stay stuck to the top of the scrolling list so it is always clear which
   part of the directory is going past. */

.service-finder__groups {
	display: flex;
	flex-direction: column;
	gap: var(--space-md);
}

.service-finder__group-head {
	position: sticky;
	/* On mobile the PAGE scrolls, so the head must clear the fixed header;
	   from 768 the list column scrolls instead and 0 is correct. */
	top: var(--header-height);
	z-index: 2;
	margin: 0 0 0.625rem;
	padding: 0.25rem 0;
	font-family: var(--font-body);
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 1.5px;
	text-transform: uppercase;
	color: var(--color-accent);
	background: var(--color-cream-light);
}

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

.service-finder__empty {
	margin: var(--space-md) 0 0;
	color: var(--color-text-muted);
}

/* ---- Card ---- */

.service-card {
	position: relative;
	padding: 0.9375rem 1.125rem;
	background: var(--color-cream-light);
	border: 1px solid var(--color-footer-line);
	border-left: 3px solid transparent;
	border-radius: var(--radius-sm);
	transition: border-color var(--transition), background-color var(--transition);
}

.service-finder__item.is-selected .service-card {
	border-color: var(--color-caramel);
	border-left-color: var(--color-caramel);
	background: var(--color-cream);
}

.service-finder__item--home .service-card {
	border-left-color: var(--color-caramel-light);
}

.service-card__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	margin: 0 0 0.375rem;
}

.service-card__badge {
	padding: 0.1875rem 0.5rem;
	font-size: 0.75rem;
	font-weight: 600;
	line-height: 1.4;
	border-radius: var(--radius-sm);
}

.service-card__badge--drug-alcohol {
	background: var(--color-badge-drug-bg);
	color: var(--color-badge-drug-text);
}

.service-card__badge--peer-support {
	background: var(--color-badge-peer-bg);
	color: var(--color-badge-peer-text);
}

.service-card__badge--family-support {
	background: var(--color-badge-family-bg);
	color: var(--color-badge-family-text);
}

.service-card__badge--crisis {
	background: var(--color-badge-crisis-bg);
	color: var(--color-badge-crisis-text);
}

.service-card__area {
	font-size: 0.8125rem;
	color: var(--color-text-muted);
}

.service-card__name {
	margin: 0 0 0.25rem;
	font-size: 1.0625rem;
	line-height: 1.3;
}

/* The button stretches over the whole card so any dead space selects it;
   the action links below opt back out with position/z-index. Nested
   interactive elements are avoided - the links are siblings, not children. */
.service-card__select {
	padding: 0;
	font: inherit;
	color: var(--color-heading);
	text-align: left;
	background: none;
	border: 0;
	cursor: pointer;
}

.service-card__select::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: var(--radius-sm);
}

.service-card__select:focus-visible {
	outline: none;
}

.service-card__select:focus-visible::after {
	outline: 2px solid var(--color-caramel);
	outline-offset: -2px;
}

.service-card__desc {
	margin: 0;
	font-size: 0.9375rem;
	line-height: 1.5;
	color: var(--color-text);
}

/* Caveat small print, e.g. "Number shown is head office, not a helpline." */
.service-card__note {
	margin: 0.375rem 0 0;
	font-size: 0.8125rem;
	line-height: 1.45;
	color: var(--color-text-muted);
}

.service-card__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.375rem 0.75rem;
	margin: 0.5rem 0 0;
	font-size: 0.875rem;
}

.service-card__action {
	position: relative;
	z-index: 1; /* above the card-wide select button */
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	color: var(--color-teal);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.service-card__action:hover {
	color: var(--color-caramel);
}

/* A phone value that is not a dialable number ("Online webchat") renders as
   plain text - same slot, no link affordance. */
.service-card__action--plain {
	color: var(--color-text-muted);
	text-decoration: none;
}

.service-card__external {
	width: 11px;
	height: 11px;
}

.service-card__external svg {
	display: block;
	width: 100%;
	height: 100%;
}

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

.service-finder__map {
	width: 100%;
	height: 100%;
	min-height: 320px;
	background: var(--color-light-grey);
}

/* Leaflet writes its own font stack; keep the panel on brand */
.service-finder__map-col .leaflet-container {
	font-family: var(--font-body);
	border-radius: var(--radius-sm);
}

.service-finder__legend {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-sm);
	margin: var(--space-xs) 0 0;
	font-size: 0.8125rem;
	color: var(--color-text-muted);
}

.service-finder__key {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
}

.service-finder__key::before {
	content: "";
	width: 10px;
	height: 10px;
	border-radius: 50%;
}

.service-finder__key--service::before {
	background: var(--color-teal);
}

.service-finder__key--selected::before {
	background: var(--color-caramel);
}

.service-finder__key--home::before {
	background: var(--color-caramel);
	border-radius: 50% 50% 50% 0;
	transform: rotate(-45deg);
}

/* ---- Map pins (Leaflet divIcon contents) ----
   Three states, all from the palette: a plain teal dot for a service, a
   larger caramel dot for the selected one, and a caramel TEARDROP for
   Littledale so the Hall reads as a different kind of thing, not just a
   different colour (per the brief: "a distinct branded pin"). */

.sf-pin {
	display: block;
	width: 100%;
	height: 100%;
}

.sf-pin__dot {
	display: block;
	box-sizing: border-box;
}

.sf-pin--service .sf-pin__dot,
.sf-pin--selected .sf-pin__dot {
	width: 18px;
	height: 18px;
	border-radius: 50%;
	border: 2px solid var(--color-cream-light);
	box-shadow: 0 1px 4px rgb(0 31 38 / 0.35);
}

.sf-pin--service .sf-pin__dot {
	background: var(--color-teal);
}

.sf-pin--selected .sf-pin__dot {
	background: var(--color-caramel);
	transform: scale(1.2);
}

.sf-pin--home .sf-pin__dot {
	position: relative;
	width: 28px;
	height: 28px;
	background: var(--color-caramel);
	border: 3px solid var(--color-cream-light);
	border-radius: 50% 50% 50% 0;
	transform: rotate(-45deg);
	box-shadow: 0 2px 6px rgb(0 31 38 / 0.4);
}

/* white centre dot, counter-rotated so it stays circular */
.sf-pin--home .sf-pin__dot::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 9px;
	height: 9px;
	background: var(--color-cream-light);
	border-radius: 50%;
}

/* ---- Cluster badge (leaflet.markercluster divIcon contents) ----
   A numbered teal circle; clicking zooms into the cluster. Littledale's
   teardrop never joins a cluster (see service-finder.js). */

.sf-cluster {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	background: var(--color-teal-dark);
	color: var(--color-text-on-dark);
	font-family: var(--font-body);
	font-size: 0.8125rem;
	font-weight: 600;
	border: 2px solid var(--color-cream-light);
	border-radius: 50%;
	box-shadow: 0 1px 4px rgb(0 31 38 / 0.35);
	transition: background-color var(--transition);
}

.leaflet-marker-icon:hover .sf-cluster {
	background: var(--color-teal);
}

/* ---- Mobile (default): list only, map behind the toggle ---- */

.service-finder__body {
	padding: var(--space-sm);
}

.service-finder__map-col {
	display: none;
}

.service-finder.is-map-view .service-finder__list-col {
	display: none;
}

.service-finder.is-map-view .service-finder__map-col {
	display: block;
}

.service-finder.is-map-view .service-finder__map {
	height: 60vh;
	min-height: 360px;
}

/* ---- Urgent help card ---- */

.service-finder__urgent {
	max-width: 30rem;
	margin: var(--space-lg) auto 0;
	padding: var(--space-md);
	background: var(--color-cream);
	border-radius: var(--radius-sm);
	text-align: center;
}

.service-finder__urgent-heading {
	margin-bottom: var(--space-sm);
	font-size: var(--text-heading-sm);
}

.service-finder__urgent-text {
	margin-bottom: var(--space-sm);
}

.service-finder__urgent-list {
	list-style: none;
	margin: 0;
	padding: 0;
	text-align: left;
	display: inline-block;
}

.service-finder__urgent-item {
	position: relative;
	padding-left: 1rem;
	margin-bottom: 0.25rem;
}

.service-finder__urgent-item::before {
	content: "\00b7";
	position: absolute;
	left: 0.25rem;
}

.service-finder__urgent-item.is-bold {
	font-weight: 700;
}

.service-finder__urgent-item a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.service-finder__urgent-item a:hover {
	color: var(--color-caramel);
}

/* ---- Tablet (768-1023): the deliberate middle treatment.
       Side by side already works at this width, so it switches to the
       desktop split early rather than stretching the mobile list wide. ---- */

@media (min-width: 768px) {
	.service-finder__filters {
		padding: var(--space-md);
	}

	/* Search shares the row with the chips from tablet up. */
	.service-finder__search {
		flex: 1 1 16rem;
	}

	/* From here the LIST COLUMN scrolls (not the page), so the sticky heads
	   anchor to the top of that scroll box instead of clearing the fixed
	   site header. */
	.service-finder__group-head {
		top: 0;
	}

	.service-finder__body {
		display: grid;
		grid-template-columns: 45fr 55fr;
		gap: var(--space-md);
		padding: var(--space-md);
	}

	/* The toggle is a mobile affordance only */
	.service-finder__views {
		display: none;
	}

	.service-finder__map-col {
		display: block;
		position: sticky;
		top: calc(var(--header-height) + 1rem);
		align-self: start;
	}

	.service-finder.is-map-view .service-finder__list-col {
		display: block;
	}

	.service-finder__list-col {
		max-height: 32rem;
		overflow-y: auto;
		padding-right: 0.5rem;
	}

	.service-finder__map {
		height: 32rem;
	}

	.service-finder__urgent {
		max-width: 34rem;
		padding: var(--space-lg);
	}
}

@media (min-width: 1024px) {
	.service-finder__list-col,
	.service-finder__map {
		max-height: 34rem;
		height: 34rem;
	}

	.service-finder__map {
		max-height: none;
	}

	.service-card__name {
		font-size: 1.125rem;
	}
}

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

@media (prefers-reduced-motion: reduce) {
	.service-card,
	.service-finder__chip,
	.service-finder__view {
		transition: none;
	}
}
