* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  color: #333;
}

/* ── Sidebar ───────────────────────────────────── */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: #fff;
  border-right: 1px solid #e8e8e8;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 12px 14px 8px;
  border-bottom: 1px solid #f0f0f0;
  background: #1677ff;
}

#sidebar-header h1 {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.ctrl-section {
  padding: 8px 12px;
  border-bottom: 1px solid #f5f5f5;
}

.ctrl-label {
  display: block;
  font-size: 11px;
  color: #888;
  margin-bottom: 4px;
}

#route-select {
  width: 100%;
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  outline: none;
}

#route-select:focus {
  border-color: #1677ff;
}

/* ── Direction Switch ───────────────────────────── */
.direction-switch .dir-btn-group {
  display: flex;
  gap: 0;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  overflow: hidden;
}

.dir-btn {
  flex: 1;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  border: none;
  background: #fafafa;
  color: #333;
  transition: all 0.15s;
  text-align: center;
}

.dir-btn:not(:last-child) {
  border-right: 1px solid #d9d9d9;
}

.dir-btn:hover:not(.active) {
  background: #f0f0f0;
}

.dir-btn.active {
  background: #1677ff;
  color: #fff;
  font-weight: 600;
}

.btn-row {
  display: flex;
  gap: 6px;
}

.btn-row button {
  flex: 1;
  padding: 5px 4px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  background: #fafafa;
  transition: all 0.15s;
}

.btn-row button:hover:not(:disabled) {
  background: #f0f0f0;
  border-color: #bbb;
}

.btn-row button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-row button.active {
  background: #fff7e6;
  border-color: #fa8c16;
  color: #d46b08;
  font-weight: 600;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 7px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: #1677ff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) {
  background: #0958d9;
}

.btn-primary:disabled {
  background: #91caff;
  cursor: not-allowed;
}

#status {
  padding: 5px 12px;
  font-size: 11px;
  color: #666;
  min-height: 22px;
  line-height: 1.4;
  word-break: break-all;
  border-bottom: 1px solid #f5f5f5;
}

#stop-list-header {
  padding: 5px 12px;
  font-size: 11px;
  color: #888;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid #f0f0f0;
}

.badge-warn {
  color: #ff4d4f;
  font-weight: 600;
}

/* ── Stop list ──────────────────────────────────── */
#stop-list {
  flex: 1;
  overflow-y: auto;
}

.stop-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f7f7f7;
  transition: background 0.1s;
}

.stop-item:hover {
  background: #f0f7ff;
}

.stop-item.no-pos {
  opacity: 0.7;
}

.stop-item.selected {
  background: #e6f4ff;
}

.stop-item.placing {
  background: #fff7e6;
  border-left: 3px solid #fa8c16;
}

.stop-seq {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #1677ff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.no-pos .stop-seq {
  background: #bfbfbf;
}

.placing .stop-seq {
  background: #fa8c16;
}

.stop-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.stop-status {
  font-size: 11px;
  flex-shrink: 0;
  color: #52c41a;
}

.no-pos .stop-status {
  color: #ff4d4f;
}

/* ── Map ────────────────────────────────────────── */
#map-container {
  flex: 1;
  height: 100vh;
}

/* ── Custom map markers ─────────────────────────── */
.amap-marker-content {
  cursor: grab;
}

.stop-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #1677ff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  user-select: none;
  pointer-events: none;
}

.stop-marker.placing-target {
  background: #fa8c16;
  border-color: #fff;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.2); }
}

/* Auto-inserted stop marker (orange) */
.stop-marker.auto-inserted {
  background: #fa8c16;
}

/* Auto-inserted stop in sidebar list */
.stop-item.auto-inserted {
  background: #fff7e6;
  border-left: 3px solid #fa8c16;
}

.stop-item.auto-inserted .stop-seq {
  background: #fa8c16;
}

/* Move buttons for auto-inserted stops */
.btn-move {
  background: none;
  border: 1px solid #d9d9d9;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  padding: 1px 4px;
  margin: 0 1px;
  line-height: 1;
  color: #666;
}

.btn-move:hover {
  background: #f0f0f0;
  border-color: #999;
  color: #333;
}

/* ── Loading Overlay ────────────────────────────── */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-content {
  background: #fff;
  border-radius: 8px;
  padding: 32px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e8e8e8;
  border-top-color: #1677ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: #333;
  font-weight: 500;
}
