/* 色板喺 theme.css，呢度只寫版面。地圖頁（首頁）專用 */
#map-page { position: relative; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
#map-wrap { position: relative; width: 100%; height: 100%; }
#map { width: 100%; height: 100%; }

/* 地圖頂部一條（2026-08-21 第二版）：搜尋框同右邊啲掣**擺喺同一個 flex 容器**。
   ⚠️ 上一版兩邊各自 absolute（搜尋 left:10px 闊 58vw、掣 right:10px），
   加多一粒「場域介紹」之後喺 375px 就疊晒——使用者實機影相捉到。
   一個容器 ＋ flex-wrap 之後，結構上冇可能再疊：夾唔落就掣自動落第二行。 */
.map-topbar {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 1000;
  display: flex; align-items: flex-start; justify-content: flex-end;
  flex-wrap: wrap; gap: 8px;
  pointer-events: none;          /* 容器本身唔阻住地圖，得入面啲掣收 event */
}
.map-topbar > * { pointer-events: auto; }
.map-topright { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.floating-btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; font-size: 14px; font-weight: 700; cursor: pointer;
  box-shadow: 0 1px 4px rgba(58,46,32,.20);
  text-decoration: none; white-space: nowrap;
  display: inline-flex; align-items: center; min-height: 40px; box-sizing: border-box;
}
.floating-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 分類圖示 marker（2026-08-21）：zoom 夠近＋分類模式先出，見 map.js makeIcon()。
   白邊同陰影令圖示喺深色底圖上都分得開——冇呢層嘅話深色分類色會同建築物溶埋。 */
.cat-marker {
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 0 0 1.5px var(--panel), 0 1px 4px rgba(58, 46, 32, .45);
  display: block;
}
.cat-marker .cat-ic { width: 100%; height: 100%; display: block; }
.cat-marker .cat-glyph {
  fill: #fff; stroke: #fff; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

/* 搜尋：而家係 .map-topbar 嘅第一個 flex item（唔再自己 absolute）。
   flex: 1 1 190px ＝ 有位就撐開到 230px，冇位就縮，再細就成個 wrap 落第二行。
   position: relative 要留——`.search-clear` 同 `.search-results` 靠佢做定位錨。 */
.search-box {
  position: relative;
  flex: 1 1 190px;
  min-width: 0;
  max-width: 230px;
}
.search-input {
  width: 100%; box-sizing: border-box;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 34px 9px 12px; font-size: 16px;
  box-shadow: 0 1px 4px rgba(58,46,32,.20);
}
.search-input::placeholder { color: var(--muted); }
/* 2026-08-21 審查：可撳範圍原本 28px。視覺維持（做大個 × 會逼住搜尋框），
   用 ::before 向外擴到 40px。 */
.search-clear {
  position: absolute; top: 5px; right: 5px; z-index: 1;
  width: 28px; height: 28px; border: none; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer;
}
.search-clear::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 40px; height: 40px; transform: translate(-50%, -50%);
}
.search-clear:active { background: var(--card); }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  max-height: min(360px, 60vh); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 2px 12px rgba(58,46,32,.22);
}
.search-result-row {
  display: flex; align-items: baseline; gap: 8px; padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.search-result-row:last-child { border-bottom: none; }
.search-result-row:active { background: var(--card); }
.search-result-code { font-size: 12px; font-weight: 800; color: var(--muted); flex: 0 0 auto; }
.search-result-main { flex: 1 1 auto; min-width: 0; }
.search-result-name { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-addr { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-empty { padding: 12px; font-size: 13px; color: var(--muted); }

.control-panel {
  position: absolute; top: 54px; right: 10px; z-index: 1000;
  width: min(280px, 78vw); max-height: calc(100% - 64px); overflow-y: auto;
  background: var(--panel); border-radius: 12px; padding: 12px;
  box-shadow: 0 2px 12px rgba(58,46,32,.22);
  display: flex; flex-direction: column; gap: 12px;
}
.control-panel.collapsed { display: none; }

.control-section { }
.control-title { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 6px; }

.mode-row { display: flex; flex-wrap: wrap; gap: 6px; }
.mode-btn {
  flex: 1 1 auto; min-width: 64px; font-size: 12px; font-weight: 700; padding: 8px 4px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer;
}
.mode-btn.active { background: var(--accent); color: var(--on-solid); border-color: var(--accent); }
.mode-note {
  font-size: 12px; line-height: 1.5; color: var(--muted); background: var(--card);
  border-radius: 8px; padding: 8px 10px; margin-top: 8px;
}

.street-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.street-chip {
  font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer;
}
.street-chip.active { background: var(--accent); color: var(--on-solid); border-color: var(--accent); font-weight: 700; }

/* 16px 唔可以再細（2026-08-21 審查 P2-13）：iOS 對焦細過 16px 嘅輸入控件
   會自動放大成版，行街單手操作嗰陣好煩。 */
.select-input {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; color: var(--text); font-size: 16px;
}

.legend { display: flex; flex-direction: column; gap: 5px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; border: 1px solid rgba(58,46,32,.35); }
.legend-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { color: var(--muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; }

.control-count { font-size: 12px; color: var(--muted); text-align: right; border-top: 1px solid var(--line); padding-top: 8px; }

/* ---------- marker popup 內容 ---------- */
.leaflet-popup-content-wrapper { background: var(--card); color: var(--text); border-radius: 12px; }
.leaflet-popup-tip { background: var(--card); }
.leaflet-popup-content { margin: 12px 14px; }
.popup-card { min-width: 200px; max-width: 260px; }
.popup-code { font-size: 15px; font-weight: 800; color: var(--accent); }
.popup-street { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.popup-name { font-size: 15px; font-weight: 700; margin: 4px 0 2px; }
.popup-row { font-size: 12px; margin: 2px 0; }
.popup-tag {
  display: inline-block; background: var(--panel); border-radius: 999px; padding: 2px 8px;
  font-size: 12px; margin: 2px 4px 0 0; color: var(--text); border: 1px solid var(--line);
}
.popup-tag-community { border-color: var(--comm-sea-other); color: var(--comm-sea-other); font-weight: 700; }
.popup-photo { max-width: 100%; max-height: 120px; border-radius: 8px; margin-top: 6px; display: block; }
/* Leaflet 自帶 CSS 有 `.leaflet-container a { color:#0078A8 }`（藍色），佢兩層 class
   嘅特異性高過單一 `.popup-link`，會蓋走我哋想要嘅白字。選擇器要疊多一層先贏得返。 */
/* popup 底部兩粒掣（2026-08-13 加咗「幫手更新呢間」之後重排主次）：
   兩粒都實色圓角會撞到分唔清撳邊粒，而且 popup 得 200-260px 闊，並排會迫爆。
   所以：各自佔一行；「睇完整檔案」＝線框次要，「幫手更新」＝實色主行動。 */
.leaflet-popup-content .popup-link {
  display: block; margin-top: 8px; font-size: 12px; font-weight: 700; text-align: center;
  color: var(--accent); background: transparent; border: 1.5px solid var(--accent);
  padding: 7px 12px; border-radius: 999px; box-sizing: border-box;
  text-decoration: none;
}

#toast {
  position: absolute; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  z-index: 1002; background: var(--green); color: var(--on-solid); font-size: 14px; font-weight: 700;
  padding: 10px 16px; border-radius: 999px; box-shadow: 0 2px 10px rgba(58,46,32,.25);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
  max-width: 90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red); }

@media (max-width: 480px) {
  .control-panel { top: 54px; right: 8px; left: 8px; width: auto; max-width: none; }
}

/* ---------- 桌面：控制面板加闊、加大內距，睇落更似正式面板（維持浮動——
   如果改做唔浮動嘅固定側欄，需要 JS 呼叫 leaflet invalidateSize() 先唔會拉花地圖，
   但呢個任務唔准改 JS，所以淨係做視覺優化，行為同 375px 一致）。 ---------- */
@media (min-width: 1024px) {
  .control-panel { width: 300px; padding: 14px; gap: 14px; }
  .floating-btn { padding: 10px 16px; font-size: 14px; }
  .control-title { font-size: 12px; }
}

/* F3+（2026-08-13）：地圖 popup 嘅「幫手更新呢間」入口——實色主掣。
   ⚠️ 要 .leaflet-popup-content 前綴：Leaflet 自帶 `.leaflet-container a` 同上面
   `.leaflet-popup-content .popup-link` 都係兩層特異性，單層 class 贏唔到（實測踩過）。 */
.leaflet-popup-content .popup-link-record {
  margin-top: 6px; font-weight: 800;
  background: var(--accent); color: var(--on-solid); border-color: var(--accent);
}
