/**
 * California Interactive Map — frontend styles.
 *
 * Every rule is scoped under .cim-map. Per-instance values arrive as CSS custom
 * properties written by Elementor's selectors onto the widget wrapper, so two
 * maps on one page never share state.
 */

/*
 * Design tokens.
 *
 * The dialog is moved to <body> while open, which puts it outside .cim-map — so
 * it must carry these itself or every var() inside it resolves to nothing and
 * the overlay paints transparent. The widget's own values are copied onto it as
 * an inline style at open time, which overrides these defaults.
 */
.cim-map,
.cim-map__dialog {
	/* Canvas */
	--cim-map-height: 620px;
	--cim-canvas-bg: #f4f4f5;

	/* Regions */
	--cim-region-fill: #060606;
	--cim-region-stroke: rgba(255, 255, 255, 0.42);
	--cim-region-stroke-width: 1;
	--cim-region-hover-fill: #e63950;
	--cim-region-hover-scale: 1;
	--cim-region-hover-glow: transparent;
	--cim-region-selected-fill: #c81d38;
	--cim-region-disabled-opacity: 0.35;
	--cim-focus-color: #ffffff;
	--cim-transition: 180ms;

	/* Pins */
	--cim-pin-color: #101010;
	--cim-pin-border: #ffffff;
	--cim-pin-border-width: 2;
	--cim-pin-hover-scale: 1.25;
	--cim-pin-pulse: #c91d3a;
	--cim-pin-shadow: rgba(0, 0, 0, 0.35);

	/* Tooltip */
	--cim-tooltip-bg: #111111;
	--cim-tooltip-color: #ffffff;

	/* Controls */
	--cim-control-bg: #ffffff;
	--cim-control-bg-hover: #111111;
	--cim-control-color: #111111;
	--cim-control-color-hover: #ffffff;
	--cim-control-size: 38px;
	--cim-control-radius: 8px;
	--cim-control-gap: 6px;
	--cim-controls-offset: 14px;
	--cim-controls-top: auto;
	--cim-controls-right: var(--cim-controls-offset);
	--cim-controls-bottom: var(--cim-controls-offset);
	--cim-controls-left: auto;

	/* Popup */
	--cim-overlay-bg: rgba(6, 6, 6, 0.62);
	--cim-dialog-bg: #ffffff;
	--cim-dialog-color: #2b2b2b;
	--cim-dialog-radius: 14px;
	--cim-dialog-max-width: 560px;
	--cim-dialog-close: #6b6b6b;
	--cim-dialog-close-hover: #111111;
	--cim-cta-bg: #c81d38;
	--cim-cta-color: #ffffff;
	--cim-cta-bg-hover: #111111;
	--cim-cta-color-hover: #ffffff;

	/* Widget-local stacking order. Deliberately small numbers. */
	--cim-z-map: 1;
	--cim-z-controls: 2;
	--cim-z-tooltip: 3;

	/* The dialog is moved to <body> on open, so it needs a page-level value
	   rather than a widget-local one. Override it if your theme goes higher. */
	--cim-dialog-z: 99999;
}

/* Layout, which belongs to the map box alone. */
.cim-map {
	position: relative;
	overflow: hidden;
	width: 100%;
	height: var(--cim-map-height);
	background-color: var(--cim-canvas-bg);
	isolation: isolate;
}

/* -------------------------------------------------------------------------
 * Viewport + SVG
 * ---------------------------------------------------------------------- */

/*
 * Themes style bare <button> elements — backgrounds, borders, radii, uppercase
 * text — and those rules beat a single class selector. Every button inside the
 * widget is therefore reset to nothing first, and re-dressed below. Scoped to
 * .cim-map and .cim-map__dialog, so nothing outside the widget is touched.
 */
.cim-map button,
.cim-map__dialog button {
	-webkit-appearance: none;
	appearance: none;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
	background-color: transparent;
	background-image: none;
	box-shadow: none;
	text-shadow: none;
	text-transform: none;
	letter-spacing: normal;
	font: inherit;
	line-height: 1;
	color: inherit;
	min-width: 0;
	min-height: 0;
	width: auto;
	height: auto;
	text-decoration: none;
	transform: none;
	transition: none;
}

.cim-map button:hover,
.cim-map button:focus,
.cim-map__dialog button:hover,
.cim-map__dialog button:focus {
	background-image: none;
	box-shadow: none;
	transform: none;
}

.cim-map__viewport {
	position: relative;
	z-index: var(--cim-z-map);
	width: 100%;
	height: 100%;
	box-sizing: border-box;
}

.cim-map__svg {
	display: block;
	width: 100%;
	height: 100%;
	overflow: visible;
}

.cim-map--pannable .cim-map__svg {
	cursor: grab;
	-webkit-user-select: none;
	user-select: none;
}

.cim-map--panning .cim-map__svg {
	cursor: grabbing;
}

/* touch-action is confined to the interactive surface, and only when touch
   gestures are switched on, so the rest of the page keeps normal scrolling. */
.cim-map--touch .cim-map__svg {
	touch-action: none;
}

/* -------------------------------------------------------------------------
 * Regions
 * ---------------------------------------------------------------------- */

.cim-map__regions path,
.cim-map__regions polygon,
.cim-map__regions polyline,
.cim-map__regions rect,
.cim-map__regions circle,
.cim-map__regions ellipse,
.cim-map__regions line {
	fill: var(--cim-region-fill);
	stroke: var(--cim-region-stroke);
	stroke-width: var(--cim-region-stroke-width);
	stroke-linejoin: round;
	vector-effect: non-scaling-stroke;
	transition:
		fill var(--cim-transition) ease,
		opacity var(--cim-transition) ease,
		transform var(--cim-transition) ease,
		filter var(--cim-transition) ease;
}

/* A per-region colour (--cim-r-fill) always wins over the generic fallback. */
.cim-map__regions .cim-region--highlighted {
	fill: var(--cim-r-fill, var(--cim-region-selected-fill));
}

/*
 * Part-filled counties: a copy of the county clipped to the chosen area and
 * laid on top. It is scenery — the county underneath keeps the pointer, the
 * focus and the hover, so this must never take any of them.
 */
.cim-map__regions .cim-region-split {
	fill: var(--cim-r-fill, var(--cim-region-selected-fill));
	pointer-events: none;
	stroke: none;
}

/* Each region scales about its own centre rather than the viewBox origin. */
.cim-map__regions .cim-region--interactive {
	cursor: pointer;
	transform-box: fill-box;
	transform-origin: center;
}

.cim-map__regions .cim-region--interactive:hover,
.cim-map__regions .cim-region--interactive.is-active {
	fill: var(--cim-r-hover, var(--cim-region-hover-fill));
}

.cim-map__regions .cim-region--interactive:hover,
.cim-map__regions .cim-region--interactive:focus-visible {
	transform: scale(var(--cim-region-hover-scale, 1));
	filter: drop-shadow(0 0 6px var(--cim-region-hover-glow, transparent));
}

/*
 * The overlay copy is a sibling and takes no pointer events, so it cannot
 * follow :hover on the county beneath it. A part-filled county therefore does
 * not pop — otherwise the two halves would visibly tear apart.
 */
.cim-map__regions .cim-region--split:hover,
.cim-map__regions .cim-region--split:focus-visible {
	transform: none;
}

.cim-map__regions .cim-region--disabled {
	opacity: var(--cim-region-disabled-opacity);
	pointer-events: none;
}

.cim-map__regions .cim-region--interactive:focus {
	outline: none;
}

.cim-map__regions .cim-region--interactive:focus-visible {
	outline: none;
	stroke: var(--cim-focus-color);
	stroke-width: 3;
	stroke-dasharray: 5 3;
	fill: var(--cim-r-hover, var(--cim-region-hover-fill));
}

/* -------------------------------------------------------------------------
 * Pins
 * ---------------------------------------------------------------------- */

/* Pins carry geometry in pixel-sized units and are counter-scaled by JS so they
   stay a constant size on screen. Until that first measurement lands they would
   render at the wrong size, so they stay hidden for one frame. */
.cim-map__pins {
	visibility: hidden;
}

.cim-map--ready .cim-map__pins {
	visibility: visible;
}

/* .cim-map__pin-scale carries the counter-scale as an SVG transform attribute,
   written by JavaScript. The hover pop lives on a nested group so the two
   compose cleanly instead of one clobbering the other. */
.cim-map__pin-hover {
	transform-box: fill-box;
	transform-origin: center;
	transition: transform var(--cim-transition) ease;
}

.cim-map__pin-dot,
.cim-map__pin-glyph > path {
	fill: var(--cim-p-color, var(--cim-pin-color));
	stroke: var(--cim-p-border, var(--cim-pin-border));
	stroke-width: var(--cim-pin-border-width);
	paint-order: stroke;
	transition: fill var(--cim-transition) ease;
}

.cim-map__pin-glyph-eye {
	fill: var(--cim-p-border, var(--cim-pin-border));
	stroke: none;
}

.cim-map__pin-hit {
	fill: transparent;
	stroke: none;
}

.cim-map__pin--interactive {
	cursor: pointer;
}

.cim-map__pin--interactive:focus {
	outline: none;
}

/* The hit circle doubles as the focus ring target: outlining a <g> is
   inconsistent across browsers, so we draw the ring on a real shape. */
.cim-map__pin--interactive:focus-visible .cim-map__pin-hit {
	fill: transparent;
	stroke: var(--cim-focus-color);
	stroke-width: 2;
	stroke-dasharray: 4 3;
	vector-effect: non-scaling-stroke;
}

.cim-map__pin--interactive:hover .cim-map__pin-hover,
.cim-map__pin--interactive:focus-visible .cim-map__pin-hover {
	transform: scale(var(--cim-pin-hover-scale));
}

.cim-map__pin-pulse {
	fill: var(--cim-pin-pulse);
	opacity: 0.55;
	transform-origin: center;
	transform-box: fill-box;
	animation: cim-pulse 2.4s ease-out infinite;
}

@keyframes cim-pulse {
	0% {
		transform: scale(1);
		opacity: 0.5;
	}

	70% {
		transform: scale(2.6);
		opacity: 0;
	}

	100% {
		transform: scale(2.6);
		opacity: 0;
	}
}

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

.cim-map__controls {
	position: absolute;
	z-index: var(--cim-z-controls);
	top: var(--cim-controls-top);
	right: var(--cim-controls-right);
	bottom: var(--cim-controls-bottom);
	left: var(--cim-controls-left);
	display: flex;
	flex-direction: column;
	gap: var(--cim-control-gap);
	width: max-content;
	height: max-content;
}

/* Two classes deep, so these outrank the bare-button reset above. */
.cim-map .cim-map__control {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--cim-control-size);
	height: var(--cim-control-size);
	border-radius: var(--cim-control-radius);
	background: var(--cim-control-bg);
	color: var(--cim-control-color);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
	cursor: pointer;
	transition: background-color var(--cim-transition) ease, color var(--cim-transition) ease, opacity var(--cim-transition) ease;
}

.cim-map .cim-map__control svg {
	width: 55%;
	height: 55%;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	pointer-events: none;
}

.cim-map .cim-map__control:hover,
.cim-map .cim-map__control:focus-visible {
	background: var(--cim-control-bg-hover);
	color: var(--cim-control-color-hover);
}

.cim-map .cim-map__control:focus-visible {
	outline: 2px solid var(--cim-control-bg-hover);
	outline-offset: 2px;
}

.cim-map .cim-map__control[disabled] {
	opacity: 0.45;
	cursor: default;
}

/* -------------------------------------------------------------------------
 * Tooltip
 * ---------------------------------------------------------------------- */

.cim-map__tooltip {
	position: absolute;
	z-index: var(--cim-z-tooltip);
	top: 0;
	left: 0;
	max-width: 220px;
	padding: 6px 10px;
	border-radius: 6px;
	background: var(--cim-tooltip-bg);
	color: var(--cim-tooltip-color);
	font-size: 13px;
	line-height: 1.35;
	text-align: center;
	/* Never intercept a click meant for the map underneath. */
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transform: translate(-50%, calc(-100% - 12px));
	transition: opacity var(--cim-transition) ease;
	/* Following the cursor, a transition on position lags behind the pointer. */
	transition-property: opacity;
}

.cim-map__tooltip.is-visible {
	opacity: 1;
	visibility: visible;
}

/* -------------------------------------------------------------------------
 * Wheel-zoom hint
 *
 * Shown only when a visitor scrolls over the map without the modifier, to
 * explain why the map did not zoom. It must never swallow a pointer event.
 * ---------------------------------------------------------------------- */

.cim-map__hint {
	position: absolute;
	z-index: var(--cim-z-tooltip);
	top: 50%;
	left: 50%;
	max-width: 80%;
	padding: 10px 18px;
	border-radius: 8px;
	background: rgba(10, 10, 12, 0.82);
	color: #ffffff;
	font-size: 14px;
	font-weight: 500;
	line-height: 1.3;
	text-align: center;
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transform: translate(-50%, -50%);
	transition: opacity 160ms ease, visibility 160ms ease;
}

.cim-map__hint.is-visible {
	opacity: 1;
	visibility: visible;
}

/* -------------------------------------------------------------------------
 * Dialog
 * ---------------------------------------------------------------------- */

/*
 * The dialog covers the viewport, not the map box.
 *
 * On open, JavaScript moves it to <body> and copies the widget's custom
 * properties onto it: .cim-map has overflow:hidden, so a dialog left inside it
 * would be cropped to the map, and position:fixed alone is not enough because
 * any ancestor with a transform — which page builders add freely — would
 * silently become its containing block.
 */
.cim-map__dialog {
	position: fixed;
	z-index: var(--cim-dialog-z, 99999);
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	box-sizing: border-box;
}

.cim-map__dialog[hidden] {
	display: none;
}

.cim-map__dialog-overlay {
	position: absolute;
	inset: 0;
	background: var(--cim-overlay-bg);
}

.cim-map__dialog-panel {
	position: relative;
	width: 100%;
	max-width: var(--cim-dialog-max-width);
	max-height: 100%;
	padding: 26px 28px;
	border-radius: var(--cim-dialog-radius);
	background: var(--cim-dialog-bg);
	color: var(--cim-dialog-color);
	box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
	overflow-y: auto;
	box-sizing: border-box;
	-webkit-overscroll-behavior: contain;
	overscroll-behavior: contain;
}

/*
 * Full screen takes the viewport less the dialog's own padding, so it never
 * touches the edges. The panel is a column so the body can scroll on its own
 * and the close button stays put rather than scrolling away with the content.
 */
.cim-map__dialog--full .cim-map__dialog-panel {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
	max-width: none;
}

.cim-map__dialog--full .cim-map__dialog-body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/*
 * Full screen makes the panel full width, not the prose. A line of text 1300px
 * long is unreadable, so the content is centred within the panel — which is
 * also roughly the room an Elementor template expects.
 */
.cim-map__dialog--full .cim-map__dialog-media,
.cim-map__dialog--full .cim-map__dialog-title,
.cim-map__dialog--full .cim-map__dialog-body {
	width: 100%;
	max-width: var(--cim-dialog-full-content, 1080px);
	margin-left: auto;
	margin-right: auto;
}

.cim-map__dialog .cim-map__dialog-close {
	position: absolute;
	top: 10px;
	right: 10px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: transparent;
	color: var(--cim-dialog-close);
	cursor: pointer;
	transition: background-color var(--cim-transition) ease, color var(--cim-transition) ease;
}

.cim-map__dialog .cim-map__dialog-close svg {
	width: 16px;
	height: 16px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	pointer-events: none;
}

.cim-map__dialog .cim-map__dialog-close:hover,
.cim-map__dialog .cim-map__dialog-close:focus-visible {
	background: rgba(0, 0, 0, 0.06);
	color: var(--cim-dialog-close-hover);
}

.cim-map__dialog .cim-map__dialog-close:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 1px;
}

.cim-map__dialog-media {
	margin: 0 0 14px;
	border-radius: calc(var(--cim-dialog-radius) - 6px);
	overflow: hidden;
}

.cim-map__dialog-media[hidden] {
	display: none;
}

.cim-map__dialog-media img {
	display: block;
	width: 100%;
	height: auto;
}

.cim-map__dialog-title {
	margin: 0 34px 8px 0;
	font-size: 20px;
	line-height: 1.25;
	color: inherit;
}

.cim-map__dialog-body {
	font-size: 15px;
	line-height: 1.55;
}

.cim-map__dialog-body > *:first-child {
	margin-top: 0;
}

.cim-map__dialog-body > *:last-child {
	margin-bottom: 0;
}

.cim-map__dialog-body img {
	max-width: 100%;
	height: auto;
}

.cim-map__dialog-cta {
	display: inline-block;
	margin-top: 16px;
	padding: 10px 18px;
	border-radius: 6px;
	background: var(--cim-cta-bg);
	color: var(--cim-cta-color);
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	transition: background-color var(--cim-transition) ease, color var(--cim-transition) ease;
}

.cim-map__dialog-cta[hidden] {
	display: none;
}

.cim-map__dialog-cta:hover,
.cim-map__dialog-cta:focus-visible {
	background: var(--cim-cta-bg-hover);
	color: var(--cim-cta-color-hover);
}

.cim-map__dialog-cta:focus-visible {
	outline: 2px solid var(--cim-cta-bg-hover);
	outline-offset: 2px;
}

/* -------------------------------------------------------------------------
 * Live region
 * ---------------------------------------------------------------------- */

.cim-map__live-region {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
 * Small screens
 * ---------------------------------------------------------------------- */

@media (max-width: 480px) {
	.cim-map__dialog {
		padding: 10px;
	}

	.cim-map__dialog-title {
		font-size: 18px;
	}
}

/* -------------------------------------------------------------------------
 * Real map (Leaflet)
 * ---------------------------------------------------------------------- */

.cim-geo {
	position: relative;
	width: 100%;
	height: var(--cim-map-height, 620px);
	overflow: hidden;
	background: var(--cim-canvas-bg, #f4f4f5);
	isolation: isolate;
}

.cim-geo__canvas {
	width: 100%;
	height: 100%;
}

.cim-geo__hint {
	position: absolute;
	z-index: 500;
	top: 50%;
	left: 50%;
	max-width: 80%;
	padding: 10px 18px;
	border-radius: 8px;
	background: rgba(10, 10, 12, 0.82);
	color: #ffffff;
	font-size: 14px;
	font-weight: 500;
	text-align: center;
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transform: translate(-50%, -50%);
	transition: opacity 160ms ease, visibility 160ms ease;
}

.cim-geo__hint.is-visible {
	opacity: 1;
	visibility: visible;
}

/* Markers are DivIcons, so the pin styling matches the SVG map. */
.cim-geo__pin {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
}

.cim-geo__dot {
	display: block;
	border-radius: 50%;
	background: var(--cim-p-color, var(--cim-pin-color, #101010));
	border: 2px solid var(--cim-pin-border, #ffffff);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
	transition: transform 140ms ease;
}

.cim-geo__marker:hover .cim-geo__dot {
	transform: scale(1.25);
}

/*
 * A teardrop points at its tip, so it sits at the bottom of its box rather
 * than centred — buildIcon() anchors it to match.
 */
.cim-geo__pin--map_pin {
	align-items: flex-end;
}

.cim-geo__glyph {
	display: block;
	fill: var(--cim-p-color, var(--cim-pin-color, #101010));
	stroke: var(--cim-p-border, var(--cim-pin-border, #ffffff));
	stroke-width: 1.4;
	filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
	transform-origin: 50% 100%;
	transition: transform 140ms ease;
}

/* The hole in the pin: painted in the border colour, not stroked. */
.cim-geo__glyph-eye {
	fill: var(--cim-p-border, var(--cim-pin-border, #ffffff));
	stroke: none;
}

.cim-geo__marker:hover .cim-geo__glyph {
	transform: scale(1.15);
}

.cim-geo__img {
	display: block;
	object-fit: contain;
	filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
	transition: transform 140ms ease;
}

.cim-geo__marker:hover .cim-geo__img {
	transform: scale(1.15);
}

.cim-geo__pulse {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	background: var(--cim-pin-pulse, #c91d3a);
	opacity: 0.5;
	transform: translate(-50%, -50%);
	animation: cim-geo-pulse 2.4s ease-out infinite;
}

@keyframes cim-geo-pulse {
	0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0.5; }
	70% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
	100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
}

.cim-geo__popup-title {
	margin: 0 0 6px;
	font-size: 15px;
	line-height: 1.3;
}

.cim-geo__popup-media img {
	display: block;
	width: 100%;
	height: auto;
	margin-bottom: 8px;
	border-radius: 6px;
}

.cim-geo__popup-body {
	font-size: 13px;
	line-height: 1.5;
}

.cim-geo__popup-cta {
	display: inline-block;
	margin-top: 10px;
	padding: 7px 14px;
	border-radius: 6px;
	background: var(--cim-cta-bg, #c81d38);
	color: var(--cim-cta-color, #fff) !important;
	font-size: 13px;
	font-weight: 600;
	text-decoration: none;
}

.cim-shortcode-error {
	padding: 12px 16px;
	border-left: 4px solid #c81d38;
	border-radius: 4px;
	background: #fdeef1;
	color: #8a1226;
	font-size: 14px;
}

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

@media (prefers-reduced-motion: reduce) {
	.cim-map__regions path,
	.cim-map__regions polygon,
	.cim-map__regions polyline,
	.cim-map__regions rect,
	.cim-map__regions circle,
	.cim-map__regions ellipse,
	.cim-map__regions line,
	.cim-map__pin-hover,
	.cim-map__pin-dot,
	.cim-map__pin-glyph > path,
	.cim-map__control,
	.cim-map__tooltip,
	.cim-map__hint,
	.cim-map__dialog-cta,
	.cim-map__dialog-close {
		transition: none;
	}

	.cim-map__pin-pulse,
	.cim-geo__pulse {
		animation: none;
		opacity: 0.4;
	}

	.cim-geo__dot,
	.cim-geo__glyph,
	.cim-geo__img,
	.cim-geo__hint {
		transition: none;
	}
}
