/* === Wiring Mode — Dual-Pane Layout, Wire UI, Mode Toggle === */

/* ─── Mode Toggle ──────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  background: var(--bg-dark);
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-left: 8px;
}

.mode-btn {
  padding: 4px 14px;
  font-size: 11px;
  font-weight: 600;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mode-btn:hover {
  color: var(--text-primary);
  background: rgba(91, 141, 239, 0.1);
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ─── Wiring Container (Dual Pane) ─────────────────────────── */
#wiring-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  background: var(--bg-dark);
}

.wiring-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 200px;
}

.pane-header {
  height: 26px;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  flex-shrink: 0;
}

.pane-header-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.pane-header-info {
  font-size: 9px;
  color: var(--text-dim);
}

/* ─── View Mode Toggle (Subway / Submittal) ──────────────── */
.view-mode-toggle {
  display: flex;
  background: var(--bg-dark);
  border-radius: 4px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.view-mode-btn {
  padding: 2px 10px;
  font-size: 9px;
  font-weight: 600;
  background: transparent;
  color: var(--text-dim);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.view-mode-btn:hover {
  color: var(--text-primary);
  background: rgba(91, 141, 239, 0.1);
}

.view-mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.pane-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #1a1a2a;
}

.pane-canvas-wrap canvas {
  position: absolute;
  top: 0;
  left: 0;
}

/* ─── Pane Divider (Draggable) ─────────────────────────────── */
.pane-divider {
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s ease;
}

.pane-divider:hover,
.pane-divider.dragging {
  background: var(--accent);
}

.pane-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 24px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
}

.pane-divider:hover::after {
  background: rgba(255, 255, 255, 0.3);
}

/* ─── Wire List Panel (Left Panel in Wiring Mode) ──────────── */
#wire-list-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.wire-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.wire-list-search {
  width: 100%;
  padding: 4px 8px;
  margin: 4px 8px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
  outline: none;
}

.wire-list-search:focus {
  border-color: var(--accent);
}

.wire-list-items {
  overflow-y: auto;
  flex: 1;
}

.wire-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 11px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.1s;
}

.wire-list-item:hover {
  background: rgba(91, 141, 239, 0.08);
}

.wire-list-item.highlighted {
  background: rgba(91, 141, 239, 0.2);
  border-left: 3px solid var(--accent);
  padding-left: 5px;
}

.wire-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.wire-list-number {
  font-weight: 600;
  min-width: 32px;
  color: var(--text-primary);
}

.wire-list-route {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 10px;
}

.wire-list-gauge {
  font-size: 9px;
  color: var(--text-dim);
  min-width: 36px;
  text-align: right;
}

/* ─── Wire Properties Panel (Right Panel in Wiring Mode) ───── */
#wire-props-panel {
  display: none;
}

.wire-prop-section {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.wire-prop-section h4 {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin: 0 0 6px 0;
}

.wire-prop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.wire-prop-label {
  font-size: 10px;
  color: var(--text-dim);
  min-width: 60px;
}

.wire-prop-value {
  font-size: 11px;
  color: var(--text-primary);
  flex: 1;
}

.wire-prop-select {
  width: 100%;
  padding: 3px 6px;
  font-size: 11px;
  background: var(--bg-dark);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 3px;
  outline: none;
}

.wire-prop-select:focus {
  border-color: var(--accent);
}

.wire-prop-input {
  width: 100%;
  padding: 3px 6px;
  font-size: 11px;
  background: var(--bg-dark);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 3px;
  outline: none;
}

.wire-prop-input:focus {
  border-color: var(--accent);
}

/* ─── Component Library Browser ────────────────────────────── */
.comp-library-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px 8px;
}

.comp-library-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 9px;
  color: var(--text-secondary);
  text-align: center;
  transition: all 0.1s;
  gap: 2px;
}

.comp-library-item:hover {
  background: rgba(91, 141, 239, 0.1);
  border-color: var(--accent);
  color: var(--text-primary);
}

.comp-library-item img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

/* ─── Wiring Toolbar Tweaks ────────────────────────────────── */
#wiring-tools {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0 8px;
}

/* ─── Circuit Color Legend ──────────────────────────────────── */
.circuit-legend {
  padding: 4px 8px;
}

.circuit-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  font-size: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s, opacity 0.15s;
  user-select: none;
}

.circuit-legend-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.circuit-legend-item.legend-active {
  background: rgba(91, 141, 239, 0.15);
  color: #d0d8e8;
}

.circuit-legend-item.legend-dimmed {
  opacity: 0.35;
}

.circuit-legend-item.legend-clear {
  margin-top: 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 4px;
}

.circuit-legend-line {
  width: 20px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ─── Circuit Editor Popup ─────────────────────────────────── */
.circuit-editor-popup {
  position: fixed;
  z-index: 1001;
  width: 260px;
  background: #1e2030;
  border: 1px solid rgba(91, 141, 239, 0.3);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
}

.circuit-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(91, 141, 239, 0.1);
  border-bottom: 1px solid rgba(91, 141, 239, 0.15);
  font-size: 11px;
  font-weight: 600;
  color: #a0b0d0;
}

.circuit-editor-close {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 16px;
  padding: 0 2px;
}

.circuit-editor-close:hover { color: #ff6666; }

.circuit-editor-body {
  padding: 10px 12px;
}

.circuit-editor-row {
  margin-bottom: 8px;
}

.circuit-editor-row label {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8090a8;
  margin-bottom: 3px;
}

.circuit-editor-input,
.circuit-editor-row select {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  color: #d0d8e8;
  outline: none;
  box-sizing: border-box;
}

.circuit-editor-input:focus,
.circuit-editor-row select:focus {
  border-color: rgba(91, 141, 239, 0.4);
}

.circuit-editor-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.circuit-editor-color-row input[type="color"] {
  width: 32px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.circuit-editor-hex {
  font-size: 11px;
  color: #8090a8;
  font-family: 'Roboto Mono', monospace;
}

.circuit-editor-row input[type="range"] {
  width: calc(100% - 40px);
  vertical-align: middle;
}

.circuit-editor-row #ce-width-val {
  font-size: 10px;
  color: #8090a8;
  margin-left: 4px;
}

.circuit-editor-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.circuit-editor-btn {
  flex: 1;
  padding: 5px 10px;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  background: #5b8def;
  color: #fff;
}

.circuit-editor-btn:hover { background: #4a7de0; }

.circuit-editor-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #a0b0d0;
}

.circuit-editor-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ─── Toggle button (Decrowd) ─────────────────────────────── */
.toggle-btn.active {
  background: rgba(91, 141, 239, 0.25) !important;
  color: #5b8def !important;
  border-color: rgba(91, 141, 239, 0.4) !important;
}

/* ─── Pane Status Bar ──────────────────────────────────────── */
.pane-status {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20px;
  background: rgba(26, 26, 42, 0.9);
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 9px;
  color: var(--text-dim);
  gap: 12px;
  z-index: 5;
}

.pane-status-coord {
  font-family: 'Courier New', monospace;
}

/* ─── Field Device Popup ─────────────────────────────────── */
.field-popup {
  position: fixed;
  z-index: 1000;
  min-width: 300px;
  max-width: 360px;
  background: var(--bg-mid, #1e1e2e);
  border: 1px solid var(--accent, #5b8def);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 12px rgba(91,141,239,0.15);
  font-family: 'Roboto Mono', Consolas, monospace;
  color: var(--text-primary, #e0e0e0);
  overflow: hidden;
}

.field-popup.hidden {
  display: none;
}

.field-popup-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(91, 141, 239, 0.1);
  border-bottom: 1px solid rgba(91, 141, 239, 0.2);
}

.field-popup-icon {
  font-size: 16px;
}

.field-popup-tag {
  font-weight: 700;
  font-size: 13px;
  color: #5b8def;
}

.field-popup-label {
  font-size: 11px;
  color: var(--text-secondary, #a0a8b8);
  flex: 1;
}

.field-popup-close {
  background: none;
  border: none;
  color: var(--text-dim, #666);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.field-popup-close:hover {
  color: #ff6666;
}

.field-popup-body {
  padding: 10px 12px;
}

.field-popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
}

.fp-key {
  font-size: 10px;
  color: var(--text-dim, #777);
  min-width: 80px;
}

.fp-val {
  font-size: 11px;
  color: var(--text-primary, #ddd);
  text-align: right;
}

.field-popup-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 8px 0;
}

.field-popup-wire-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.fp-wire-num {
  font-weight: 600;
  font-size: 11px;
  color: #5b8def;
  min-width: 40px;
}

.fp-wire-route {
  font-size: 10px;
  color: var(--text-secondary, #aaa);
}

.field-popup-canvas {
  width: 100%;
  height: 100px;
  border-radius: 4px;
  display: block;
}

.field-popup-footer {
  margin-top: 4px;
}

/* ─── Responsive: collapse panels on narrow screens ────────── */
@media (max-width: 1000px) {
  .wiring-pane {
    min-width: 150px;
  }
}
