/**
 * Offices Map — front-end styles
 *
 * Everything is scoped under #offices-root so nothing leaks into the theme
 * and Elementor's global styles can't bleed in either.
 */

#offices-root {
	--om-accent: #7300e2;
	--om-accent-soft: rgba(115, 0, 226, 0.12);
	--om-accent-line: rgba(115, 0, 226, 0.35);
	--om-ink: #101014;
	--om-ink-soft: #5c5c6a;
	--om-surface: #ffffff;
	--om-surface-alt: #f6f5f9;
	--om-border: rgba(16, 16, 20, 0.1);
	--om-radius: 12px;
	--om-map-height: var(--offices-map-height, 460px);

	box-sizing: border-box;
	color: var(--om-ink);
	font-family: inherit;

	/*
	 * Do NOT add `container-type: inline-size` here. It applies size
	 * containment, so the contents stop contributing to the intrinsic
	 * width. Inside an Elementor row-direction flex container the widget is
	 * sized shrink-to-fit, so containment collapses this element to ~0 and
	 * everything overflows. Plain media queries are used below instead.
	 */

	/* Fill the parent whether it is a block, flex or grid context. */
	display: block;
	width: 100%;
	max-width: 100%;
	min-width: 0;
	flex: 1 1 100%;
	align-self: stretch;
	justify-self: stretch;
}

/*
 * Elementor's shortcode widget and its inner wrapper are shrink-to-fit in a
 * row-direction container. Force them to stretch, scoped with :has() so no
 * other shortcode on the site is affected.
 */
.elementor-widget-shortcode:has(#offices-root),
.elementor-shortcode:has(#offices-root) {
	width: 100%;
	max-width: 100%;
	min-width: 0;
	flex: 1 1 100%;
	align-self: stretch;
}

#offices-root *,
#offices-root *::before,
#offices-root *::after {
	box-sizing: border-box;
}

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

/* ── Layout ─────────────────────────────────────────────────────────── */

/*
 * Single column, in this order:
 *   1. locate button
 *   2. map
 *   3. manual selector
 *   4. office details
 *
 * The order comes from the DOM, not from CSS `order`, so keyboard and
 * screen-reader navigation follow what is on screen.
 */
#offices-block {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 16px;
	width: 100%;
	min-width: 0;
}

/* Full-width form controls look unbalanced — cap the narrow ones. */
#offices-root {
	--om-control-width: 440px;
}

@media (max-width: 900px) {
	#offices-root {
		--om-map-height: 340px;
		--om-control-width: 100%;
	}
}

/* ── Locate button ──────────────────────────────────────────────────── */

#office-locate-wrapper {
	display: flex;
	min-width: 0;
}

/*
 * Collapse the wrapper while the button is hidden, otherwise an empty flex
 * item leaves a stray gap above the map.
 */
#office-locate-wrapper:not(:has(#office-locate:not([hidden]))) {
	display: none;
}

/* ── Manual selector ────────────────────────────────────────────────── */

#office-select-wrapper {
	display: flex;
	flex-direction: column;
	gap: 10px;
	width: 100%;
	max-width: var(--om-control-width);
	min-width: 0;
}

#offices-root #office-select {
	width: 100%;
	padding: 12px 40px 12px 14px;
	border: 1px solid var(--om-border);
	border-radius: var(--om-radius);
	background-color: var(--om-surface);
	background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235c5c6a' d='M1.4 0 6 4.6 10.6 0 12 1.4 6 7.4 0 1.4z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 14px center;
	color: var(--om-ink);
	font: inherit;
	font-size: 15px;
	line-height: 1.3;
	appearance: none;
	cursor: pointer;
	transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

#offices-root #office-select:hover {
	border-color: var(--om-accent-line);
}

#offices-root #office-select:focus-visible {
	outline: none;
	border-color: var(--om-accent);
	box-shadow: 0 0 0 3px var(--om-accent-soft);
}

#offices-root #office-locate {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 9px;
	width: auto;
	max-width: 100%;
	padding: 11px 18px;
	border: 1px solid var(--om-accent-line);
	border-radius: var(--om-radius);
	background: transparent;
	color: var(--om-accent);
	font: inherit;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	cursor: pointer;
	transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

#offices-root #office-locate .locate-text {
	color: #fff;
}

#offices-root #office-locate:hover:not(:disabled) {
	border-color: var(--om-accent);
	background: var(--om-accent-soft);
}

#offices-root #office-locate:focus-visible {
	outline: none;
	border-color: var(--om-accent);
	box-shadow: 0 0 0 3px var(--om-accent-soft);
}

#offices-root #office-locate:disabled {
	opacity: 0.65;
	cursor: progress;
}

#offices-root #office-locate[data-state="error"] {
	border-color: var(--om-border);
	color: var(--om-ink-soft);
}

/* Crosshair icon, drawn in CSS so there is no extra request. */
#offices-root .locate-icon {
	position: relative;
	flex: 0 0 auto;
	width: 13px;
	height: 13px;
	border: 1.5px solid currentColor;
	border-radius: 50%;
}

#offices-root .locate-icon::after {
	content: "";
	position: absolute;
	inset: 3px;
	border-radius: 50%;
	background: currentColor;
}

#offices-root #office-locate[data-state="busy"] .locate-icon {
	animation: offices-pulse 1.1s ease-in-out infinite;
}

@keyframes offices-pulse {
	0%,
	100% {
		opacity: 1;
		transform: scale(1);
	}
	50% {
		opacity: 0.35;
		transform: scale(0.82);
	}
}

/* ── Info panel ─────────────────────────────────────────────────────── */

#offices-info-panel {
	width: 100%;
	min-width: 0;
	padding: 22px 24px;
	border: 1px solid var(--om-border);
	border-radius: var(--om-radius);
	background: var(--om-surface-alt);
}

#offices-root .panel-label {
	margin: 0 0 6px;
	color: var(--om-accent);
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.12em;
	text-transform: uppercase;
}

#offices-root .panel-city {
	margin: 0;
	font-size: 22px;
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: -0.01em;
}

#offices-root .panel-divider {
	width: 34px;
	height: 2px;
	margin: 14px 0;
	background: var(--om-accent);
	border-radius: 2px;
}

#offices-root .panel-address {
	margin: 0;
	color: var(--om-ink-soft);
	font-size: 14px;
	line-height: 1.6;
}

#offices-root .panel-address:empty {
	display: none;
}

#offices-root .panel-phone {
	display: inline-block;
	margin-top: 12px;
	color: var(--om-ink);
	font-size: 14px;
	font-weight: 600;
	text-decoration: none;
	border-bottom: 1px solid var(--om-accent-line);
	transition: color 0.18s ease, border-color 0.18s ease;
}

#offices-root .panel-phone:hover {
	color: var(--om-accent);
	border-color: var(--om-accent);
}

/* ── Map ────────────────────────────────────────────────────────────── */

#offices-map-wrapper {
	position: relative;
	align-self: stretch;
	width: 100%;
	min-width: 0; /* Without this a grid item can't shrink and squeezes. */
	height: var(--om-map-height);
	overflow: hidden;
	border: 1px solid var(--om-border);
	border-radius: var(--om-radius);
}

#offices-map {
	width: 100%;
	height: 100%;
	min-height: 300px;
	background: var(--om-surface-alt);
	z-index: 0; /* Keeps Leaflet panes below theme headers and modals. */
}

/* ── Leaflet reset ──────────────────────────────────────────────────── */

/*
 * Themes and Elementor set `img { max-width: 100%; height: auto }` globally.
 * Leaflet positions fixed-size tiles absolutely, so that rule resizes every
 * tile and the map renders stretched, compressed or with visible seams.
 * !important is genuinely required here — the theme rules are equally
 * specific and load in an unpredictable order.
 */
#offices-root .leaflet-container img,
#offices-root .leaflet-pane img,
#offices-root .leaflet-tile,
#offices-root .leaflet-marker-icon,
#offices-root .leaflet-marker-shadow,
#offices-root .leaflet-image-layer,
#offices-root .leaflet-tile-pane img {
	max-width: none !important;
	max-height: none !important;
	min-width: 0 !important;
	min-height: 0 !important;
	padding: 0 !important;
	margin: 0 !important;
	border: 0 !important;
	border-radius: 0 !important;
	box-shadow: none !important;
	background: none !important;
	object-fit: fill !important;
	aspect-ratio: auto !important;
}

/*
 * Attribution is required by the CARTO basemap terms and by the OpenStreetMap
 * licence, so it is displayed — only toned down so it does not fight the
 * design. Do not set display:none here.
 */
#offices-root .leaflet-control-attribution {
	padding: 2px 7px;
	background: rgba( 255, 255, 255, 0.82 );
	color: #55555f;
	font-size: 10px;
	line-height: 1.5;
}

#offices-root .leaflet-control-attribution a {
	color: #40404a;
	text-decoration: underline;
}

/* ── Tile consent gate (opt-in) ─────────────────────────────────────── */

.om-tile-consent {
	position: absolute;
	inset: 0;
	z-index: 500; /* Above Leaflet's panes, below its popups (600+). */
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	padding: 24px;
	background: var( --om-surface-alt, #f6f6f8 );
	text-align: center;
}

.om-tile-consent-text {
	margin: 0;
	max-width: 46ch;
	color: var( --om-ink-dim, #55555f );
	font-size: 13px;
	line-height: 1.55;
}

#offices-root .om-tile-consent-btn {
	padding: 11px 18px;
	border: 1px solid var( --om-border, #e2e2e8 );
	border-radius: var( --om-radius, 8px );
	background: var( --om-surface, #fff );
	color: var( --om-ink, #1a1a20 );
	font: inherit;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
}

#offices-root .om-tile-consent-btn:hover,
#offices-root .om-tile-consent-btn:focus-visible {
	border-color: var( --om-ink, #1a1a20 );
}

/* The popup address is its own element now, so it needs its own line. */
#offices-root .popup-address {
	display: block;
}

/* Leaflet sizes tiles inline; never let a theme override those values. */
#offices-root .leaflet-tile-container img {
	width: 256px;
	height: 256px;
}

/* Some themes force `display: block` or floats on images inside content. */
#offices-root .leaflet-container img {
	float: none !important;
	display: block;
}

/* Elementor and some themes apply transitions to all images, which makes
 * panning stutter as every tile animates into place. */
#offices-root .leaflet-container img,
#offices-root .leaflet-container .leaflet-tile {
	transition: none !important;
	animation: none !important;
}

/* Guard against a global `* { box-sizing: border-box }` shifting tile math. */
#offices-root .leaflet-container,
#offices-root .leaflet-container * {
	box-sizing: content-box;
}

/* Restore border-box for our own UI inside the map. */
#offices-root .leaflet-popup-content-wrapper,
#offices-root .leaflet-popup-content,
#offices-root .leaflet-control,
#offices-root .leaflet-control *,
#offices-root .map-pin {
	box-sizing: border-box;
}

/* Skeleton shimmer while the tiles and data load. */
#offices-root[data-state="loading"] #offices-map::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(
		100deg,
		var(--om-surface-alt) 30%,
		#eceaf2 50%,
		var(--om-surface-alt) 70%
	);
	background-size: 220% 100%;
	animation: offices-shimmer 1.4s ease-in-out infinite;
}

@keyframes offices-shimmer {
	from {
		background-position: 140% 0;
	}
	to {
		background-position: -40% 0;
	}
}

/* ── Pins ───────────────────────────────────────────────────────────── */

#offices-root .map-pin {
	width: 16px;
	height: 16px;
	border: 2.5px solid var(--om-surface);
	border-radius: 50%;
	background: var(--om-ink-soft);
	box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
	transition: transform 0.18s ease, background 0.18s ease;
	cursor: pointer;
}

#offices-root .map-pin:hover {
	transform: scale(1.25);
}

#offices-root .map-pin.active {
	background: var(--om-accent);
	transform: scale(1.4);
	box-shadow: 0 0 0 6px var(--om-accent-soft), 0 1px 6px rgba(0, 0, 0, 0.32);
}

#offices-root .leaflet-popup-content-wrapper {
	border-radius: 10px;
	box-shadow: 0 6px 22px rgba(16, 16, 20, 0.16);
}

#offices-root .leaflet-popup-content {
	margin: 12px 14px;
	font-size: 13px;
	line-height: 1.55;
}

#offices-root .popup-city {
	display: block;
	margin-bottom: 3px;
	font-size: 14px;
	font-weight: 700;
}

#offices-root .popup-badge {
	display: inline-block;
	margin-bottom: 6px;
	padding: 2px 7px;
	border-radius: 4px;
	background: var(--om-accent-soft);
	color: var(--om-accent);
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

/* ── Fallback list ──────────────────────────────────────────────────── */

#offices-fallback-list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 18px;
	margin: 26px 0 0;
	padding: 0;
	list-style: none;
}

#offices-fallback-list li {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding-left: 12px;
	border-left: 2px solid var(--om-accent-line);
	font-size: 13px;
	line-height: 1.55;
}

#offices-root .fallback-city {
	font-size: 14px;
	font-weight: 700;
}

#offices-root .fallback-address {
	color: var(--om-ink-soft);
}

#offices-root .fallback-phone {
	color: var(--om-ink);
	font-weight: 600;
	text-decoration: none;
}

#offices-root .fallback-phone:hover {
	color: var(--om-accent);
}

/*
 * Hidden only once the interactive map is live. Crawlers and no-JS
 * visitors keep the full list.
 */
#offices-root[data-state="ready"] #offices-fallback-list {
	display: none;
}

/*
 * If the data fails to load, hide the broken interactive shell and let the
 * server-rendered list stand in.
 */
#offices-root[data-state="error"] #offices-block {
	display: none;
}

/* ── Motion preferences ─────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
	#offices-root *,
	#offices-root *::after {
		animation: none !important;
		transition: none !important;
	}
}

/* ── Print ──────────────────────────────────────────────────────────── */

@media print {
	#offices-root #offices-block {
		display: none;
	}

	#offices-root #offices-fallback-list {
		display: grid !important;
	}
}
