/* Community Map — all selectors are namespaced .cm so themes cannot bleed in. */

.cm {
	/* Supplier orange / customer blue is the one hue pair that stays legible
	   for every common form of colour blindness. Shape backs it up anyway. */
	--cm-supplier: #e07a1f;
	--cm-customer: #1f6feb;
	--cm-you: #7c3aed;

	--cm-surface: rgba(255, 255, 255, 0.92);
	--cm-surface-solid: #ffffff;
	--cm-ink: #171b22;
	--cm-ink-soft: #5b6470;
	--cm-line: rgba(23, 27, 34, 0.1);
	--cm-shadow: 0 1px 2px rgba(16, 20, 27, 0.08), 0 12px 28px -12px rgba(16, 20, 27, 0.35);
	--cm-radius: 12px;

	font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	color: var(--cm-ink);
	max-width: 1100px;
	margin: 0 auto;
}

.cm--dark {
	--cm-surface: rgba(20, 24, 31, 0.9);
	--cm-surface-solid: #14181f;
	--cm-ink: #eef1f5;
	--cm-ink-soft: #9aa4b2;
	--cm-line: rgba(255, 255, 255, 0.12);
}

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

/* ------------------------------------------------------------- container */

.cm__frame {
	position: relative;
	height: var(--cm-height, 70vh);
	min-height: 440px;
	border-radius: 20px;
	overflow: hidden;
	background: #e6e8eb;
	box-shadow: var(--cm-shadow);
}

.cm__frame.is-full {
	position: fixed;
	inset: 0;
	height: 100dvh;
	width: 100vw;
	border-radius: 0;
	z-index: 99999;
}

.cm__map {
	position: absolute;
	inset: 0;
	z-index: 1;
}

/* ------------------------------------------------------- interaction lock */

.cm__guard {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: grid;
	place-items: center;
	border: 0;
	padding: 0;
	background: transparent;
	cursor: pointer;
	appearance: none;
}

.cm__frame.is-live .cm__guard {
	pointer-events: none;
}

.cm__guard-label {
	padding: 10px 20px;
	border-radius: 999px;
	background: rgba(16, 20, 27, 0.78);
	color: #fff;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.01em;
	backdrop-filter: blur(6px);
	opacity: 0;
	transform: translateY(6px);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.cm__guard:hover .cm__guard-label,
.cm__guard:focus-visible .cm__guard-label {
	opacity: 1;
	transform: none;
}

.cm__frame.is-live .cm__guard-label {
	opacity: 0;
}

/* ---------------------------------------------------------------- controls */

.cm__controls {
	position: absolute;
	top: 16px;
	right: 16px;
	z-index: 3;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 8px;
	max-width: calc(100% - 32px);
}

.cm__panel {
	display: flex;
	gap: 4px;
	padding: 5px;
	border-radius: var(--cm-radius);
	background: var(--cm-surface);
	border: 1px solid var(--cm-line);
	box-shadow: var(--cm-shadow);
	backdrop-filter: blur(10px);
}

.cm__legend {
	flex-direction: column;
	align-items: stretch;
}

.cm__btn,
.cm__chip {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	padding: 7px 11px;
	border: 0;
	border-radius: 9px;
	background: transparent;
	color: var(--cm-ink);
	font: inherit;
	font-size: 13px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.cm__btn:hover,
.cm__chip:hover {
	background: color-mix(in srgb, var(--cm-ink) 8%, transparent);
}

.cm__btn:focus-visible,
.cm__chip:focus-visible,
.cm__expand:focus-visible,
.cm__guard:focus-visible {
	outline: 2px solid var(--cm-customer);
	outline-offset: 2px;
}

.cm__chip {
	justify-content: flex-start;
	opacity: 0.45;
	white-space: nowrap;
}

.cm__chip.is-on {
	opacity: 1;
}

.cm__chip b {
	margin-left: auto;
	padding-left: 8px;
	font-variant-numeric: tabular-nums;
	color: var(--cm-ink-soft);
	font-weight: 700;
}

.cm__key {
	width: 11px;
	height: 11px;
	flex: none;
}

.cm__key--supplier {
	background: var(--cm-supplier);
	border-radius: 2px;
	transform: rotate(45deg);
}

.cm__key--customer {
	background: var(--cm-customer);
	border-radius: 50%;
}

/* ------------------------------------------------------------------ status */

.cm__status {
	position: absolute;
	left: 16px;
	bottom: 16px;
	z-index: 3;
	margin: 0;
	max-width: min(340px, calc(100% - 32px));
	padding: 9px 13px;
	border-radius: var(--cm-radius);
	border: 1px solid var(--cm-line);
	background: var(--cm-surface);
	box-shadow: var(--cm-shadow);
	backdrop-filter: blur(10px);
	font-size: 12.5px;
	line-height: 1.45;
	color: var(--cm-ink-soft);
}

.cm__status[data-tone="warn"] {
	color: #9a5b06;
}

.cm__status[data-tone="error"] {
	color: #b42318;
}

.cm__status[hidden] {
	display: none;
}

/* ------------------------------------------------------------- expand button */

.cm__expand {
	position: absolute;
	left: 16px;
	top: 16px;
	z-index: 3;
	padding: 9px 15px;
	border: 1px solid var(--cm-line);
	border-radius: var(--cm-radius);
	background: var(--cm-surface);
	color: var(--cm-ink);
	font: inherit;
	font-size: 13px;
	font-weight: 700;
	cursor: pointer;
	box-shadow: var(--cm-shadow);
	backdrop-filter: blur(10px);
}

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

.cm-pin__shape {
	display: block;
	width: 18px;
	height: 18px;
	margin: 2px;
	border: 2.5px solid #fff;
	box-shadow: 0 1px 6px rgba(16, 20, 27, 0.45);
}

.cm-pin--supplier .cm-pin__shape {
	background: var(--cm-supplier, #e07a1f);
	border-radius: 3px;
	transform: rotate(45deg);
}

.cm-pin--customer .cm-pin__shape {
	background: var(--cm-customer, #1f6feb);
	border-radius: 50%;
}

.cm-pin--other .cm-pin__shape {
	background: #6b7280;
	border-radius: 50%;
}

.cm-pin--you .cm-pin__shape {
	width: 12px;
	height: 12px;
	background: var(--cm-you, #7c3aed);
	border-radius: 50%;
	box-shadow: 0 0 0 6px rgba(124, 58, 237, 0.18);
}

.cm-pin:focus-visible .cm-pin__shape {
	outline: 2px solid #111;
	outline-offset: 3px;
}

/* ------------------------------------------------------------------ popups */

.cm-pop {
	min-width: 180px;
	font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.cm-pop__tag {
	display: inline-block;
	margin-bottom: 6px;
	padding: 3px 7px;
	border-radius: 5px;
	font-size: 10px;
	font-weight: 800;
	letter-spacing: 0.07em;
	text-transform: uppercase;
}

.cm-pop__tag--supplier {
	background: #fdf0e2;
	color: #a9530a;
}

.cm-pop__tag--customer {
	background: #e6efff;
	color: #1a4fad;
}

.cm-pop__tag--other {
	background: #eef0f3;
	color: #475467;
}

.cm-pop__name {
	display: block;
	font-size: 15px;
	font-weight: 700;
	line-height: 1.25;
	color: #171b22;
}

.cm-pop__place {
	display: block;
	margin-top: 2px;
	font-size: 12.5px;
	color: #5b6470;
}

.cm-pop__foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin-top: 10px;
	padding-top: 9px;
	border-top: 1px solid rgba(23, 27, 34, 0.1);
	font-size: 11.5px;
	color: #5b6470;
}

.cm-pop__badge {
	padding: 2px 7px;
	border-radius: 5px;
	background: #eef0f3;
	font-weight: 700;
}

.cm-pop__badge.is-signed::before {
	content: "✓ ";
}

.cm-pop__signature {
	width: 100%;
	max-height: 54px;
	object-fit: contain;
	filter: grayscale(1);
	opacity: 0.85;
}

.leaflet-popup-content-wrapper {
	border-radius: 12px;
	box-shadow: 0 12px 32px -12px rgba(16, 20, 27, 0.45);
}

.leaflet-popup-content {
	margin: 12px 14px;
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 720px) {
	.cm__frame {
		border-radius: 14px;
		min-height: 380px;
	}

	.cm__controls {
		top: 12px;
		right: 12px;
		gap: 6px;
	}

	.cm__btn,
	.cm__chip {
		padding: 8px 10px;
		font-size: 12px;
	}

	.cm__expand,
	.cm__guard-label {
		display: none;
	}

	.cm__status {
		left: 12px;
		right: 12px;
		bottom: 12px;
		max-width: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cm *,
	.cm .leaflet-pane {
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
	}
}
