/* ============================================================
   基础重置
   ============================================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; font-size: 14px; color: #1f2937; background: #f9fafb; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
ul { list-style: none; }

/* ============================================================
   工具栏
   ============================================================ */
.toolbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 1000;
  background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.12);
  display: flex; align-items: center; padding: 0 12px; gap: 10px;
}
.toolbar-left { display: flex; align-items: center; }
.app-title { font-size: 16px; font-weight: 700; color: #1f2937; white-space: nowrap; }
.toolbar-center { flex: 1; display: flex; justify-content: center; }
.toolbar-center select {
  padding: 5px 10px; border: 1px solid #d1d5db; border-radius: 20px;
  background: #f9fafb; color: #374151; font-size: 13px; cursor: pointer;
  max-width: 200px; width: 100%;
}
.toolbar-right { display: flex; align-items: center; gap: 6px; }

/* ============================================================
   按钮样式
   ============================================================ */
.icon-btn {
  padding: 6px 10px; border-radius: 8px; background: #f3f4f6;
  color: #374151; font-size: 14px; transition: background .15s;
  white-space: nowrap;
}
.icon-btn:hover { background: #e5e7eb; }
.icon-btn.active { background: #dbeafe; color: #1d4ed8; }
.icon-btn-sm {
  width: 28px; height: 28px; border-radius: 6px; background: #f3f4f6;
  color: #6b7280; font-size: 14px; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn-sm:hover { background: #e5e7eb; color: #374151; }
.text-btn { padding: 5px 10px; border-radius: 6px; color: #6b7280; font-size: 12px; transition: all .15s; }
.text-btn:hover { background: #f3f4f6; color: #374151; }
.btn-primary { padding: 8px 20px; border-radius: 8px; background: #2563eb; color: #fff; font-weight: 600; transition: background .15s; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { padding: 8px 20px; border-radius: 8px; background: #f3f4f6; color: #374151; font-weight: 500; transition: background .15s; }
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger { padding: 8px 20px; border-radius: 8px; background: #fee2e2; color: #dc2626; font-weight: 500; transition: background .15s; }
.btn-danger:hover { background: #fecaca; }

/* ============================================================
   主体布局
   ============================================================ */
.main-layout {
  position: fixed; top: 52px; bottom: 0; left: 0; right: 0;
  display: flex;
}
#map { flex: 1; height: 100%; }

/* ============================================================
   地图标记
   ============================================================ */
.map-marker {
  width: 36px; height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2.5px solid;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.22);
  transition: transform .15s, box-shadow .15s;
  cursor: pointer;
}
.map-marker:hover { transform: rotate(-45deg) scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.map-marker.selected { transform: rotate(-45deg) scale(1.25); box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.marker-emoji { transform: rotate(45deg); font-size: 17px; line-height: 1; }

/* 印章 / 景点 / 急救站 / 观景台 / 营地 / 停车 / 山峰 / 餐饮 — 默认泪滴形（上方已定义）*/

/* 公交车站 — 横向圆角矩形（标牌感） */
.map-marker.marker-bus {
  width: 34px; height: 22px;
  border-radius: 6px;
  transform: none;
}
.map-marker.marker-bus:hover  { transform: scale(1.15); }
.map-marker.marker-bus.selected { transform: scale(1.25); }
.map-marker.marker-bus .marker-emoji { transform: none; font-size: 14px; }

/* 厕所 — 正圆形 */
.map-marker.marker-toilet {
  width: 28px; height: 28px;
  border-radius: 50%;
  transform: none;
}
.map-marker.marker-toilet:hover   { transform: scale(1.15); }
.map-marker.marker-toilet.selected { transform: scale(1.25); }
.map-marker.marker-toilet .marker-emoji { transform: none; font-size: 14px; }

/* 凉亭 — 圆角正方形（屋顶感） */
.map-marker.marker-shelter {
  width: 30px; height: 30px;
  border-radius: 8px;
  transform: none;
}
.map-marker.marker-shelter:hover   { transform: scale(1.15); }
.map-marker.marker-shelter.selected { transform: scale(1.25); }
.map-marker.marker-shelter .marker-emoji { transform: none; font-size: 16px; }

.user-location-marker {
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(59,130,246,.35); border: 3px solid #2563eb;
  box-shadow: 0 0 0 6px rgba(59,130,246,.15);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(59,130,246,.4); }
  70%  { box-shadow: 0 0 0 12px rgba(59,130,246,0); }
  100% { box-shadow: 0 0 0 0 rgba(59,130,246,0); }
}

/* ============================================================
   侧边栏
   ============================================================ */
.sidebar {
  position: fixed; right: 0; top: 52px; bottom: 0; z-index: 800;
  width: 280px;
  background: #fff; overflow-y: auto;
  box-shadow: -2px 0 10px rgba(0,0,0,.08);
  display: flex; flex-direction: column;
  transition: transform .25s ease;
}
.sidebar.collapsed { transform: translateX(100%); }

.sidebar-section { padding: 16px; border-bottom: 1px solid #f3f4f6; }
.sidebar-section:last-of-type { border-bottom: none; flex: 1; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-header h3 { font-size: 13px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; background: #f3f4f6; font-size: 11px; color: #6b7280; font-weight: 600; }

/* 类别列表 */
#category-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
}
.category-item {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  border-radius: 8px; cursor: pointer; transition: background .15s;
}
.category-item:hover { background: #f9fafb; }
.category-item.active { background: #eff6ff; }
.cat-icon {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.cat-info { flex: 1; min-width: 0; }
.cat-name { font-weight: 500; color: #374151; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-count { font-size: 10px; color: #9ca3af; white-space: nowrap; }
.cat-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.category-item:hover .cat-actions { opacity: 1; }
.cat-route-btn {
  padding: 3px 8px; border-radius: 5px; font-size: 11px; font-weight: 600;
  color: #2563eb; background: #dbeafe; transition: background .15s;
}
.cat-route-btn:hover { background: #bfdbfe; }

.add-category-btn {
  width: 100%; padding: 7px; border-radius: 8px; border: 1.5px dashed #d1d5db;
  color: #9ca3af; font-size: 13px; margin-top: 6px; transition: all .15s;
}
.add-category-btn:hover { border-color: #2563eb; color: #2563eb; background: #eff6ff; }

/* 类别显示切换按钮 */
.cat-toggle-strip {
  display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px;
}
.cat-toggle-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
  border: 1.5px solid #e5e7eb; background: #f3f4f6; color: #9ca3af;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.cat-toggle-btn:hover { opacity: .8; }
.cat-toggle-hidden { opacity: .4; filter: grayscale(1); }

/* 点位列表 */
.waypoint-group { margin-bottom: 12px; }
.waypoint-group-title {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  font-weight: 600; color: #9ca3af; padding: 4px 0; margin-bottom: 4px;
}
.waypoint-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; transition: background .15s;
}
.waypoint-item:hover { background: #f9fafb; }
.waypoint-item:hover .wp-delete { opacity: 1; }
.wp-icon { font-size: 16px; flex-shrink: 0; }
.wp-info { flex: 1; min-width: 0; }
.wp-name { font-size: 13px; font-weight: 500; color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wp-note { font-size: 11px; color: #9ca3af; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wp-delete { opacity: 0; padding: 2px 6px; border-radius: 4px; font-size: 12px; color: #ef4444; background: #fee2e2; transition: opacity .15s; }
.wp-delete:hover { background: #fecaca; }
.wp-route-btn {
  opacity: 0; padding: 3px 8px; border-radius: 5px; font-size: 11px; font-weight: 600;
  color: #2563eb; background: #dbeafe; transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
.wp-route-btn:hover { background: #bfdbfe; }
.waypoint-item:hover .wp-route-btn { opacity: 1; }

.empty-hint { padding: 20px 10px; text-align: center; color: #9ca3af; font-size: 13px; }
.empty-hint p:first-child { font-size: 24px; margin-bottom: 8px; }

/* 侧边栏底部 */
.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid #f3f4f6;
  display: flex; gap: 8px; justify-content: center;
}

/* ============================================================
   距离面板
   ============================================================ */
.distance-panel {
  position: fixed; bottom: 0; left: 0; right: 280px; z-index: 999;
  background: #fff; border-top: 1px solid #e5e7eb;
  box-shadow: 0 -4px 20px rgba(0,0,0,.1);
  padding: 14px 20px; max-height: 220px; overflow-y: auto;
  transform: translateY(100%); transition: transform .3s ease;
}
.distance-panel.visible { transform: translateY(0); }
.sidebar.collapsed ~ * .distance-panel,
.distance-panel.sidebar-collapsed { right: 0; }

.distance-panel-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.distance-panel-header span { font-weight: 700; font-size: 14px; color: #374151; }
.panel-actions { display: flex; align-items: center; gap: 8px; }

.distance-summary { font-size: 14px; color: #6b7280; margin-bottom: 8px; }
.distance-summary strong { color: #1f2937; font-size: 16px; }
.distance-note { font-size: 11px; color: #f59e0b; margin-left: 8px; }

#distance-segments { display: flex; flex-direction: column; gap: 4px; }
.segment-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: #f9fafb; border-radius: 6px; font-size: 12px; color: #6b7280;
}
.segment-item .seg-arrow { color: #d1d5db; }
.segment-item .seg-dist { margin-left: auto; font-weight: 600; color: #374151; }
.segment-item .seg-straight { font-size: 10px; color: #f59e0b; }

/* ============================================================
   模态框
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.visible { opacity: 1; pointer-events: all; }

.modal {
  background: #fff; border-radius: 16px; width: 360px; max-width: 90vw;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  transform: scale(.95) translateY(10px); transition: transform .2s;
}
.modal-overlay.visible .modal { transform: scale(1) translateY(0); }
.modal-sm { width: 300px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 0; margin-bottom: 14px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: #1f2937; }

.modal-body { padding: 0 20px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; overflow-y: auto; }
.modal-body label { font-size: 12px; font-weight: 600; color: #6b7280; margin-top: 4px; }
.modal-body input[type="text"],
.modal-body input[type="color"],
.modal-body select,
.modal-body textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid #e5e7eb; border-radius: 8px;
  color: #1f2937; background: #f9fafb; transition: border-color .15s;
  outline: none;
}
.modal-body input[type="color"] { padding: 4px 8px; height: 36px; }
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus { border-color: #2563eb; background: #fff; }
.modal-body textarea { resize: none; }
.required { color: #ef4444; }
.coord-preview { font-size: 11px; color: #9ca3af; padding: 2px 0; }

.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 20px 20px;
}

/* 详情模态框 */
.detail-category { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #6b7280; margin-bottom: 8px; }
.detail-note { font-size: 13px; color: #374151; line-height: 1.6; margin-bottom: 8px; background: #f9fafb; border-radius: 8px; padding: 8px 12px; }
.detail-note:empty { display: none; }
.detail-coords { font-size: 11px; color: #9ca3af; font-family: monospace; }

/* 时刻表 */
.tt-wrap { margin-top: 12px; }
.tt-label { font-size: 12px; font-weight: 700; color: #1f2937; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.tt-revised { font-size: 10px; font-weight: 400; color: #9ca3af; }
.tt-grid { display: flex; gap: 10px; }
.tt-col { flex: 1; min-width: 0; }
.tt-dir { font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 12px; margin-bottom: 6px; white-space: nowrap; }
.tt-dir-hongu { background: #dbeafe; color: #1d4ed8; }
.tt-dir-tanabe { background: #f3f4f6; color: #374151; }
.tt-times { display: flex; flex-wrap: wrap; gap: 4px; }
.tt-time { font-size: 12px; font-variant-numeric: tabular-nums; padding: 2px 6px; border-radius: 6px; background: #f9fafb; color: #6b7280; border: 1px solid #e5e7eb; }
.tt-time.tt-soon { background: #dcfce7; color: #15803d; border-color: #86efac; font-weight: 700; }
.tt-time.tt-past { color: #d1d5db; border-color: #f3f4f6; background: transparent; }
.tt-empty { font-size: 12px; color: #d1d5db; }
.tt-note { font-size: 10px; color: #9ca3af; margin-top: 8px; }

/* ============================================================
   Toast 提示
   ============================================================ */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2937; color: #fff; padding: 10px 22px;
  border-radius: 24px; font-size: 13px; z-index: 3000;
  opacity: 0; transition: opacity .3s, transform .3s;
  pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #059669; }
.toast.error   { background: #dc2626; }
.toast.warning { background: #d97706; }

/* ============================================================
   加载遮罩
   ============================================================ */
.loading-overlay {
  position: fixed; inset: 0; z-index: 2500;
  background: rgba(255,255,255,.75); backdrop-filter: blur(2px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.loading-overlay.visible { opacity: 1; pointer-events: all; }
.spinner {
  width: 40px; height: 40px; border: 4px solid #e5e7eb;
  border-top-color: #2563eb; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: #6b7280; }

/* ============================================================
   下载离线地图
   ============================================================ */
.dl-info-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; padding: 4px 0; border-bottom: 1px solid #f3f4f6;
}
.dl-info-row span:first-child { color: #9ca3af; }
.dl-info-row span:last-child  { color: #374151; font-weight: 500; }
.dl-progress-wrap { margin: 12px 0 4px; }
.dl-progress-bg {
  height: 8px; background: #f3f4f6; border-radius: 4px; overflow: hidden;
}
.dl-progress-bar {
  height: 100%; width: 0; background: #2563eb; border-radius: 4px;
  transition: width .25s ease;
}
.dl-progress-labels {
  display: flex; justify-content: space-between; margin-top: 4px;
  font-size: 11px; color: #9ca3af;
}
#dl-fail-text { color: #ef4444; }
#dl-status { font-size: 12px; color: #6b7280; min-height: 18px; }
#dl-status.dl-status-ok { color: #059669; font-weight: 600; }

/* ============================================================
   位置共享 — 队伍UI
   ============================================================ */
.room-join-row {
  display: flex; gap: 6px; margin-top: 4px;
}
.room-join-row input {
  flex: 1; text-transform: uppercase; letter-spacing: 2px; font-weight: 700; font-size: 15px;
}
.btn-create-room {
  width: 100%; padding: 7px; border-radius: 8px;
  border: 1.5px dashed #d1d5db; color: #6b7280; font-size: 13px;
  margin-top: 6px; cursor: pointer; background: none; transition: all .15s;
}
.btn-create-room:hover { border-color: #2563eb; color: #2563eb; background: #eff6ff; }

.room-code-display {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  padding: 10px 12px; background: #f0fdf4; border-radius: 8px; border: 1.5px solid #86efac;
}
.room-code-label { font-size: 12px; color: #6b7280; white-space: nowrap; }
.room-code-value { font-size: 22px; letter-spacing: 4px; color: #059669; flex: 1; font-family: monospace; }
.btn-copy {
  padding: 4px 10px; border-radius: 6px; background: #dcfce7;
  color: #059669; font-size: 12px; font-weight: 600; cursor: pointer; border: none;
  transition: background .15s;
}
.btn-copy:hover { background: #bbf7d0; }

/* ============================================================
   位置共享 — 队员标记
   ============================================================ */
.teammate-marker {
  width: 36px; height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: #7c3aed; border: 2.5px solid #6d28d9;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  cursor: pointer;
}
.teammate-marker span {
  transform: rotate(45deg);
  color: #fff; font-size: 15px; font-weight: 700; line-height: 1;
}
.teammate-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #7c3aed; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.team-member-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 6px; border-radius: 8px; transition: background .15s;
}
.team-member-item:hover { background: #f9fafb; }

/* ============================================================
   Leaflet 覆盖
   ============================================================ */
.leaflet-popup-content-wrapper { border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.leaflet-popup-content { margin: 12px 16px; }
.popup-name { font-weight: 700; font-size: 14px; color: #1f2937; margin-bottom: 4px; }
.popup-cat { font-size: 12px; color: #6b7280; margin-bottom: 4px; }
.popup-note { font-size: 12px; color: #374151; margin-bottom: 8px; }
.popup-actions { display: flex; gap: 6px; }
.popup-btn {
  padding: 4px 10px; border-radius: 5px; font-size: 12px; cursor: pointer; border: none;
}
.popup-btn-detail { background: #dbeafe; color: #2563eb; }
.popup-btn-delete { background: #fee2e2; color: #dc2626; }

/* ============================================================
   添加模式提示条
   ============================================================ */
.add-mode-banner {
  position: fixed; top: 52px; left: 0; right: 0; z-index: 900;
  background: #2563eb; color: #fff; text-align: center;
  padding: 8px; font-size: 13px; font-weight: 600;
  pointer-events: none;
}

/* ============================================================
   响应式 — 移动端
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { width: 260px; }
  .distance-panel { right: 0 !important; }
  .toolbar-center { display: none; }
  .app-title { font-size: 14px; }
}
@media (max-width: 480px) {
  .sidebar { width: 100%; }
  .modal { width: 95vw; }
}
