/* Benchtop — breadboard layout. Boxes (UI Elements) are absolutely-positioned
   cards on a dotted canvas; wires are drawn as SVG paths on an overlay. */

.benchtop {
  display: flex;
  position: fixed;
  top: 57px; /* below the fixed top nav */
  left: 0;
  right: 0;
  bottom: 0;
  background: #f8fafc;
}

/* ── Palette ─────────────────────────────────────────────── */
.benchtop__palette {
  width: 16rem;
  flex: 0 0 16rem;
  overflow-y: auto;
  border-right: 1px solid #e5e7eb;
  background: #ffffff;
  padding: 1rem;
}

.benchtop__palette-header {
  margin-bottom: 1rem;
}

.benchtop__new-place {
  margin-top: 0.75rem;
  width: 100%;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 0.375rem;
  padding: 0.375rem 0.5rem;
  cursor: pointer;
}
.benchtop__new-place:hover {
  background: #dbeafe;
}

.benchtop__section {
  margin-bottom: 1rem;
}

.benchtop__section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  margin-bottom: 0.5rem;
}

.benchtop__count {
  font-weight: 500;
  color: #9ca3af;
  background: #f3f4f6;
  border-radius: 9999px;
  padding: 0 0.5rem;
}

.benchtop__chips {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.benchtop__chip {
  font-size: 0.8125rem;
  padding: 0.375rem 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid #e5e7eb;
  border-left: 3px solid #2563eb;
  background: #ffffff;
  cursor: grab;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.benchtop__chip:hover {
  background: #f9fafb;
}
.benchtop__chip:active {
  cursor: grabbing;
}

.benchtop__empty {
  font-size: 0.75rem;
  color: #9ca3af;
  font-style: italic;
}

/* ── Canvas ──────────────────────────────────────────────── */
.benchtop__canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
}

.benchtop__canvas {
  position: absolute;
  inset: 0;
  background-color: #f8fafc;
  background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
  background-size: 20px 20px;
  touch-action: none;
}

.benchtop__wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* Pan/zoom layer — boxes live here; the transform handles pan + zoom. It must
   not capture pointer events so empty-canvas clicks reach the canvas itself. */
.benchtop__world {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  pointer-events: none;
}

.benchtop__wire {
  fill: none;
  stroke: #2563eb;
  stroke-width: 2;
  pointer-events: stroke;
  cursor: pointer;
}
.benchtop__wire:hover {
  stroke: #1d4ed8;
  stroke-width: 3;
}
.benchtop__wire--temp {
  stroke: #93c5fd;
  stroke-dasharray: 5 4;
  pointer-events: none;
}

/* Local sketch connection (text boxes / informal links). */
.benchtop__wire--sketch {
  stroke: #94a3b8;
  stroke-dasharray: 6 5;
}
.benchtop__wire--sketch:hover {
  stroke: #64748b;
}

.benchtop__wire-label {
  fill: #475569;
  font-size: 11px;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #f8fafc;
  stroke-width: 3px;
}

.benchtop__hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #94a3b8;
  font-size: 0.9375rem;
  pointer-events: none;
  text-align: center;
}

/* ── Boxes (UI Element places) ───────────────────────────── */
.benchtop__box {
  position: absolute;
  min-width: 12rem;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
  z-index: 1;
  pointer-events: auto;
}

.benchtop__box-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.375rem;
  padding: 0.5rem 0.625rem;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  border-radius: 0.5rem 0.5rem 0 0;
  cursor: grab;
  user-select: none;
}
.benchtop__box-header:active {
  cursor: grabbing;
}

.benchtop__box-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.benchtop__box-remove {
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}
.benchtop__box-remove:hover {
  color: #ef4444;
}

/* Text sketch box — a quick, local idea before it becomes a UI Element. */
.benchtop__box--text {
  background: #fefce8;
  border-color: #fde68a;
}
.benchtop__box--text .benchtop__box-header {
  background: #fef9c3;
  border-bottom-color: #fde68a;
}

.benchtop__grip {
  color: #a8a29e;
  font-size: 0.875rem;
  line-height: 1;
  cursor: grab;
}

.benchtop__text-input {
  flex: 1 1 auto;
  min-width: 6rem;
  border: none;
  background: transparent;
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
  padding: 0;
}
.benchtop__text-input:focus {
  outline: none;
}

.benchtop__upgrade {
  width: 100%;
  font-size: 0.75rem;
  font-weight: 500;
  color: #b45309;
  background: transparent;
  border: 1px dashed #fcd34d;
  border-radius: 0.375rem;
  padding: 0.25rem;
  cursor: pointer;
}
.benchtop__upgrade:hover {
  background: #fef3c7;
}

.benchtop__box-body {
  padding: 0.25rem 0;
}

.benchtop__affordance {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3125rem 0.75rem;
  font-size: 0.8125rem;
  color: #334155;
}
.benchtop__affordance:hover {
  background: #f8fafc;
}

.benchtop__affordance-name {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.benchtop__row-marker {
  flex: 0 0 auto;
  color: #94a3b8;
  font-size: 0.75rem;
  line-height: 1;
}

.benchtop__child-input {
  flex: 1 1 auto;
  min-width: 5rem;
  border: none;
  background: transparent;
  font-size: 0.8125rem;
  color: #334155;
  padding: 0;
}
.benchtop__child-input:focus {
  outline: none;
}

.benchtop__row-remove {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: #cbd5e1;
  font-size: 0.875rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  opacity: 0;
}
.benchtop__affordance:hover .benchtop__row-remove {
  opacity: 1;
}
.benchtop__row-remove:hover {
  color: #ef4444;
}

/* Add-child menu (UI Element / Text). */
.benchtop__menu {
  display: flex;
  flex-direction: column;
  min-width: 9rem;
}
.benchtop__menu-item {
  text-align: left;
  font-size: 0.8125rem;
  color: #334155;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  padding: 0.5rem 0.625rem;
  cursor: pointer;
}
.benchtop__menu-item:hover {
  background: #f1f5f9;
}

.benchtop__handle {
  position: absolute;
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 9999px;
  border: 2px solid #ffffff;
  cursor: crosshair;
}

/* Affordance handle → a real, persisted interaction (wire). */
.benchtop__handle--wire {
  background: #2563eb;
  box-shadow: 0 0 0 1px #2563eb;
}
.benchtop__handle--wire:hover {
  background: #1d4ed8;
}

/* Box handle → a local sketch connection. */
.benchtop__handle--link {
  background: #94a3b8;
  box-shadow: 0 0 0 1px #94a3b8;
}
.benchtop__handle--link:hover {
  background: #64748b;
}

.benchtop__box-footer {
  padding: 0.375rem 0.625rem 0.5rem;
  border-top: 1px solid #f1f5f9;
}

.benchtop__add-affordance {
  width: 100%;
  font-size: 0.75rem;
  font-weight: 500;
  color: #2563eb;
  background: transparent;
  border: 1px dashed #bfdbfe;
  border-radius: 0.375rem;
  padding: 0.25rem;
  cursor: pointer;
}
.benchtop__add-affordance:hover {
  background: #eff6ff;
}

/* ── Find-or-create popover ──────────────────────────────── */
.benchtop__popover {
  position: fixed;
  z-index: 50;
  width: 20rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.15);
  padding: 1rem;
}

.benchtop__form-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 0.75rem;
}

.benchtop__form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: #374151;
  margin: 0.5rem 0 0.25rem;
}

.benchtop__form-hint {
  font-weight: 400;
  color: #9ca3af;
}

.benchtop__form-input {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.625rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
}

.benchtop__form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.benchtop__form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.benchtop__form-cancel {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
  background: #f3f4f6;
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  cursor: pointer;
}

.benchtop__form-submit {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #ffffff;
  background: #2563eb;
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  cursor: pointer;
}
.benchtop__form-submit:hover {
  background: #1d4ed8;
}
