.diagram-bezier-control,
.diagram-waypoint,
.diagram-waypoint-add {
  cursor: grab;
  touch-action: none;
}

.diagram-bezier-control,
.diagram-waypoint {
  transition: fill 80ms ease, stroke 80ms ease;
}

.diagram-bezier-control:hover,
.diagram-waypoint:hover {
  fill: var(--diagram-control-soft);
  stroke: var(--diagram-control-hover);
}

.diagram-bezier-control:active,
.diagram-waypoint:active,
.diagram-waypoint-add:active {
  cursor: grabbing;
}

.diagram-waypoint-add {
  opacity: 0.4;
  transition: opacity 120ms ease;
}

.diagram-waypoint-add:hover {
  opacity: 1;
}

.diagram-waypoint-add:hover circle {
  fill: var(--diagram-control-soft);
}

.diagram-route-failed > path:nth-child(2) {
  stroke: var(--diagram-route-warning);
  stroke-dasharray: 8 4;
}

.diagram-quick-create {
  position: absolute;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 320px;
  min-width: 0;
  max-width: calc(100% - 16px);
  max-height: calc(100% - 24px);
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 32px var(--shadow);
  overflow-x: hidden;
  overflow-y: auto;
  user-select: none;
  animation: diagram-quick-enter 160ms var(--transition-ease) both;
}

.diagram-quick-header {
  display: flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.diagram-quick-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  min-width: 0;
}

.diagram-quick-shape {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 72px;
  padding: 8px 4px;
  border: 2px solid var(--transparent);
  border-radius: 6px;
  background: var(--transparent);
  color: var(--secondary);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, transform 80ms ease;
}

.diagram-quick-shape:hover {
  background: var(--hover);
  color: var(--brand);
  border-color: var(--border);
}

.diagram-quick-shape:active {
  transform: scale(0.94);
}

.diagram-quick-shape:focus-visible {
  outline: none;
  border-color: var(--brand);
}

.diagram-quick-shape svg {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}

.diagram-quick-label {
  display: block;
  width: 100%;
  min-width: 0;
  color: inherit;
  font-size: 10px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diagram-toolbar-shapes {
  top: auto;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  animation: diagram-toolbar-shapes-enter 160ms var(--transition-ease) both;
}

.diagram-advanced-properties {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding-top: 12px;
  border-top: 2px solid var(--border);
}

.diagram-advanced-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.diagram-coordinate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.diagram-toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  color: var(--secondary);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.diagram-toggle-row input {
  position: absolute;
  right: 0;
  width: 40px;
  height: 24px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.diagram-toggle-track {
  position: relative;
  display: block;
  flex-shrink: 0;
  width: 40px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--background);
  pointer-events: none;
  transition: background 160ms ease, border-color 160ms ease;
}

.diagram-toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--muted);
  transition: transform 160ms var(--transition-ease), background 160ms ease;
}

.diagram-toggle-row input:checked + .diagram-toggle-track {
  border-color: var(--brand);
  background: var(--brand);
}

.diagram-toggle-row input:checked + .diagram-toggle-track::after {
  background: var(--black);
  transform: translateX(16px);
}

.diagram-toggle-row input:focus-visible + .diagram-toggle-track {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.diagram-waypoint-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.diagram-waypoint-list:empty {
  display: none;
}

.diagram-waypoint-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--background);
}

.diagram-waypoint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
  color: var(--secondary);
  font-size: 12px;
}

.diagram-waypoint-header button {
  width: 24px;
  height: 24px;
  padding: 4px;
}

.diagram-waypoint-header button:hover {
  color: var(--danger);
}

.diagram-waypoint-header svg {
  width: 14px;
  height: 14px;
}

.diagram-reset-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--background);
  color: var(--secondary);
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.diagram-reset-button:hover {
  border-color: var(--muted);
  background: var(--hover);
  color: var(--white);
}

.diagram-route-warning {
  padding: 8px;
  border-radius: 6px;
  background: var(--diagram-route-warning-soft);
  color: var(--diagram-route-warning);
  font-size: 12px;
  line-height: 160%;
  overflow-wrap: anywhere;
}

@keyframes diagram-quick-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes diagram-toolbar-shapes-enter {
  from {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .diagram-quick-create,
  .diagram-toolbar-shapes {
    animation: none;
  }

  .diagram-toggle-track,
  .diagram-toggle-track::after,
  .diagram-quick-shape {
    transition: none;
  }
}