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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f5f5f5;
}

/* ── 頂部搜尋列 ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #3f51b5;
  flex-shrink: 0;
  z-index: 10;
}
.search-wrap {
  position: relative;
  flex: 1;
}
.search-input {
  width: 100%;
  padding: 8px 36px 8px 16px;
  border-radius: 20px;
  border: none;
  font-size: 14px;
  outline: none;
  background: rgba(255,255,255,0.18);
  color: white;
}
.search-input::placeholder { color: rgba(255,255,255,0.6); }
.search-input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.3);
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 10px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.search-clear:hover { background: rgba(255,255,255,0.45); }
.result-count { color: rgba(255,255,255,0.85); font-size: 12px; white-space: nowrap; }
.site-title { color: #fff; font-size: 15px; font-weight: 700; white-space: nowrap; letter-spacing: 0.5px; }

/* ── 主體佈局 ── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── 左側面板 ── */
.left-panel {
  width: 320px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e0e0e0;
  background: #ffffff;
  overflow: hidden;
}

/* ── 篩選區塊 ── */
.filter-section { padding: 8px 12px; border-bottom: 1px solid #eeeeee; }
.filter-label {
  font-size: 10px;
  color: #9e9e9e;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
  font-weight: 600;
}

/* 主分類 chips */
.chips-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  border: 1.5px solid transparent;
  background: #e8eaf6;
  color: #3949ab;
  user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-weight: 500;
}
.chip:hover { background: #c5cae9; }
.chip.active { background: #3f51b5; color: white; border-color: #3f51b5; }
.chip .count {
  opacity: 0.7;
  font-size: 10px;
  background: rgba(255,255,255,0.25);
  padding: 0 4px;
  border-radius: 6px;
}
.chip.active .count { background: rgba(255,255,255,0.3); opacity: 1; }

/* 有備註 toggle chip */
.notes-chip { background: #e8f5e9; color: #2e7d32; }
.notes-chip:hover { background: #c8e6c9; }
.notes-chip.active { background: #388e3c; color: white; border-color: #388e3c; }

/* 子分類 */
.sub-chips-container { display: flex; flex-direction: column; gap: 8px; }
.sub-group { display: flex; flex-direction: column; gap: 4px; }
.sub-group-label { font-size: 10px; font-weight: 700; color: #5c6bc0; letter-spacing: 0.3px; }
.sub-group-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.sub-chip {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
  background: #ede7f6;
  color: #4527a0;
  user-select: none;
  transition: background 0.15s;
  border: 1.5px solid transparent;
  font-weight: 500;
}
.sub-chip:hover { background: #d1c4e9; }
.sub-chip.active { background: #7c4dff; color: white; border-color: #7c4dff; }

/* 已啟用篩選 badges */
.badges-section { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 4px; }
.badges-row { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.badge {
  background: #fff8e1;
  border: 1px solid #ffcc80;
  color: #e65100;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.1s;
  font-weight: 500;
}
.badge:hover { background: #ffe0b2; }
.clear-all-btn {
  color: #e53935;
  background: none;
  border: none;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  white-space: nowrap;
  text-decoration: underline;
  align-self: center;
}
.clear-all-btn:hover { color: #b71c1c; }

/* ── 清單標頭 ── */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  border-bottom: 1px solid #eeeeee;
  flex-shrink: 0;
  background: #fafafa;
}
.list-count { font-size: 11px; color: #757575; }
.sort-select {
  font-size: 11px;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 2px 6px;
  color: #555;
  background: white;
  cursor: pointer;
}

/* ── 地點清單 ── */
.place-list { flex: 1; overflow-y: auto; }

.place-card {
  padding: 10px 13px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.1s;
  border-left: 3px solid transparent;
}
.place-card:hover { background: #f5f7ff; }
.place-card.active {
  background: #e8eaf6;
  border-left-color: #3f51b5;
}
.card-name {
  font-size: 13px;
  font-weight: 600;
  color: #212121;
  margin-bottom: 5px;
  line-height: 1.3;
}
.card-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 5px;
  align-items: center;
}
.tag {
  padding: 2px 7px;
  border-radius: 9px;
  font-size: 10px;
  color: white;
  font-weight: 500;
  letter-spacing: 0.2px;
}
.tag.sub { opacity: 0.85; }
.tag.no-coord {
  background: #bdbdbd;
  font-size: 9px;
}
.card-notes {
  font-size: 11px;
  color: #555;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}
.card-location { font-size: 10px; color: #7986cb; }
.card-location a { color: inherit; text-decoration: none; }
.card-location a:hover { text-decoration: underline; }

/* 空結果 / 載入中 */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: #9e9e9e;
  font-size: 14px;
  line-height: 1.8;
}
.empty-state small { display: block; font-size: 12px; color: #bdbdbd; margin-top: 4px; }
.empty-state.error { color: #e53935; }

.loading-state {
  padding: 48px 24px;
  text-align: center;
  color: #9e9e9e;
  font-size: 13px;
}
.loading-state::before {
  content: '';
  display: block;
  width: 28px;
  height: 28px;
  border: 3px solid #e8eaf6;
  border-top-color: #3f51b5;
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 地圖 ── */
.map-wrapper { flex: 1; position: relative; background: #e8edf2; }
#map { position: absolute; inset: 0; }

.map-placeholder {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #78909c;
  font-size: 13px;
  pointer-events: none;
  z-index: 0;
}
.map-placeholder.hidden { display: none; }
.map-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #cfd8dc;
  border-top-color: #3f51b5;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.map-placeholder.error .map-loading-spinner { display: none; }
.map-placeholder.error { color: #e53935; }

/* ── 定位按鈕 ── */
.locate-btn {
  position: absolute;
  bottom: 120px;
  right: 10px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px;
  color: #555;
  transition: box-shadow 0.15s, color 0.15s;
}
.locate-btn:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.3); color: #3f51b5; }
.locate-btn.locating { color: #3f51b5; animation: pulse 1s ease-in-out infinite; }
.locate-btn.located  { color: #1a73e8; }
.locate-btn.error    { color: #e53935; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.locate-btn svg { width: 100%; height: 100%; }


/* ── 圖例 ── */
.map-legend {
  background: white;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  margin: 8px;
  min-width: 90px;
}
.legend-item { display: flex; align-items: center; gap: 7px; padding: 2px 0; color: #444; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; border: 1.5px solid rgba(0,0,0,0.15); }

/* ── 手機版 tab ── */
.mobile-tabs { display: none; }

/* ── 工具 ── */
.hidden { display: none !important; }

/* ── 手機響應式 (≤ 640px) ── */
@media (max-width: 640px) {
  body { height: 100dvh; }

  /* 頂部：標題縮小，搜尋列優先 */
  .topbar { padding: 6px 10px; gap: 8px; }
  .site-title { font-size: 12px; letter-spacing: 0; flex-shrink: 0; }
  .result-count { display: none; }
  .search-input { font-size: 15px; padding: 7px 32px 7px 14px; }

  .main-layout {
    flex-direction: column;
    position: relative;
  }

  .left-panel {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
    position: absolute;
    inset: 0;
    z-index: 2;
    transition: transform 0.25s ease;
  }
  .left-panel.tab-hidden {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .map-wrapper {
    position: absolute;
    inset: 0;
    z-index: 1;
    transition: opacity 0.25s ease;
  }
  .map-wrapper.tab-hidden {
    opacity: 0;
    pointer-events: none;
  }

  .mobile-tabs {
    display: flex;
    flex-shrink: 0;
    border-top: 1px solid #e0e0e0;
    background: white;
    z-index: 20;
  }
  .tab-btn {
    flex: 1;
    padding: 12px 10px;
    border: none;
    background: white;
    font-size: 14px;
    color: #757575;
    cursor: pointer;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
  }
  .tab-btn.active {
    color: #3f51b5;
    background: #e8eaf6;
    border-top: 2px solid #3f51b5;
  }

  /* 篩選區觸控目標放大 */
  .chip { padding: 7px 14px; font-size: 13px; }
  .notes-chip { padding: 7px 14px; font-size: 13px; }
  .sub-chip { padding: 7px 14px; font-size: 12px; }
  .filter-section { padding: 10px 12px; }

  /* 地點卡片 */
  .place-card { padding: 12px 14px; }
  .card-name { font-size: 14px; }
  .card-notes { font-size: 12px; -webkit-line-clamp: 3; }
  .tag { font-size: 11px; padding: 3px 8px; }

  /* 清單標頭 */
  .list-header { padding: 8px 12px; }
  .list-count { font-size: 12px; }
  .sort-select { font-size: 12px; padding: 4px 8px; }

  /* 水平捲動 chips */
  .chips-row { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .chips-row::-webkit-scrollbar { display: none; }
}
