/* ============================================================
   地圖找房（/map.html，2026-11-10）
   沿用 style.css 的 token；所有框都是 iPhone 式圓角（WJQ 硬性偏好）。
   桌機：左側 420px 面板（搜尋＋清單）＋右側地圖。
   手機：地圖滿版，上方浮動搜尋列，下方橫向滑動的物件卡。
   ============================================================ */
body.page-map {
  padding-bottom: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.page-map .site-header { flex: 0 0 auto; }
.page-map #wrmAgentBanner { display: none; }
.page-map .agent-bar { position: relative; flex: 0 0 auto; }

.map-app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
}

/* ---------------- 面板 ---------------- */
.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
}
.map-controls { padding: 16px 16px 10px; display: flex; flex-direction: column; gap: 10px; }

.map-search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 4px 4px 4px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
}
.map-search:focus-within { border-color: var(--accent); }
.map-search .icon { width: 18px; height: 18px; color: var(--text-tertiary); flex: 0 0 auto; }
.map-search input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font: inherit;
  font-size: 15px;
  color: var(--text-primary);
  -webkit-appearance: none;
  appearance: none;
}
.map-search input::-webkit-search-cancel-button { display: none; }
.map-search-submit {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 18px;
  border: none;
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.map-search-submit:active { transform: scale(0.97); }

.map-control-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-city-switch { display: inline-flex; gap: 6px; }
.map-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.map-chip:hover { border-color: var(--border-strong); }
.map-chip:active { transform: scale(0.97); }
.map-chip .icon { width: 16px; height: 16px; }
.map-filter-btn .filter-toggle-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface);
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.map-filter-btn .filter-toggle-count[hidden] { display: none; }
.map-locate-btn { margin-left: auto; }

.map-status { margin: 0; font-size: 13px; color: var(--text-secondary); min-height: 0; }
.map-status:empty { display: none; }
.map-status[data-tone="warn"] {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.map-results { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.map-results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 16px 8px;
}
.map-results-head strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-result-count { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.map-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.map-unlocated {
  margin: 0;
  padding: 10px 16px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}
.map-unlocated a { color: var(--text-primary); text-decoration: underline; text-underline-offset: 3px; }

/* ---------------- 物件卡（橫式） ---------------- */
.map-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.map-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-soft); }
.map-card.is-selected { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.map-card-media {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-secondary);
}
.map-card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.map-card-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(29, 28, 26, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}
.map-card-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 2px 4px 2px 0; }
.map-card-loc { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--text-tertiary); }
.map-card-loc-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-card-dist { color: var(--accent-strong); font-weight: 600; white-space: nowrap; }
.map-card-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.map-card-rooms { font-size: 12px; color: var(--text-secondary); }
.map-card-price { display: flex; align-items: baseline; gap: 4px; margin-top: auto; }
.map-card-price strong { font-size: 16px; }
.map-card-price span { font-size: 12px; color: var(--text-secondary); }
.map-card-price em { margin-left: auto; font-style: normal; font-size: 11.5px; color: var(--text-secondary); }
.map-card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.map-card-tags span {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-secondary);
  font-size: 11.5px;
  color: var(--text-secondary);
}
.map-card-skeleton .sk-img { width: 100%; height: 100%; }
.map-empty {
  padding: 28px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.map-empty .empty-title { font-weight: 600; }
.map-empty .empty-sub { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* ---------------- 地圖 ---------------- */
.map-canvas-wrap { position: relative; min-height: 0; }
.map-canvas { position: absolute; inset: 0; background: var(--surface-secondary); }

.map-price-pin {
  padding: 4px 10px;
  border: 1.5px solid #fff;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(29, 28, 26, 0.18), 0 4px 12px rgba(29, 28, 26, 0.12);
  cursor: pointer;
  transition: transform .12s var(--ease), background .15s var(--ease), color .15s var(--ease);
}
.map-price-pin:hover, .map-price-pin.is-hover { transform: scale(1.08); z-index: 2; }
.map-price-pin.is-selected { background: var(--ink); color: var(--surface); z-index: 3; }
.maplibregl-marker:has(.map-price-pin.is-selected) { z-index: 3; }
.maplibregl-marker:has(.map-price-pin.is-hover) { z-index: 2; }

.map-cluster {
  width: 38px;
  height: 38px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: rgba(29, 28, 26, 0.9);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(29, 28, 26, 0.25);
  cursor: pointer;
  transition: transform .12s var(--ease);
}
.map-cluster.is-md { width: 46px; height: 46px; font-size: 14px; }
.map-cluster.is-lg { width: 54px; height: 54px; font-size: 15px; background: rgba(140, 113, 66, 0.94); }
.map-cluster:hover { transform: scale(1.06); }
.map-me-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #2F7CF6;
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(47, 124, 246, 0.2), 0 2px 6px rgba(0, 0, 0, 0.25);
}
.map-address-pin svg {
  width: 34px;
  height: 34px;
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 1.6;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}
.map-address-pin svg circle { fill: #fff; stroke: none; }

/* MapLibre 內建控制項也要圓角 */
.page-map .maplibregl-ctrl-group { border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow-mid); }
.page-map .maplibregl-ctrl-attrib { border-radius: 999px; }
.page-map .maplibregl-ctrl-attrib.maplibregl-compact { border-radius: 999px; }

/* ---------------- 篩選選單 ---------------- */
.map-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(29, 28, 26, 0.32);
}
.map-sheet-overlay[hidden], .map-filter-sheet[hidden] { display: none; }
.map-filter-sheet {
  position: fixed;
  z-index: 90;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: min(720px, calc(100dvh - 48px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-strong);
  animation: fade-drop .18s var(--ease);
}
.map-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.map-sheet-head h2 { margin: 0; font-size: 18px; }
.map-sheet-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface-secondary);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}
.map-filter-form {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 20px 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.map-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 10px 14px;
  background: var(--surface-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.map-field-wide { grid-column: 1 / -1; }
.map-field select,
.map-field input {
  width: 100%;
  min-height: 32px;
  padding: 2px 22px 2px 0;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.map-field input { padding-right: 0; }
.map-field select {
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%236E6860' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 2px center / 12px;
  cursor: pointer;
}
.map-field select:disabled { color: var(--text-tertiary); cursor: not-allowed; }
.map-field:focus-within { border-color: var(--accent); }
.map-tag-panel .feature-group { margin: 6px 0 10px; }
.map-tag-panel .feature-check-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
}
.map-tag-panel .feature-check-row label.is-checked { border-color: var(--ink); color: var(--text-primary); background: var(--surface-secondary); }
.map-tag-panel input[type="checkbox"] { accent-color: var(--ink); }
.map-sheet-actions {
  display: flex;
  gap: 10px;
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.map-sheet-actions .btn { flex: 1 1 0; }

/* ---------------- 手機 ---------------- */
@media (max-width: 767.98px) {
  .map-app { display: block; }
  .map-canvas-wrap { position: absolute; inset: 0; }
  .map-panel {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: transparent;
    border: none;
    pointer-events: none;
    justify-content: space-between;
  }
  .map-controls { padding: 10px 12px 0; pointer-events: auto; }
  .map-search { min-height: 48px; box-shadow: var(--shadow-mid); }
  .map-control-row { gap: 6px; flex-wrap: nowrap; }
  .map-chip { min-height: 36px; padding: 0 12px; box-shadow: var(--shadow-mid); }
  .map-locate-btn span { display: none; }
  .map-locate-btn { width: 36px; padding: 0; justify-content: center; }
  .map-status[data-tone="warn"] { background: rgba(255, 255, 255, 0.96); box-shadow: var(--shadow-mid); }
  .map-status:not(:empty):not([data-tone="warn"]) {
    align-self: flex-start;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow-soft);
  }

  .map-results { flex: 0 0 auto; pointer-events: auto; padding-bottom: 10px; }
  .map-results-head {
    align-self: flex-start;
    margin: 0 12px 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow-soft);
    max-width: calc(100% - 24px - 96px);
  }
  .map-results-head strong { font-size: 13.5px; }
  .map-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 12px 4px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  .map-list::-webkit-scrollbar { display: none; }
  .map-card {
    flex: 0 0 min(84vw, 340px);
    grid-template-columns: 96px minmax(0, 1fr);
    scroll-snap-align: center;
    box-shadow: var(--shadow-mid);
  }
  .map-empty { flex: 1 0 calc(100% - 0px); background: rgba(255, 255, 255, 0.97); border-style: solid; box-shadow: var(--shadow-mid); }
  .map-unlocated {
    margin: 6px 12px 0;
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow-soft);
    font-size: 12px;
    align-self: flex-start;
  }
  /* 放大縮小鈕移到卡片上方 */
  .page-map .maplibregl-ctrl-bottom-right { bottom: 190px; }
  .page-map .maplibregl-ctrl-bottom-left,
  .page-map .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib { margin-bottom: 0; }

  .map-filter-sheet {
    top: auto;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    left: 8px;
    right: 8px;
    transform: none;
    width: auto;
    max-height: calc(88dvh - 8px);
    border-radius: var(--radius-lg);
  }
  .map-filter-form { grid-template-columns: 1fr 1fr; gap: 8px; padding: 6px 16px 10px; }
  .map-field { padding: 8px 12px; }
  .map-sheet-actions { padding: 12px 16px 14px; }
}
@media (max-width: 360px) {
  .map-chip { padding: 0 10px; font-size: 13px; }
}
