/* ============================================
   City Walks — 城市漫步路线规划器
   ============================================ */

:root {
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #eef2f8;
  --border: rgba(32, 79, 193, 0.5);
  --border-focus: rgba(32, 79, 193, 0.5);
  --text: #204fc1;
  --text-dim: rgba(32, 79, 193, 0.55);
  --text-muted: rgba(32, 79, 193, 0.3);
  --accent: #204fc1;
  --accent-hover: #1a3f9e;
  --accent-text: #ffffff;
  --accent-dim: rgba(32, 79, 193, 0.1);
  --danger: #c05040;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  --radius: 0;
}

/* 暗色主题 */
.dark {
  --bg: #1e1e1e;
  --bg-elevated: #1e1e1e;
  --bg-hover: #2a2a2a;
  --border: rgba(70, 110, 200, 0.4);
  --border-focus: rgba(70, 110, 200, 0.65);
  --text: #7ea8f4;
  --text-dim: rgba(126, 168, 244, 0.7);
  --text-muted: rgba(126, 168, 244, 0.4);
  --accent: #6ba0f8;
  --accent-hover: #8cb8fa;
  --accent-text: #ffffff;
  --accent-dim: rgba(107, 160, 248, 0.18);
}

/* ========== 基础重置 ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ========== 侧边栏 ========== */
.sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 24px;
  border-right: 1px solid var(--border);
  z-index: 1000;
  overflow-y: auto;
  gap: 16px;
}

.sidebar-header h1 {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ========== 输入区域 ========== */
.input-wrapper {
  position: relative;
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s;
}

.input-group input:focus {
  border-color: var(--border-focus);
}

.input-group input::placeholder {
  color: var(--text-muted);
}

/* ========== 下拉建议 ========== */
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  z-index: 2000;
}

.suggestions.hidden { display: none; }

.suggestions li {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
}

.suggestions li:last-child { border-bottom: none; }

.suggestions li:hover,
.suggestions li.active {
  background: var(--bg-hover);
  color: var(--text);
}

.suggestions li .suggest-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.suggestions li .suggest-detail {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========== 按钮（统一风格） ========== */
.btn {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text-dim);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-focus);
}
.btn:active { opacity: 0.7; }
.btn:disabled {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* 主要按钮 */
.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-text);
}
.btn-primary:disabled {
  background: var(--accent-dim);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  font-weight: 500;
}

/* 幽灵按钮（无背景） */
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  border-color: var(--border-focus);
  color: var(--text);
}

/* ========== 操作按钮组 ========== */
.actions {
  display: flex;
  gap: 8px;
}
.actions .btn { flex: 1; }

/* ========== 循环路径开关 ========== */
.loop-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}
.loop-toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ========== 路线显示开关（地图下方叠加，独立切换） ========== */
.route-mode-overlay {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 6px;
}

.route-toggle-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text-dim);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.route-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-focus);
}
.route-toggle-btn:active { opacity: 0.7; }
.route-toggle-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* ========== 地点列表 ========== */
.places-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.places-section h3 span { color: var(--text-dim); }

.place-list {
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
}

.place-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  transition: opacity 0.15s;
}

.place-list li:last-child { border-bottom: none; }

.place-list li:hover .delete-btn { opacity: 1; }

.place-list li .order-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.place-list li .order-badge:hover,
.place-list li .order-badge.is-start {
  background: var(--accent);
  color: var(--accent-text);
}

.place-list li .place-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}

.place-list li .delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 4px;
  border-radius: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.place-list li .delete-btn:hover { color: var(--danger); }

.empty-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 24px 0;
}

/* ========== 路线信息 ========== */
.route-info {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.route-info.hidden { display: none; }

.route-info h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.route-order {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  background: none;
  margin: 0;
  padding: 0;
}

.total-distance {
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  font-family: var(--font-mono);
}

/* ========== 地图标记 ========== */
.marker-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-text);
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  border: 1px solid var(--accent-text);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
}

.arrow-icon {
  background: transparent !important;
  border: none !important;
}

/* ========== 地图容器 ========== */
.map-container {
  flex: 1;
  height: 100vh;
  position: relative;
}

/* ========== 地图风格选择 ========== */
.map-style-select {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1000;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.map-style-select:hover {
  background: var(--bg-hover);
  border-color: var(--border-focus);
  color: var(--text);
}

/* 悬浮在地图上的按钮（主题切换等）继承 map-style-select 样式 */

/* Leaflet 覆盖 */
.leaflet-container {
  background: var(--bg);
}

.leaflet-control-zoom a {
  background: rgba(255,255,255,0.85) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
  font-size: 16px !important;
  font-weight: 500 !important;
  line-height: 28px !important;
  width: 28px !important;
  height: 28px !important;
  transition: background 0.15s !important;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-hover) !important;
}
.dark .leaflet-control-zoom a {
  background: rgba(0,0,0,0.45) !important;
  color: var(--text) !important;
}
.dark .leaflet-control-zoom a:hover {
  background: rgba(0,0,0,0.7) !important;
}
.leaflet-control-zoom a:first-child {
  border-bottom: none !important;
}

.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  color: var(--text-muted) !important;
  font-size: 11px !important;
  border: 1px solid var(--border) !important;
}
.dark .leaflet-control-attribution {
  background: rgba(0,0,0,0.45) !important;
  color: var(--text-dim) !important;
}

.leaflet-control-attribution a {
  color: var(--text-dim) !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
}

.leaflet-popup-tip {
  background: var(--bg-elevated) !important;
}

/* ========== 响应式（手机布局：高度 > 宽度时） ========== */
@media (max-aspect-ratio: 1/1) {
  body {
    flex-direction: column;
  }

  /* 地图在上方，占 1/3 高度 */
  .map-container {
    order: -1;
    height: 33.33vh;
    flex: 0 0 33.33vh;
  }

  /* 侧边栏在下方，填充剩余空间 */
  .sidebar {
    width: 100%;
    min-width: 100%;
    flex: 1 1 0;
    padding: 12px 14px;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-y: auto;
    gap: 8px;
  }

  .sidebar-header h1 {
    font-size: 28px;
  }

  .subtitle {
    font-size: 12px;
  }

  .place-list {
    max-height: 120px;
  }

  .route-mode-overlay {
    bottom: 8px;
  }

  /* 地图控件适配 */
  .map-style-select {
    top: 4px;
    right: 4px;
    font-size: 11px;
    padding: 3px 6px;
  }

  .map-style-select.theme-toggle {
    top: 30px;
  }

  .leaflet-control-zoom {
    top: 60px;
  }
}

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--border-focus); }
