/* 备案号悬浮条（固定右下角，合规要求） */
#beianBar {
  position: fixed;
  bottom: 6px;
  right: 8px;
  z-index: 1100;
  font-size: 11px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  user-select: none;
}
#beianBar a {
  color: inherit;
  text-decoration: none;
}
#beianBar a:hover {
  text-decoration: underline;
  color: #fff;
}

/* 全局重置，优化移动端体验 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  display: flex; /* 保留flex布局 */
  /* 横竖屏 safe-area 自适应：取基础间距和系统安全区中的较大值
     - 竖屏 iOS：top ≈ 50px（灵动岛）、bottom ≈ 34px（Home 条）
     - 横屏 iOS：left/right ≈ 44px（齐刘海两侧）
     - Android 刘海/打孔屏：top/bottom 按系统上报值自动适配 */
  padding-top: max(min(1.6vw, 1vh, 16px), env(safe-area-inset-top));
  padding-right: max(min(1.6vw, 1vh, 16px), env(safe-area-inset-right));
  padding-bottom: max(min(1.6vw, 1vh, 16px), env(safe-area-inset-bottom));
  padding-left: max(min(1.6vw, 1vh, 16px), env(safe-area-inset-left));
  height: 100vh; /* 旧浏览器兜底 */
  height: 100dvh; /* dvh：动态视口高度，避开移动端地址栏的高度跳变 */
  overflow: hidden;
  position: relative; /* 为固定定位元素提供参考 */
}

/* 左侧悬浮图层控制面板（仿天地图样式） */
.layer-panel {
  position: fixed;
  top: 0;
  left: 0;
  transform: translateX(-240px); /* fallback，由 JS 覆盖 */
  width: 240px; /* fallback，由 JS 覆盖 */
  height: 100%;
  background: #fff;
  border-right: 1px solid #99cc99;
  padding: 15px 10px;
  padding-top: 1vh;
  box-sizing: border-box;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  z-index: 1666;
  transition: transform 0.3s ease;
  /* 面板自身不滚动，用 flex 布局让内容区滚动 */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* 细滚动条，与面板风格统一 */
  scrollbar-width: thin;
  scrollbar-color: rgba(106, 170, 106, 0.3) transparent;
}
.layer-panel::-webkit-scrollbar {
  width: 6px;
}
.layer-panel::-webkit-scrollbar-track {
  background: transparent;
}
.layer-panel::-webkit-scrollbar-thumb {
  background: rgba(106, 170, 106, 0.25);
  border-radius: 3px;
}
.layer-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(106, 170, 106, 0.45);
}

/* 【修复】提升active类优先级，明确覆盖默认transform */
.layer-panel.active {
  transform: translateX(0) !important;
}

/* 面板拖拽时全局状态 */
body.resizing-panel {
  cursor: ew-resize !important;
  user-select: none !important;
}

/* 悬浮触发按钮（logo/手柄） */
.layer-trigger {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 40px;
  height: 80px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-left: none;
  border-radius: 0 8px 8px 0;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  z-index: 1000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  color: #666;
  font-size: 14px;
  transition: background 0.2s;
}

.layer-trigger:active {
  background: #f5f5f5;
  color: #333;
}

.layer-panel h3 {
  font-size: 16px;
  color: #333;
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}
.about-link {
  color: #999;
  font-size: 15px;
  text-decoration: none;
  line-height: 1;
  transition: color 0.2s;
  margin-left: auto;
  cursor: pointer;
  flex-shrink: 0;
}
.about-link:hover {
  color: #1976d2;
}
#selectAllRow {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  color: #333;
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}
.layer-item {
  display: flex;
  align-items: center;
  padding: 8px 5px;
  margin-bottom: 5px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}
.layer-item:hover {
  background: #f5f5f5;
}
.layer-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-right: 10px;
  cursor: pointer;
}
.layer-item label {
  flex: 1;
  font-size: 14px;
  color: #666;
  cursor: pointer;
}

#map {
  flex: 1; /* 保留flex布局的自适应 */
  height: 100%;
  width: min(96%, 100vw - 6px);
  margin: 0 auto;
  position: relative;
  border: min(1.6px, 1vh) dashed #99cc99;
  border-radius: max(6px, 0.6vw);
  overflow: hidden;
  touch-action: pan-x pan-y;
  transition: box-shadow 0.3s ease;
}

#map:active {
  box-shadow: 0 0 16px rgba(153, 204, 153, 0.6);
}

/* ========== 【方案A】Tooltip 样式（替代旧 Popup 样式）========== */

/* 悬停提示 Tooltip */
.leaflet-tooltip.hover-tooltip {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #4a8c4a;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  font-size: 12px;
  color: #333;
  padding: 0;
  max-width: 300px;
}

.leaflet-tooltip.hover-tooltip::before {
  display: none; /* 隐藏箭头 */
}

.leaflet-tooltip.hover-tooltip .feature-popup table {
  width: 100%;
  border-collapse: collapse;
}

.leaflet-tooltip.hover-tooltip .feature-popup table td {
  padding: 3px 5px;
  border-bottom: 1px solid #eee;
}

.leaflet-tooltip.hover-tooltip .feature-popup table tr:last-child td {
  border-bottom: none;
}

.leaflet-tooltip.hover-tooltip .feature-popup {
  margin: 8px 10px;
}

/* 站点标签 Tooltip */
.leaflet-tooltip.station-label-tooltip {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #8b7355;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  font-size: 11px;
  color: #5a4a3a;
  padding: 2px 6px;
  white-space: nowrap;
}

.leaflet-tooltip.station-label-tooltip::before {
  border-right-color: #8b7355;
}

.leaflet-tooltip.station-label-tooltip.top::before {
  border-top-color: #8b7355;
}

/* ========== 搜索框（侧边栏内） ========== */
.search-bar {
  padding: 0 5px;
  position: relative;
}

.search-bar input[type="text"] {
  width: 100%;
  padding: 7px 28px 7px 12px;
  font-size: 13px;
  border: 1px solid #99cc99;
  border-radius: 16px;
  background: #f8fcf8;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
  outline: none;
  color: #333;
  transition:
    border-color 0.2s,
    background 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%) translate(0, -1px);
  font-size: 12px;
  color: #999;
  cursor: pointer;
  display: none;
  user-select: none;
  padding: 4px;
  border-radius: 25%;
  transition:
    color 0.15s,
    background 0.15s;
}
.search-clear:hover {
  color: #e5534b;
  font-size: 16px;
  /* background: #f0e0e0; */
}
.search-clear.visible {
  display: block;
}

.search-bar input[type="text"]:focus {
  border-color: #4a8c4a;
  background: #fff;
  border-radius: 16px 16px 0 0;
}

.search-results {
  display: none;
  background: #fff;
  border: 1px solid #c8e0c8;
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  max-height: 65vh;
  overflow-y: auto;
  position: absolute;
  top: calc(100% + 4px);
  left: 5px;
  right: 5px;
  z-index: 2000;
}

.search-results.open {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: #f0f7f0;
}

.search-result-tag {
  flex-shrink: 0;
  font-size: 12px;
  color: #fff;
  background: #6aaa6a;
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
}

.search-result-text {
  color: #333;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.search-result-text mark {
  background: #ffe066;
  color: #333;
  border-radius: 2px;
  padding: 0 1px;
}

.search-empty {
  padding: 10px 12px;
  font-size: 12px;
  color: #999;
  text-align: center;
}

/* 侧边栏右侧拖拽手柄（透明，hover 微绿） */
.panel-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 12px;
  cursor: ew-resize;
  z-index: 10;
  touch-action: none;
  background: transparent;
  transition: background 0.2s;
}
.panel-resize-handle:hover,
.panel-resize-handle.active {
  background: rgba(106, 170, 106, 0.15);
}

/* ========== 聚类开关 ========== */
.toggle-bars-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-bottom: 1px solid #e8e8e8;
  margin-bottom: 4px;
}

.toggle-bars-row .cluster-toggle-bar {
  flex: 1 1 120px;
  min-width: 120px;
  margin-bottom: 0;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  box-sizing: border-box;
}

.cluster-toggle-bar {
  padding: 6px 5px 8px;
  display: block;
  border-bottom: 1px solid #e8e8e8;
  margin-bottom: 4px;
  position: relative;
}

.cluster-toggle-text {
  font-size: 12px;
  color: #555;
  position: relative;
  z-index: 0; /* 文字在按钮下方 */
  padding-right: 48px; /* 给按钮留出空间 */
}

.cluster-toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between; /* 文字左、按钮右 */
  cursor: pointer;
  position: relative;
}

/* 隐藏原生 checkbox */
.cluster-toggle-label input[type="checkbox"] {
  display: none;
}

/* 开关滑块 - 绝对定位在右边，在文字上方 */
.cluster-toggle-switch {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 20px;
  background: #ccc;
  border-radius: 10px;
  transition: background 0.2s;
  z-index: 1; /* 在文字上方 */
}

.cluster-toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* 开启状态 */
.cluster-toggle-label input[type="checkbox"]:checked + .cluster-toggle-switch {
  background: #4a8c4a;
}

.cluster-toggle-label
  input[type="checkbox"]:checked
  + .cluster-toggle-switch::after {
  transform: translateX(16px);
}

.leaflet-popup.hover-popup {
  pointer-events: none;
}

.leaflet-popup.hover-popup .leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #4a8c4a;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.leaflet-popup.hover-popup .leaflet-popup-content {
  font-size: 12px;
  color: #333;
  margin: 8px 10px;
}

.leaflet-popup.hover-popup .leaflet-popup-tip-container {
  display: none;
}

.leaflet-popup.hover-popup .feature-popup table {
  width: 100%;
  border-collapse: collapse;
}

.leaflet-popup.hover-popup .feature-popup table td {
  padding: 3px 5px;
  border-bottom: 1px solid #eee;
}

.leaflet-popup.hover-popup .feature-popup table tr:last-child td {
  border-bottom: none;
}

/* ========== 加载缓冲动画 ========== */
#loadingOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.45);
  z-index: 999999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
#loadingOverlay.active {
  display: flex;
}
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: loadingSpin 0.8s linear infinite;
}
@keyframes loadingSpin {
  to {
    transform: rotate(360deg);
  }
}
#loadingMessage {
  color: #fff;
  font-size: 15px;
  font-family: sans-serif;
  letter-spacing: 1px;
}

/* 版本号（图层面板底部） */
.app-version {
  color: rgba(0, 0, 0, 0.3);
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: center;
  padding: 4px;
  user-select: none;
  cursor: pointer;
  transition: color 0.15s;
}
.app-version:hover {
  color: rgba(0, 0, 0, 0.55);
}

/* SW 更新提示 toast */
.update-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10000;
  animation: toastIn 0.3s ease-out;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.update-toast button {
  background: #4caf50;
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 5px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.update-toast button:hover {
  background: #66bb6a;
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* 版本号清理菜单（版号上方） */
.refresh-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px 4px;
  flex-shrink: 0;
}

/* 版本号固定在面板底部 */
#appVersion {
  flex-shrink: 0;
  margin-bottom: -12px;
}
.refresh-menu button {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
  text-align: center;
  background: #e8e8ed;
  color: #333;
  transition: background 0.12s;
}
.refresh-menu button:hover {
  background: #d8d8de;
}

/* 悬浮窗右下角缩放按钮 */
.popup-zoom-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(74, 154, 74, 0.85);
  color: #fff;
  border: none;
  font-size: 12px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition:
    background 0.15s,
    transform 0.1s;
  padding: 0;
}
.popup-zoom-btn:hover {
  background: #3a8a3a;
  transform: scale(1.1);
}

/* ========== 搜索结果自定义 hover 提示卡片 ==========*/
#searchTooltip {
  display: none;
  position: fixed;
  z-index: 9999;
  background: #fff;
  border: 1px solid #99cc99;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: #333;
  max-width: 360px;
  max-height: 280px;
  overflow-x: hidden;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  pointer-events: auto;
}
#searchTooltip.visible {
  display: block;
}
#searchTooltip .tt-key {
  color: #6aaa6a;
  font-weight: 600;
}
#searchTooltip .tt-val {
  color: #333;
}

/* 面板内容滚动区：占满剩余高度 */
#layerItemsContainer {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0; /* flex 子元素溢出滚动必须 */
  /* 细滚动条 */
  scrollbar-width: thin;
  scrollbar-color: rgba(106, 170, 106, 0.3) transparent;
}
#layerItemsContainer::-webkit-scrollbar {
  width: 6px;
}
#layerItemsContainer::-webkit-scrollbar-track {
  background: transparent;
}
#layerItemsContainer::-webkit-scrollbar-thumb {
  background: rgba(106, 170, 106, 0.25);
  border-radius: 3px;
}
#layerItemsContainer::-webkit-scrollbar-thumb:hover {
  background: rgba(106, 170, 106, 0.45);
}

/* 侧边栏图钉按钮 */
.sidebar-pin-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 0 4px;
  opacity: 0.35;
  transition:
    opacity 0.2s,
    transform 0.2s;
  line-height: 1;
  flex-shrink: 0;
}
.sidebar-pin-btn:hover {
  opacity: 0.7;
}
.sidebar-pin-btn.active {
  opacity: 1;
  transform: rotate(45deg);
}

/* 侧边栏钉住状态：面板进入文档流，地图让出空间 */
body.sidebar-pinned {
  overflow: hidden;
}
body.sidebar-pinned #layerPanel {
  position: relative !important;
  transform: none !important;
  transition: none !important;
  flex-shrink: 0;
  height: 100%;
  z-index: auto;
}
body.sidebar-pinned #map {
  flex: 1 !important;
  width: auto !important;
  margin: 0 !important;
}
body.sidebar-pinned .layer-trigger {
  display: none !important;
}

/* ========== 打印样式（window.print() 导出图片）========== */
@media print {
  /* 隐藏所有非地图元素 */
  body.sidebar-pinned #layerPanel,
  #layerPanel,
  #layerTrigger,
  .leaflet-control-container,
  .update-toast,
  #searchTooltip,
  .pm-draw,
  .pm-toolbar,
  .pm-actions-container,
  .search-container,
  .search-input,
  .search-dropdown,
  #pointDropEditor,
  .color-picker-popup,
  .hover-tooltip,
  .leaflet-tooltip,
  .leaflet-popup {
    display: none !important;
  }

  /* 地图占满整页 */
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
  }

  #map, .map-container, #app-wrapper {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  /* 确保底图图层可见 */
  .leaflet-layer,
  .leaflet-tile,
  .leaflet-tile-loaded,
  .leaflet-overlay-pane svg,
  .leaflet-overlay-pane canvas {
    visibility: visible !important;
    display: block !important;
  }

  /* 强制打印背景色（底图瓦片）*/
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
