/* ========== 全局样式 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --brand-luckin: #0066CC;
  --brand-cotti: #E60012;
  --brand-guming: #FF6600;
  --brand-chabaidao: #FFD700;
  --brand-nayuki: #00BFA5;
  --brand-heytea: #FF2D55;
  --bg: #f5f5f5;
  --card-bg: #ffffff;
  --text: #333;
  --text-secondary: #666;
  --border: #e0e0e0;
  --shadow: 0 2px 12px rgba(0,0,0,0.1);
  --radius: 10px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ========== 控制栏 ========== */
#control-bar {
  background: var(--card-bg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  z-index: 1000;
  padding: 8px 12px;
  flex-shrink: 0;
}

.title {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row.filters {
  gap: 8px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.filter-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 500;
}

select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
  min-width: 0;
  max-width: 140px;
}

select:focus {
  border-color: #4285f4;
}

/* ========== 品牌筛选 ========== */
#brand-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.brand-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  user-select: none;
}

.brand-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.brand-chip.active {
  color: #fff;
}

.brand-chip .chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.brand-chip .chip-count {
  font-size: 0.7rem;
  opacity: 0.7;
}

.brand-chip-all {
  border-color: #999;
  color: #555;
}

.brand-chip-all.active {
  background: #555;
  border-color: #555;
  color: #fff;
}

/* 品牌颜色 */
.brand-luckin { border-color: var(--brand-luckin); }
.brand-luckin.active { background: var(--brand-luckin); border-color: var(--brand-luckin); }
.brand-luckin .chip-dot { background: var(--brand-luckin); }

.brand-cotti { border-color: var(--brand-cotti); }
.brand-cotti.active { background: var(--brand-cotti); border-color: var(--brand-cotti); }
.brand-cotti .chip-dot { background: var(--brand-cotti); }

.brand-guming { border-color: var(--brand-guming); }
.brand-guming.active { background: var(--brand-guming); border-color: var(--brand-guming); }
.brand-guming .chip-dot { background: var(--brand-guming); }

.brand-chabaidao { border-color: #E6A800; }
.brand-chabaidao.active { background: #E6A800; border-color: #E6A800; }
.brand-chabaidao .chip-dot { background: var(--brand-chabaidao); }

.brand-nayuki { border-color: var(--brand-nayuki); }
.brand-nayuki.active { background: var(--brand-nayuki); border-color: var(--brand-nayuki); }
.brand-nayuki .chip-dot { background: var(--brand-nayuki); }

.brand-heytea { border-color: var(--brand-heytea); }
.brand-heytea.active { background: var(--brand-heytea); border-color: var(--brand-heytea); }
.brand-heytea .chip-dot { background: var(--brand-heytea); }

/* ========== 地图 ========== */
#map {
  flex: 1;
  width: 100%;
  z-index: 1;
}

/* 自定义 Marker */
.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  border: 2px solid #fff;
  transition: transform 0.2s;
}

.custom-marker:hover,
.custom-marker.selected {
  transform: rotate(-45deg) scale(1.3);
  z-index: 999 !important;
}

.marker-icon-inner {
  transform: rotate(45deg);
  font-size: 14px;
  filter: brightness(0) invert(1);
}

/* Leaflet popup 样式覆盖 */
.leaflet-popup-content-wrapper {
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
  margin: 0;
  min-width: 240px;
  max-width: 320px;
}

.leaflet-popup-close-button {
  z-index: 10;
  color: #666 !important;
  font-size: 18px !important;
  padding: 4px 8px !important;
}

.popup-card {
  padding: 0;
}

.popup-header {
  padding: 12px 14px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.popup-brand-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  color: #fff;
  font-weight: 600;
}

.popup-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  flex: 1;
  line-height: 1.3;
}

.popup-body {
  padding: 0 14px 12px;
}

.popup-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.popup-row:last-child {
  margin-bottom: 0;
}

.popup-row .popup-icon {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.popup-row .popup-value {
  flex: 1;
  word-break: break-all;
}

.popup-actions {
  display: flex;
  border-top: 1px solid #f0f0f0;
}

.popup-actions button {
  flex: 1;
  padding: 10px;
  border: none;
  background: #f8f9fa;
  font-size: 0.82rem;
  cursor: pointer;
  color: #4285f4;
  font-weight: 500;
  transition: background 0.2s;
}

.popup-actions button:first-child {
  border-right: 1px solid #f0f0f0;
}

.popup-actions button:hover {
  background: #e8f0fe;
}

/* ========== 详情弹窗 ========== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
}

.modal.show {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  animation: fadeIn 0.2s;
}

.modal-content {
  position: relative;
  background: var(--card-bg);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 75vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
  padding: 20px 16px 30px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  z-index: 10;
}

#modal-body h2 {
  font-size: 1.15rem;
  margin-bottom: 4px;
  padding-right: 30px;
}

#modal-body .brand-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  color: #fff;
  margin-bottom: 14px;
}

#modal-body .info-item {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

#modal-body .info-item .info-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

#modal-body .info-item .info-value {
  color: var(--text-secondary);
}

#modal-body .modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

#modal-body .modal-actions button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-primary {
  background: #4285f4;
  color: #fff;
}

.btn-primary:hover {
  background: #3367d6;
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

/* ========== 统计栏 ========== */
#stats-bar {
  position: absolute;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  box-shadow: var(--shadow);
  z-index: 1000;
  white-space: nowrap;
}

/* ========== 移动端底部导航 ========== */
#mobile-nav {
  display: none;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  z-index: 1000;
  flex-shrink: 0;
}

.mobile-nav-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.mobile-nav-btn.active {
  color: #4285f4;
  font-weight: 600;
}

/* ========== 列表视图 ========== */
#store-list {
  display: none;
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 8px;
}

#store-list.show {
  display: block;
}

.store-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: all 0.2s;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.store-card:active {
  transform: scale(0.98);
}

.store-card .card-brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.store-card .card-info {
  flex: 1;
  min-width: 0;
}

.store-card .card-name {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.store-card .card-brand {
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 8px;
  color: #fff;
  display: inline-block;
  margin-bottom: 4px;
}

.store-card .card-addr {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.store-card .card-dist {
  font-size: 0.75rem;
  color: #999;
  margin-top: 2px;
}

/* ========== 动画 ========== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ========== PC 端适配 ========== */
@media (min-width: 768px) {
  #control-bar {
    padding: 10px 20px;
  }

  .title {
    font-size: 1.3rem;
  }

  select {
    max-width: 180px;
  }

  #brand-filters {
    gap: 8px;
  }

  .brand-chip {
    padding: 6px 14px;
    font-size: 0.82rem;
  }

  .modal-content {
    border-radius: 16px;
    max-width: 460px;
    margin-bottom: 40px;
  }

  #stats-bar {
    bottom: 20px;
  }

  #store-list {
    padding: 12px 16px;
  }

  .store-card {
    padding: 14px 16px;
  }
}

/* ========== 移动端适配 ========== */
@media (max-width: 767px) {
  #control-bar {
    padding: 6px 8px;
  }

  .title {
    font-size: 1rem;
  }

  .control-row {
    gap: 6px;
    margin-bottom: 4px;
  }

  select {
    font-size: 0.8rem;
    padding: 5px 6px;
  }

  .brand-chip {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  #mobile-nav {
    display: flex;
  }

  #stats-bar {
    bottom: 56px;
  }

  #map {
    flex: 1;
  }

  #store-list.show {
    display: block;
  }
}
