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

/* Map Wrapper - Default dimensions so map always has size (editor and frontend) */
/*
 * Bricks adds .brxe-tbd-map to the root; we use .tbd-map-wrapper for both.
 * Default: width 100%, height 500px; min dimensions prevent zero-size in builder.
 * Height/width from Bricks style tab override these when set.
 */
.tbd-map-wrapper,
.brxe-tbd-map.tbd-map-wrapper {
	position: relative;
	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;
}

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

/* Fallback: Show map after 2 seconds even if data-initialized isn't set (prevents permanent hiding) */
.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;
	}
}

/* Ensure map is always visible in builder preview (shorter fade-in for better UX) */
.bricks-preview .tbd-map-wrapper,
#bricks-preview .tbd-map-wrapper,
.bricks-builder .tbd-map-wrapper {
	opacity: 1 !important;
	/* Override fade-in animation for builder */
	animation: none !important;
}

/* Builder-specific: Show map immediately with faster transition */
.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;
}

/* Ensure Leaflet container fills wrapper */
.tbd-map-wrapper .leaflet-container {
	position: absolute;
	top: 0;
	left: 0;
	width: 100% !important;
	height: 100% !important;
	opacity: 0;
	transition: opacity 0.3s ease-in-out;
	/* Inherit border-radius from parent (set via Bricks style tab) */
	border-radius: inherit;
	/* Ensure container respects parent's border-radius */
	overflow: hidden;
}

/* Show Leaflet container when map is ready */
.tbd-map-wrapper[data-initialized="true"] .leaflet-container {
	opacity: 1;
}

.tbd-map-wrapper.loading {
	display: flex;
	align-items: center;
	justify-content: center;
}

.tbd-map-wrapper.loading::before {
	content: "Loading map...";
	color: #666;
	font-size: 14px;
}

/* Map Container - Additional styling */
.tbd-map-wrapper .leaflet-container {
	font-family: inherit;
}

/* Leaflet attribution – hidden (was oversized e.g. Ukraine flag) */
.tbd-map-wrapper .leaflet-control-attribution.leaflet-control {
	display: none !important;
}

/* Custom marker icon (Bricks icon picker: SVG or icon font) – stroke, fill, width, height from picker */
.tbd-marker-div-icon {
	background: none !important;
	border: none !important;
}
.tbd-marker-div-icon .tbd-marker-icon-wrap {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	line-height: 1;
	box-sizing: border-box;
}
.tbd-marker-div-icon .tbd-marker-icon-wrap .icon-svg,
.tbd-marker-div-icon .tbd-marker-icon-wrap 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-wrap .tbd-marker-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: inherit;
	color: var(--tbd-marker-fill, currentColor);
}

/* Popup Styles */
.tbd-marker-popup {
	max-width: 300px;
}

.tbd-marker-popup h3 {
	margin: 0 0 10px 0;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.4;
}

.tbd-marker-popup p {
	margin: 0 0 10px 0;
	font-size: 14px;
	line-height: 1.5;
}

.tbd-marker-popup p:last-child {
	margin-bottom: 0;
}

/* Leaflet Popup Styles - Global styles for popups (they're appended to body) */
.leaflet-popup-content {
	/* Default styles - will be overridden by Bricks typography controls */
}

.leaflet-popup-content h3 {
	/* Default heading styles - will be overridden by Bricks typography controls */
	margin: 0 0 10px 0;
}


/* Cluster Styles - Enhanced for visibility */
.marker-cluster {
	background-color: #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 div {
	width: 100%;
	height: 100%;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
}

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

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

	.tbd-marker-popup {
		max-width: 250px;
	}
}

/* Popup template loading and error states */
.tbd-popup-loading {
	padding: 30px 20px;
	text-align: center;
	color: #666;
	min-height: 60px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

/* Spinner animation */
.tbd-popup-spinner {
	display: inline-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;
	margin-bottom: 12px;
}

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

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

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

/* Map Connector Element - Hidden by default, used only for data collection */
.tbd-map-connector {
	display: none !important;
	visibility: hidden !important;
	position: absolute !important;
	left: -9999px !important;
}

