/* public/css/pages/map.css — 地圖搜尋頁面 */

/* main-content 預設有 padding/overflow-y:auto，地圖頁需要滿版無捲動 */
.main-content.map-content {
  padding: 0;
  overflow: hidden;
  background: none;
}

.map-container {
  position: relative;
  /* position:relative 沒有搭配 z-index 不會建立新的堆疊環境，裡面的 .map-search-card
     (z-index:1000) 跟 Leaflet 自己內部的 pane/控制項 (z-index 最高到 1000) 就會直接
     跳出這個容器、跟頁面外層的 .topbar/.sidebar 搶堆疊順序——topbar 原本 z-index 又是
     廢的 (position:static)，兩個問題疊在一起，地圖內容才會蓋過導覽列。這裡明確給一個
     z-index，讓這個容器自己建立堆疊環境，裡面的東西不管數字多高都出不去 */
  z-index: 1;
  width: 100%;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--bg-base);
}

/* === 浮動搜尋卡 === */
.map-search-card {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: 320px;
  max-width: calc(100% - 32px);
  padding: 12px 14px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(var(--glass-blur));
}

.map-search-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-search-input-wrap .icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.map-search-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
}
.map-search-input::placeholder {
  color: var(--text-muted);
}

.map-search-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
}
.map-search-clear:hover {
  color: var(--text-primary);
}
.map-search-clear .icon {
  width: 16px;
  height: 16px;
}

.map-search-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 1em;
}

.map-search-meta .map-pending-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
  flex-shrink: 0;
}

/* === 背景定位進度條 === */
.map-progress {
  margin-top: 8px;
}

.map-progress-bar-track {
  width: 100%;
  height: 5px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  overflow: hidden;
}

.map-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient-brand);
  border-radius: var(--radius-sm);
  transition: width 0.4s ease-out;
}

.map-progress-label {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === 地址不完整清單 === */
.map-incomplete-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
  padding: 6px 0 0;
  background: none;
  border: none;
  border-top: 1px solid var(--glass-border);
  color: var(--warning);
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
}
.map-incomplete-toggle .icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.map-incomplete-list {
  margin-top: 6px;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-incomplete-item {
  display: block;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-decoration: none;
  line-height: 1.4;
}
.map-incomplete-item:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}
.map-incomplete-item .name {
  color: var(--text-primary);
  font-weight: 500;
}
.map-incomplete-item .addr {
  color: var(--text-muted);
}

/* === 載入中 / 空狀態 === */
.map-loading,
.map-empty-state {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-secondary);
  background: var(--bg-base);
  text-align: center;
  padding: 24px;
}

.map-loading .icon,
.map-empty-state .icon {
  width: 32px;
  height: 32px;
  color: var(--text-muted);
}

.map-empty-state p {
  max-width: 320px;
  font-size: 0.9rem;
}

/* === Marker / 群集自訂樣式 === */
.reca-marker-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}

.reca-cluster-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
  border: 2px solid rgba(255, 255, 255, 0.25);
}

/* hover tooltip 的內容排版 — 容器本身 (.leaflet-tooltip) 刻意不覆寫背景/文字顏色，
   維持 Leaflet 預設的白色泡泡樣式；文字顏色會自然繼承 Leaflet 預設的 color:#222，
   這裡只調整間距/字重/換行，不能再套用深色主題的淺色系變數 (在白底上會看不清楚) */
.map-popup-title {
  font-weight: 600;
  margin-bottom: 4px;
}
.map-popup-company {
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.map-popup-meta {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-bottom: 2px;
}
.map-popup-address {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-top: 4px;
}

/* Leaflet 預設 tooltip 是 white-space:nowrap 且沒有寬度上限，公司名/地址一長就會把
   泡泡撐超出畫面或被裁切——這裡只修換行/寬度，不動背景/邊框/陰影等顏色相關樣式。
   寬度沒有寫死，是「內容多寡自動決定寬度，最多到這個上限」，上限本身也跟著螢幕寬度
   自動縮小 (calc(100vw - 40px))，窄螢幕不會被撐出畫面外 */
.leaflet-tooltip {
  white-space: normal;
  width: max-content;
  max-width: min(280px, calc(100vw - 40px));
  line-height: 1.5;
}

/* Leaflet 縮放控制/歸屬文字，套用深色配色，避免預設淺色控制項與版面衝突 */
.leaflet-control-zoom a {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border-color: var(--glass-border) !important;
}
.leaflet-control-attribution {
  background: rgba(17, 24, 39, 0.7) !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* === RWD === */
@media (max-width: 1024px) {
  .map-search-card {
    left: 12px;
    right: 12px;
    top: 12px;
    width: auto;
    max-width: none;
  }
}
