/* ============================================================
   羽见 · 观鸟地图 — 自定义样式
   仅用于 Tailwind 无法表达的动态/复合样式（地图标记、滚动条、
   分段控件状态、动画、腾讯地图信息窗口定制等）
   ============================================================ */

:root {
  --moss-600: #326e46;
  --moss-700: #2a583a;
  --ink: #1e293b;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 滚动条 ---------------- */
.custom-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.custom-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.custom-scroll::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}
.custom-scroll::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ---------------- 分段控件 ---------------- */
.seg-btn {
  height: 28px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #64748b;
  background: transparent;
  transition: all 0.18s ease;
}
.seg-btn:hover {
  color: #334155;
  background: rgba(255, 255, 255, 0.7);
}
.seg-btn.active {
  background: #ffffff;
  color: var(--moss-700);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
  font-weight: 600;
}

/* ---------------- 类群 / 稀有度胶囊 ---------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 27px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  transition: all 0.18s ease;
  cursor: pointer;
  user-select: none;
}
.chip:hover {
  border-color: #94a3b8;
  transform: translateY(-1px);
}
.chip.active {
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px -4px rgba(15, 23, 42, 0.35);
}
.chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
}

/* 物种标签 */
.stag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 11.5px;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #e2e8f0;
}
.stag button {
  color: #94a3b8;
  font-size: 12px;
  line-height: 1;
}
.stag button:hover {
  color: #e11d48;
}

/* ---------------- 线性图标 ---------------- */
.ico {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: -0.15em;
}
.stag .ico {
  color: var(--moss-600);
}
.stag button .ico {
  color: inherit;
  vertical-align: 0;
}
.map-tool .ico {
  pointer-events: none;
}

/* ---------------- 地图工具按钮 ---------------- */
.map-tool {
  width: 34px;
  height: 32px;
  border-radius: 8px;
  font-size: 15px;
  display: grid;
  place-items: center;
  color: #475569;
  transition: all 0.16s ease;
}
.map-tool:hover {
  background: #f1f5f9;
  color: #1e293b;
}
.map-tool.active {
  background: #e0efe3;
  color: var(--moss-700);
  box-shadow: inset 0 0 0 1px #96c6a1;
}

/* ---------------- 观测点标记 ---------------- */
.bird-pin {
  position: relative;
  border-radius: 999px;
  border: 1.5px solid #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
  transition: transform 0.15s ease;
  cursor: pointer;
}
.bird-pin::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.bird-pin:hover {
  transform: scale(1.45);
  z-index: 500;
}
.bird-pin.rare {
  border: 2px solid #f43f5e;
}
.bird-pin.selected {
  transform: scale(1.7);
  z-index: 600;
  box-shadow: 0 0 0 5px rgba(50, 110, 70, 0.25);
}
.bird-pin.pulse {
  animation: pinPulse 1.6s ease-out 2;
}
@keyframes pinPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(50, 110, 70, 0.55);
  }
  100% {
    box-shadow: 0 0 0 16px rgba(50, 110, 70, 0);
  }
}

/* 鸟点（地点本身）标记 */
.spot-pin {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: #fff;
  border: 1.5px solid #cbd5e1;
  display: grid;
  place-items: center;
  font-size: 12px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.18);
  cursor: pointer;
  transition: all 0.15s ease;
}
.spot-pin:hover {
  border-color: var(--moss-600);
  transform: scale(1.12);
}
.spot-pin.active {
  border-color: var(--moss-600);
  background: #e0efe3;
  box-shadow: 0 0 0 4px rgba(50, 110, 70, 0.18);
}

/* 选点十字准星 */
.origin-pin {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--moss-600);
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px rgba(50, 110, 70, 0.3), 0 4px 10px rgba(15, 23, 42, 0.3);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
}

/* ---------------- 腾讯地图容器与信息窗口 ---------------- */
#map {
  width: 100%;
  height: 100%;
  font-family: inherit;
  background: #e2e8f0;
  /* 关键：腾讯地图会在容器内插入 z-index:1000 的图层，
     若 #map 不形成独立层叠上下文，该图层会盖住 z-[900] 的自定义工具条，
     导致底图切换、热区、缩放等按钮点不到。这里隔离出来。 */
  position: absolute;
  z-index: 0;
  isolation: isolate;
}

/* 腾讯地图自带控件（指北针 + 缩放按钮）会吸附在右上角，
   与自定义工具条位置冲突。缩放与视角操作已由右侧工具条接管，
   这里直接隐藏自带控件，保证任何浏览器下都不再遮挡。 */
#map .rotate-circle,
#map .tmap-zoom-control,
#map .tmap-scale-control,
#map .tmap-pitch-control {
  display: none !important;
}

/* 兜底：部分版本控件外层容器会占用点击区域，一并收掉 */
#map div[contenteditable="false"]:has(> .rotate-circle):has(> .tmap-zoom-control),
#map div[contenteditable="false"]:has(> .tmap-zoom-control) {
  pointer-events: none !important;
}
.bird-info {
  width: 238px;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 28px -10px rgba(15, 23, 42, 0.45);
  line-height: 1.45;
}
#map .tmap-attribution,
#map .tmap-copyright {
  font-size: 9px !important;
  opacity: 0.7;
}
.pop-media {
  position: relative;
  height: 104px;
  background: linear-gradient(135deg, #e0efe3, #cbd5e1);
  overflow: hidden;
}
.pop-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pop-media .pop-emoji {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 40px;
  opacity: 0.85;
}
.pop-rare {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(244, 63, 94, 0.92);
  color: #fff;
  font-weight: 600;
}

/* 热区圆 */
.heat-ring {
  transition: all 0.25s ease;
}

/* ---------------- 记录卡片 ---------------- */
.rec-card {
  border: 1px solid #e9eef4;
  border-radius: 12px;
  padding: 9px 10px;
  background: #fff;
  transition: all 0.16s ease;
  cursor: pointer;
}
.rec-card:hover {
  border-color: #96c6a1;
  background: #f7fbf8;
  transform: translateX(-2px);
  box-shadow: 0 6px 16px -10px rgba(15, 23, 42, 0.4);
}
.rec-card.selected {
  border-color: var(--moss-600);
  background: #f2f8f3;
  box-shadow: 0 0 0 2px rgba(50, 110, 70, 0.14);
}

/* ---------------- 环形图 / 条形 ---------------- */
.donut {
  width: 58px;
  height: 58px;
  border-radius: 999px;
  position: relative;
  background: #eef2f7;
}
.donut::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 999px;
  background: #fff;
}
.donut-legend-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: #64748b;
  line-height: 1.2;
}
.mini-bar-track {
  height: 5px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
}
.mini-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

/* 图片加载失败时的回退 */
.img-fallback {
  display: grid !important;
  place-items: center;
}
.img-fallback::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1.5px solid #94a3b8;
  opacity: 0.65;
}

/* ---------------- 动画 ---------------- */
.pop-in {
  animation: popIn 0.24s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}
@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.fade-in {
  animation: fadeIn 0.3s ease both;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.slide-up {
  animation: slideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------------- 响应式：侧栏与记录栏 ---------------- */
@media (max-width: 767px) {
  #sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 330px);
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 12px 0 32px -12px rgba(15, 23, 42, 0.4);
  }
  #sidebar.open {
    transform: none;
  }
}

@media (max-width: 1279px) {
  #results-rail {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 344px;
    max-width: 88vw;
    transform: translateX(102%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: -12px 0 32px -12px rgba(15, 23, 42, 0.4);
  }
  #results-rail.open {
    transform: none;
  }
}

/* ---------------- 移动端体验优化 ---------------- */
@media (max-width: 767px) {
  /* 触控目标放大：分段控件与胶囊 */
  .seg-btn {
    height: 34px;
    font-size: 12.5px;
  }
  .chip {
    height: 31px;
    padding: 0 11px;
    font-size: 12.5px;
  }
  .map-tool {
    width: 36px;
    height: 34px;
  }
  /* 记录入口固定在底部居中，拇指可达，避免与右上角工具条抢位置 */
  #btn-toggle-results {
    position: fixed;
    left: 50%;
    bottom: calc(46px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    height: 40px;
    padding: 0 18px;
    border-radius: 999px;
    font-size: 12.5px;
    z-index: 950;
  }
  /* 移动端图例铺开在开关按钮上方 */
  #legend-card {
    right: 10px;
    bottom: calc(58px + env(safe-area-inset-bottom));
    max-width: 176px;
  }
  /* 记录列表在窄屏接近全宽，读起来不挤 */
  #results-rail.open {
    box-shadow: -12px 0 32px -12px rgba(15, 23, 42, 0.4);
  }
  #toast {
    bottom: calc(96px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 479px) {
  #results-rail {
    width: 100%;
    max-width: 100%;
  }
}

/* 地图浮层提示（腾讯地图信息窗口内文本） */
.bird-info .pop-media {
  height: 104px;
}
