/* ============ 基础 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --brand-line: #c7d2fe;
  --ink: #0f172a;
  --ink-soft: #64748b;
  --ink-faint: #94a3b8;
  --line: #e6eaf2;
  --bg: #f4f6fb;
  --card: #ffffff;
  --price: #ea580c;
  --price-soft: #fff7ed;
  --center: #ef4444;
  --shadow: 0 2px 12px rgba(15, 23, 42, .06);
  --shadow-hover: 0 10px 24px rgba(79, 70, 229, .16);
  --sidebar-w: 380px;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#app { display: flex; height: 100vh; height: 100dvh; width: 100vw; overflow: hidden; }

/* ============ 左侧面板 ============ */
#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 1000;
}
.side-header {
  padding: 20px 20px 16px;
  background: linear-gradient(135deg, var(--brand-2) 0%, var(--brand) 45%, var(--brand-dark) 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(67, 56, 202, .22);
}
.side-header h1 { font-size: 19px; font-weight: 700; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.radius-tag {
  font-size: 11px; font-weight: 600; background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.5); border-radius: 20px; padding: 2px 10px;
  backdrop-filter: blur(4px);
}
.subtitle { font-size: 12px; opacity: .9; margin-top: 6px; }

/* 中心信息卡 */
.center-card {
  display: flex; align-items: center; gap: 12px;
  margin: 14px 16px 0; padding: 13px 15px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
}
.center-dot {
  width: 15px; height: 15px; border-radius: 50%; flex: 0 0 15px;
  background: var(--center); border: 3px solid #fecaca;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, .14);
}
.center-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.center-meta strong { font-size: 14px; }
.center-meta span { font-size: 11.5px; color: var(--ink-soft); }

/* 图层筛选 */
.layer-box { margin: 13px 16px 0; padding: 13px 15px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.layer-box h2, .list-head h2 { font-size: 13px; font-weight: 700; color: var(--ink); }
.layer-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 12px; padding: 6px 12px; border-radius: 20px; user-select: none;
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  transition: all .15s;
}
.chip input { display: none; }
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; }
.chip.on { color: var(--brand-dark); border-color: var(--brand-line); background: var(--brand-soft); font-weight: 600; }
.chip.off { opacity: .4; }
.ring-toggle { display: flex; align-items: center; gap: 7px; margin-top: 12px; font-size: 12px; color: var(--ink-soft); cursor: pointer; }
.ring-toggle input { accent-color: var(--brand); width: 15px; height: 15px; }

/* 小区列表 */
.list-box { flex: 1 1 auto; min-height: 0; margin: 13px 16px 0; display: flex; flex-direction: column; }
.list-head { display: flex; flex-direction: column; gap: 9px; padding-bottom: 9px; }
.list-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list-title-row h2 { white-space: nowrap; }
.list-toggle {
  display: none; align-items: center; gap: 4px; flex: 0 0 auto;
  border: 1px solid var(--brand-line); background: var(--brand-soft); color: var(--brand-dark);
  font-size: 11.5px; font-weight: 700; font-family: inherit; border-radius: 20px;
  padding: 5px 12px; cursor: pointer;
}
.list-head h2 em { font-style: normal; color: var(--brand); }
#searchInput {
  width: 100%; padding: 9px 13px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 11px; outline: none; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
#searchInput:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }

.community-list { list-style: none; overflow-y: auto; padding-right: 4px; flex: 1 1 auto; min-height: 0; }
.community-list::-webkit-scrollbar { width: 5px; }
.community-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
.cm-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  padding: 11px 13px; margin-bottom: 9px; cursor: pointer; transition: all .15s;
}
.cm-item:hover { border-color: var(--brand); box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.cm-item.active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(79, 70, 229, .18); }
.cm-row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cm-name { font-size: 14px; font-weight: 700; }
.cm-dist { font-size: 12px; color: var(--brand); font-weight: 700; white-space: nowrap; }
.cm-addr { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.cm-row2 { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.cm-price { font-size: 12.5px; color: var(--price); font-weight: 700; }
.cm-price b { font-size: 14px; }
.cm-count { font-size: 11px; color: var(--ink-faint); }

.side-footer { padding: 12px 20px 15px; font-size: 10.5px; color: var(--ink-faint); line-height: 1.7; }

/* ============ 地图 ============ */
#map { flex: 1 1 auto; height: 100%; min-height: 0; background: #e8edf5; }
.leaflet-container { font-family: inherit; }
.leaflet-bar a { color: var(--brand-dark); }

/* 中心标记 */
.mk-center { position: relative; background: transparent; border: none; border-radius: 0; }
.mk-center .pin {
  width: 20px; height: 20px; border-radius: 50%; background: var(--center);
  border: 4px solid #fff; box-shadow: 0 0 0 2px rgba(239, 68, 68, .45), 0 2px 6px rgba(0,0,0,.28);
  position: relative;
}
.mk-center .pulse {
  position: absolute; left: 50%; top: 50%; width: 20px; height: 20px;
  transform: translate(-50%,-50%); border-radius: 50%; background: rgba(239, 68, 68, .32);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse { 0% { width: 20px; height: 20px; opacity: .9; } 100% { width: 56px; height: 56px; opacity: 0; } }

/* 小区标记（水滴形） */
.mk-community { background: transparent; border: none; }
.mk-community .tear {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0;
  background: var(--brand); transform: rotate(-45deg);
  border: 2.5px solid #fff; box-shadow: 0 2px 7px rgba(67, 56, 202, .4);
  display: flex; align-items: center; justify-content: center;
}
.mk-community .tear span { transform: rotate(45deg); color: #fff; font-size: 12px; font-weight: 700; }
.mk-community.active .tear { background: #f59e0b; box-shadow: 0 3px 9px rgba(217, 119, 6, .5); z-index: 999; }
.mk-community.active { z-index: 1000; }

/* 设施标记（圆底白字） */
.mk-fac { background: transparent; border: none; }
.mk-fac .dot {
  width: 24px; height: 24px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; border: 2.5px solid #fff;
  box-shadow: 0 1.5px 5px rgba(15, 23, 42, .3);
}

/* ============ 弹窗 ============ */
.leaflet-popup-content-wrapper { border-radius: 15px; box-shadow: 0 12px 34px rgba(15, 23, 42, .22); }
.leaflet-popup-content { margin: 15px 17px; width: 272px; }
.leaflet-popup-tip { box-shadow: 0 12px 34px rgba(15, 23, 42, .14); }
.pop-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.pop-title .badge { font-size: 10px; background: var(--brand); color: #fff; border-radius: 6px; padding: 2px 7px; font-weight: 600; }
.pop-addr { font-size: 11.5px; color: var(--ink-soft); margin-top: 5px; line-height: 1.5; }
.pop-meta { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 9px; }
.pop-meta span { font-size: 11px; background: var(--brand-soft); color: var(--brand-dark); border-radius: 7px; padding: 3px 9px; font-weight: 600; }
.pop-meta .straight { background: var(--price-soft); color: #c2410c; }
.pop-sec-title { font-size: 12px; font-weight: 700; margin: 13px 0 6px; padding-top: 11px; border-top: 1px dashed var(--line); }
.pop-listings { list-style: none; }
.pop-listings li { display: flex; align-items: baseline; gap: 6px; font-size: 12px; padding: 4px 0; border-bottom: 1px dotted #eef2f7; flex-wrap: wrap; }
.pop-listings li:last-child { border-bottom: none; }
.pl-type { flex: 0 0 30px; color: var(--ink-faint); font-size: 10.5px; }
.pl-layout { color: var(--ink); font-weight: 600; }
.pl-area { color: var(--ink-faint); font-size: 11px; }
.pl-price { margin-left: auto; color: var(--price); font-weight: 700; white-space: nowrap; }
.pl-src { font-size: 10px; color: var(--ink-faint); }
.pop-note { font-size: 11px; color: var(--ink-soft); background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; margin: 9px 0 0; line-height: 1.5; }
.pop-more { display: inline-block; margin-top: 11px; font-size: 12px; font-weight: 600; color: var(--brand); text-decoration: none; }
.pop-more:hover { text-decoration: underline; }
.pop-fac-dist { font-size: 12px; color: var(--brand-dark); font-weight: 600; margin-top: 7px; }

/* ============ 响应式：手机端（精简顶栏 + 大地图，名单全屏抽屉） ============ */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  #sidebar {
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0 0 20px 20px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .1);
  }
  .side-header {
    padding: calc(12px + env(safe-area-inset-top)) 16px 11px;
    border-radius: 0 0 16px 16px;
  }
  .side-header h1 { font-size: 16.5px; }
  .subtitle { font-size: 11px; margin-top: 4px; }

  .center-card { margin: 10px 12px 0; padding: 9px 12px; gap: 10px; border-radius: 12px; }
  .center-meta span { font-size: 10.5px; }

  .layer-box { margin: 10px 12px 0; padding: 10px 12px; border-radius: 12px; }
  .layer-toggles {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 3px;
  }
  .layer-toggles::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; padding: 7px 13px; font-size: 12.5px; }
  .ring-toggle { margin-top: 10px; }

  /* 名单入口条（折叠态） */
  .list-box { margin: 10px 12px 12px; flex: 0 0 auto; }
  .list-head { gap: 0; padding-bottom: 0; }
  .list-title-row {
    width: 100%; cursor: pointer;
    background: var(--brand-soft); border: 1px solid var(--brand-line);
    border-radius: 12px; padding: 11px 14px;
  }
  .list-toggle {
    display: inline-flex; padding: 4px 0 4px 12px; background: transparent;
    border: none; border-left: 1px solid var(--brand-line); border-radius: 0;
  }
  .community-list, #searchInput { display: none; }
  .cm-item { padding: 11px 13px; }
  .side-footer { display: none; }

  #map { flex: 1 1 auto; }
  .leaflet-popup-content { width: auto; min-width: 150px; max-width: 78vw; margin: 13px 14px; }
  .leaflet-top { top: calc(8px + env(safe-area-inset-top)); }
  .leaflet-bottom { bottom: calc(8px + env(safe-area-inset-bottom)); }

  /* 展开态：名单全屏抽屉 */
  body.list-open #sidebar {
    position: fixed; inset: 0; z-index: 2000;
    height: 100dvh; max-height: none;
    border-radius: 0; border-bottom: none; box-shadow: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.list-open .center-card,
  body.list-open .layer-box { display: none; }
  body.list-open .list-box { flex: 1 1 auto; min-height: 0; margin: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  body.list-open .list-head { gap: 9px; padding-bottom: 9px; }
  body.list-open .list-title-row { background: transparent; border: none; border-radius: 0; padding: 0; cursor: default; }
  body.list-open .list-toggle { border-left: none; padding: 5px 12px; border: 1px solid var(--brand-line); border-radius: 20px; background: var(--brand-soft); }
  body.list-open #searchInput { display: block; }
  body.list-open .community-list { display: block; flex: 1 1 auto; min-height: 0; }
}
