/* ====== 補給站/道館地圖 ====== */
/* 地圖外框：相對定位，讓內部浮動面板以它為基準；高度填滿可視區（扣掉導覽列） */
#map-app .map-app-wrap {
  position: relative;
  /* full-bleed：突破 .main-container 的 max-width，佔滿整個視窗寬度 */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  /* 扣掉：導覽列高 + .main-container 的 25px 上內距 + 8px 呼吸空間 */
  height: calc(100vh - var(--nav-height, 60px) - 33px);
  height: calc(100dvh - var(--nav-height, 60px) - 33px); /* 手機扣掉網址列，貼合實際可視高 */
  min-height: 420px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

#map-app .s2map {
  width: 100%;
  height: 100%;
  background: #ddd;
}

/* 手機長按地圖時，不要出現 iOS 的反白選取區塊 / 放大鏡選單 */
#map-app .s2map,
#map-app .pegman-control {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
/* 但彈出視窗內的文字（名稱、座標）仍可選取複製 */
#map-app .leaflet-popup-content {
  -webkit-user-select: text;
  user-select: text;
}

/* 頂部控制容器：面板 + 搜尋框直向堆疊，不再各自固定 top 互相重疊
   當作「中間欄」：left/right 由 JS 依左右兩側 Leaflet 控制項的實際寬度動態設定，
   右側會在「選擇地圖」圖層清單展開後一併算入其展開寬度（見 map-app.js）。 */
#map-app .map-topbar {
  position: absolute; top: 10px; z-index: 1001;
  left: var(--topbar-left, 50px);
  right: var(--topbar-right, 48px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  pointer-events: none;            /* 容器空白處不擋地圖操作 */
}
#map-app .map-topbar > * { pointer-events: auto; }

/* 頂部控制列 */
#map-app .panel {
  background: rgba(255, 255, 255, 0.95); padding: 8px 12px; border-radius: 8px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4); font: 14px/1.4 system-ui, sans-serif;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: 100%;
}
#map-app .panel select, #map-app .panel input { font-size: 14px; padding: 2px 4px; }

/* 停在地圖分頁時鎖住頁面捲動：地圖已滿版，避免滑一滑捲離地圖
   （html 也要鎖：iOS Safari 只鎖 body 時觸控捲動仍會漏） */
html.map-noscroll, html.map-noscroll body { overflow: hidden; }

/* 地圖分頁把 footer 一併隱藏：讓頁面沒有任何可捲的剩餘高度，
   連「聚焦輸入框時瀏覽器自動捲動」這類程式化捲動也無處可捲。
   其他分頁的 copyright / fair-use 聲明不受影響。 */
html.map-noscroll .site-footer { display: none; }
/* body 底部 padding 也會製造 5px 可捲高度，一併歸零 */
html.map-noscroll body { padding-bottom: 0; }

/* 說明 / FAQ（SEO 文字內容）：平常收合成彈窗，由 ❓ 按鈕開啟。
   內容保留在 DOM 中供搜尋引擎索引，不佔頁面高度。 */
#map-app .map-seo {
  display: none;
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0, 0, 0, 0.45);
  align-items: center; justify-content: center;
  padding: 16px;
  font: 15px/1.75 system-ui, "Microsoft JhengHei", sans-serif; color: #2d3748;
}
#map-app .map-seo.open { display: flex; }
#map-app .map-seo-inner {
  position: relative;
  background: #fff; border-radius: 14px;
  max-width: 820px; width: 100%;
  max-height: 85dvh; overflow-y: auto;
  padding: 20px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
#map-app .map-seo-close {
  position: sticky; top: 0; float: right;
  border: none; background: #f0f2f5; color: #555;
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 15px; cursor: pointer;
}
#map-app .map-seo-close:hover { background: #e2e8f0; }
#map-app .map-seo h1 { font-size: 1.6rem; font-weight: 800; color: #1a202c; margin-bottom: 12px; }
#map-app .map-seo h2 { font-size: 1.2rem; font-weight: 700; color: #1a202c; margin: 24px 0 10px; }
#map-app .map-seo p { margin-bottom: 12px; color: #4a5568; }
#map-app .map-seo .map-features { list-style: none; padding: 0; margin: 0 0 14px; }
#map-app .map-seo .map-features li {
  padding: 8px 12px; margin-bottom: 6px; background: #f5f8fc; border-radius: 8px; color: #2d3748;
}
#map-app .map-seo .map-regions { font-size: 14px; color: #718096; }
#map-app .map-seo details {
  border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; background: #fff;
}
#map-app .map-seo summary { cursor: pointer; font-weight: 600; color: #2b6cb0; }
#map-app .map-seo details[open] summary { margin-bottom: 8px; }
#map-app .map-seo details p { margin: 0; font-size: 14px; }

/* 定位控制項（縮放鈕正下方，標準 Leaflet 樣式） */
#map-app .locate-control a {
  display: flex; align-items: center; justify-content: center;
}
#map-app .locate-control svg { fill: #333; transition: fill .15s; }
#map-app .locate-control a:hover svg { fill: #2b6cb0; }
#map-app .locate-control.locating svg { fill: #2b6cb0; animation: locateSpin 1s linear infinite; }
@keyframes locateSpin { to { transform: rotate(360deg); } }
#map-app .panel label { font-weight: 600; }
#map-app .panel .status { color: #555; font-size: 13px; }
#map-app .panel .warn { color: #c0392b; font-weight: 600; }

/* 座標讀值列 */
#map-app .coordbox {
  position: absolute; bottom: 8px; left: 8px; z-index: 1000;
  background: rgba(0, 0, 0, 0.7); color: #fff; padding: 4px 8px; border-radius: 5px;
  font: 12px/1.4 monospace; pointer-events: none;
}

/* Pegman 小人控制盒 */
#map-app .pegman-control {
  background: #fff; padding: 6px; border-radius: 8px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4); text-align: center; width: 66px;
}
#map-app .pegman-control .peg {
  font-size: 34px; line-height: 34px; cursor: grab; user-select: none;
  /* 交給 Pointer Events 處理拖曳：阻止瀏覽器把觸控當成捲動/縮放手勢 */
  touch-action: none;
}
#map-app .pegman-control .peg:active { cursor: grabbing; }
#map-app .pegman-control .hint { font: 10px/1.2 system-ui, sans-serif; color: #666; margin-top: 2px; }
#map-app .pegman-control .reset {
  display: none; margin-top: 4px; font-size: 11px; cursor: pointer;
  color: #2b6cb0; text-decoration: underline;
}
#map-app .person-marker-icon { text-align: center; }

/* 搜尋框 */
#map-app .searchbox {
  width: 280px; max-width: 100%;
  font: 14px system-ui, sans-serif;
}
#map-app .searchbox .row {
  display: flex; background: #fff; border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}
#map-app .searchbox input {
  flex: 1; border: none; padding: 8px 10px; font-size: 14px; outline: none; min-width: 0;
}
#map-app .searchbox button {
  border: none; background: #2b6cb0; color: #fff; padding: 0 14px; cursor: pointer; font-size: 15px;
}
#map-app .searchbox button:hover { background: #2c5282; }
#map-app .searchbox .results {
  margin-top: 4px; background: #fff; border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4); display: none; max-height: 50vh; overflow-y: auto;
}
#map-app .searchbox .results div {
  padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #eee; font-size: 13px;
}
#map-app .searchbox .results div:last-child { border-bottom: none; }
#map-app .searchbox .results div:hover { background: #ebf8ff; }
#map-app .searchbox .results .empty { color: #888; cursor: default; }

/* 排名統計：面板上的按鈕 + 結果清單 */
#map-app #rankBtn {
  border: none; background: #2b6cb0; color: #fff; padding: 4px 10px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
#map-app #rankBtn:hover { background: #2c5282; }
#map-app .rankbox {
  width: 320px; max-width: 100%;
  background: #fff; border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  font: 13px/1.5 system-ui, sans-serif;
}
#map-app .rank-tabs {
  display: flex; border-bottom: 1px solid #e2e8f0; background: #f7fafc;
}
#map-app .rank-tabs button {
  flex: 1; border: none; background: transparent; padding: 8px 4px;
  cursor: pointer; font-size: 12px; color: #4a5568; white-space: nowrap;
}
#map-app .rank-tabs button.active {
  background: #fff; color: #2b6cb0; font-weight: 700;
  box-shadow: inset 0 -2px 0 #2b6cb0;
}
#map-app .rank-tabs .rank-close { flex: 0 0 32px; color: #a0aec0; }
#map-app .rank-region {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-bottom: 1px solid #e2e8f0; background: #fff;
}
#map-app .rank-region label { font-weight: 600; color: #4a5568; }
#map-app .rank-region select { flex: 1; font-size: 13px; padding: 2px 4px; }
#map-app .rank-list { max-height: 40vh; overflow-y: auto; }
#map-app .rank-list .row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #f0f2f5;
}
#map-app .rank-list .row:hover { background: #ebf8ff; }
#map-app .rank-list .rank-no {
  flex: 0 0 26px; text-align: center; font-weight: 800; color: #718096;
}
#map-app .rank-list .rank-cnt { flex: 0 0 auto; font-weight: 700; color: #2b6cb0; }
#map-app .rank-list .rank-near {
  flex: 1; min-width: 0; color: #4a5568;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#map-app .rank-list .empty { padding: 12px; color: #888; text-align: center; }

/* 面板開關鈕：桌面版不需要（面板常駐），只在手機出現 */
#map-app .panel-toggle-control { display: none; }
#map-app .panel-toggle-control a { font-size: 16px; }
#map-app .panel-toggle-control.is-open a { background: #ebf8ff; }

/* 手機：控制列避開左上縮放/定位鈕、右上圖層鈕，中間堆疊
   left/right 交給 JS 動態計算（見 map-app.js），這裡只調整間距與字級 */
@media (max-width: 768px) {
  #map-app .map-topbar {
    top: 8px;
  }
  #map-app .panel {
    width: 100%; gap: 6px 8px; padding: 6px 8px; font-size: 13px;
  }
  #map-app .searchbox { width: 100%; }

  /* 手機上面板預設收合，點 ⚙️ 才展開，讓地圖視野乾淨 */
  #map-app .panel-toggle-control { display: block; }
  #map-app .map-topbar .panel { display: none; }
  #map-app.panel-open .map-topbar .panel { display: flex; }
}

/* ===== 手機版地圖操作教學（一次性標注卡）===== */
#map-app .map-tutorial {
  display: none;
  position: absolute; inset: 0; z-index: 2500;
  background: rgba(15, 23, 42, 0.62);
  align-items: center; justify-content: center;
  padding: 16px;
}
#map-app .map-tutorial.open { display: flex; }

/* 角落標籤：釘在四角，天然對齊真實控制項（⚙️左上、選擇底圖右上、🧍右下）*/
#map-app .map-tutorial .mt-label {
  position: absolute;
  background: rgba(255, 255, 255, 0.96);
  color: #1a202c; font: 600 13px/1.3 system-ui, sans-serif;
  padding: 6px 11px; border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  animation: mtPulse 1.6s ease-in-out infinite;
}
#map-app .map-tutorial .mt-tl { top: 12px; left: 56px; }    /* 避開左上縮放鈕 */
#map-app .map-tutorial .mt-tr { top: 12px; right: 12px; }
#map-app .map-tutorial .mt-br { bottom: 88px; right: 12px; } /* 在 🧍 控制盒上方 */
@keyframes mtPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

#map-app .map-tutorial .mt-card {
  background: #fff; border-radius: 16px;
  max-width: 340px; width: 100%;
  padding: 20px 22px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.45);
}
#map-app .map-tutorial .mt-card h3 {
  margin: 0 0 14px; font-size: 1.15rem; color: #111827;
}
#map-app .map-tutorial .mt-card ul {
  margin: 0 0 18px; padding: 0; list-style: none;
}
#map-app .map-tutorial .mt-card li {
  margin: 11px 0; color: #374151; line-height: 1.6; font-size: 14px;
}
#map-app .map-tutorial .mt-card li b { color: #2b6cb0; }
#map-app .map-tutorial .mt-done {
  width: 100%; border: none; border-radius: 10px;
  background: #2b6cb0; color: #fff; font-size: 15px; font-weight: 700;
  padding: 12px; cursor: pointer;
}
#map-app .map-tutorial .mt-done:hover { background: #2c5282; }

/* 「重看地圖操作教學」按鈕（❓ 說明彈窗內）：只在手機顯示 */
#map-app .map-seo-tutorial { display: none; }
@media (max-width: 768px) {
  #map-app .map-seo-tutorial {
    display: inline-block;
    border: 1px solid #2b6cb0; background: #ebf8ff; color: #2b6cb0;
    padding: 8px 14px; border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer;
  }
}
