/* ── tokens ── */
:root {
  --bg: #f4f6fa;
  --surface: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #475569;
  --success: #059669;
  --success-hover: #047857;
  --danger: #dc2626;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: #e8edf5;
}

body {
  margin: 0 auto;
  max-width: 430px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (min-width: 480px) {
  body {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 32px rgba(15, 23, 42, 0.1);
  }
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s, opacity 0.15s;
}
.btn:active { opacity: 0.88; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: #334155; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); text-decoration: none; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 0 10px;
}
.btn-ghost:hover { color: var(--text); background: #f1f5f9; text-decoration: none; }
.btn-help {
  width: 44px;
  height: 44px;
  padding: 0;
  background: #eef2f7;
  color: var(--muted);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.btn-help:hover { background: #e2e8f0; color: var(--text); }

/* ── auth pages ── */
.page-auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.card {
  width: min(380px, 100%);
  padding: 28px 24px 24px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.card-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.form label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.form label:first-of-type { margin-top: 0; }

.form input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 16px;
  background: #fff;
  touch-action: manipulation;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form .btn-primary {
  width: 100%;
  height: 48px;
  min-height: 48px;
  margin-top: 20px;
  font-size: 16px;
}

.msg {
  margin-top: 12px;
  min-height: 20px;
  font-size: 14px;
  color: var(--danger);
}

.card-foot {
  margin-top: 18px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

/* ── map page (mobile-first) ── */
html {
  height: 100%;
  height: -webkit-fill-available;
}

body.page-map {
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  min-height: 100vh;
  overflow: hidden;
  max-width: 100%;
  margin: 0;
}

.page-map {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  margin: 0;
  height: 100%;
  min-height: 0;
  background: var(--bg);
}

@media (min-width: 480px) {
  .page-map {
    max-width: 430px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 32px rgba(15, 23, 42, 0.1);
  }
}

.map-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  flex: 1;
  height: 100%;
  min-height: 0;
  padding-top: env(safe-area-inset-top, 0);
}

@supports not (height: 100dvh) {
  .map-shell {
    height: 100vh;
  }
}

.map-header {
  flex-shrink: 0;
  z-index: 1100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 12px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.map-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.user-chip {
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip strong {
  color: var(--text);
  font-weight: 600;
}

.map-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  color: var(--muted);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-icon:active { opacity: 0.85; background: #e2e8f0; }

.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--muted);
  pointer-events: none;
  line-height: 1;
}

#searchInput {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 38px;
  border: 1px solid var(--border);
  border-radius: 22px;
  font: inherit;
  font-size: 16px;
  background: #f8fafc;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}
#searchInput:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: min(50vh, 280px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1200;
}

.search-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  background: transparent;
  text-align: left;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.search-item:last-child { border-bottom: 0; }
.search-item:active { background: #f8fafc; }

.search-item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.search-item-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.map-wrap {
  position: relative;
  min-height: 0;
  /* 部分旧 WebView 算不出 grid 1fr 高度，用视口减去头尾兜底 */
  min-height: 180px;
  min-height: calc(100vh - 260px);
  min-height: calc(100dvh - 260px);
  overflow: hidden;
}

#map {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

.leaflet-container {
  width: 100% !important;
  height: 100% !important;
  font: inherit;
  touch-action: none;
  background: #dde3ed;
}

.leaflet-pane,
.leaflet-tile-pane {
  z-index: 1;
}

/* 选点标记（CSS 圆点，不依赖 leaflet/images/*.png） */
.wloc-pin {
  background: transparent !important;
  border: none !important;
}
.wloc-pin-dot {
  width: 22px;
  height: 22px;
  background: var(--primary);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.35);
  box-sizing: border-box;
}

.leaflet-control-zoom {
  border: 0 !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12) !important;
  margin-bottom: calc(8px + env(safe-area-inset-bottom, 0)) !important;
  margin-right: 8px !important;
}

.leaflet-control-zoom a {
  min-width: 40px;
  min-height: 40px;
  line-height: 40px;
  touch-action: manipulation;
  font-size: 18px;
}

.layers {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 1000;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border);
}

.layer-btn {
  min-height: 36px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.layer-btn:active { background: #f1f5f9; color: var(--text); }
.layer-btn.active { background: var(--primary); color: #fff; }

.map-footer {
  flex-shrink: 0;
  z-index: 1100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
}

.coord-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}

.coord-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.coord-field span { padding-left: 2px; }

.coord-field input {
  width: 100%;
  height: 40px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  background: #f8fafc;
}
.coord-field input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.status {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: #eef2ff;
  font-size: 12px;
  color: #3730a3;
  line-height: 1.4;
  word-break: break-all;
}
.status.status-ok {
  background: #ecfdf5;
  color: #047857;
}
.status.status-err {
  background: #fef2f2;
  color: #b91c1c;
}

.map-footer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: 8px;
  align-items: stretch;
}

.btn-compact {
  min-height: 48px;
  height: 48px;
  padding: 0 8px;
  font-size: 14px;
}

.btn-save {
  min-height: 48px;
  height: 48px;
  font-size: 16px;
  font-weight: 700;
}

/* legacy topbar (unused on map) — keep for reference */
.topbar {
  display: none;
}

.toolbar { display: none; }

.input-num {
  width: 72px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  text-align: center;
}
.input-num:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ── help modal ── */
.help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.4);
  padding: 24px 16px;
  overflow: auto;
}
.help-overlay.open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-panel {
  width: min(360px, 100%);
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.help-head h2 { margin: 0; font-size: 17px; font-weight: 700; }

.help-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.help-close:hover { background: #f1f5f9; color: var(--text); }

.help-body {
  padding: 18px 18px 22px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}
.help-body ol {
  margin: 0;
  padding-left: 1.3em;
}
.help-body li { margin-bottom: 10px; }
.help-body li:last-child { margin-bottom: 0; }
.help-code {
  display: block;
  margin-top: 8px;
  padding: 8px 10px;
  background: #f1f5f9;
  border-radius: 6px;
  font-size: 12px;
  word-break: break-all;
  color: #1d4ed8;
}

@media (max-width: 360px) {
  .map-footer-actions {
    grid-template-columns: 1fr 1fr;
  }
  .btn-save {
    grid-column: 1 / -1;
  }
}
