/* ========================================
   Leaflet 地圖自訂樣式
   ======================================== */

/* Marker Cluster 圖標 */
.custom-cluster-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(var(--marker-scale, 1));
}

.cluster-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 600;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
  will-change: box-shadow, transform;
}

.cluster-icon:hover {
  transform: scale(1.1);
}

.cluster-small {
  width: 30px;
  height: 30px;
  font-size: 12px;
  background: linear-gradient(135deg, #3B82F6, #60A5FA);
  animation: cluster-pulse 2s ease-in-out infinite;
}

.cluster-medium {
  width: 40px;
  height: 40px;
  font-size: 14px;
  background: linear-gradient(135deg, #2563EB, #3B82F6);
  animation: cluster-pulse 2s ease-in-out infinite;
}

.cluster-large {
  width: 50px;
  height: 50px;
  font-size: 16px;
  background: linear-gradient(135deg, #D97706, #F59E0B);
  animation: cluster-pulse 1.5s ease-in-out infinite;
}

/* Cluster 脈動動畫 */
@keyframes cluster-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3); }
  50% { box-shadow: 0 2px 16px rgba(59, 130, 246, 0.5); }
}

/* 深色模式 Cluster */
[data-theme='dark'] .cluster-small {
  background: linear-gradient(135deg, #60A5FA, #93C5FD);
  color: #0F172A;
}

[data-theme='dark'] .cluster-medium {
  background: linear-gradient(135deg, #3B82F6, #60A5FA);
  color: #0F172A;
}

[data-theme='dark'] .cluster-large {
  background: linear-gradient(135deg, #FBBF24, #FCD34D);
  color: #0F172A;
}

[data-theme='dark'] .cluster-icon {
  animation: cluster-pulse-dark 2s ease-in-out infinite;
}

@keyframes cluster-pulse-dark {
  0%, 100% { box-shadow: 0 2px 8px rgba(96, 165, 250, 0.3); }
  50% { box-shadow: 0 2px 16px rgba(96, 165, 250, 0.5); }
}

/* Popup 樣式 */
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 0;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0;
  min-width: 200px;
}

.leaflet-popup-tip {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.project-popup {
  padding: 12px 16px;
}

.popup-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.popup-city-tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  background: linear-gradient(135deg, #3B82F6, #60A5FA);
  color: white;
}

.popup-completed-tag {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  border: 1.5px solid #93C5FD;
  background: transparent;
  color: #3B82F6;
}

.popup-district {
  font-size: 12px;
  color: var(--text-secondary);
}

.popup-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
  line-height: 1.3;
}

.popup-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.popup-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.popup-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.popup-stat-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-color);
}

.popup-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: white !important;
  background: linear-gradient(135deg, #3B82F6, #2563EB);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.popup-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  background: linear-gradient(135deg, #60A5FA, #3B82F6);
}

.popup-new-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px 16px;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #3B82F6;
  background: transparent;
  border: 1px solid #3B82F6;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.popup-new-tab:hover {
  background: #EFF6FF;
  color: #2563EB;
}

/* 深色模式 Popup */
[data-theme='dark'] .leaflet-popup-content-wrapper {
  background: #1E293B;
}

[data-theme='dark'] .leaflet-popup-tip {
  background: #1E293B;
}

[data-theme='dark'] .popup-city-tag {
  background: linear-gradient(135deg, #60A5FA, #3B82F6);
  color: #0F172A;
}

[data-theme='dark'] .popup-completed-tag {
  border-color: #60A5FA;
  color: #93C5FD;
}

[data-theme='dark'] .popup-link {
  background: linear-gradient(135deg, #60A5FA, #3B82F6);
  color: #0F172A !important;
}

[data-theme='dark'] .popup-link:hover {
  background: linear-gradient(135deg, #93C5FD, #60A5FA);
}

[data-theme='dark'] .popup-new-tab {
  color: #60A5FA;
  border-color: #60A5FA;
}

[data-theme='dark'] .popup-new-tab:hover {
  background: rgba(96, 165, 250, 0.1);
  color: #93C5FD;
}

/* Leaflet 控制項樣式 */
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--background-alt) !important;
}

[data-theme='dark'] .leaflet-control-zoom a {
  background: #1E293B !important;
  color: #F1F5F9 !important;
  border-color: #334155 !important;
}

[data-theme='dark'] .leaflet-control-zoom a:hover {
  background: #334155 !important;
}

/* 地圖容器 */
.leaflet-container {
  font-family: inherit;
}

/* Attribution 樣式 */
.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.8) !important;
}

[data-theme='dark'] .leaflet-control-attribution {
  background: rgba(30, 41, 59, 0.9) !important;
  color: #94A3B8 !important;
}

[data-theme='dark'] .leaflet-control-attribution a {
  color: #60A5FA !important;
}

/* 自訂標記樣式（水滴形 Drop Pin） */
:root {
  --marker-scale: 1;
}

.labeled-marker {
  transform: scale(var(--marker-scale));
  transform-origin: center bottom;
}

/* 水滴形圖釘 - 純色版（簡化設計） */
.marker-pin {
  width: 28px;
  height: 38px;
  position: relative;
  transition: transform 0.2s ease, filter 0.2s ease;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
}

/* 水滴形狀本體 - 純色 + 白邊 */
.marker-pin::before {
  content: '';
  position: absolute;
  width: 28px;
  height: 28px;
  background: #60A5FA;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  top: 0;
  left: 0;
  border: 2.5px solid #FFFFFF;
  box-sizing: border-box;
}

/* 中心白點 */
.marker-pin::after {
  content: '';
  width: 10px;
  height: 10px;
  background: #FFFFFF;
  border-radius: 50%;
  position: absolute;
  top: 9px;
  left: 9px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Hover 效果 - 僅桌面設備 */
@media (hover: hover) {
  .labeled-marker:hover .marker-pin {
    transform: scale(1.15) translateY(-2px);
    filter: drop-shadow(0 6px 12px rgba(59, 130, 246, 0.5));
  }
}

/* 脈動動畫 - 地面陰影 */
.labeled-marker::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 14px;
  height: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  transform: translateX(-50%);
  animation: marker-shadow-pulse 2s ease-in-out infinite;
}

@keyframes marker-shadow-pulse {
  0%, 100% {
    transform: translateX(-50%) scale(1);
    opacity: 0.3;
  }
  50% {
    transform: translateX(-50%) scale(1.3);
    opacity: 0.15;
  }
}

/* 價格區間色碼 - 純色版 */
/* 低價位 < 50萬/坪：綠色 */
.marker-price-low .marker-pin::before {
  background: #34D399;
}
.marker-price-low::after {
  background: rgba(52, 211, 153, 0.3);
}
@media (hover: hover) {
  .marker-price-low:hover .marker-pin {
    filter: drop-shadow(0 6px 12px rgba(52, 211, 153, 0.5));
  }
}

/* 中價位 50-80萬/坪：藍色 (預設) */
.marker-price-mid .marker-pin::before {
  background: #60A5FA;
}
.marker-price-mid::after {
  background: rgba(96, 165, 250, 0.3);
}
@media (hover: hover) {
  .marker-price-mid:hover .marker-pin {
    filter: drop-shadow(0 6px 12px rgba(96, 165, 250, 0.5));
  }
}

/* 高價位 80-100萬/坪：橙色 */
.marker-price-high .marker-pin::before {
  background: #F59E0B;
}
.marker-price-high::after {
  background: rgba(245, 158, 11, 0.3);
}
@media (hover: hover) {
  .marker-price-high:hover .marker-pin {
    filter: drop-shadow(0 6px 12px rgba(245, 158, 11, 0.5));
  }
}

/* 豪宅 > 100萬/坪：紅色 */
.marker-price-premium .marker-pin::before {
  background: #F87171;
}
.marker-price-premium::after {
  background: rgba(248, 113, 113, 0.3);
}
@media (hover: hover) {
  .marker-price-premium:hover .marker-pin {
    filter: drop-shadow(0 6px 12px rgba(248, 113, 113, 0.5));
  }
}

/* 選中的建案圖標 - 放大 + 持續脈衝動畫 + 高亮光暈 */
.marker-selected .marker-pin {
  transform: scale(1.6) translateY(-4px);
  filter: drop-shadow(0 0 16px rgba(59, 130, 246, 0.9));
  z-index: 1000 !important;
  animation: pulse-selected 1s ease-in-out infinite;
}

.marker-selected::after {
  animation: none !important;
  transform: translateX(-50%) scale(1.5);
  opacity: 0.5;
  background: rgba(59, 130, 246, 0.4);
}

@keyframes pulse-selected {
  0%, 100% {
    transform: scale(1.6) translateY(-4px);
    filter: drop-shadow(0 0 16px rgba(59, 130, 246, 0.9));
  }
  50% {
    transform: scale(1.8) translateY(-6px);
    filter: drop-shadow(0 0 24px rgba(59, 130, 246, 1));
  }
}

/* 深色模式選中狀態 */
[data-theme='dark'] .marker-selected .marker-pin {
  animation: pulse-selected-dark 1s ease-in-out infinite;
}

@keyframes pulse-selected-dark {
  0%, 100% {
    transform: scale(1.6) translateY(-4px);
    filter: drop-shadow(0 0 16px rgba(96, 165, 250, 0.9));
  }
  50% {
    transform: scale(1.8) translateY(-6px);
    filter: drop-shadow(0 0 24px rgba(96, 165, 250, 1));
  }
}

[data-theme='dark'] .marker-selected::after {
  background: rgba(96, 165, 250, 0.5);
}

/* 深色模式標記 */
[data-theme='dark'] .marker-pin {
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.5));
}

[data-theme='dark'] .marker-pin::before {
  border-color: rgba(255, 255, 255, 0.8);
}

/* 深色模式價格色碼 - 稍亮版 */
[data-theme='dark'] .marker-price-low .marker-pin::before {
  background: #6EE7B7;
}

[data-theme='dark'] .marker-price-mid .marker-pin::before {
  background: #93C5FD;
}

[data-theme='dark'] .marker-price-high .marker-pin::before {
  background: #FBBF24;
}

[data-theme='dark'] .marker-price-premium .marker-pin::before {
  background: #FCA5A5;
}

/* ===== 建案名稱 Tooltip（zoom >= 15 時永久顯示） ===== */
.marker-name-tooltip {
  background: rgba(255, 255, 255, 0.92) !important;
  border: none !important;
  border-radius: 4px !important;
  padding: 2px 6px !important;
  font-size: 11px !important;
  font-weight: 800 !important;
  color: #1E293B !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15) !important;
  white-space: nowrap !important;
}
.marker-name-tooltip::before {
  display: none !important;
}

[data-theme='dark'] .marker-name-tooltip {
  background: rgba(30, 41, 59, 0.92) !important;
  color: #F1F5F9 !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3) !important;
}

.marker-tooltip-name {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  color: inherit;
}

.marker-tooltip-price {
  font-size: 10px;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 2px;
  color: #DC2626;
}

[data-theme='dark'] .marker-tooltip-price {
  color: #FCA5A5;
}

/* ===== 行政區 Polygon 圖層 ===== */
.district-tooltip {
  border-radius: 8px !important;
  padding: 8px 12px !important;
  font-size: 12px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12) !important;
  border: 1px solid rgba(148, 163, 184, 0.3) !important;
}
