/* ===================================================
   测绘系统 UI —— 风格对齐参考系统
   关键设计:半透明毛玻璃顶栏、胶囊按钮、突出大字、彩色分类
   =================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --c-primary: #FF6B00;        /* 主橙色 */
  --c-info: #409EFF;            /* 主蓝色 */
  --c-success: #67c23a;         /* 成功绿 */
  --c-warning: #e6a23c;         /* 警告黄 */
  --c-danger: #f56c6c;          /* 危险红 */
  --c-text: #222;
  --c-text-2: #666;
  --c-text-3: #999;
  --c-bg-glass: rgba(0, 0, 0, 0.5);
  --c-bg-glass-light: rgba(255, 255, 255, 0.97);
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: #466399;
}

/* ============ 顶栏 ============ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 48px;
  /* 不透明背景替代 backdrop-filter,在微信 X5 / 低端机上不再卡 */
  background: rgba(0, 0, 0, 0.78);
  color: #fff; display: flex; align-items: center;
  padding: 0 12px; z-index: 1000;
  gap: 10px;
  justify-content: space-between;
}
.logo {
  font-size: 15px; font-weight: 600; color: #fff;
  letter-spacing: 1px; flex-shrink: 0;
  display: flex; align-items: center; gap: 4px;
}
.basemap-switch {
  display: flex; align-items: center; gap: 6px;
  flex: 1; min-width: 0;
}
.basemap-switch .label {
  color: rgba(255,255,255,.7); margin-right: 4px;
  font-size: 12px; flex-shrink: 0;
}
.basemap-switch button {
  border: none; padding: 5px 12px;
  border-radius: 14px; cursor: pointer;
  font-size: 12px; font-weight: 500;
  color: #fff;
  background: rgba(255,255,255,.18);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.basemap-switch button:hover:not(.active) { background: rgba(255,255,255,.28); }
.basemap-switch button.active { background: var(--c-info); }
.topbar-right { flex-shrink: 0; }
.coord {
  background: rgba(0,0,0,.4); color: #fff;
  padding: 5px 10px; border-radius: 14px;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 11px; white-space: nowrap;
}

/* ============ 左侧工具栏(胶囊风格) ============ */
.sidebar {
  position: fixed; top: 60px; left: 12px; z-index: 999;
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(255,255,255,.95);
  padding: 8px; border-radius: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
.sidebar button {
  width: 40px; height: 40px; border: none;
  background: transparent;
  border-radius: 10px; cursor: pointer;
  font-size: 16px; font-weight: 600;
  color: var(--c-text-2);
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
}
.sidebar button:hover { background: #f3f4f6; }
.sidebar button.active {
  background: var(--c-info); color: #fff;
}

/* ============ 右侧面板(抽屉风格) ============ */
.panel {
  position: fixed; top: 60px; right: 12px; width: 320px;
  max-height: calc(100vh - 80px);
  background: var(--c-bg-glass-light);
  border-radius: 14px; padding: 14px; overflow-y: auto;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
  z-index: 999;
  transition: transform .25s ease;
}
.panel-section { margin-bottom: 16px; }
.panel-section h3 {
  font-size: 14px; margin-bottom: 8px;
  color: var(--c-text); font-weight: 600;
}
.panel-section ul {
  font-size: 13px; color: var(--c-text-2);
  line-height: 1.8; padding-left: 20px;
}
.panel-section code {
  background: #f3f4f6; padding: 1px 4px;
  border-radius: 3px; font-size: 12px;
}
.row { display: flex; gap: 6px; margin-bottom: 6px; }
.row input {
  flex: 1; padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 8px; font-size: 14px;
  outline: none;
  min-width: 0;
}
.row input:focus { border-color: var(--c-info); }
.row button {
  padding: 8px 14px;
  background: var(--c-info); color: #fff;
  border: none; border-radius: 8px;
  cursor: pointer; font-size: 14px;
  white-space: nowrap;
}
.row button:hover { filter: brightness(.92); }
.panel-section button {
  margin-top: 6px; padding: 8px 14px;
  background: var(--c-info); color: #fff;
  border: none; border-radius: 8px;
  cursor: pointer; font-size: 14px;
  margin-right: 6px;
}
.panel-section button:hover { filter: brightness(.92); }
.poi-list { list-style: none; padding: 0; max-height: 260px; overflow-y: auto; }
.poi-list li {
  padding: 8px;
  border-bottom: 1px solid #eee;
  cursor: pointer; font-size: 13px;
}
.poi-list li:hover { background: #f9fafb; }
.poi-list .addr { color: var(--c-text-3); font-size: 12px; }
.info {
  margin-top: 8px; padding: 8px;
  background: #f9fafb; border-radius: 6px;
  font-size: 13px; color: var(--c-text);
  min-height: 24px;
}

/* 面板遮罩(移动端用) */
.panel-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 998;
}
.panel-backdrop.show { display: block; }

/* 没内容可显示时整个面板藏起来(避免空白卡片) */
.panel.panel-empty { display: none; }
.panel.panel-empty .panel-close { display: none !important; }

/* 面板关闭按钮(移动端显示) */
.panel-close {
  display: none; position: absolute; top: 8px; right: 10px;
  width: 28px; height: 28px; border: none;
  background: transparent;
  font-size: 22px; line-height: 1;
  cursor: pointer; color: var(--c-text-3);
}

/* ============ 地图 ============ */
#map { position: absolute; top: 48px; left: 0; right: 0; bottom: 0; }

/* Leaflet 测量标签 */
.measure-label {
  background: rgba(0,0,0,.7); color: #fff;
  padding: 4px 8px; border-radius: 4px;
  font-size: 13px; white-space: nowrap;
  border: none !important;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

/* ============ 顶部提示条(胶囊) ============ */
#topTip {
  position: fixed; top: 56px; left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  background: rgba(0,0,0,.65); color: #fff;
  padding: 7px 16px; border-radius: 20px;
  font-size: 13px; white-space: nowrap;
  display: none;
}

/* ============ 十字准星(白线 + 橙点) ============ */
#crosshair {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  z-index: 900;
  pointer-events: none; display: none;
}
.ch-h { position: absolute; top: 50%; left: -20px; width: 40px; height: 1px; background: rgba(255,255,255,.9); box-shadow: 0 0 2px rgba(0,0,0,.6); }
.ch-v { position: absolute; left: 50%; top: -20px; height: 40px; width: 1px; background: rgba(255,255,255,.9); box-shadow: 0 0 2px rgba(0,0,0,.6); }
.ch-circle { position: absolute; top: 50%; left: 50%; width: 20px; height: 20px; border: 1.5px solid rgba(255,255,255,.9); border-radius: 50%; transform: translate(-50%,-50%); box-shadow: 0 0 2px rgba(0,0,0,.6); }
.ch-dot { position: absolute; top: 50%; left: 50%; width: 4px; height: 4px; background: #fff; border-radius: 50%; transform: translate(-50%,-50%); }

/* ============ 常驻定位按钮(悬浮圆钮) ============ */
#locateFab {
  position: fixed; right: 16px; bottom: 24px;
  z-index: 950;
  width: 44px; height: 44px;
  border: none; border-radius: 50%;
  background: #fff; color: var(--c-info);
  font-size: 20px; line-height: 44px; text-align: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s, box-shadow .15s;
}
#locateFab:hover { box-shadow: 0 3px 14px rgba(0,0,0,.35); }
#locateFab:active { transform: scale(.92); }
/* 定位进行中:旋转反馈 */
#locateFab.locating { animation: fab-spin 1s linear infinite; color: var(--c-primary); }
@keyframes fab-spin { to { transform: rotate(360deg); } }

/* ============ 底部操作面板(参考系统风格) ============ */
.bottom-panel {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 1001;
  background: rgba(255,255,255,.97);
  padding: 12px 14px 10px;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -2px 12px rgba(0,0,0,.15);
  display: none; flex-direction: column;
  gap: 10px;
}
.bp-stats { text-align: center; margin-bottom: 4px; }
.bp-head { display: flex; align-items: center; justify-content: space-between; }
.bp-title { font-size: 13px; font-weight: 600; color: var(--c-text-2); }
.bp-done {
  border: none; background: #f4f4f5; color: var(--c-text-2);
  padding: 5px 12px; border-radius: 14px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bp-done:hover { background: #e9e9eb; }
.bp-main { display: flex; align-items: baseline; justify-content: center; gap: 4px; }
#bpValue {
  font-size: 44px; font-weight: 700;
  color: var(--c-text); line-height: 1;
}
#bpUnit { font-size: 18px; color: var(--c-text-2); margin-left: 4px; }
.bp-detail { font-size: 12px; color: var(--c-text-3); margin-top: 2px; text-align: center; }

.bp-actions { display: flex; gap: 6px; justify-content: center; }
.bp-btn {
  flex: 1; padding: 10px 0; border: none;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bp-add    { background: var(--c-primary); color: #fff; }
.bp-undo   { background: #fef0f0; color: var(--c-danger); }
.bp-clear  { background: #f4f4f5; color: var(--c-text-2); }
.bp-btn:disabled { opacity: .4; cursor: not-allowed; }

/* 图形类型切换(点 / 线 / 面)分段控件 */
.bp-modes {
  display: flex; gap: 6px; justify-content: center;
}
.bp-mode {
  flex: 1; padding: 8px 0; border: none;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  color: var(--c-text-2);
  background: #f4f4f5;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
}
.bp-mode:hover:not(.active) { background: #e9e9eb; }
.bp-mode.active { background: var(--c-info); color: #fff; }

/* GeoJSON 导出 / 导入(文字链接式辅助入口) */
.bp-geojson {
  display: flex; gap: 16px; justify-content: center;
  padding-top: 2px;
}
.bp-link {
  border: none; background: transparent;
  color: var(--c-info); font-size: 12px;
  cursor: pointer; padding: 2px 4px;
  -webkit-tap-highlight-color: transparent;
  text-decoration: underline;
}
.bp-link:hover { filter: brightness(.85); }

/* ===================================================
   移动端适配(< 768px)
   =================================================== */
@media (max-width: 768px) {
  /* 顶栏:底图按钮变下拉 */
  .topbar { padding: 0 8px; gap: 6px; }
  .logo { font-size: 14px; }
  .coord { font-size: 10px; padding: 3px 8px; }

  .basemap-switch { position: relative; }
  .basemap-switch .label { display: none; }
  /* 收起态:只显示当前项(带 ▾) */
  .basemap-switch > button { display: none; }
  .basemap-switch > button.basemap-current {
    display: inline-block; padding: 5px 12px; font-size: 12px;
  }
  .basemap-switch > button.basemap-current::after { content: " ▾"; font-size: 9px; }

  /* 展开态:当前项仍显示在顶栏,其余项以浮层从下方弹出 */
  .basemap-switch.open {
    position: absolute; top: 8px; left: 60px;
    z-index: 1002;
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    background: rgba(255,255,255,.98);
    border-radius: 10px; padding: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    min-width: 130px;
  }
  .basemap-switch.open > button {
    display: block; text-align: left;
    padding: 9px 12px; font-size: 13px;
    color: #333; background: transparent;
    border-radius: 6px;
  }
  .basemap-switch.open > button::after { content: none; }
  .basemap-switch.open > button.active {
    background: var(--c-info); color: #fff;
  }

  /* 左侧工具栏:底部横排(App 风格) */
  .sidebar {
    top: auto; bottom: 12px; left: 12px; right: 12px;
    flex-direction: row; justify-content: space-around;
    padding: 6px; border-radius: 14px;
  }
  .sidebar button { width: 44px; height: 44px; font-size: 16px; }

  /* 右侧面板:底部抽屉化(只占下半屏,不遮挡左上角绘图工具条) */
  .panel {
    top: auto; right: 0; left: 0; bottom: 0; width: auto;
    max-height: 60vh; overflow-y: auto;
    border-radius: 14px 14px 0 0;
    transform: translateY(110%);
    z-index: 1200;
  }
  .panel.show { transform: translateY(0); }
  .panel-close { display: block; }

  /* 地图:腾出顶栏 + 底部工具条 */
  #map { top: 48px; bottom: 70px; }

  /* 定位按钮:移到底部工具栏上方,避免重叠 */
  #locateFab { right: 12px; bottom: 82px; }
}

/* ===================================================
   缩放控件(+/- 按钮)—— 锚点固定为地图中心
   =================================================== */
.zoom-controls {
  position: fixed;
  right: 16px;
  bottom: 80px;          /* 桌面:在 locateFab(bottom:24)之上 */
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: #fff; color: var(--c-info);
  font-size: 22px; font-weight: 600;
  line-height: 40px; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s, box-shadow .15s;
  user-select: none;
}
.zoom-btn:hover { box-shadow: 0 3px 12px rgba(0,0,0,.3); }
.zoom-btn:active { transform: scale(.92); }

/* 移动端:缩放控件再往上挪,避免压到 sidebar */
@media (max-width: 768px) {
  .zoom-controls { right: 12px; bottom: 138px; }  /* locateFab 是 82,这里是 82+40+16 */
}

/* 小屏(< 420px)再压缩 */
@media (max-width: 420px) {
  .coord { display: none; }
  .sidebar button { width: 40px; height: 40px; }
  .row input { font-size: 16px; }
}

/* ===================================================
   "我的位置"标记(替代 Leaflet 默认 41×49 大头针)
   16px 蓝点 + 白色描边 + 半透明脉冲圈
   =================================================== */
.my-location-marker {
  position: relative;
  width: 16px;
  height: 16px;
  pointer-events: auto;
}
.my-location-pulse {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 16px; height: 16px;
  background: rgba(66, 133, 244, .35);
  border-radius: 50%;
  z-index: 1;
  animation: my-loc-pulse 2s ease-out infinite;
}
.my-location-dot {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  background: #4285F4;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  z-index: 2;
}
@keyframes my-loc-pulse {
  0%   { transform: translate(-50%, -50%) scale(1);   opacity: .55; }
  100% { transform: translate(-50%, -50%) scale(2.6); opacity: 0;   }
}