:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e5e7eb;
  --line-soft: #f0f1f3;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --brand: #2b6cff;
  --brand-soft: #eaf1ff;
  --new: #2b6cff;
  --contacted: #f59e0b;
  --intent: #ef4444;
  --deal: #16a34a;
  --invalid: #94a3b8;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(15, 23, 42, .08);
  --shadow-lg: 0 8px 32px rgba(15, 23, 42, .14);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 13px; transition: .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #c9cdd4; background: #fafbfc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1f5ae6; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--line-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.danger { color: #dc2626; border-color: #fecaca; background: #fef2f2; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, select.input {
  height: 34px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; outline: none; transition: .15s; width: 100%;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(43, 108, 255, .1); }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.6; }

.tag {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px;
  border-radius: 4px; font-size: 11px; background: var(--line-soft); color: var(--text-2);
  white-space: nowrap;
}
.tag.blue { background: var(--brand-soft); color: var(--brand); }
.tag.green { background: #e8f8ee; color: var(--deal); }
.tag.red { background: #fee9e9; color: var(--intent); }
.tag.orange { background: #fff3e0; color: #d97706; }
.tag.gray { background: #f1f3f5; color: var(--text-3); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.new { background: var(--new); }
.dot.contacted { background: var(--contacted); }
.dot.intent { background: var(--intent); }
.dot.deal { background: var(--deal); }
.dot.invalid { background: var(--invalid); }

.muted { color: var(--text-3); }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.hide { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 56px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 16px; flex: none; z-index: 30;
}
.logo { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo .mark {
  width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, #2b6cff, #5b8cff);
  color: #fff; display: grid; place-items: center; font-size: 14px;
}
.search-wrap { position: relative; flex: 1; max-width: 460px; }
.search-wrap .input { padding-left: 34px; height: 36px; }
.search-wrap svg { position: absolute; left: 10px; top: 9px; opacity: .45; }

/* ---------- 布局 ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.main { flex: 1; display: flex; min-height: 0; }
.side {
  width: 372px; flex: none; background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { width: 100%; height: 100%; }

/* ---------- 列表 ---------- */
.side-head {
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 8px; flex: none;
}
.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.card {
  padding: 12px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; transition: .12s;
}
.card:hover { background: #fafbfc; }
.card.active { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
.card .name { font-weight: 600; font-size: 14px; line-height: 1.4; margin-bottom: 5px; display: flex; gap: 6px; align-items: flex-start; }
.card .name span { flex: 1; }
.card .meta { color: var(--text-2); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .addr { color: var(--text-3); font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .tags { margin-top: 7px; display: flex; gap: 5px; flex-wrap: wrap; }

.empty { padding: 60px 20px; text-align: center; color: var(--text-3); font-size: 13px; }
.loading { padding: 24px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ---------- 地图浮层 ---------- */
.map-tools {
  position: absolute; right: 14px; top: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 10;
}
.map-tools .btn { background: #fff; box-shadow: var(--shadow); height: 36px; }
.addr-bar {
  position: absolute; left: 14px; top: 14px; z-index: 10;
  background: #fff; border-radius: 999px; box-shadow: var(--shadow);
  padding: 4px 5px; display: flex; gap: 4px; align-items: center;
  max-width: 320px;
}
.addr-bar input {
  border: 0; background: transparent; height: 32px; min-width: 160px; width: 220px;
  font-size: 13px; padding: 0 10px; outline: none;
}
.addr-bar .btn { height: 32px; border-radius: 999px; }
.map-hint {
  position: absolute; left: 50%; transform: translateX(-50%); top: 14px; z-index: 10;
  background: rgba(31, 35, 41, .86); color: #fff; padding: 7px 14px; border-radius: 999px;
  font-size: 12px; box-shadow: var(--shadow); backdrop-filter: blur(4px);
}
.radius-bar {
  position: absolute; left: 14px; bottom: 22px; z-index: 10; background: #fff;
  border-radius: 999px; box-shadow: var(--shadow); padding: 4px; display: flex; gap: 2px;
}
.radius-bar button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 999px;
  font-size: 12px; color: var(--text-2);
}
.radius-bar button.on { background: var(--brand); color: #fff; }

.legend {
  position: absolute; right: 14px; bottom: 22px; z-index: 10; background: #fff;
  border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px;
  display: flex; flex-direction: column; gap: 5px;
}
.legend .row { gap: 6px; color: var(--text-2); }

/* ---------- 详情抽屉 ---------- */
.drawer {
  position: absolute; right: 0; top: 0; bottom: 0; width: 400px; background: #fff;
  box-shadow: var(--shadow-lg); z-index: 40; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s cubic-bezier(.4, 0, .2, 1);
}
.drawer.open { transform: none; }
.drawer-head { padding: 16px; border-bottom: 1px solid var(--line-soft); flex: none; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer-foot { padding: 12px 16px; border-top: 1px solid var(--line-soft); flex: none; display: flex; gap: 8px; }

.kv { display: grid; grid-template-columns: 84px 1fr; gap: 8px 10px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-all; }

.sec-title {
  font-size: 12px; color: var(--text-3); margin: 18px 0 8px; display: flex; align-items: center; gap: 8px;
}
.sec-title::after { content: ''; flex: 1; height: 1px; background: var(--line-soft); }

.status-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.status-picker button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px;
  font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 5px;
}
.status-picker button.on { border-color: currentColor; font-weight: 500; }
.status-picker button.on.new { color: var(--new); background: #eef4ff; }
.status-picker button.on.contacted { color: #d97706; background: #fff8ec; }
.status-picker button.on.intent { color: var(--intent); background: #fef2f2; }
.status-picker button.on.deal { color: var(--deal); background: #f0fdf4; }
.status-picker button.on.invalid { color: var(--invalid); background: #f8fafc; }

.phone-chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; margin: 0 6px 6px 0; background: #fff;
}
.phone-chip a { font-variant-numeric: tabular-nums; }

/* ---------- 筛选面板 ---------- */
.filter-pop {
  position: absolute; top: 56px; right: 16px; width: 380px; background: #fff; z-index: 50;
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 16px;
}
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-3); margin-bottom: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 10px;
  font-size: 12px; color: var(--text-2);
}
.chips button.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  background: rgba(31, 35, 41, .92); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 999; opacity: 0; transition: .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.banner {
  background: #fff8ec; border: 1px solid #fde4b8; color: #92610a; padding: 10px 14px;
  border-radius: 8px; font-size: 13px; margin-bottom: 12px; line-height: 1.7;
}
.banner.blue { background: var(--brand-soft); border-color: #c7dbff; color: #1b4bb8; }
.banner.red { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

/* ---------- 后台 ---------- */
.admin { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs button {
  border: 0; background: transparent; padding: 10px 16px; font-size: 14px; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 4px; font-size: 15px; }
.panel .sub { color: var(--text-3); font-size: 12px; margin-bottom: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px;
}
.stat .n { font-size: 26px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--text-3); font-size: 12px; margin-top: 4px; }

.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 34px; text-align: center;
  color: var(--text-3); transition: .15s; background: #fafbfc;
}
.drop.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; padding: 9px 10px; background: #fafbfc; border-bottom: 1px solid var(--line);
  color: var(--text-2); font-weight: 500; white-space: nowrap; position: sticky; top: 0;
}
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); }
table.grid tr:hover td { background: #fafbfc; }
.scroll-x { overflow: auto; max-height: 460px; border: 1px solid var(--line); border-radius: 8px; }

.progress { height: 8px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, #2b6cff, #5b8cff); transition: width .3s; }

.log {
  background: #0f172a; color: #cbd5e1; border-radius: 8px; padding: 12px; font-size: 12px;
  font-family: Consolas, Monaco, monospace; height: 190px; overflow-y: auto; line-height: 1.7;
}
.log .ok { color: #4ade80; }
.log .err { color: #f87171; }
.log .warn { color: #fbbf24; }

.src-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 10px; }
.src-card h4 { margin: 0 0 4px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.src-card p { margin: 4px 0; color: var(--text-2); font-size: 13px; line-height: 1.7; }

/* ---------- v2 移动端布局 ---------- */
.app.v2 {
  display: flex; flex-direction: column; height: 100vh;
}
.top-search {
  flex: none; display: flex; gap: 8px; align-items: center;
  padding: 10px 12px; background: #fff; border-bottom: 1px solid var(--line);
}
.top-search .search-wrap { flex: 1; max-width: none; }
.top-search .search-wrap .input { height: 38px; padding-left: 34px; }
.top-search .btn { height: 38px; }

.map-section {
  flex: 1; position: relative; min-height: 0;
}
.map-section #map { width: 100%; height: 100%; }

.addr-float {
  position: absolute; left: 12px; top: 12px; right: 70px; z-index: 10;
  display: flex; gap: 6px; align-items: center;
  background: #fff; border-radius: 999px; padding: 4px 5px; box-shadow: var(--shadow);
}
.addr-float .input { border: 0; background: transparent; height: 34px; flex: 1; min-width: 0; padding: 0 10px; }
.addr-float .btn { height: 34px; border-radius: 999px; }

.locate-btn {
  position: absolute; right: 12px; top: 12px; z-index: 10;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: #fff; box-shadow: var(--shadow); font-size: 12px; color: var(--text-2);
}

.bottom-sheet {
  flex: none; height: 38vh; min-height: 220px; max-height: 50vh;
  background: #fff; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
  margin-top: -10px; position: relative; z-index: 20;
  display: flex; flex-direction: column;
}
.bs-header {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--line-soft);
}
.tab-bar { display: flex; gap: 4px; flex: 1; }
.tab-bar button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 999px;
  font-size: 13px; color: var(--text-2); white-space: nowrap;
}
.tab-bar button.on { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.bs-body { flex: 1; overflow-y: auto; padding: 10px 12px; min-height: 0; }
.bs-count { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }

.drawer-foot { gap: 8px; }
#btnFav.on { background: #fef2f2; border-color: #fecaca; color: #dc2626; }

/* 弹窗 */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
.modal.hide { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-body {
  position: relative; background: #fff; width: 100%; max-width: 420px;
  border-radius: 16px 16px 0 0; padding: 16px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-content .input { width: 100%; }

/* ---------- 移动端 ---------- */
@media (max-width: 820px) {
  .main { flex-direction: column-reverse; }
  .side { width: 100%; height: 44%; border-right: 0; border-top: 1px solid var(--line); }
  .map-wrap { height: 56%; }
  .drawer { width: 100%; }
  .filter-pop { width: calc(100% - 24px); right: 12px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .logo span { display: none; }
  .legend { display: none; }
  .addr-bar { left: 10px; top: 10px; max-width: calc(100% - 120px); }
  .addr-bar input { width: auto; flex: 1; min-width: 110px; }
  .map-tools { right: 10px; top: 10px; }
  .app.v2 .drawer { width: 100%; }
}

/* ---------- Key 配置卡片 ---------- */
.key-card { border-color: #c7dbff; background: linear-gradient(180deg, #fff 0%, #f8fbff 100%); }
.key-card .key-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.key-card .key-head h3 { margin: 0; }
.key-badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; background: #f1f3f5; color: var(--text-2);
}
.key-badge.on { background: #e8f8ee; color: #15803d; }
.key-badge.on::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #22c55e; }
.key-badge.off { background: #fee9e9; color: #b91c1c; }
.key-badge.off::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #ef4444; }
.key-badge.warn { background: #fff8ec; color: #b45309; }
.key-badge.warn::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #f59e0b; }
#tmapKeyInput[type="password"] { font-family: Consolas, Monaco, monospace; letter-spacing: .5px; padding-right: 52px; }
#geoKeyBar { font-size: 13px; }
