/* 服務地圖頁主內容區：縱向 flex，讓地圖自動填滿剩餘空間 */
.content-wrapper {
	display: flex;
	flex-direction: column;
}

.map-wrapper {
	width: calc(100% - 35px);
	min-height: 0;
	margin: 0 16px;
	border-radius: var(--radius-md);
	overflow: hidden;
	box-shadow: var(--shadow-md);
	background: #B5D0EA;
	position: relative;
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	margin-bottom: 20px;
}

#map {
	width: 100%;
	flex: 1 1 auto;
	min-height: 0;
	border-radius: 0;
	overflow: hidden;
	background: #B5D0EA;
}

.map-legend {
	position: absolute;
	bottom: 28px;
	left: 12px;
	z-index: 10;
	background: rgba(255, 255, 255, 0.18);
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	border: 1px solid rgba(255, 255, 255, 0.35);
	border-radius: var(--radius-md);
	padding: 12px 14px;
	margin: 0;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-height: calc(100% - 48px);
	overflow-y: auto;
	scrollbar-width: none;
	-ms-overflow-style: none;
	min-width: 160px;
	max-width: min(calc(100% - 24px), 520px);
}

.map-legend::-webkit-scrollbar {
	display: none;
}

/* 圖例列表：預設單欄，較寬時自動改為兩欄，避免單一長條過長 */
.legend-list {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 8px 18px;
}

@media (min-width: 420px) {
	.legend-list {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (min-width: 640px) {
	.legend-list {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

.legend-item {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	font-size: 0.95rem;
	font-weight: 600;
	color: #000000;
	text-shadow: 0 1px 2px rgba(255, 255, 255, 0.55);
	line-height: 1.35;
	min-height: 26px;
}

.legend-item-hidden {
	display: none;
}

.legend-dot {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	flex-shrink: 0;
	margin-top: 2px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.legend-label {
	word-break: break-word;
	overflow-wrap: break-word;
}

/* 展開/收合按鈕：長者友善，點擊區足夠大 */
.legend-toggle {
	align-self: flex-start;
	min-height: 44px;
	padding: 8px 14px;
	border: 1px solid rgba(0, 0, 0, 0.15);
	border-radius: var(--radius-pill);
	background: rgba(255, 255, 255, 0.78);
	color: #2E5A7A;
	font-size: 0.95rem;
	font-weight: 700;
	cursor: pointer;
	transition: background 0.2s var(--ease-out), transform 0.1s var(--ease-out);
	white-space: nowrap;
}

.legend-toggle:hover,
.legend-toggle:focus {
	background: #FFFFFF;
	outline: 2px solid rgba(46, 90, 122, 0.35);
	outline-offset: 2px;
}

.legend-toggle:active {
	transform: scale(0.98);
}

/* ====== 全螢幕按鈕（地圖右上角） ====== */
.map-fs-btn {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 15;
	width: 46px;
	height: 46px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 1px solid rgba(255, 255, 255, 0.35);
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.82);
	color: #2E5A7A;
	font-size: 1.25rem;
	cursor: pointer;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
	transition: background 0.2s var(--ease-out), transform 0.1s var(--ease-out);
}

.map-fs-btn:hover,
.map-fs-btn:focus {
	background: #FFFFFF;
	outline: 2px solid rgba(46, 90, 122, 0.35);
	outline-offset: 2px;
}

.map-fs-btn:active {
	transform: scale(0.95);
}

/* 全螢幕狀態：容器填滿整個螢幕（覆寫 JS 設定的 inline 尺寸） */
.map-wrapper:fullscreen,
.map-wrapper:-webkit-full-screen,
.map-wrapper:-moz-full-screen {
	width: 100vw !important;
	height: 100vh !important;
	margin: 0 !important;
	border-radius: 0 !important;
}

.map-wrapper:fullscreen #map {
	flex: 1 1 auto;
}

/* 服務地圖側邊詳情彈窗 */
.map-popup-overlay {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: rgba(0, 0, 0, 0.22);
	z-index: 20;
	visibility: hidden;
	opacity: 0;
	transition: visibility 0.25s var(--ease-out), opacity 0.25s var(--ease-out);
	pointer-events: none;
}

.map-popup-overlay.open {
	visibility: visible;
	opacity: 1;
	pointer-events: auto;
}

.map-popup {
	position: absolute;
	top: 0;
	right: 0;
	width: 75%;
	max-width: 280px;
	height: 100%;
	background: rgba(45, 55, 65, 0.94);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	color: #FFFFFF;
	z-index: 21;
	display: flex;
	flex-direction: column;
	padding: 52px 18px 20px;
	visibility: hidden;
	opacity: 0;
	transform: translateX(100%);
	transition: visibility 0.3s var(--ease-out), opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out);
	pointer-events: none;
}

.map-popup.open {
	visibility: visible;
	opacity: 1;
	transform: translateX(0);
	pointer-events: auto;
}

.map-popup .popup-close {
	position: absolute;
	top: 14px;
	right: 14px;
	width: 44px;
	height: 44px;
	background: rgba(255, 255, 255, 0.15);
	border: none;
	border-radius: 50%;
	color: #FFFFFF;
	font-size: 1.4rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s var(--ease-out);
}

.map-popup .popup-close:hover {
	background: rgba(255, 255, 255, 0.25);
}

.map-popup .popup-title {
	font-size: 1.25rem;
	font-weight: 700;
	text-align: center;
	line-height: 1.4;
	margin-bottom: 20px;
	padding: 0 8px;
}

.map-popup .popup-body {
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.map-popup .popup-body::-webkit-scrollbar {
	width: 4px;
}

.map-popup .popup-body::-webkit-scrollbar-thumb {
	background: rgba(255, 255, 255, 0.25);
	border-radius: 2px;
}

.map-popup .popup-row {
	margin-bottom: 16px;
	font-size: 1rem;
	line-height: 1.7;
}

.map-popup .popup-row:last-child {
	margin-bottom: 0;
}

.map-popup .popup-label {
	color: rgba(255, 255, 255, 0.72);
	font-weight: 600;
	margin-bottom: 3px;
}

.map-popup .popup-value {
	color: #FFFFFF;
	word-break: break-word;
}

.map-popup .popup-value a {
	color: #87CEFA;
	text-decoration: underline;
	word-break: break-word;
}

.map-popup .popup-value a[href^="tel:"] {
	color: #FFFFFF;
	text-decoration: none;
}

.map-popup .popup-value a[href^="tel:"]:hover {
	text-decoration: underline;
}

.popup-value {
	margin-left:5px;
}

/* 地圖載入 / 後臺請求等待層 */
.map-loading {
	position: absolute;
	inset: 0;
	z-index: 30;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	background: rgba(181, 208, 234, 0.6);
	backdrop-filter: blur(2px);
	-webkit-backdrop-filter: blur(2px);
	border-radius: var(--radius-md);
	color: #2E5A7A;
	font-size: 1rem;
	font-weight: 600;
	text-align: center;
	padding: 20px;
}

.map-loading.hidden {
	display: none;
}

.map-loading.error {
	background: rgba(255, 245, 245, 0.94);
	color: #C62828;
}

.map-loading-spinner {
	width: 48px;
	height: 48px;
	border: 5px solid rgba(46, 90, 122, 0.25);
	border-top-color: #2E5A7A;
	border-radius: 50%;
	animation: mapSpin 0.9s linear infinite;
}

.map-loading.error .map-loading-spinner {
	display: none;
}

.map-loading-text {
	max-width: 80%;
	line-height: 1.5;
}

.map-loading-retry {
	margin-top: 6px;
	min-height: 50px;
	padding: 12px 28px;
	border: none;
	border-radius: var(--radius-pill);
	background: #FE6E63;
	color: #FFFFFF;
	font-size: 1.05rem;
	font-weight: 700;
	cursor: pointer;
	box-shadow: var(--shadow-sm);
	transition: background 0.2s var(--ease-out);
}

.map-loading-retry:hover {
	background: #e85b50;
}

.map-loading-retry.hidden {
	display: none;
}

@keyframes mapSpin {
	to { transform: rotate(360deg); }
}

/* ====== 電話撥號確認彈出框 ====== */
.phone-modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.45);
	z-index: 100;
	visibility: hidden;
	opacity: 0;
	transition: visibility 0.25s var(--ease-out), opacity 0.25s var(--ease-out);
	pointer-events: none;
}

.phone-modal-overlay.open {
	visibility: visible;
	opacity: 1;
	pointer-events: auto;
}

.phone-modal {
	position: fixed;
	top: 50%;
	left: 50%;
	width: 90%;
	min-width: 280px;
	max-width: 380px;
	background: rgba(45, 55, 65, 0.96);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	color: #FFFFFF;
	border-radius: var(--radius-md);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
	z-index: 101;
	padding: 54px 22px 24px;
	visibility: hidden;
	opacity: 0;
	transform: translate(-50%, -50%) scale(0.96) translateY(12px);
	transition: visibility 0.3s var(--ease-out), opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out);
	pointer-events: none;
	display: flex;
	flex-direction: column;
}

.phone-modal.open {
	visibility: visible;
	opacity: 1;
	transform: translate(-50%, -50%) scale(1) translateY(0);
	pointer-events: auto;
}

.phone-modal-close {
	position: absolute;
	top: 10px;
	right: 10px;
	width: 44px;
	height: 44px;
	background: rgba(255, 255, 255, 0.12);
	border: none;
	border-radius: 50%;
	color: #FFFFFF;
	font-size: 1.3rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s var(--ease-out);
}

.phone-modal-close:hover,
.phone-modal-close:focus {
	background: rgba(255, 255, 255, 0.22);
}

.phone-modal-title {
	font-size: 1.15rem;
	font-weight: 700;
	text-align: center;
	line-height: 1.45;
	margin-bottom: 18px;
	padding: 0 4px;
}

.phone-modal-body {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.phone-modal-info {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	padding: 12px 16px;
	background: rgba(255, 255, 255, 0.08);
	border-radius: var(--radius-md);
}

.phone-modal-label {
	font-size: 0.92rem;
	color: rgba(255, 255, 255, 0.72);
	font-weight: 600;
}

.phone-modal-number {
	font-size: 1.35rem;
	font-weight: 700;
	color: #FFFFFF;
	letter-spacing: 0.5px;
}

.phone-modal-message {
	margin: 0;
	padding: 10px 14px;
	background: rgba(255, 179, 167, 0.12);
	border: 1px solid rgba(255, 179, 167, 0.35);
	border-radius: var(--radius-md);
	color: #FFB3A7;
	font-size: 0.95rem;
	line-height: 1.55;
	text-align: center;
}

.phone-modal-actions {
	display: flex;
	flex-direction: row;
	gap: 12px;
	justify-content: center;
}

.phone-modal-btn {
	flex: 1 1 0;
	min-height: 48px;
	padding: 10px 18px;
	border: 1px solid transparent;
	border-radius: var(--radius-pill);
	font-size: 1rem;
	font-weight: 700;
	cursor: pointer;
	transition: background 0.2s var(--ease-out), transform 0.1s var(--ease-out);
}

.phone-modal-btn:active {
	transform: scale(0.98);
}

.phone-modal-btn-primary {
	background: #87CEFA;
	color: #2D3741;
	border-color: #87CEFA;
}

.phone-modal-btn-primary:hover,
.phone-modal-btn-primary:focus {
	background: #B3E0FA;
}

.phone-modal-btn-secondary {
	background: transparent;
	color: #FFFFFF;
	border-color: rgba(255, 255, 255, 0.35);
}

.phone-modal-btn-secondary:hover,
.phone-modal-btn-secondary:focus {
	background: rgba(255, 255, 255, 0.1);
}

.phone-modal-btn-success {
	background: #43A047;
	color: #FFFFFF;
	border-color: #43A047;
}

.phone-modal-btn-success:hover,
.phone-modal-btn-success:focus {
	background: #66BB6A;
}

/* 小螢幕適配：避免 modal 過寬，內距與按鈕縮小 */
@media (max-width: 360px) {
	.phone-modal {
		width: 92%;
		padding: 50px 16px 20px;
	}

	.phone-modal-number {
		font-size: 1.2rem;
	}

	.phone-modal-actions {
		gap: 8px;
	}

	.phone-modal-btn {
		min-height: 44px;
		padding: 8px 12px;
		font-size: 0.95rem;
	}
}

/* ====== 重疊標記選擇彈窗（同一位置有多個服務單位） ====== */
.marker-select-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.45);
	z-index: 120;
	display: none;
}
.marker-select-overlay.open { display: block; }

.marker-select-modal {
	position: fixed;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%) scale(0.96);
	z-index: 121;
	width: min(92vw, 440px);
	max-height: 80vh;
	overflow-y: auto;
	background: #FFFFFF;
	border-radius: var(--radius-md);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
	padding: 1.4rem 1.25rem 1.1rem;
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}
.marker-select-modal.open {
	visibility: visible;
	opacity: 1;
	pointer-events: auto;
	transform: translate(-50%, -50%) scale(1);
}

.marker-select-close {
	position: absolute;
	top: 0.5rem;
	right: 0.5rem;
	width: 44px;
	height: 44px;
	border: none;
	background: transparent;
	color: #5b7286;
	font-size: 1.3rem;
	cursor: pointer;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
}
.marker-select-close:hover,
.marker-select-close:focus {
	background: rgba(46, 90, 122, 0.1);
	color: #2E5A7A;
	outline: none;
}

.marker-select-title {
	font-size: 1.2rem;
	font-weight: 700;
	color: #2E5A7A;
	margin-bottom: 0.85rem;
	padding-right: 2.5rem;
}

.marker-select-list {
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
}

.marker-select-item {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 2px;
	text-align: left;
	width: 100%;
	min-height: 56px;
	padding: 0.7rem 0.9rem;
	border: 1px solid rgba(46, 90, 122, 0.18);
	border-radius: var(--radius-md);
	background: #F4F8FB;
	cursor: pointer;
	font-family: inherit;
	color: #1e293b;
	transition: background 0.15s ease, border-color 0.15s ease;
}
.marker-select-item:hover,
.marker-select-item:focus {
	background: #E6F0F7;
	border-color: rgba(46, 90, 122, 0.4);
	outline: none;
}

.marker-select-name {
	font-size: 1.1rem;
	font-weight: 700;
	line-height: 1.35;
}

.marker-select-cat {
	font-size: 0.92rem;
	color: #5b7286;
}

@media (max-width: 360px) {
	.marker-select-modal {
		width: 94%;
		padding: 1.2rem 0.9rem 0.9rem;
	}
	.marker-select-item {
		min-height: 52px;
		padding: 0.6rem 0.8rem;
	}
}