/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  background: #f5f5f5;
}

/* ===== Map ===== */
#map {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1;
}

/* ===== Custom Marker ===== */
.custom-marker-icon {
  background: none !important;
  border: none !important;
}

/* ===== Custom Popup ===== */
.custom-popup .leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  padding: 0;
  overflow: hidden;
}
.custom-popup .leaflet-popup-content {
  margin: 0;
  min-width: 220px;
}
.custom-popup .leaflet-popup-tip {
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
}

.marker-popup {
  padding: 14px 16px 10px;
}
.marker-popup h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 210px;
}
.marker-popup .popup-category {
  font-size: 11px;
  color: #888;
  margin-bottom: 6px;
}
.marker-popup .popup-desc {
  font-size: 12px;
  color: #555;
  line-height: 1.5;
  margin-bottom: 6px;
  word-break: break-all;
}
.marker-popup .popup-coords {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 10px;
}
.marker-popup .popup-actions {
  display: flex;
  gap: 6px;
}
.marker-popup .popup-actions button {
  flex: 1;
  padding: 5px 0;
  font-size: 12px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.marker-popup .btn-edit { background: #e3f2fd; color: #1565c0; }
.marker-popup .btn-edit:hover { background: #bbdefb; }
.marker-popup .btn-delete { background: #fce4ec; color: #c62828; }
.marker-popup .btn-delete:hover { background: #f8bbd0; }
.marker-popup .btn-route { background: #e8f5e9; color: #2e7d32; }
.marker-popup .btn-route:hover { background: #c8e6c9; }

/* ===== Toolbar ===== */
#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  background: #2196F3;
  color: #fff;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.toolbar-title {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}
.toolbar-actions {
  display: flex;
  gap: 6px;
}
.toolbar-btn {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.toolbar-btn:hover { background: rgba(255,255,255,0.32); }
.toolbar-btn span { margin-right: 2px; }

/* ===== Side Panel ===== */
#side-panel {
  position: fixed;
  top: 50px; right: 0; bottom: 36px;
  width: 280px;
  z-index: 999;
  background: #fff;
  box-shadow: -2px 0 12px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}
#side-panel.collapsed {
  transform: translateX(100%);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
}
.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: #333;
}
.btn-icon {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #999;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-icon:hover { background: #f0f0f0; color: #333; }
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Marker List Item */
.marker-item {
  display: flex;
  align-items: flex-start;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.marker-item:hover {
  background: #f5f5f5;
}
.marker-item.active {
  background: #e3f2fd;
}
.marker-item .item-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  margin-right: 10px;
  flex-shrink: 0;
}
.marker-item .item-info {
  flex: 1;
  min-width: 0;
}
.marker-item .item-name {
  font-size: 13px;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.marker-item .item-desc {
  font-size: 11px;
  color: #999;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.marker-item .item-actions {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}
.marker-item:hover .item-actions { opacity: 1; }
.marker-item .item-actions button {
  background: #f0f0f0;
  border: none;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  cursor: pointer;
  color: #666;
}
.marker-item .item-actions button:hover { background: #e0e0e0; }
.marker-item .route-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  background: #2196F3;
  color: white;
  font-size: 10px;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.empty-hint {
  text-align: center;
  color: #bbb;
  font-size: 13px;
  padding: 40px 16px;
}

/* ===== Status Bar ===== */
#status-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1000;
  height: 36px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 13px;
  color: #666;
}
#route-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
#route-separator { color: #ddd; }
#route-distance { font-weight: 600; color: #2196F3; }
#route-waypoints span:first-child { color: #999; }
#waypoint-names { color: #555; }

/* ===== Marker Form Overlay ===== */
#marker-form-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}
#marker-form-overlay.hidden {
  display: none;
}

.form-container {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  padding: 24px;
  width: 360px;
  max-width: 90vw;
  animation: formIn 0.25s ease;
}
@keyframes formIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.form-container h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 18px;
  color: #333;
}
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  margin-bottom: 5px;
}
.required { color: #e74c3c; }
.form-group input[type="text"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: #2196F3;
  box-shadow: 0 0 0 3px rgba(33,150,243,0.12);
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.btn {
  flex: 1;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #2196F3; color: #fff; }
.btn-primary:hover { background: #1976D2; }
.btn-secondary { background: #f0f0f0; color: #666; }
.btn-secondary:hover { background: #e0e0e0; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  #toolbar {
    height: 44px;
    padding: 0 10px;
  }
  .toolbar-title { font-size: 15px; }
  .toolbar-btn { font-size: 12px; padding: 5px 8px; }
  .toolbar-btn span { display: none; }
  #side-panel { width: 260px; }
  #status-bar { font-size: 12px; height: 32px; padding: 0 10px; }
}
