/**
 * LEDitgo Partner Map
 *
 * Loaded after MapPress's own stylesheet (registered with `mappress` as a
 * dependency). Nothing here edits MapPress; the overrides target classes MapPress
 * already emits.
 */

.lpm {
	--lpm-accent: #3461ac;
	--lpm-highlight: #f7a717;
	--lpm-text: #676767;
	--lpm-muted: #919999;
	--lpm-line: #e2e8f0;
	--lpm-surface: #ffffff;
	--lpm-surface-alt: #f8fafc;
	--lpm-sidebar-width: 340px;

	display: flex;
	align-items: stretch;
	height: var(--lpm-height, 640px);
	border: 1px solid var(--lpm-line);
	border-radius: 10px;
	overflow: hidden;
	background: var(--lpm-surface);
	color: var(--lpm-text);
	font-size: 16px;
}

/* ------------------------------------------------------------------ sidebar */

.lpm-sidebar {
	display: flex;
	flex-direction: column;
	flex: 0 0 var(--lpm-sidebar-width);
	max-width: var(--lpm-sidebar-width);
	background: var(--lpm-surface);
	border-right: 1px solid var(--lpm-line);
	overflow: hidden;
}

.lpm-sidebar-header {
	padding: 18px 20px 10px;
	border-bottom: 1px solid var(--lpm-line);
}

.lpm-sidebar-title {
	margin: 0 0 4px;
	font-size: 1rem;
	font-weight: 700;
	color: var(--lpm-accent);
}

.lpm-sidebar-count {
	margin: 0;
	font-size: 0.78rem;
	color: var(--lpm-muted);
}

/* ------------------------------------------------------------------- search */

.lpm-search {
	position: relative;
	margin: 12px 20px 0;
}

.lpm-search-icon {
	position: absolute;
	left: 10px;
	top: 50%;
	transform: translateY(-50%);
	color: var(--lpm-muted);
	pointer-events: none;
}

.lpm-search-input {
	width: 100%;
	box-sizing: border-box;
	padding: 9px 12px 9px 34px;
	border: 1px solid var(--lpm-line);
	border-radius: 8px;
	background: var(--lpm-surface-alt);
	color: var(--lpm-text);
	font: inherit;
	font-size: 0.85rem;
	outline: none;
	transition: border-color 0.2s;
}

.lpm-search-input:focus {
	border-color: var(--lpm-highlight);
}

/* ------------------------------------------------------------------- groups */

.lpm-groups {
	flex: 1;
	overflow-y: auto;
	padding: 12px 0 20px;
	scrollbar-width: thin;
	scrollbar-color: var(--lpm-line) transparent;
}

.lpm-group + .lpm-group {
	margin-top: 2px;
}

.lpm-group-toggle {
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	padding: 10px 20px 8px;
	border: 0;
	background: none;
	font: inherit;
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: #94a3b8;
	cursor: pointer;
	text-align: left;
	transition: color 0.15s;
}

.lpm-group-toggle:hover,
.lpm-group-toggle:focus-visible {
	color: var(--lpm-highlight);
}

.lpm-group-label {
	flex: 1;
}

.lpm-group-count {
	padding: 3px 10px;
	border-radius: 20px;
	background: var(--lpm-highlight);
	color: #fff;
	font-size: 0.7rem;
	letter-spacing: 0;
}

.lpm-chevron {
	width: 8px;
	height: 8px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg) translate(-2px, -2px);
	transition: transform 0.2s;
}

.lpm-group.is-open .lpm-chevron {
	transform: rotate(225deg) translate(-2px, -2px);
}

/* -------------------------------------------------------------------- items */

.lpm-item {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 9px 20px;
	border: 0;
	border-left: 3px solid transparent;
	background: none;
	font: inherit;
	text-align: left;
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s;
}

.lpm-item:hover {
	background: #fff8ec;
	border-left-color: var(--lpm-highlight);
}

.lpm-item.is-selected {
	background: #eef2fb;
	border-left-color: var(--lpm-accent);
}

.lpm-avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 36px;
	width: 36px;
	height: 36px;
	border-radius: 8px;
	background: linear-gradient(135deg, var(--lpm-accent), var(--lpm-highlight));
	color: #fff;
	font-size: 0.75rem;
	font-weight: 700;
	overflow: hidden;
}

/*
 * The POI's own thumbnail, when it has one. Logos are usually wider than tall and
 * shouldn't be cropped, so this contains rather than covers, on a neutral tile.
 * `!important` on max-width/height because themes routinely style content images.
 */
.lpm-avatar-image {
	background: var(--lpm-surface-alt);
	object-fit: contain;
	padding: 2px;
	box-sizing: border-box;
	max-width: 36px !important;
	max-height: 36px !important;
	border: 1px solid var(--lpm-line);
	box-shadow: none;
}

.lpm-item-info {
	flex: 1;
	min-width: 0;
}

.lpm-item-name {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 0.84rem;
	font-weight: 600;
	color: var(--lpm-accent);
}

.lpm-item-arrow {
	flex: 0 0 auto;
	color: var(--lpm-muted);
}

.lpm-empty {
	padding: 40px 20px;
	text-align: center;
	font-size: 0.84rem;
	color: #94a3b8;
}

/* ---------------------------------------------------------------------- map */

.lpm-map {
	flex: 1;
	min-width: 0;
	position: relative;
}

/* MapPress writes an inline width/height onto its layout root; the flex column
   owns the size here. */
.lpm-map .mapp-layout {
	width: 100% !important;
	height: 100% !important;
	max-width: none;
}

/* MapPress's own POI list stays rendered — its `mapp-selected` class is how we
   learn that a marker was clicked — but it must not be visible. */
.lpm-map .mapp-sidebar,
.lpm-map .mapp-sidebar-toggle,
.lpm-map .mapp-footer {
	display: none !important;
}

/* ------------------------------------------------------------------ markers */

/*
 * MapPress free renders every marker as
 *   <img class="leaflet-marker-icon" src="{baseurl}/images/red-dot.png">
 * sized 32x32 with the anchor at [16,32]. getIconUrl() ignores the POI's iconid,
 * so the src cannot be changed without editing the plugin.
 *
 * Instead the raster is collapsed by padding the content box to zero width, and our
 * pin is painted as the element background. Height goes to 40px with a matching
 * -40px top margin so the tip of the pin stays exactly on the anchor point.
 *
 * The [src$="red-dot.png"] guard leaves MapPress's geolocation marker alone.
 */
.lpm-map img.leaflet-marker-icon[src$="red-dot.png"] {
	box-sizing: border-box !important;
	width: 32px !important;
	height: 40px !important;
	margin-top: -40px !important;
	padding-left: 32px;
	background: url(pin.svg) no-repeat center center / contain;
	filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
	transition: background-image 0.12s ease, transform 0.12s ease;
}

/*
 * Selected pin. MapPress toggles `mapp-marker-scale` on the marker element itself
 * when its Highlight setting is "Scale" — its own rule for that class
 * (`.mapp-marker-scale img`) is a descendant selector and never matches on Leaflet,
 * so the class is free for us to use.
 *
 * Note this class tracks hover as well as selection; MapPress exposes only one
 * boolean for both.
 */
.lpm-map img.leaflet-marker-icon[src$="red-dot.png"].mapp-marker-scale {
	background-image: url(pin-active.svg);
	transform-origin: 50% 100%;
}

/* ------------------------------------------------------------------- popups */

/*
 * Note on the fallbacks below: MapPress renders the popup as an absolutely
 * positioned overlay, and it only inherits the palette because it happens to sit
 * inside .lpm. Literal fallbacks keep the button readable even if that ever changes
 * — white text on an unresolved background would otherwise be invisible.
 */

/*
 * MapPress builds the popup as
 *   .mapp-ib-wrapper > .mapp-ib-content > .mapp-ib > .mapp-iw
 *                                                      > .mapp-thumbnail   (React)
 *                                                      > .mapp-info
 *                                                          > .mapp-template (our markup)
 * Only the contents of .mapp-template come from the popup template — everything
 * else is React, so it is reachable by CSS but not by markup. `thumbsPopup` is set
 * to "top" for our pages, which puts MapPress's own `mapp-thumb-top` class on
 * .mapp-iw and stacks the logo above the text.
 */

.lpm-map .mapp-ib {
	border: 0;
	border-radius: 12px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.lpm-map .mapp-iw {
	width: 260px;
	min-width: 0;
}

/* Logo strip. The inline height MapPress writes here only exists when both
   thumbWidth and thumbHeight are set, hence !important. */
.lpm-map .mapp-iw .mapp-thumbnail {
	height: 64px !important;
	width: 100% !important;
	background: var(--lpm-surface-alt, #f8fafc);
	border-bottom: 1px solid var(--lpm-line, #e2e8f0);
	padding: 8px;
	box-sizing: border-box;
}

/* MapPress ships `object-fit: cover; max-width: none` on popup images, which crops
   wide partner logos. Contain them instead. The width/height presentation
   attributes on the img are overridden by these rules. */
.lpm-map .mapp-iw .mapp-thumbnail img {
	width: 100% !important;
	height: 100% !important;
	max-width: 100% !important;
	max-height: 100% !important;
	object-fit: contain;
}

/* MapPress reserves min-height: 100px here, which leaves dead space under short
   popups. */
.lpm-map .mapp-iw .mapp-info {
	padding: 14px 16px;
	min-height: 0;
}

/* `.mapp-ib .mapp-iw *` sets font-size: 13px at (0,2,1), so anything that changes
   a size has to outweigh it — the .lpm-map prefix does. */
.lpm-map .mapp-ib .mapp-iw .mapp-title {
	margin-bottom: 4px;
	font-size: 0.95rem;
	font-weight: 700;
	line-height: 1.25;
	color: var(--lpm-accent, #3461ac);
}

.lpm-map .mapp-ib .mapp-iw .mapp-body {
	font-size: 0.8rem;
	line-height: 1.45;
	color: var(--lpm-text, #676767);
}

/*
 * The partner-site button. This anchor is appended to the location's description in
 * PHP (LPM_Config::add_popup_links) because MapPress escapes POI Data values when it
 * renders them, so a data field alone can never be clickable.
 */
.lpm-map .mapp-ib .mapp-iw a.lpm-popup-link {
	display: block;
	margin-top: 12px;
	padding: 9px 10px;
	border-radius: 6px;
	background: var(--lpm-highlight, #f7a717);
	/* MapPress forces `color: #4272db !important` on every popup link
	   (css/mappress.css:842) to beat theme styles, so this has to match its weight. */
	color: #fff !important;
	font-size: 0.78rem;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	transition: background 0.15s ease;
}

.lpm-map .mapp-ib .mapp-iw a.lpm-popup-link:hover,
.lpm-map .mapp-ib .mapp-iw a.lpm-popup-link:focus {
	background: var(--lpm-accent, #3461ac);
	color: #fff !important;
}

/* Both fields drive the sidebar and the button rather than the popup text, so keep
   MapPress's auto-generated rows out. Hiding the rows instead of the whole
   .mapp-data table means any field added later still shows up. */
.lpm-map .mapp-data-region,
.lpm-map .mapp-data-website {
	display: none;
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 782px) {
	.lpm {
		flex-direction: column;
		height: auto;
	}

	.lpm-sidebar {
		flex: 0 0 auto;
		max-width: none;
		height: 45vh;
		border-right: 0;
		border-bottom: 1px solid var(--lpm-line, #e2e8f0);
	}

	.lpm-map {
		height: var(--lpm-height, 640px);
		max-height: 60vh;
	}
}

@media (prefers-reduced-motion: reduce) {
	.lpm *,
	.lpm-map img.leaflet-marker-icon[src$="red-dot.png"] {
		transition: none !important;
	}
}
