:root {
  --accent: #2f7cf6;
  --accent-dark: #1f5fd0;
  --danger: #ff3b30;
  --green: #1faa59;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e2e6ec;
  --text: #1c2333;
  --muted: #8a94a6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 360px;
  min-width: 360px;
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

.sidebar-head {
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-head h1 {
  font-size: 17px;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-head .badge {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.sidebar-body {
  flex: 1;
  min-height: 0;             /* 关键：允许在 flex 容器内收缩并滚动 */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

.section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
  flex-shrink: 0;
}
.section-title {
  font-size: 14px;
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
}
.section-body { padding: 12px; }

/* ---------- 按钮 ---------- */
button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  transition: background .12s, border-color .12s, transform .05s;
}
button:hover { background: #f0f4fb; }
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-block { display: block; width: 100%; }

.btn-icon {
  padding: 6px 9px;
  font-size: 14px;
  line-height: 1;
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
.form-add {
  display: none;
}
.form-add.open { display: block; }

.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input[type="text"], .field input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); }

.coord-row { display: flex; gap: 8px; }
.coord-row .field { flex: 1; }

.photos-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  margin-top: 6px;
}
.photos-preview:empty::after {
  content: "（暂无照片，可点下方按钮上传）";
  color: var(--muted);
  font-size: 12px;
}
.photo-thumb-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.photo-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-del:hover { background: rgba(255,59,48,.9); }

/* ---------- 点位列表 ---------- */
.point-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: #fff;
}
.point-thumb-wrap {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: #eef2f8;
  display: flex;
  align-items: center;
  justify-content: center;
}
.point-thumb-ph {
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
}
.point-thumb { width: 100%; height: 100%; object-fit: cover; }
.point-main { flex: 1; min-width: 0; }
.point-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.point-coord { font-size: 11px; color: var(--muted); }
.point-btns { display: flex; gap: 4px; }
.point-btns button { padding: 6px 9px; font-size: 15px; min-width: 34px; min-height: 34px; }

/* ---------- 路线 ---------- */
.route-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
}
.route-order {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.route-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-btns { display: flex; gap: 4px; }
.route-btns button { padding: 5px 9px; font-size: 15px; line-height: 1.2; min-width: 34px; min-height: 34px; }

/* ---------- 结果 ---------- */
.result-head { font-weight: 700; font-size: 13px; margin-bottom: 8px; color: var(--accent-dark); }
.result-leg {
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
}
.leg-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ff9500;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.leg-body { flex: 1; min-width: 0; }
.leg-title { font-size: 13px; font-weight: 600; }
.leg-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.leg-meta b { color: var(--text); }
.result-total {
  margin-top: 8px;
  padding: 10px;
  background: #eef7f1;
  border: 1px solid #cdebd9;
  border-radius: 8px;
  font-size: 14px;
}

.saved-route {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
}
.saved-name { flex: 1; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-count { font-size: 11px; color: var(--muted); white-space: nowrap; }
.saved-btns { display: flex; gap: 4px; }
.saved-btns button { padding: 7px 10px; font-size: 13px; }

.muted { color: var(--muted); font-size: 12px; }

/* ---------- 地图 ---------- */
.map-wrap { flex: 1; position: relative; height: 100%; z-index: 1; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; }

.map-wrap.picking #map { cursor: crosshair; }

/* 底图切换按钮 */
.base-switch {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 800;
  display: flex;
  gap: 6px;
}
.base-switch button {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.base-switch button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pick-hint {
  display: none;
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.leaflet-error {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 1001;
  background: #fff;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  color: var(--danger);
  font-size: 14px;
}
.leaflet-error.show { display: flex; }

/* 点位标记 */
.pt-marker { background: transparent; border: none; }
.pt-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 2px;
}

/* 路线中点标签 */
.leg-label { background: transparent; border: none; }
.leg-label-inner {
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,.92);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

/* 弹窗 */
.popup { max-width: 260px; }
.popup-title { font-weight: 700; font-size: 14px; }
.popup-desc { font-size: 12px; color: #555; margin-top: 3px; }
.popup-coord { font-size: 11px; color: var(--muted); margin-top: 3px; }
.popup-photos { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.popup-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  cursor: zoom-in;
  border: 1px solid var(--border);
}
.popup-actions { display: flex; gap: 6px; }
.popup-actions button { padding: 8px 12px; font-size: 14px; }
.popup-view-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  font-size: 13px;
  background: #eef6ff;
  border: 1px solid #cfe4ff;
  color: var(--accent-dark);
  border-radius: 8px;
}

/* ---------- 灯箱 ---------- */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0,0,0,.85);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 4px 30px rgba(0,0,0,.5);
}
.lightbox-close {
  position: absolute;
  top: 18px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.35);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  display: none;
  padding: 0;
  z-index: 3001;
}
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }
.lightbox-count {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 14px;
  background: rgba(0,0,0,.45);
  padding: 4px 12px;
  border-radius: 14px;
  z-index: 3001;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1c2333;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  max-width: 80vw;
  z-index: 4000;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-err { background: var(--danger); }

/* ---------- 侧边栏切换按钮（移动端） ---------- */
.btn-sidebar {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

/* ---------- 导航模式 ---------- */
.fab-nav {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 26px;
  padding: 13px 26px;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0,0,0,.32);
}
/* 顶部指示卡（高德风格） */
.nav-top {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px; right: 12px;
  z-index: 80;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  padding: 14px 16px;
  align-items: center;
  gap: 14px;
}
.nav-top.open { display: flex; }
.nav-top-arrow {
  width: 58px; height: 58px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #eef6ff;
  border-radius: 14px;
}
.nav-arrow-glyph {
  font-size: 38px;
  color: var(--accent);
  line-height: 1;
  display: inline-block;
  transition: transform .15s linear;
}
.nav-top-body { flex: 1; min-width: 0; }
.nav-top-action { font-size: 24px; font-weight: 800; line-height: 1.1; }
.nav-top-sub { font-size: 13px; color: #666; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-arrive {
  margin-top: 8px;
  width: 100%;
  padding: 9px 12px;
  font-size: 15px;
  font-weight: 700;
  background: #1faa59;
  color: #fff;
  border: none;
  border-radius: 10px;
}
.nav-arrive:active { background: #178a48; }
.nav-close {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #f2f4f7;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: #555;
  padding: 0;
}

/* 底部控制条 */
.nav-bottom {
  display: none;
  position: fixed;
  left: 12px; right: 12px; bottom: 16px;
  z-index: 80;
  background: rgba(255,255,255,.96);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  padding: 8px 12px;
  align-items: center;
  gap: 8px;
}
.nav-bottom.open { display: flex; }
.nav-bottom button { padding: 9px 14px; font-size: 14px; border-radius: 10px; }
.nav-bottom button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.nav-diag { flex: 1; font-size: 11px; color: var(--muted); text-align: right; }

/* 我的位置：蓝点 + 朝向指针 */
.me-marker { background: transparent; border: none; }
.me-wrap { position: relative; width: 40px; height: 40px; }
.me-heading {
  position: absolute;
  left: 50%; top: 50%;
  width: 44px; height: 44px;
  margin: -22px 0 0 -22px;
  transform-origin: center;
  background: linear-gradient(to bottom, rgba(26,115,232,.42), rgba(26,115,232,.05));
  clip-path: polygon(50% 0%, 70% 50%, 50% 50%, 30% 50%);
}
.me-dot {
  position: absolute;
  left: 50%; top: 50%;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: #1a73e8;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(26,115,232,.4), 0 2px 6px rgba(0,0,0,.4);
}

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .sidebar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    height: auto;            /* 由 top/bottom 撑满视口，避免 100% 解析问题 */
    width: 360px;
    max-width: 88vw;
    min-width: 0;
    transform: translateX(-100%);
    transition: transform .25s;
    box-shadow: 2px 0 12px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .btn-sidebar { display: block; }
  .sidebar-head { padding-left: 60px; }
}
