/**
 * TBD Map Frontend Styles
 *
 * @package TBD_Map
 * @since 1.0.0
 */

/* Map Wrapper - Default dimensions so map always has size (editor and frontend) */
.tbd-map-wrapper,
.brxe-tbd-map.tbd-map-wrapper {
	position: relative;
	z-index: 0;
	isolation: isolate;
	width: 100%;
	min-width: 200px;
	height: 500px;
	min-height: 300px;
	background-color: #f0f0f0;
	overflow: hidden;
	opacity: 0;
	transition: opacity 0.3s ease-in-out;
	box-sizing: border-box;
	display: block;
}

.tbd-map-wrapper[data-initialized="true"] {
	opacity: 1;
}

.tbd-map-wrapper:not([data-initialized]) {
	animation: tbd-map-fade-in 0.3s ease-in-out 2s forwards;
}

@keyframes tbd-map-fade-in {
	to {
		opacity: 1;
	}
}

.bricks-preview .tbd-map-wrapper,
#bricks-preview .tbd-map-wrapper,
.bricks-builder .tbd-map-wrapper {
	opacity: 1 !important;
	animation: none !important;
}

.bricks-preview .tbd-map-wrapper:not([data-initialized]),
#bricks-preview .tbd-map-wrapper:not([data-initialized]) {
	opacity: 0.8;
	transition: opacity 0.2s ease-in-out;
}

/* Leaflet adds .leaflet-container to the wrapper itself. Do not use a descendant
 * selector here — a map inside a marker popup is also .leaflet-container and would
 * be position:absolute against the outer map, covering the Bricks popup content. */
.tbd-map-wrapper.leaflet-container {
	width: 100%;
	border-radius: inherit;
	overflow: hidden;
	font-family: inherit;
}

.leaflet-popup .tbd-map-wrapper,
.leaflet-popup .tbd-map-wrapper.leaflet-container,
.brx-popup-content .tbd-map-wrapper,
.brx-popup-content .tbd-map-wrapper.leaflet-container {
	position: relative !important;
	inset: auto !important;
	width: 100%;
	z-index: 0;
}

/* Keep map UI inside a local stacking context (below typical fixed headers/menus). */
.tbd-map-wrapper .leaflet-pane,
.tbd-map-wrapper .leaflet-tile-pane {
	z-index: 1;
}

.tbd-map-wrapper .leaflet-overlay-pane {
	z-index: 2;
}

.tbd-map-wrapper .leaflet-shadow-pane {
	z-index: 3;
}

.tbd-map-wrapper .leaflet-marker-pane {
	z-index: 4;
}

.tbd-map-wrapper .leaflet-tooltip-pane {
	z-index: 5;
}

.tbd-map-wrapper .leaflet-popup-pane {
	z-index: 6;
}

.tbd-map-wrapper .leaflet-control {
	z-index: 7;
}

.tbd-marker-div-icon {
	background: none !important;
	border: none !important;
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
	box-sizing: border-box;
}

.tbd-marker-div-icon .icon-svg,
.tbd-marker-div-icon svg {
	width: 100% !important;
	height: 100% !important;
	display: block;
	fill: var(--tbd-marker-fill, currentColor);
	stroke: var(--tbd-marker-stroke, none);
	stroke-width: var(--tbd-marker-stroke-width, 0);
	box-sizing: border-box;
}

.tbd-marker-div-icon .tbd-marker-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: inherit;
	color: var(--tbd-marker-fill, currentColor);
}

/* Default (manual) Leaflet popups — typography from element controls */
.leaflet-popup.tbd-default-leaflet-popup .leaflet-popup-content h3 {
	margin: 0 0 10px 0;
}

.leaflet-popup.tbd-default-leaflet-popup .leaflet-popup-content p {
	margin: 0 0 10px 0;
	line-height: 1.5;
}

.leaflet-popup.tbd-default-leaflet-popup .leaflet-popup-content p:last-child {
	margin-bottom: 0;
}

/* Bricks template popups — strip Leaflet chrome/typography; template CSS only */
.leaflet-popup.tbd-bricks-leaflet-popup {
	padding: 0;
	/* Leaflet centers using _containerWidth on this node; must match infobox width */
	width: var(--brx-info-box-width, auto);
	max-width: none;
	box-sizing: border-box;
}

/* Card-style Bricks infobox — no Leaflet pointer triangle */
.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-tip-container {
	display: none !important;
	width: 0 !important;
	height: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
	overflow: hidden !important;
	pointer-events: none !important;
}

.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-content-wrapper {
	position: relative;
	overflow: visible;
	background: transparent !important;
	box-shadow: none !important;
	border: none !important;
	padding: 0 !important;
	margin: 0 !important;
	width: 100%;
	box-sizing: border-box;
}

.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-content {
	margin: 0 !important;
	padding: 0 !important;
	min-width: 0 !important;
	line-height: normal !important;
	box-sizing: border-box;
	width: 100% !important;
	max-width: 100% !important;
	white-space: normal !important;
}

/* Neutralize Leaflet default spacing on bare tags so Bricks element rules win */
.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-content :is(p, h1, h2, h3, h4, h5, h6, ul, ol, figure, blockquote, pre) {
	margin: 0;
	padding: 0;
	line-height: inherit;
}

.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-content .brx-popup {
	line-height: normal;
}

/* Close: reset Leaflet defaults (asymmetric padding, fixed 18×14 box) and center the × in user styling */
.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-close-button.tbd-bricks-popup-close-in-bricks,
.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-close-button.tbd-bricks-popup-close-in-bricks:hover,
.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-close-button.tbd-bricks-popup-close-in-bricks:focus,
.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-close-button.tbd-bricks-popup-close-in-bricks:active {
	position: absolute;
	top: 10px;
	right: 10px;
	left: auto;
	bottom: auto;
	z-index: 2;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	visibility: visible;
	opacity: 1;
	width: auto;
	height: auto;
	min-width: 28px;
	min-height: 28px;
	margin: 0;
	padding: 0;
	font-family: Tahoma, Verdana, sans-serif;
	font-size: 24px;
	font-weight: 700;
	line-height: 1;
	color: #757575;
	text-align: center;
	text-decoration: none;
	background: transparent;
	border: none;
	box-shadow: none;
	outline: none;
	cursor: pointer;
	pointer-events: auto;
}

.leaflet-popup.tbd-bricks-leaflet-popup .leaflet-popup-close-button.tbd-bricks-popup-close-in-bricks > span {
	display: block;
	flex: 0 0 auto;
	line-height: 1;
	font-size: inherit;
	font-weight: inherit;
}

/* Hide Leaflet’s default close on the outer shell (only the in-card button is used) */
.leaflet-popup.tbd-bricks-leaflet-popup > .leaflet-popup-close-button:not(.tbd-bricks-popup-close-in-bricks) {
	display: none !important;
}

.leaflet-popup.tbd-bricks-leaflet-popup .brx-popup {
	position: relative;
	overflow: visible;
	display: block;
	box-sizing: border-box;
	width: var(--brx-info-box-width, auto);
	max-width: var(--brx-info-box-width, none);
}

.leaflet-popup.tbd-bricks-leaflet-popup .brx-popup .brx-popup-content {
	position: relative;
	width: 100%;
	box-sizing: border-box;
	padding: 0;
	margin: 0;
	height: auto;
	min-height: 0;
	max-height: none;
}

/* Image fill helper only — layout/spacing from Bricks template CSS */
.leaflet-popup.tbd-bricks-leaflet-popup .brx-popup .brxe-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.leaflet-popup.tbd-bricks-leaflet-popup .brx-popup .brxe-image {
	overflow: hidden;
}

/* Cluster Styles */
.marker-cluster {
	background-color: var(--tbd-cluster-bg, #3388ff);
	color: #fff;
	border-radius: 50%;
	text-align: center;
	font-weight: bold;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 3px solid #fff;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.marker-cluster-small {
	width: 40px !important;
	height: 40px !important;
	line-height: 40px;
	font-size: 12px;
}

.marker-cluster-medium {
	width: 50px !important;
	height: 50px !important;
	line-height: 50px;
	font-size: 14px;
}

.marker-cluster-large {
	width: 60px !important;
	height: 60px !important;
	line-height: 60px;
	font-size: 16px;
}

.marker-cluster span {
	display: block;
	line-height: 1;
}

@media (max-width: 768px) {
	.tbd-map-wrapper {
		min-height: 300px;
	}
}

.tbd-popup-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 16px;
	text-align: center;
	color: #666;
}

.tbd-popup-spinner {
	display: block;
	width: 32px;
	height: 32px;
	border: 3px solid rgba(0, 0, 0, 0.1);
	border-top-color: #3388ff;
	border-radius: 50%;
	animation: tbd-popup-spin 0.8s linear infinite;
}

@keyframes tbd-popup-spin {
	0% {
		transform: rotate(0deg);
	}
	100% {
		transform: rotate(360deg);
	}
}

.tbd-popup-loading-text {
	font-size: 14px;
	color: #666;
}

.tbd-popup-error {
	padding: 16px;
	text-align: center;
	color: #d63638;
	font-size: 14px;
}

/* Connector uses <template> element — hidden by spec, no CSS needed. */
