/* ============================================================
   Signa - Dark Theme CSS
   ============================================================ */

:root {
  --bg-primary: #1e1e24;
  --bg-panel: #282830;
  --bg-input: #1a1a22;
  --bg-button: #35353f;
  --bg-button-hover: #45454f;
  --bg-button-active: #55555f;
  --text-primary: #dcdee4;
  --text-secondary: #8c909b;
  --accent: #5096ff;
  --accent-hover: #6aa6ff;
  --signal-high: #32dc64;
  --signal-low: #505560;
  --border: #3a3a44;
  --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 6px;
  --radius-sm: 4px;
  --panel-pad: 12px;
  --transition: 150ms ease;
}

/* ---- Reset ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-primary);
}

/* ============================================================
   Page grid: toolbar | main | bottom
   ============================================================ */

body {
  display: flex;
  flex-direction: column;
}

#toolbar {
  height: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#main-area {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

#bottom-area {
  height: 250px;
  min-height: 120px;
  display: flex;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Main area: palette | circuit | code-editor
   ============================================================ */

#component-palette {
  width: 170px;
  min-width: 170px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

#circuit-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

#circuit-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#code-editor {
  width: 380px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}

/* ============================================================
   Bottom split: serial (left) | tabbed right panel
   ============================================================ */

#serial-panel {
  width: 350px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

#bottom-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.tab {
  padding: 6px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-ui);
  border-bottom: 2px solid transparent;
  transition: color var(--transition);
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
  flex: 1;
  overflow: auto;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

#tab-waveform {
  position: relative;
}

#waveform-canvas {
  width: 100%;
  flex: 1;
  display: block;
  min-height: 0;
}

#tab-inspector {
  padding: var(--panel-pad);
}

#tab-cpu {
  padding: var(--panel-pad);
}

/* ============================================================
   Panels
   ============================================================ */

.panel {
  background: var(--bg-panel);
  overflow: hidden;
}

.panel-header {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--panel-pad);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.panel-header-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.panel-header-btn:hover {
  background: var(--bg-button);
  color: var(--text-primary);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--panel-pad);
  min-height: 0;
}

.placeholder-text {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 12px;
}

/* ============================================================
   Toolbar
   ============================================================ */

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 0.5px;
  margin-right: 8px;
}

.toolbar-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
}

.toolbar-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  min-width: 48px;
  white-space: nowrap;
}

.toolbar-btn {
  height: 30px;
  min-width: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-button);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  user-select: none;
}

.toolbar-btn:hover {
  background: var(--bg-button-hover);
  border-color: var(--text-secondary);
}

.toolbar-btn:active {
  background: var(--bg-button-active);
}

.toolbar-btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.toolbar-btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.toolbar-select {
  height: 30px;
  padding: 0 8px;
  background: var(--bg-button);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
}

.toolbar-status {
  margin-left: auto;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-connected {
  background: var(--signal-high);
  box-shadow: 0 0 6px var(--signal-high);
}

.status-disconnected {
  background: #ff4444;
  box-shadow: 0 0 6px #ff4444;
}

/* Speed slider */
#speed-slider {
  width: 100px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  cursor: pointer;
}

#speed-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  cursor: pointer;
}

/* ============================================================
   Serial terminal
   ============================================================ */

.serial-output {
  flex: 1;
  overflow-y: auto;
  padding: 8px var(--panel-pad);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--signal-high);
  background: var(--bg-input);
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 0;
}

.serial-input-row {
  display: flex;
  border-top: 1px solid var(--border);
}

.serial-input {
  flex: 1;
  height: 30px;
  padding: 0 8px;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  background: var(--bg-input);
}

.serial-input::placeholder {
  color: var(--text-secondary);
}

.serial-input-row .toolbar-btn {
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
  height: 30px;
  font-size: 11px;
}

/* ============================================================
   Code Editor
   ============================================================ */

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.editor-toolbar select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  font-family: var(--font-ui);
}

.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-ui);
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.editor-wrapper {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.line-numbers {
  width: 40px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 4px;
  text-align: right;
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
}

.line-numbers span {
  display: block;
}

.line-numbers .error-line {
  background: rgba(255, 60, 60, 0.3);
  color: #ff6666;
  border-radius: 2px;
}

#code-textarea {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  padding: 8px;
  border: none;
  outline: none;
  resize: none;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.editor-output {
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  border-top: 1px solid var(--border);
  max-height: 80px;
  overflow-y: auto;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.editor-output.success { color: var(--signal-high); }
.editor-output.error { color: #ff6666; }

.editor-examples {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.editor-examples select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.status-ok { color: var(--signal-high); }
.status-error { color: #ff6666; }
.status-building { color: var(--accent); }
.status-running { color: var(--accent); }

/* ============================================================
   Component Palette
   ============================================================ */

.palette-header {
  padding: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.palette-category {
  padding: 8px 12px 4px;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  border-radius: var(--radius-sm);
  margin: 2px 6px;
  transition: background var(--transition);
}

.palette-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.palette-icon {
  width: 28px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--bg-input);
  border-radius: 3px;
  flex-shrink: 0;
}

.palette-label {
  font-size: 12px;
  color: var(--text-primary);
}

/* ============================================================
   CPU panel
   ============================================================ */

.register-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.register-cell {
  display: flex;
  justify-content: space-between;
  padding: 2px 4px;
  border-radius: 2px;
  background: var(--bg-input);
}

.register-cell.changed {
  background: rgba(255, 200, 0, 0.15);
}

.register-name {
  color: var(--text-secondary);
}

.register-value {
  color: var(--text-primary);
}

.sreg-row {
  display: flex;
  gap: 4px;
  margin: 8px 0;
  flex-wrap: wrap;
}

.sreg-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 22px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  transition: background var(--transition), color var(--transition);
}

.sreg-flag.set {
  background: rgba(50, 220, 100, 0.2);
  color: var(--signal-high);
  border-color: var(--signal-high);
}

.cpu-info {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.8;
}

.cpu-info span {
  color: var(--text-primary);
}

.cpu-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  margin-top: 10px;
}

.cpu-section-label:first-child {
  margin-top: 0;
}

/* ============================================================
   Inspector panel
   ============================================================ */

.inspector-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.inspector-type {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.inspector-field {
  margin-bottom: 10px;
}

.inspector-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.inspector-field input[type="range"] {
  width: 100%;
}

.inspector-field input[type="number"],
.inspector-field input[type="text"] {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
}

.inspector-field input[type="number"]:focus,
.inspector-field input[type="text"]:focus {
  border-color: var(--accent);
}

.inspector-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
}

.led-indicator {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
  border: 1px solid var(--border);
}

.led-indicator.on {
  box-shadow: 0 0 10px currentColor;
}

.inspector-json {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg-input);
  padding: 8px;
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
}

.lcd-preview {
  font-family: var(--font-mono);
  font-size: 14px;
  background: #2a5a2a;
  color: #00ff00;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  line-height: 1.6;
  letter-spacing: 2px;
  white-space: pre;
}

.lcd-preview.backlight-off {
  background: #1a2a1a;
  color: #005500;
}

.seven-seg-display {
  font-family: var(--font-mono);
  font-size: 36px;
  font-weight: 700;
  color: #ff3333;
  text-align: center;
  background: var(--bg-input);
  padding: 12px;
  border-radius: var(--radius-sm);
  text-shadow: 0 0 12px rgba(255, 50, 50, 0.5);
}

/* ============================================================
   Scrollbars
   ============================================================ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ============================================================
   Canvas overlay for component tooltips (future)
   ============================================================ */

.canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}
