/*
 * Jamuh Läden – colors come straight from Blocksy's global vars, so the
 * component follows the site's light/dark mode. Fallbacks only matter
 * outside Blocksy. --jms-page-bg is set by stores.js from the real page background.
 */

.jms {
	--jms-text: var(--theme-text-color, #111111);
	--jms-accent: var(--theme-palette-color-1, #F1C232);
	--jms-accent-2: var(--theme-palette-color-2, #7BD9B4);
	--jms-link: var(--theme-link-initial-color, var(--jms-text));
	--jms-link-hover: var(--theme-link-hover-color, var(--jms-accent));
	--jms-btn-bg: var(--theme-button-background-initial-color, var(--jms-accent));
	--jms-btn-text: var(--theme-button-text-initial-color, #111111);
	--jms-line: var(--theme-border-color, color-mix(in srgb, var(--jms-text) 15%, transparent));
	--jms-muted: color-mix(in srgb, var(--jms-text) 70%, transparent);
	--jms-surface: color-mix(in srgb, var(--jms-text) 5%, transparent);
	--jms-page-bg: Canvas;
	--jms-radius: 6px;
	--jms-height: 72vh;

	color: var(--jms-text);
	font-size: 0.85em;
	line-height: 1.5;
	margin: 0 0 2em;
}

.jms *,
.jms *::before,
.jms *::after {
	box-sizing: border-box;
}

.jms [hidden] {
	display: none !important;
}

/* ---------- Controls */

.jms__controls {
	display: grid;
	gap: 14px;
	margin-bottom: 16px;
}

.jms__chip,
.jms__view,
.jms__btn,
.jms__reset,
.jms-item__show {
	font: inherit;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.jms__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.jms__chip {
	padding: 6px 14px;
	border: 2px solid var(--jms-line);
	border-radius: 999px;
	background: transparent;
	color: var(--jms-text);
	font-size: 0.9em;
	line-height: 1.3;
}

.jms__chip:hover {
	border-color: var(--jms-accent);
}

.jms__chip[aria-pressed="true"] {
	border-color: var(--jms-btn-bg);
	background: var(--jms-btn-bg);
	color: var(--jms-btn-text);
}

.jms__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.jms__status {
	margin: 0;
	color: var(--jms-muted);
	font-size: 0.9em;
}

.jms__views {
	display: none;
	border: 2px solid var(--jms-line);
	border-radius: 999px;
	padding: 2px;
}

.jms__view {
	padding: 4px 14px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--jms-text);
	font-size: 0.9em;
}

.jms__view[aria-pressed="true"] {
	background: var(--jms-text);
	color: var(--jms-page-bg);
}

.jms :focus-visible {
	outline: 2px solid var(--jms-accent-2);
	outline-offset: 2px;
}

/* ---------- Layout */

.jms__body {
	display: grid;
	gap: 16px;
}

.jms--js .jms__body {
	grid-template-columns: minmax(300px, 400px) 1fr;
	height: var(--jms-height);
	min-height: 520px;
	max-height: 900px;
}

.jms__listwrap {
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: var(--jms-line) transparent;
	border-top: 1px solid var(--jms-line);
}

/* Without JS: plain card grid, no map. */
.jms:not(.jms--js) .jms__list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	column-gap: 24px;
}

.jms__list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.jms__empty {
	padding: 24px 0;
	color: var(--jms-muted);
}

.jms__reset {
	margin-left: 6px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--jms-link);
	text-decoration: underline;
}

/* ---------- Items */

.jms-item {
	position: relative;
	margin: 0;
	padding: 14px 14px 14px 16px;
	border-bottom: 1px solid var(--jms-line);
	border-left: 3px solid transparent;
	transition: background-color 0.15s, border-color 0.15s;
}

.jms-item:hover {
	background: var(--jms-surface);
}

.jms-item.is-active {
	border-left-color: var(--jms-accent);
	background: var(--jms-surface);
}

.jms-item__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 10px;
}

.jms .jms-item__title {
	margin: 0 0 2px;
	color: var(--jms-text);
	font-size: 1.05em;
	font-weight: 600;
	line-height: 1.35;
}

.jms-item__addr {
	margin: 0 0 6px;
	color: var(--jms-muted);
}

.jms-item__street,
.jms-item__city {
	display: block;
}

.jms-icon {
	flex: none;
	width: 1.15em;
	height: 1.15em;
}

.jms-item__links {
	display: flex;
	flex-wrap: wrap;
	gap: 4px 16px;
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: 0.92em;
}

.jms-item__links li {
	margin: 0;
	padding: 0;
}

.jms .jms-item__links a,
.jms-popup__body .jms-item__links a {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--jms-link);
	text-decoration: none;
	overflow-wrap: anywhere;
}

.jms-item__links .jms-icon {
	color: var(--jms-accent-2);
}

.jms .jms-item__links a:hover,
.jms .jms-item__links a:focus-visible,
.jms-popup__body .jms-item__links a:hover {
	color: var(--jms-link-hover);
}

.jms .jms-item__links a:hover span,
.jms-popup__body .jms-item__links a:hover span {
	text-decoration: underline;
}

/* Target icon, top right on the title line. */
.jms-item__show {
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	margin: -6px -6px 0 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	color: var(--jms-muted);
	transition: color 0.15s, background-color 0.15s;
}

.jms-item__show .jms-icon {
	width: 20px;
	height: 20px;
}

.jms-item__show:hover,
.jms-item.is-active .jms-item__show {
	color: var(--jms-accent);
	background: var(--jms-surface);
}

.jms--nomap .jms-item__show {
	display: none;
}

/* Desktop with working map: compact entries, the whole entry opens the store on the map. */
@media (min-width: 800px) {
	.jms--compact:not(.jms--nomap) .jms__list .jms-item__street,
	.jms--compact:not(.jms--nomap) .jms__list .jms-item__links {
		display: none;
	}

	.jms--compact:not(.jms--nomap) .jms__list .jms-item__addr {
		margin: 0;
	}

	.jms--compact:not(.jms--nomap) .jms-item {
		cursor: pointer;
	}

	.jms--compact:not(.jms--nomap) .jms-item__show::after {
		content: "";
		position: absolute;
		inset: 0;
	}

	.jms--compact:not(.jms--nomap) .jms-item:hover .jms-item__show {
		color: var(--jms-accent);
	}

	.jms--compact:not(.jms--nomap) .jms-item:has(.jms-item__show:focus-visible) {
		outline: 2px solid var(--jms-accent-2);
		outline-offset: -2px;
	}

	.jms--compact:not(.jms--nomap) .jms-item__show:focus-visible {
		outline: none;
	}
}

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

.jms__map {
	position: relative;
	min-height: 320px;
	border-radius: var(--jms-radius);
	overflow: hidden;
	background: var(--jms-surface);
}

.jms__canvas,
.jms__canvas.maplibregl-map {
	position: absolute;
	inset: 0;
}

.jms--maploading .jms__map::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 32px;
	height: 32px;
	margin: -16px 0 0 -16px;
	border: 3px solid var(--jms-line);
	border-top-color: var(--jms-accent);
	border-radius: 50%;
	animation: jms-spin 0.8s linear infinite;
}

@keyframes jms-spin {
	to { transform: rotate(360deg); }
}

.jms__overlay {
	position: absolute;
	inset: 0;
	z-index: 3;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	padding: 24px;
	background: var(--jms-surface);
	color: var(--jms-muted);
	text-align: center;
}

.jms__overlay p {
	max-width: 36ch;
	margin: 0;
}

.jms__btn {
	padding: 10px 22px;
	border: 0;
	border-radius: var(--jms-radius);
	background: var(--jms-btn-bg);
	color: var(--jms-btn-text);
	font-weight: 600;
}

.jms .maplibregl-ctrl-group {
	border-radius: var(--jms-radius);
}

/* Attribution: collapsed by default, muted. */
.jms .maplibregl-ctrl-attrib {
	font-size: 11px;
}

.jms .maplibregl-ctrl-attrib.maplibregl-compact {
	background: color-mix(in srgb, var(--jms-page-bg) 75%, transparent);
	color: var(--jms-muted);
}

.jms .maplibregl-ctrl-attrib a {
	color: var(--jms-muted);
}

.jms--dark .maplibregl-ctrl-attrib-button {
	filter: invert(1);
}

.jms .maplibregl-ctrl-attrib-button {
	opacity: 0.5;
}

.jms .maplibregl-ctrl-attrib-button:hover,
.jms .maplibregl-compact-show .maplibregl-ctrl-attrib-button {
	opacity: 1;
}

/* Popup: page background + Blocksy text/link colors. */
.jms-popup .maplibregl-popup-content {
	padding: 14px 34px 14px 16px;
	border-radius: var(--jms-radius);
	background: var(--jms-page-bg);
	color: var(--jms-text);
	font-size: 15px;
	line-height: 1.45;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.jms-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.jms-popup.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.jms-popup.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
	border-top-color: var(--jms-page-bg);
}

.jms-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.jms-popup.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.jms-popup.maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
	border-bottom-color: var(--jms-page-bg);
}

.jms-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip {
	border-right-color: var(--jms-page-bg);
}

.jms-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip {
	border-left-color: var(--jms-page-bg);
}

.jms-popup .maplibregl-popup-close-button {
	top: 6px;
	right: 6px;
	width: 26px;
	height: 26px;
	color: var(--jms-text);
	font-size: 20px;
	line-height: 1;
	border-radius: 4px;
}

.jms-popup .maplibregl-popup-close-button:hover {
	background: var(--jms-surface);
}

.jms-popup__body strong {
	display: block;
	margin-bottom: 4px;
	color: var(--theme-headings-color, var(--jms-text));
	font-size: 1.05em;
}

.jms-popup__body p {
	margin: 0;
	color: var(--jms-muted);
}

.jms-popup__body .jms-item__links {
	flex-direction: column;
	gap: 6px;
	margin-top: 10px;
	font-size: 1em;
}

/* ---------- Mobile: list / map toggle */

@media (max-width: 799px) {
	.jms {
		font-size: 0.8em;
	}

	.jms__chips {
		flex-wrap: nowrap;
		overflow-x: auto;
		margin: 0 -16px;
		padding: 0 16px 4px;
		scrollbar-width: none;
	}

	.jms__chips::-webkit-scrollbar {
		display: none;
	}

	.jms__chip {
		flex: none;
	}

	.jms--js .jms__views {
		display: inline-flex;
	}

	.jms--nomap .jms__views {
		display: none;
	}

	.jms--js .jms__body {
		display: block;
		height: auto;
		min-height: 0;
		max-height: none;
	}

	.jms__listwrap {
		overflow: visible;
	}

	.jms--js[data-view="list"] .jms__map,
	.jms--nomap .jms__map {
		display: none;
	}

	.jms--js[data-view="map"]:not(.jms--nomap) .jms__listwrap {
		display: none;
	}

	.jms--js[data-view="map"] .jms__map {
		height: 70vh;
		min-height: 360px;
	}

	.jms-item {
		padding: 12px 8px 12px 12px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.jms-item,
	.jms--maploading .jms__map::after {
		transition: none;
		animation: none;
	}
}
