/* ===== 全局 ===== */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #1f2a37;
  background: #f5f7fa;
}
a { color: #1565c0; text-decoration: none; }

/* ===== 顶部导航 ===== */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px;
  background: #ffffff; border-bottom: 1px solid #e3e8ef;
  position: sticky; top: 0; z-index: 1000;
}
.brand { font-weight: 700; font-size: 18px; }
.site-nav a {
  margin-left: 18px; padding: 6px 10px; border-radius: 6px; color: #475569;
}
.site-nav a.active, .site-nav a:hover { background: #e8f0fe; color: #1565c0; }

/* ===== 首页 ===== */
.home { max-width: 1100px; margin: 0 auto; padding: 32px 20px; }
.hero h1 { font-size: 28px; line-height: 1.3; margin: 0 0 12px; }
.hero p { color: #64748b; font-size: 16px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 28px 0; }
.card {
  background: #fff; border: 1px solid #e3e8ef; border-radius: 12px; padding: 22px;
  transition: .15s; display: block; color: #1f2a37;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.card-emoji { font-size: 34px; }
.card h2 { margin: 10px 0 6px; }
.card p { color: #64748b; font-size: 14px; line-height: 1.6; }
.note { background: #fff; border: 1px solid #e3e8ef; border-radius: 12px; padding: 18px 22px; }
.note h3 { margin-top: 0; }
.note li { margin: 6px 0; color: #475569; }
code { background: #eef2f7; padding: 1px 6px; border-radius: 4px; }

/* ===== 布局：侧栏 + 地图 ===== */
.layout { position: relative; display: flex; height: calc(100vh - 56px); }
.side {
  width: 340px; min-width: 300px; padding: 16px; overflow-y: auto;
  background: #fff; border-right: 1px solid #e3e8ef;
}
.side h3 { margin: 4px 0 12px; }
.map { flex: 1; height: 100%; }
.hint-text { color: #64748b; font-size: 13px; }

/* ===== 物种列表 ===== */
.species-list .sp-list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
  border: 1px solid #eef2f7;
  user-select: none;   /* 双击时阻止文字选中 */
}
.species-list .sp-list-item:hover { background: #f1f5f9; }
.sp-list-sub { font-size: 12px; color: #94a3b8; }
.sp-empty { color: #94a3b8; font-size: 13px; padding: 8px; }

/* ===== 物种搜索框 ===== */
.species-search {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}
.species-search input[type="text"] {
  flex: 1; padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 13px; outline: none; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.species-search input[type="text"]:focus {
  border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.species-search-count {
  font-size: 12px; color: #94a3b8; min-width: 50px; text-align: right;
}
.species-search-input {
  width: 100%; padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 13px; outline: none; background: #fff; margin-bottom: 4px;
  transition: border-color .15s, box-shadow .15s;
}
.species-search-input:focus {
  border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

/* ===== 标签过滤：种类 / 保护级别（v24 标签搜索） ===== */
.species-tags {
  display: flex; flex-direction: column; gap: 4px; margin: 4px 0 8px;
}
.species-tags-row {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
}
.species-tags-label {
  font-size: 12px; color: #64748b; font-weight: 600; min-width: 36px;
}
.species-tag {
  display: inline-block; padding: 3px 9px; font-size: 12px; line-height: 1.4;
  border: 1px solid #d1d5db; border-radius: 12px; background: #fff;
  color: #475569; cursor: pointer; user-select: none;
  transition: background-color .12s, border-color .12s, color .12s;
}
.species-tag:hover {
  background: #f1f5f9; border-color: #94a3b8;
}
.species-tag.active {
  background: #2563eb; border-color: #1d4ed8; color: #fff; font-weight: 600;
}
.species-tip {
  margin-top: 8px; font-size: 12px; color: #94a3b8; line-height: 1.5;
  padding: 6px 8px; background: #f8fafc; border-radius: 6px;
}

/* ===== 弹窗坐标系标识 ===== */
.popup-crs {
  display: inline-block; margin-left: 4px; padding: 1px 5px;
  background: #eef2ff; color: #4338ca; border-radius: 4px;
  font-size: 11px; font-weight: 500;
}
.popup-coord { font-size: 12px; color: #475569; margin: 4px 0; }

/* 顶部状态条：云端读取中/成功/失败提示 */
.map-status {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 500; padding: 6px 14px; border-radius: 999px; font-size: 12px;
  background: rgba(15, 23, 42, 0.82); color: #e2e8f0; box-shadow: 0 2px 8px rgba(0,0,0,.18);
  pointer-events: none; max-width: 90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map-status.ok { background: rgba(22, 101, 52, 0.9); }
.map-status.warn { background: rgba(153, 27, 27, 0.9); }

/* ===== 上传表单 ===== */
.upload-form label { display: block; font-size: 13px; margin: 10px 0 4px; color: #475569; }
.upload-form select, .upload-form input[type=text],
.upload-form input[type=number], .upload-form textarea {
  width: 100%; padding: 8px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 14px; font-family: inherit;
}
.upload-form button {
  margin-top: 14px; width: 100%; padding: 10px; border: none; border-radius: 8px;
  background: #1565c0; color: #fff; font-size: 15px; cursor: pointer;
}
.upload-form button:hover { background: #0d4ea3; }
.upload-msg { margin-top: 10px; font-size: 13px; }
.contrib-list { list-style: none; padding: 0; margin: 0; }
.contrib-list li { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed #e3e8ef; color: #475569; }
.muted { color: #94a3b8; font-size: 13px; }

/* ===== 社区 ===== */
.post-form label { display: block; font-size: 13px; margin: 10px 0 4px; color: #475569; }
.post-form input, .post-form textarea {
  width: 100%; padding: 8px; border: 1px solid #cbd5e1; border-radius: 8px; font-family: inherit;
}
.post-form button {
  margin-top: 10px; padding: 8px 16px; border: none; border-radius: 8px;
  background: #1565c0; color: #fff; cursor: pointer;
}
.post-list { list-style: none; padding: 0; margin: 14px 0 0; }
.post-item { background: #f8fafc; border: 1px solid #eef2f7; border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.post-meta { font-size: 12px; color: #94a3b8; margin-bottom: 4px; }
.post-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }

/* ===== 地图图标 ===== */
.sp-icon-wrap { background: transparent; border: none; }
.sp-icon {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid #555;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
/* 图例 */
.legend-box {
  background: #fff; padding: 10px 12px; border-radius: 8px; line-height: 1.7;
  box-shadow: 0 1px 5px rgba(0,0,0,.2); font-size: 12px; max-width: 230px;
}
.legend-toggle {
  display: flex; align-items: center; gap: 5px; width: 100%;
  border: none; background: transparent; padding: 0; cursor: pointer;
  font-size: 12px; font-weight: 700; color: #1f2a37; font-family: inherit;
}
.legend-arrow { display: inline-block; transition: transform .2s; color: #64748b; }
.legend-box.collapsed .legend-arrow { transform: rotate(-90deg); }
.legend-box.collapsed .legend-body { display: none; }
.legend-sec { font-weight: 700; margin-top: 6px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.lg-item { display: inline-flex; align-items: center; gap: 4px; }
.lg-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.lg-ring { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #555; display: inline-block; }

/* ===== 弹窗 ===== */
.popup { max-width: 260px; }
.popup-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.popup-emoji { font-size: 18px; }
.popup-name { font-weight: 700; font-size: 15px; }
.popup-tag { color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 10px; }
.popup-sci { font-style: italic; color: #64748b; margin: 4px 0; font-size: 13px; }
.popup-rep { font-size: 12px; color: #94a3b8; }
.popup-summary { font-size: 13px; margin: 6px 0; line-height: 1.5; }
.popup-links a { margin-right: 12px; font-size: 13px; }
.popup-src { font-size: 11px; color: #b0b8c4; margin-top: 4px; }

/* ===== 页脚 ===== */
.site-footer { text-align: center; color: #94a3b8; font-size: 12px; padding: 16px; }

/* ===== 移动端：底部 Tab 导航 + 侧栏抽屉 + 全屏地图 ===== */
.mobile-tabbar, .drawer-toggle { display: none; }

@media (max-width: 960px) {
  /* 顶部导航：隐藏原本的链接（改由底部 Tab 承载），仅留品牌 */
  .site-header { padding: 0 12px; height: 50px; }
  .site-nav { display: none; }
  .brand { font-size: 16px; }

  /* 布局：地图占满 header 以下整屏（dvh 适配 iOS 地址栏），侧栏作为底部抽屉浮层 */
  .layout { height: calc(100vh - 50px); height: calc(100dvh - 50px); }
  /* min-height 兜底：防止任何旧版/混搭 CSS 或 iOS flex 高度塌陷把地图算成 0（表现为整屏白） */
  .map { height: 100%; min-height: 320px; }

  /* 图例浮在地图上：限宽限高，默认已由 JS 折叠，展开时也不许遮满屏幕 */
  .legend-box { max-width: 72vw; max-height: 46vh; overflow: auto; }

  /* 关键：Leaflet 左下/右下控件（图例、attribution）默认贴地图容器底边，
     会被悬浮的底部 Tab 栏（56px）盖住——整体上移避开 */
  .leaflet-bottom { bottom: 64px; }

  .side {
    position: fixed; left: 0; right: 0; bottom: 56px; top: auto;
    max-height: 62vh; width: 100%;
    background: #fff; border-right: none; border-top: 1px solid #e3e8ef;
    border-radius: 16px 16px 0 0;
    transform: translateY(105%); transition: transform .3s ease; z-index: 1200;
    box-shadow: 0 -6px 24px rgba(0,0,0,.18);
    -webkit-overflow-scrolling: touch;
  }
  .side.open { transform: translateY(0); }

  /* 底部 Tab 导航 */
  .mobile-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0;
    height: 56px; background: #fff; border-top: 1px solid #e3e8ef;
    z-index: 1300; padding: env(safe-area-inset-bottom) 0 0;
  }
  .mobile-tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: #64748b; font-size: 11px; text-decoration: none;
  }
  .mobile-tabbar a span { line-height: 1; }
  .mobile-tabbar a.active { color: #1565c0; }
  .mobile-tabbar a.active span { font-weight: 700; }

  /* 抽屉开关 */
  .drawer-toggle {
    display: block; position: fixed; right: 12px; bottom: 68px; z-index: 1250;
    padding: 10px 14px; border: none; border-radius: 22px;
    background: #1565c0; color: #fff; font-size: 14px; box-shadow: 0 3px 10px rgba(0,0,0,.25);
    cursor: pointer;
  }

  /* 上传表单在抽屉中更易操作 */
  .upload-form button, .geo-bar button { padding: 12px; font-size: 16px; }
  .upload-form select, .upload-form input[type=text], .upload-form input[type=number],
  .upload-form textarea, .post-form input, .post-form textarea { font-size: 16px; padding: 10px; }

  /* PWA 安装提示条（移动端，悬于 Tab 栏与抽屉开关之上） */
  #install-bar {
    display: none; position: fixed; left: 8px; right: 8px; bottom: 112px; z-index: 1400;
    align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px;
    background: #2e8b57; color: #fff; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.28);
  }
  #install-bar.show { display: flex; }
  #install-bar .install-txt { flex: 1; }
  #install-bar .install-btn {
    background: #fff; color: #2e8b57; border: 0; border-radius: 14px;
    padding: 6px 14px; font-weight: 600; cursor: pointer; font-size: 14px;
  }
  #install-bar .install-x {
    background: transparent; color: #fff; border: 0; font-size: 20px; line-height: 1;
    cursor: pointer; padding: 0 4px;
  }
}

@media (max-width: 960px) {
  /* 仅首页卡片单列。注意：此处不再覆盖 .layout/.map/.side ——
     旧版里本块的 .layout{height:auto} 与 .map{height:70vh} 会覆盖上面的全屏布局，
     导致"地图只占半屏/下方大片空白"，已被移除。 */
  .cards { grid-template-columns: 1fr; }
}

/* ===== 定位与拍照（上传页） ===== */
.geo-bar { display: flex; align-items: center; gap: 10px; margin: 4px 0 6px; }
.geo-bar button {
  padding: 8px 12px; border: none; border-radius: 8px; background: #0d9488; color: #fff;
  font-size: 14px; cursor: pointer; flex: 1;
}
.geo-bar button:hover { background: #0f766e; }
/* 纠偏开关：琥珀色与定位按钮区分，flex:0.7 略窄 */
.geo-bar #btn-offset { background: #d97706; flex: 0.7; font-size: 13px; padding: 8px 8px; }
.geo-bar #btn-offset:hover { background: #b45309; }
.geo-bar .realtime {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px;
  color: #475569; white-space: nowrap;
}
#loc-status { margin: 0 0 8px; }
.photo-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.photo-thumb {
  position: relative; width: 72px; height: 72px; border-radius: 8px;
  overflow: hidden; border: 1px solid #e3e8ef;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-rm {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; line-height: 18px;
  border: none; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff;
  cursor: pointer; font-size: 13px;
}

/* ===== 图层开关（上传页） ===== */
.layer-bar { background: #f8fafc; border: 1px solid #eef2f7; border-radius: 8px; padding: 10px 12px; }
.layer-bar label {
  display: flex; align-items: center; gap: 6px; font-size: 13px;
  color: #475569; margin: 4px 0; cursor: pointer;
}
.layer-bar p { margin: 8px 0 0; }
.badge-count {
  display: inline-block; min-width: 20px; padding: 1px 7px; margin-left: 4px;
  background: #0d9488; color: #fff; border-radius: 10px;
  font-size: 12px; text-align: center; vertical-align: middle;
}

/* ===== 我的上传列表（可删除） ===== */
.contrib-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px dashed #e3e8ef;
}
.contrib-main { flex: 1; min-width: 0; cursor: pointer; }
.contrib-main:hover .contrib-title { color: #1565c0; }
.contrib-title { font-size: 14px; color: #1f2a37; font-weight: 600; }
.contrib-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; word-break: break-all; }
.tag-public, .tag-photo {
  display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px;
  background: #e8f0fe; color: #1565c0; font-weight: 400; margin-left: 4px;
}
.tag-photo { background: #fef3c7; color: #b45309; }
.contrib-del, .post-del {
  flex: none; padding: 5px 10px; border: 1px solid #fecaca; border-radius: 6px;
  background: #fff; color: #dc2626; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.contrib-del:hover, .post-del:hover { background: #dc2626; color: #fff; border-color: #dc2626; }

/* ===== 社区：我的发言标记与删除 ===== */
.post-mine-tag {
  display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px;
  background: #0d9488; color: #fff; margin-left: 4px;
}
.post-item { position: relative; }
.post-del { margin-top: 8px; }

/* ===== 弹窗内的删除按钮 ===== */
.popup-del-row { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #e3e8ef; }
.popup-del-btn {
  width: 100%; padding: 6px 10px; border: 1px solid #fecaca; border-radius: 6px;
  background: #fff; color: #dc2626; font-size: 13px; cursor: pointer;
}
.popup-del-btn:hover { background: #dc2626; color: #fff; border-color: #dc2626; }

/* 弹窗：照片 / 坐标 / 我上传标记 */
.popup-coord { font-size: 11px; color: #64748b; margin: 4px 0; }
.popup-photos { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.popup-photos img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 6px;
  cursor: pointer; border: 1px solid #e3e8ef;
}
.popup-mine { background: #0d9488 !important; }

/* 移动端增强：放大点按区域，避免误触 */
@media (max-width: 960px) {
  .upload-form button, .geo-bar button { padding: 12px; font-size: 16px; }
  .upload-form select, .upload-form input[type=text], .upload-form input[type=number],
  .upload-form textarea, .post-form input, .post-form textarea { font-size: 16px; padding: 10px; }
  .site-nav a { margin-left: 10px; padding: 8px; font-size: 14px; }
  .popup { max-width: 220px; }
}

/* ===== 运行模式提示（单机模式 / file:// 打开时显示） ===== */
.mode-tip {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 16px; background: #fffbeb;
  border-bottom: 1px solid #fde68a; color: #78350f;
  font-size: 13px; line-height: 1.65;
}
.mode-tip-icon { flex: none; }
.mode-tip-text { flex: 1; }
.mode-tip-text b { color: #b45309; }
.mode-tip code {
  background: #fef3c7; padding: 1px 5px; border-radius: 4px;
  font-family: Consolas, Menlo, monospace; font-size: 12px;
}
.mode-tip-close {
  flex: none; border: none; background: transparent; color: #a16207;
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.mode-tip-close:hover { color: #dc2626; }
