/* 华年养老地图 · M 端样式
 * 布局：全屏地图 + 吸顶搜索 + 底部三档抽屉，适配 iOS 安全区。
 */

:root {
  --brand: #E5533D;
  --ink: #1f2328;
  --ink-2: #6b7280;
  --line: #e8e6e1;
  --bg: #ffffff;
  --map-bg: #e8e6e1;
  --sheet-h: 78vh;
  --snap-collapsed: 88px;
  --snap-half: 42vh;
  --radius: 14px;
  --shadow: 0 -2px 16px rgba(0, 0, 0, .12);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

/* 覆盖式组件自身声明了 display，需强制让 hidden 生效（灯箱/清空按钮等） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--map-bg);
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ============ 地图 ============ */
#map {
  position: absolute;
  inset: 0;
  background: var(--map-bg);
}
.leaflet-control-zoom,
.leaflet-control-attribution { display: none; }
.leaflet-container { background: var(--map-bg); }

/* 点位图钉 */
.poi-pin { background: none; border: none; }
.poi-pin svg { width: 100%; height: 100%; display: block; }
.poi-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 2px;
  padding: 1px 6px;
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  color: var(--ink);
  background: rgba(255, 255, 255, .94);
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .16);
  pointer-events: none;
}

/* ============ 顶部搜索与分类 ============ */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 600;
  padding: calc(var(--safe-t) + 10px) 12px 8px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, .96) 62%, rgba(255, 255, 255, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.search-row {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 6px 0 14px;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.search-ico {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--ink-2);
}
.search-row input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  font-size: 15px;
  color: var(--ink);
  background: transparent;
  -webkit-appearance: none;
}
.search-row input::placeholder { color: #9aa0a6; }

/* 隐藏浏览器自带的搜索框清除按钮，统一用自定义按钮 */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-results-button {
  -webkit-appearance: none;
  display: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--ink-2);
  background: #f2f1ee;
}
.icon-btn:active { background: #e4e2dd; }
.icon-btn svg { width: 18px; height: 18px; }

.chips {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-bottom: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 13px;
  line-height: 1;
  color: var(--ink);
  background: #fff;
  border: 1px solid transparent;
  border-radius: 16px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .1);
}
.chip[aria-pressed="true"] {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

/* ============ 悬浮按钮与底图菜单 ============ */
.fab {
  position: absolute;
  right: 12px;
  z-index: 600;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .14);
  bottom: calc(var(--snap-half) + 16px + var(--safe-b));
}
.fab:active { background: #f2f1ee; }

.layer-menu {
  position: absolute;
  right: 12px;
  z-index: 700;
  min-width: 132px;
  padding: 6px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .18);
  bottom: calc(var(--snap-half) + 68px + var(--safe-b));
}
.layer-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 8px;
}
.layer-opt:active { background: #f2f1ee; }
.layer-opt .dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #d5d2cc;
}
.layer-opt.active { color: var(--brand); font-weight: 600; }
.layer-opt.active .dot { background: var(--brand); }
.layer-link {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid #eee;
  color: #555;
  text-decoration: none;
}

/* ============ 底部抽屉 ============ */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 800;
  display: flex;
  flex-direction: column;
  height: var(--sheet-h);
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(36vh);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  will-change: transform;
  touch-action: none;
}
.sheet.dragging { transition: none; }

.sheet-handle {
  display: grid;
  place-items: center;
  height: 22px;
  flex: 0 0 auto;
  cursor: grab;
}
.sheet-handle span {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: #d5d2cc;
}

.sheet-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 16px 10px;
  flex: 0 0 auto;
}
/* 收起态把安全区补进可见条，避免与 iOS 底部指示条重叠 */
.sheet[data-snap="collapsed"] .sheet-head { padding-bottom: calc(10px + var(--safe-b)); }
.sheet-head strong { font-size: 16px; }
.muted { font-size: 12px; color: var(--ink-2); }

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px calc(16px + var(--safe-b));
  touch-action: pan-y;
}

/* ============ 列表卡片 ============ */
.card {
  display: flex;
  gap: 10px;
  padding: 12px;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card.active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.card-thumb {
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
  border-radius: 10px;
  object-fit: cover;
  background: #f2f1ee;
}
.card-main { flex: 1; min-width: 0; }
.card-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}
.card-title span {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 400;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
}
.card-meta {
  margin-top: 5px;
  font-size: 12px;
  color: var(--ink-2);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-sub { margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.card-sub b { color: var(--brand); font-weight: 600; }

.empty {
  padding: 40px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-2);
}

/* ============ 详情 ============ */
.detail { padding-bottom: 8px; }
.detail h2 {
  margin: 2px 0 6px;
  font-size: 19px;
  line-height: 1.35;
}
.detail .tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.detail .tag {
  padding: 4px 9px;
  font-size: 12px;
  color: var(--ink-2);
  background: #f5f4f1;
  border-radius: 6px;
}
.detail .facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.detail .fact {
  padding: 9px 10px;
  background: #f7f6f3;
  border-radius: 10px;
}
.detail .fact dt { font-size: 11px; color: var(--ink-2); margin-bottom: 3px; }
.detail .fact dd { margin: 0; font-size: 14px; font-weight: 600; }
.detail .block { margin: 14px 0; }
.detail .block h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 500;
}
.detail .block p {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}
.detail .block p a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
}
.detail .gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.detail .gallery img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: #f2f1ee;
}

.actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 10px 0 calc(4px + var(--safe-b));
  background: linear-gradient(to top, #fff 70%, rgba(255, 255, 255, 0));
}
.btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  border: 0;
  border-radius: 12px;
  background: #f2f1ee;
  color: var(--ink);
}
.btn.primary { color: #fff; background: var(--brand); }
.btn:active { opacity: .85; }
.btn svg { width: 17px; height: 17px; }

/* ============ 灯箱 / 提示 ============ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .92);
}
.lightbox img { max-width: 100%; max-height: 86vh; object-fit: contain; }
.lightbox-close {
  position: absolute;
  top: calc(var(--safe-t) + 12px);
  right: 12px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: #fff;
  background: rgba(255, 255, 255, .16);
  border: 0;
  border-radius: 50%;
}
.lightbox-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-b) + 16px);
  padding: 0 20px;
  font-size: 13px;
  color: #fff;
  text-align: center;
}

.toast {
  position: fixed;
  top: calc(var(--safe-t) + 70px);
  left: 50%;
  z-index: 1400;
  transform: translateX(-50%);
  padding: 9px 20px;
  font-size: 13px;
  color: #fff;
  background: rgba(0, 0, 0, .78);
  border-radius: 20px;
  white-space: nowrap;
}

.offline-tip {
  position: fixed;
  left: 12px;
  right: 12px;
  z-index: 1300;
  bottom: calc(var(--safe-b) + 12px);
  padding: 9px 14px;
  font-size: 13px;
  text-align: center;
  color: #7a4a12;
  background: #fff6e5;
  border: 1px solid #f0d9a8;
  border-radius: 10px;
}

/* ============ 全屏页面（二级 / 三级） ============ */
.page {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  background: #fff;
  transform: translateX(0);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  will-change: transform;
}
.page[hidden] { display: none !important; }
.page.enter { transform: translateX(100%); }
.page.leave { transform: translateX(100%); transition: transform .24s cubic-bezier(.4, 0, .9, .4); }
.page.dragging { transition: none; }

/* 系统开启「减弱动态效果」时不做位移动画 */
@media (prefers-reduced-motion: reduce) {
  .page, .sheet, .chip, .card, .pitem { transition: none !important; }
}

/* 二级页：顶部返回 + 搜索框 */
.page-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: calc(var(--safe-t) + 8px) 12px 8px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.back-btn,
.back-fab {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--ink);
  background: #f2f1ee;
  border: 0;
  border-radius: 50%;
}
.back-btn:active,
.back-fab:active { background: #e4e2dd; }
.back-btn svg,
.back-fab svg { width: 20px; height: 20px; }

.page-search {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 4px 0 12px;
  background: #f5f4f1;
  border-radius: 20px;
}
.page-search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  font-size: 15px;
  color: var(--ink);
  background: transparent;
  -webkit-appearance: none;
}
.page-search input::placeholder { color: #9aa0a6; }

/* 页面切换时临时铺一层透明遮罩，拦截同一手势产生的穿透点击 */
.click-shield {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: transparent;
  touch-action: none;
}

.page-hint {
  padding: 40px 12px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-2);
}

/* 二级页：搜索结果浮在地图上，列表是可折叠抽屉 */
.page-searchlist { background: transparent; pointer-events: none; }
.page-searchlist .page-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  pointer-events: auto;
  border-bottom: 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .1);
}
.page-searchlist .sheet { pointer-events: auto; }

/* 进入搜索页时隐藏首页的搜索/分类/抽屉，避免透过透明页面露出来 */
body.searching #sheet,
body.searching .topbar,
body.searching .fab,
body.searching .layer-menu { visibility: hidden; }

/* 左图右文列表 */
.plist { display: block; }
.pitem {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.pitem:active { background: #faf9f7; }
.pitem-img {
  width: 84px;
  height: 84px;
  flex: 0 0 auto;
  border-radius: 10px;
  object-fit: cover;
  background: #f2f1ee;
}
.pitem-img.placeholder {
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.pitem-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pitem-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}
.pitem-title span {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 400;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
}
.pitem-meta {
  margin-top: 5px;
  font-size: 12px;
  color: var(--ink-2);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pitem-sub {
  margin-top: auto;
  padding-top: 6px;
  font-size: 12px;
  color: var(--ink-2);
}
.pitem-sub b { color: var(--brand); font-weight: 600; }

/* 三级页：详情地图 + 底部信息卡 */
.page-detail { background: var(--map-bg); }
/* z-index:0 让地图成为独立层叠上下文，否则 Leaflet 内部 pane 的 z-index(400+) 会盖住信息卡 */
.detail-map { position: absolute; inset: 0; z-index: 0; }
.detail-map .leaflet-control-zoom { display: none; }

.back-fab {
  position: absolute;
  left: 12px;
  top: calc(var(--safe-t) + 12px);
  z-index: 20;
  width: 40px;
  height: 40px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .16);
}

.detail-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  max-height: 62vh;
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  will-change: transform;
}
/* 收起态：与首页附近列表 / 搜索结果列表的收起高度一致（88px + 安全区） */
.detail-card.collapsed { transform: translateY(calc(100% - 88px - var(--safe-b))); }
.detail-card.no-anim { transition: none; }
.detail-handle {
  display: grid;
  place-items: center;
  height: 22px;
  flex: 0 0 auto;
  cursor: pointer;
  touch-action: manipulation;
}
.detail-handle span {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: #d5d2cc;
}
.detail-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 0;
}
.detail-scroll .detail { padding-bottom: 0; }
