/* ================= 晓庄校园导航 样式 ================= */
:root {
  --primary: #0f766e;
  --primary-dark: #0b5d57;
  --accent: #e65100;
  --warn: #b45309;
  --bg: #f4f7f6;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(15, 60, 50, 0.14);
  --topbar-h: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
}

#map {
  position: absolute;
  inset: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)) 0 0 0;
  z-index: 0;
  background: #e8efec;
}

/* ---------------- 顶栏 ---------------- */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px; padding-right: 10px;
  background: linear-gradient(135deg, var(--primary), #115e59 60%, #0b6ea8);
  color: #fff;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0,0,0,.22);
}
#topbar .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex: none;
}
#topbar .tt {
  font-size: 15px; font-weight: 700; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
#topbar .tt small { display: block; font-weight: 400; font-size: 10.5px; opacity: .85; }
#topbar button {
  border: none; background: rgba(255,255,255,.16); color: #fff;
  border-radius: 9px; padding: 7px 9px; font-size: 12px;
  cursor: pointer; flex: none; white-space: nowrap;
}
#topbar button.on { background: #ffd54f; color: #4a3b00; font-weight: 700; }
#gps-chip {
  font-size: 10.5px; padding: 4px 7px; border-radius: 20px;
  background: rgba(0,0,0,.32); color: #fff; flex: none;
}
#gps-chip.on { background: #22c55e; }

/* ---------------- 安全提示 ---------------- */
#secure-warn {
  position: absolute;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 6px);
  left: 8px; right: 8px;
  z-index: 900;
  display: none;
  align-items: center; gap: 8px;
  background: #fffbeb; color: #92400e;
  border: 1px solid #fcd34d;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: var(--shadow);
}

/* ---------------- 楼栋标记 ---------------- */
.bmark-wrap { background: transparent; border: none; }
.bmark {
  width: 40px; height: 40px; margin: 0 auto;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--c, #757575);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
  border: 2px solid #fff;
}
.bmark .bmark-ic { transform: rotate(45deg); font-size: 19px; line-height: 1; }
.bmark.custom { border-radius: 50%; transform: none; background: #1e8e3e; }
.bmark.startmark { border-radius: 50%; transform: none; background: #c62828; }
.bmark-lbl {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 38px; white-space: nowrap;
  background: rgba(255,255,255,.92);
  color: #111; font-size: 10.5px; font-weight: 600;
  padding: 1px 5px; border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  pointer-events: none;
}
.bmark-est {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 55px; white-space: nowrap;
  background: #f59e0b; color: #fff; font-size: 8.5px; font-weight: 700;
  padding: 0 4px; border-radius: 4px; pointer-events: none;
}
/* iPhone 自带地图同款"我的位置"蓝点 */
.user-dot {
  width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #57abff, #1482ff 52%, #0061e6);
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.30),
              0 0 14px rgba(0, 122, 255, 0.55),
              0 3px 8px rgba(10, 40, 120, 0.35);
  display: flex; align-items: center; justify-content: center;
}
.user-arrow { line-height: 0; display: flex; transition: transform .4s ease, opacity .3s ease; }
.user-arrow.hidden { opacity: 0; }

/* 弹窗 */
.bpop { min-width: 200px; font-size: 13px; }
.bpop-title { font-weight: 700; font-size: 14.5px; margin-bottom: 4px; }
.bpop .est-tag { font-size: 9px; background: #f59e0b; color: #fff; border-radius: 4px; padding: 1px 4px; vertical-align: 2px; }
.bpop-desc { color: var(--muted); margin-bottom: 8px; line-height: 1.45; }
.bpop-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.bpop-btns button {
  border: none; border-radius: 8px; padding: 6px 10px; font-size: 12px;
  background: var(--primary); color: #fff; cursor: pointer;
}
.bpop-btns button:nth-child(2) { background: var(--accent); }
body.edit .bpop-btns button:nth-child(n+3) { background: #37474f; }

/* ---------------- 底部操作卡片 ---------------- */
#sheet {
  position: absolute;
  left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 1001;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: 62vh;
  display: flex; flex-direction: column;
}
#sheet.sheet-collapsed { }
#sheet.nav-active { opacity: 0; pointer-events: none; }
#sheet-head {
  padding: 10px 12px; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  background: #fafcfb; border-bottom: 1px solid var(--line);
}
#sheet-head .t { font-weight: 700; font-size: 13.5px; color: var(--primary-dark); flex: 1; }
#sheet-head .hint { font-size: 10.5px; color: var(--muted); }
#sheet-body { padding: 10px 12px 12px; overflow-y: auto; }

.mode-row { display: flex; gap: 8px; margin-bottom: 10px; }
.mode-row button {
  flex: 1; padding: 9px 6px; border-radius: 10px; border: 1.5px solid var(--line);
  background: #fff; color: var(--muted); font-size: 13px; cursor: pointer;
}
.mode-row button.on {
  border-color: var(--primary); background: #e6f4f1; color: var(--primary-dark); font-weight: 700;
}

.field { margin-bottom: 8px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.field select {
  width: 100%; padding: 10px 8px; border-radius: 10px;
  border: 1.5px solid var(--line); background: #fff; font-size: 14px; color: var(--text);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='2' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
.field input[type=text] {
  width: 100%; padding: 10px 8px; border-radius: 10px;
  border: 1.5px solid var(--line); font-size: 14px;
}
#start-wrap.gps select { display: none; }
#start-gps-text { font-size: 13px; color: var(--primary-dark); background: #eef7f5; padding: 9px; border-radius: 10px; display: none; }
#start-wrap.gps #start-gps-text { display: block; }

#end-hint { font-size: 11.5px; color: var(--muted); margin: 4px 2px 8px; }

.row2 { display: flex; gap: 8px; align-items: flex-end; }
.row2 .field { flex: 1; margin-bottom: 0; }
.row2 .field:last-child { flex: none; }

#btn-go {
  width: 100%; margin-top: 10px;
  border: none; border-radius: 12px; padding: 13px;
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff; font-size: 15.5px; font-weight: 800;
  cursor: pointer; box-shadow: 0 4px 14px rgba(22,163,74,.35);
}
#btn-go:active { transform: scale(.98); }

/* ---------------- 导航指示条 ---------------- */
#navbar {
  position: absolute;
  left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 1002;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: none;
}
#navbar.show { display: block; }
#nav-top { display: flex; align-items: center; gap: 12px; }
#nav-arrow {
  flex: none; width: 52px; height: 52px; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #0b6ea8);
  color: #fff; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
}
#nav-instr {
  flex: 1; font-size: 15px; font-weight: 700; line-height: 1.35; min-width: 0;
}
#nav-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
#nav-progress-wrap { height: 6px; background: var(--line); border-radius: 4px; margin-top: 10px; overflow: hidden; }
#nav-progress { height: 100%; width: 0; background: linear-gradient(90deg, #16a34a, #84cc16); border-radius: 4px; transition: width .6s ease; }
#nav-btns { display: flex; gap: 8px; margin-top: 10px; }
#nav-btns button {
  flex: 1; border: none; border-radius: 10px; padding: 10px;
  font-size: 13.5px; font-weight: 700; cursor: pointer;
}
#btn-recalc { background: #fff7ed; color: #c2410c; border: 1.5px solid #fed7aa; }
#btn-stop { background: #fef2f2; color: #b91c1c; border: 1.5px solid #fecaca; }

/* ---------------- 编辑工具栏 ---------------- */
#editbar {
  position: absolute;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 6px);
  left: 8px; right: 8px;
  z-index: 902;
  display: none;
  align-items: center; gap: 6px;
  background: #fef2f2; color: #7f1d1d;
  border: 1px solid #fecaca; border-radius: 10px;
  padding: 7px 8px; font-size: 11.5px;
  box-shadow: var(--shadow);
}
#editbar.show { display: flex; flex-wrap: wrap; }
#editbar span { flex: 1; min-width: 120px; }
#editbar button {
  border: none; border-radius: 8px; padding: 6px 9px; font-size: 11.5px; font-weight: 700; cursor: pointer;
}
#btn-save-center { background: #e0f2fe; color: #075985; }
#btn-export { background: #16a34a; color: #fff; }
#btn-exit-edit { background: #37474f; color: #fff; }

/* ---------------- 遮罩层 ---------------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(17, 25, 22, .5);
  z-index: 2000;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.overlay.show { display: flex; }
.overlay .card {
  background: #fff; border-radius: 16px; max-width: 420px; width: 100%;
  padding: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.35);
  max-height: 82vh; overflow-y: auto;
}
.overlay .card h3 { font-size: 16px; margin-bottom: 10px; color: var(--primary-dark); }
.overlay .card p, .overlay .card li { font-size: 13px; line-height: 1.6; color: #374151; }
.overlay .card ol { padding-left: 18px; margin: 6px 0; }
.overlay .card .qr-box { text-align: center; margin: 12px 0; }
.overlay .card img.qr { width: 190px; height: 190px; border-radius: 10px; border: 1px solid var(--line); }
.overlay .card .url-row { display: flex; gap: 6px; }
.overlay .card .url-row input {
  flex: 1; padding: 9px; font-size: 12px; border: 1.5px solid var(--line); border-radius: 9px;
}
.overlay .card button.primary {
  border: none; background: var(--primary); color: #fff; font-weight: 700;
  padding: 9px 14px; border-radius: 9px; cursor: pointer; font-size: 13px;
}
.overlay .card .close-btn {
  margin-top: 12px; width: 100%; padding: 10px; border: 1.5px solid var(--line);
  background: #fff; border-radius: 10px; cursor: pointer; font-size: 13px; color: var(--muted);
}
.note {
  background: #fefce8; border: 1px solid #fde68a; color: #854d0e;
  border-radius: 10px; padding: 8px 10px; font-size: 12px; line-height: 1.5; margin: 8px 0;
}

/* ---------------- Toast ---------------- */
#toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%) translateY(16px);
  background: rgba(23, 32, 28, .94); color: #fff;
  font-size: 13px; line-height: 1.45;
  padding: 10px 16px; border-radius: 12px;
  max-width: 86vw; text-align: center;
  z-index: 3000;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Leaflet 细节 ---------------- */
.leaflet-control-zoom a { border-radius: 6px !important; }
.leaflet-popup-content-wrapper { border-radius: 12px !important; }
.leaflet-popup-content { margin: 12px 14px !important; }

/* 编辑模式下拖拽提示 */
body.edit .bmark { cursor: grab; }
body.edit .bmark:active { cursor: grabbing; }

@media (min-width: 720px) {
  #sheet, #navbar { max-width: 460px; margin: 0 auto; }
}