* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  display: flex;
  height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #1a1a1a;
}

/* Sidebar */
#sidebar {
  width: 440px;
  min-width: 440px;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
  background: #fafafa;
  border-right: 1px solid #ddd;
  position: relative;
}

h1 { font-size: 1.4rem; }
.subtitle { font-size: 0.85rem; color: #666; margin-bottom: 16px; }
h2 { font-size: 1rem; margin: 16px 0 8px; }
.hint { font-size: 0.8rem; color: #888; margin-bottom: 10px; }

#btn-logout {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* Phase bar */
#phase-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}
.phase-step {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e8e8e8;
  border-radius: 4px;
  color: #999;
}
.phase-step.active { background: #2563eb; color: #fff; }
.phase-step.done { background: #16a34a; color: #fff; }

/* Panels */
.panel { animation: fadeIn 0.15s ease; }
.hidden { display: none !important; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}
.form-group label { font-size: 0.8rem; font-weight: 600; }
.form-group input, textarea {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
}
textarea { font-family: monospace; resize: vertical; }
.form-check label { font-size: 0.8rem; font-weight: 600; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; }
.inline-check { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8rem; font-weight: 600; cursor: pointer; margin-top: 4px; }
.inline-check input[type="checkbox"] { width: 14px; height: 14px; }
details { margin: 10px 0; }
summary { cursor: pointer; font-size: 0.85rem; font-weight: 600; }

/* Buttons */
button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: #2563eb; color: #fff; width: 100%; margin-top: 12px; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-secondary { background: #e5e7eb; color: #1a1a1a; }
.btn-secondary:hover { background: #d1d5db; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row .btn-primary { flex: 1; margin-top: 0; }
.btn-row .btn-secondary { flex: 0; white-space: nowrap; }
#btn-toggle-clusters { min-width: 124px; }
#btn-toggle-corrected { min-width: 140px; }

#btn-import-csv { margin-top: 6px; background: #e5e7eb; }
.btn-upload {
  display: inline-block;
  padding: 8px 16px;
  background: #2563eb;
  color: #fff;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-upload:hover { background: #1d4ed8; }
.csv-section { margin: 10px 0; }

/* Points list */
#points-list {
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 10px;
}
.point-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  font-size: 0.8rem;
  border-bottom: 1px solid #eee;
}
.point-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.point-actions { display: flex; gap: 2px; flex-shrink: 0; }
.point-btn {
  cursor: pointer;
  font-weight: bold;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 0.85rem;
  line-height: 1;
}
.point-btn:hover { background: #e5e7eb; }
.point-btn.remove { color: #ef4444; }
.point-btn.edit { color: #666; }
.point-btn.save { color: #16a34a; }
.point-btn.cancel { color: #ef4444; }
.point-item input { padding: 2px 4px; font-size: 0.75rem; border: 1px solid #ccc; border-radius: 3px; }

/* Centroids / clusters list */
#centroids-list, #clusters-summary {
  max-height: 260px;
  overflow-y: auto;
  font-size: 0.8rem;
}
#routes-summary {
  font-size: 0.8rem;
}
.centroid-item, .cluster-item, .route-item {
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}
.route-header {
  cursor: pointer;
  user-select: none;
}
.route-stops {
  width: 100%;
  padding-left: 20px;
  font-size: 0.75rem;
  color: #555;
}
.route-stops.hidden {
  display: none;
}
.stop-item {
  padding: 3px 6px;
  border-bottom: 1px solid #f0f0f0;
  cursor: grab;
  border-radius: 3px;
  transition: background 0.1s;
}
.stop-item:active { cursor: grabbing; }
.stop-item:hover {
  background: #f0f4ff;
}
.stop-item.selected {
  background: #dbeafe;
  font-weight: 600;
}
.stop-item.dragging {
  opacity: 0.4;
  background: #e5e7eb;
}
.stop-item.drop-above {
  box-shadow: 0 -2px 0 0 #2563eb;
}
.stop-item.drop-below {
  box-shadow: 0 2px 0 0 #2563eb;
}
.cluster-item.draggable-cluster { cursor: grab; }
.cluster-item.draggable-cluster:active { cursor: grabbing; }
.cluster-item.dragging { opacity: 0.4; background: #e5e7eb; }
.cluster-item.drop-above { box-shadow: 0 -2px 0 0 #2563eb; }
.cluster-item.drop-below { box-shadow: 0 2px 0 0 #2563eb; }
.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Undeliverable clusters/routes */
.undeliverable { opacity: 0.55; }
.undeliverable span:not(.color-dot) { color: #888; }
.btn-toggle-deliver {
  margin-left: auto;
  padding: 2px 8px;
  font-size: 0.7rem;
  background: #e5e7eb;
  border-radius: 4px;
  cursor: pointer;
}
.btn-toggle-deliver:hover { background: #d1d5db; }
.undeliverable .btn-toggle-deliver { background: #dbeafe; color: #2563eb; }
.undeliverable .btn-toggle-deliver:hover { background: #bfdbfe; }

/* Assignments list */
#assignments-list {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.8rem;
}
.assignment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-bottom: 1px solid #eee;
}
.assignment-label { min-width: 40px; }
.assignment-item.selected {
  background: #dbeafe;
  border-radius: 4px;
}
.cluster-select {
  padding: 2px 4px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.8rem;
  margin-left: auto;
}

/* Endpoint badges (start/end of clusters) */
.endpoint-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.endpoint-badge.start { background: #16a34a; }
.endpoint-badge.end { background: #dc2626; }
.cluster-endpoints {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  margin-top: 4px;
  padding-left: 22px;
}
.btn-set-endpoint {
  padding: 1px 6px;
  font-size: 0.7rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #f9fafb;
  cursor: pointer;
  margin-right: 6px;
}
.btn-set-endpoint:hover { background: #e5e7eb; }
.endpoint-link { color: #2563eb; text-decoration: none; font-weight: 600; cursor: pointer; }
.endpoint-link:hover { text-decoration: underline; }
.cluster-start { border-left: 3px solid #16a34a; }
.cluster-end { border-left: 3px solid #dc2626; }

/* Map endpoint markers */
.endpoint-map-badge {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  border: 2px solid #fff;
}
.endpoint-map-badge.start { background: #16a34a; }
.endpoint-map-badge.end { background: #dc2626; }

/* Loading */
#loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 1000;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #ddd;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Previous jobs */
.jobs-section { margin-top: 16px; }
.jobs-list {
  max-height: 240px;
  overflow-y: auto;
  margin-top: 6px;
}
.job-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  font-size: 0.8rem;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s;
}
.job-item:hover { background: #f0f4ff; }
.job-meta { color: #888; font-size: 0.72rem; }

/* Map */
#map { flex: 1; height: 100vh; }
