* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #0e0e12; color: #d0d0d8; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 13px; }

#app { display: flex; height: 100vh; width: 100vw; }

/* ---- Toolbar ---- */
#toolbar {
  width: 120px; min-width: 120px;
  background: #16161e; border-right: 1px solid #2a2a38;
  display: flex; flex-direction: column; padding: 6px; gap: 3px;
  overflow-y: auto; scrollbar-width: thin;
}
.toolbar-title { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #6a6a80; padding: 6px 4px 2px; }
.toolbar-sep { height: 1px; background: #2a2a38; margin: 4px 0; }
.tool-btn {
  display: flex; align-items: center; gap: 6px;
  background: #1e1e28; border: 1px solid #2a2a38; border-radius: 4px;
  color: #b0b0c0; padding: 6px 8px; cursor: pointer; font-size: 11px;
  transition: background .15s, border-color .15s;
}
.tool-btn:hover { background: #28283a; border-color: #4a4a60; }
.tool-btn.active { background: #2a2850; border-color: #6c5ce7; color: #e0d8ff; }
.tool-btn svg { flex-shrink: 0; width: 20px; height: 20px; }

.marker-icon {
  font-size: 9px; font-weight: 700; padding: 2px 4px; border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; text-align: center; flex-shrink: 0;
}
.marker-in { background: #1a4a2a; color: #4ade80; }
.marker-out { background: #4a1a2a; color: #f87171; }
.marker-vp { background: #4a3a1a; color: #facc15; }
.marker-gnd { background: #1a2a4a; color: #60a5fa; }

/* ---- Main Area ---- */
#main-area {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
#board {
  flex: 1; display: block; cursor: crosshair;
}
#bottom-bar {
  height: auto; min-height: 52px; max-height: 80px;
  background: #16161e; border-top: 1px solid #2a2a38;
  display: flex; align-items: center; padding: 0 12px; gap: 16px;
}
#sim-controls { display: flex; align-items: center; gap: 8px; }
#btn-simulate {
  background: #22c55e; color: #000; border: none; border-radius: 4px;
  padding: 6px 16px; font-weight: 700; font-size: 12px; cursor: pointer;
  transition: background .15s;
}
#btn-simulate:hover { background: #16a34a; }
#btn-simulate.active { background: #ef4444; }
#btn-simulate.active:hover { background: #dc2626; }
#signal-type {
  background: #1e1e28; color: #d0d0d8; border: 1px solid #2a2a38;
  border-radius: 4px; padding: 4px 6px; font-size: 11px;
}
.vol-knob-wrap { display: flex; align-items: center; gap: 4px; }
.vol-label-text { font-size: 11px; color: #888; }
.vol-knob { cursor: pointer; line-height: 0; }
.vol-knob svg { display: block; }
.vol-val { font-size: 10px; color: #c084fc; min-width: 28px; }

#circuits-bar { display: flex; align-items: center; gap: 4px; }
.circuit-bar-btn {
  background: #1e1e28; color: #a0a0b0; border: 1px solid #2a2a38;
  border-radius: 3px; padding: 4px 10px; font-size: 11px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.circuit-bar-btn:hover { background: #28283a; border-color: #4a4a60; }

/* Circuits panel */
#circuits-panel {
  position: fixed; bottom: 60px; left: 130px; right: 190px;
  max-height: 50vh; background: #16161e; border: 1px solid #2a2a38;
  border-radius: 8px 8px 0 0; z-index: 150;
  display: flex; flex-direction: column;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
}
.cp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid #2a2a38;
  font-size: 12px; font-weight: 700; color: #c084fc;
}
.cp-close {
  background: none; border: none; color: #888; font-size: 18px;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.cp-close:hover { color: #f87171; }
.cp-list {
  overflow-y: auto; padding: 6px; display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 45vh;
}
.cp-entry {
  background: #1e1e28; border: 1px solid #2a2a38; border-radius: 6px;
  padding: 8px 10px; cursor: pointer; width: 170px;
  transition: background .15s, border-color .15s;
}
.cp-entry:hover { background: #28283a; border-color: #4a4a60; }
.cp-entry-name { font-size: 12px; font-weight: 600; color: #d0d0d8; margin-bottom: 2px; }
.cp-entry-sub { font-size: 10px; color: #666; }
.cp-entry-actions { display: flex; gap: 4px; margin-top: 6px; }
.cp-entry-btn {
  flex: 1; padding: 3px 6px; font-size: 10px; border-radius: 3px;
  background: #2a2850; color: #c084fc; border: 1px solid #3a3870; cursor: pointer;
}
.cp-entry-btn:hover { background: #3a3870; }
.cp-entry-btn.del { background: #3a1a1a; color: #f87171; border-color: #5a2a2a; }
.cp-entry-btn.del:hover { background: #5a2a2a; }

/* Save dialog */
#save-dialog { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.sd-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.sd-content {
  position: relative; background: #1a1a24; border: 1px solid #4a4a60;
  border-radius: 8px; padding: 16px 20px; min-width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
}
.sd-header { font-size: 14px; font-weight: 700; color: #c084fc; margin-bottom: 12px; }
.sd-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sd-row label { font-size: 11px; color: #888; min-width: 70px; }
.sd-row input {
  flex: 1; background: #16161e; color: #d0d0d8; border: 1px solid #2a2a38;
  border-radius: 4px; padding: 6px 8px; font-size: 12px;
}
.sd-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.sd-btn {
  padding: 6px 16px; border-radius: 4px; font-size: 12px; cursor: pointer;
  border: 1px solid #2a2a38; background: #1e1e28; color: #a0a0b0;
}
.sd-btn:hover { background: #28283a; }
.sd-btn-primary { background: #2a2850; color: #c084fc; border-color: #6c5ce7; }
.sd-btn-primary:hover { background: #3a3870; }

#board-type { display: flex; gap: 2px; margin-right: 8px; }
.board-type-btn {
  background: #1e1e28; color: #a0a0b0; border: 1px solid #2a2a38;
  border-radius: 3px; padding: 4px 8px; font-size: 10px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.board-type-btn:hover { background: #28283a; border-color: #4a4a60; }
.board-type-btn.active { background: #2a2850; border-color: #6c5ce7; color: #e0d8ff; }

#perf-controls { display: flex; align-items: center; gap: 6px; }
.perf-size-label {
  display: flex; align-items: center; gap: 3px;
  font-size: 10px; color: #888;
}
.perf-size-label input {
  width: 46px; background: #1e1e28; color: #d0d0d8; border: 1px solid #2a2a38;
  border-radius: 3px; padding: 3px 4px; font-size: 10px; text-align: center;
}
.flip-btn {
  background: #1e1e28; color: #a0a0b0; border: 1px solid #2a2a38;
  border-radius: 3px; padding: 4px 8px; font-size: 10px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.flip-btn:hover { background: #28283a; border-color: #4a4a60; }
.flip-btn.active { background: #4a3a1a; border-color: #b87333; color: #e0c090; }

#analyser { border-radius: 4px; background: #0a0a10; margin-left: auto; }

/* ---- Sidebar ---- */
#sidebar {
  width: 180px; min-width: 180px;
  background: #16161e; border-left: 1px solid #2a2a38;
  display: flex; flex-direction: column; overflow-y: auto; scrollbar-width: thin;
}
.sidebar-section { padding: 10px; border-bottom: 1px solid #2a2a38; }
.sidebar-title { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #6a6a80; margin-bottom: 6px; }
.help-text p { font-size: 11px; color: #888; margin-bottom: 4px; line-height: 1.4; }
.help-text b { color: #b0b0c0; }
.hint { color: #555 !important; font-style: italic; }
#netlist-text { font-size: 10px; color: #888; white-space: pre-wrap; font-family: monospace; }

/* ---- Properties Panel ---- */
.prop-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.prop-row label { font-size: 11px; color: #888; }
.prop-row input, .prop-row select {
  width: 80px; background: #1e1e28; color: #d0d0d8; border: 1px solid #2a2a38;
  border-radius: 3px; padding: 2px 4px; font-size: 11px;
}
.prop-type { font-size: 12px; font-weight: 600; color: #c084fc; margin-bottom: 6px; }
.prop-delete-btn {
  display: block; width: 100%; margin-top: 10px;
  background: #3a1a1a; color: #f87171; border: 1px solid #5a2a2a;
  border-radius: 4px; padding: 5px 0; font-size: 11px; cursor: pointer;
  transition: background .15s;
}
.prop-delete-btn:hover { background: #5a2a2a; }

/* ---- Component Popup ---- */
#comp-popup {
  position: fixed; z-index: 200;
  background: #1a1a24; border: 1px solid #4a4a60; border-radius: 8px;
  padding: 0; min-width: 220px; max-width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
  font-size: 12px;
}
.popup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: #22222e; border-radius: 8px 8px 0 0;
  border-bottom: 1px solid #2a2a38;
}
.popup-header span { font-weight: 700; color: #c084fc; font-size: 13px; }
#popup-close {
  background: none; border: none; color: #888; font-size: 18px;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
#popup-close:hover { color: #f87171; }
#popup-body { padding: 10px 12px; }
#popup-body .prop-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
#popup-body .prop-row label { font-size: 11px; color: #888; min-width: 50px; }
#popup-body .prop-row input, #popup-body .prop-row select {
  flex: 1; max-width: 130px; background: #16161e; color: #d0d0d8;
  border: 1px solid #2a2a38; border-radius: 4px; padding: 4px 6px; font-size: 11px;
}
#popup-body .knob-svg { display: block; }
#popup-body .prop-row input[type="color"] { width: 32px; height: 24px; padding: 0; border: none; cursor: pointer; }
#comp-popup .prop-delete-btn { margin: 4px 12px 10px; width: calc(100% - 24px); }
.popup-pos-btns { display: flex; gap: 4px; }
.popup-pos-btns button {
  flex: 1; padding: 4px 6px; font-size: 10px; border-radius: 3px;
  background: #1e1e28; color: #a0a0b0; border: 1px solid #2a2a38; cursor: pointer;
}
.popup-pos-btns button.active { background: #2a2850; border-color: #6c5ce7; color: #e0d8ff; }
.popup-pos-btns button:hover { background: #28283a; }
.popup-range-row { display: flex; align-items: center; gap: 6px; }
.popup-range-val { font-size: 11px; color: #c084fc; min-width: 36px; text-align: right; }
