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

:root {
  --bg-primary: #1e1e2e;
  --bg-secondary: #181825;
  --bg-surface: #252538;
  --bg-toolbar: #11111b;
  --text-primary: #cdd6f4;
  --text-secondary: #a6adc8;
  --text-muted: #6c7086;
  --accent: #89b4fa;
  --accent-hover: #74c7ec;
  --green: #a6e3a1;
  --red: #f38ba8;
  --yellow: #f9e2af;
  --border: #313244;
  --radius: 6px;
  --toolbar-height: 48px;
  --panel-header-height: 30px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* --- Toolbar --- */
#toolbar {
  height: var(--toolbar-height);
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toolbar-left button {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.toolbar-left button:hover {
  background: var(--accent);
  color: var(--bg-toolbar);
  border-color: var(--accent);
}

.app-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.device-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#device-select {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  min-width: 140px;
}

#device-select:hover,
#device-select:focus {
  border-color: var(--accent);
  outline: none;
}

.toolbar-icon-btn {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.toolbar-icon-btn:hover {
  background: var(--bg-primary);
  border-color: var(--accent);
  color: var(--accent);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-actions button {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.toolbar-actions button:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg-toolbar);
  border-color: var(--accent);
}

.toolbar-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar-actions button .icon {
  font-size: 14px;
}

#connection-status {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.status-disconnected {
  background: rgba(243, 139, 168, 0.15);
  color: var(--red);
}

.status-connected {
  background: rgba(166, 227, 161, 0.15);
  color: var(--green);
}

/* --- Main Layout --- */
#workspace-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--toolbar-height));
}

/* --- Top Area (Blockly + Projects sidebar) --- */
#top-area {
  flex: 1 1 65%;
  display: flex;
  position: relative;
  min-height: 200px;
  overflow: hidden;
}

#blockly-area {
  flex: 1;
  position: relative;
  min-width: 200px;
  overflow: hidden;
}

#blockly-div {
  position: absolute;
  inset: 0;
}

/* --- Bottom Panels --- */
#bottom-panels {
  flex: 0 0 35%;
  min-height: 0;
  display: flex;
  position: relative;
  border-top: 1px solid var(--border);
}

#bottom-panels.all-collapsed {
  flex: 0 0 var(--panel-header-height);
  min-height: var(--panel-header-height);
}

.resize-handle.horizontal {
  position: absolute;
  top: -3px;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  z-index: 10;
}

/* --- Generic Panel --- */
.ide-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ide-panel .panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ide-panel.collapsed .panel-body {
  display: none;
}

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

.panel-header .panel-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.panel-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

/* --- Bottom panel specifics --- */
#code-panel, #terminal-panel {
  flex: 1;
  overflow: hidden;
}

#code-panel {
  border-right: 1px solid var(--border);
}

#code-panel.collapsed,
#terminal-panel.collapsed {
  flex: 0 0 auto;
}

/* --- Code Preview --- */
#code-preview {
  flex: 1;
  overflow: auto;
  background: var(--bg-secondary);
  padding: 10px 14px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: pre;
  tab-size: 4;
  margin: 0;
}

/* --- Terminal --- */
#terminal-panel .panel-body {
  background: var(--bg-secondary);
}

#terminal-output {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: var(--green);
  white-space: pre-wrap;
  word-break: break-all;
}

#terminal-input-row {
  display: flex;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#terminal-input {
  flex: 1;
  background: var(--bg-toolbar);
  color: var(--text-primary);
  border: none;
  padding: 8px 12px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  outline: none;
}

#terminal-input:disabled { opacity: 0.5; }
#terminal-input::placeholder { color: var(--text-muted); }

/* --- Projects Sidebar Panel --- */
#projects-panel {
  width: 280px;
  min-width: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  transition: width 0.15s ease;
  position: relative;
}

#projects-panel.collapsed {
  width: 30px;
  min-width: 30px;
}

#projects-panel.collapsed .panel-header {
  display: none;
}

#projects-panel.collapsed .panel-toggle {
  writing-mode: horizontal-tb;
}

#side-tools-rail {
  display: flex;
  flex-direction: column;
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 30px;
  gap: 6px;
}

#projects-panel:not(.collapsed) .panel-header,
#projects-panel:not(.collapsed) .panel-body {
  margin-right: 30px;
}

#projects-panel.collapsed #side-tools-rail {
  top: 6px;
}

.side-rail-btn {
  width: 30px;
  min-height: 110px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: none;
  border-right: none;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 0;
  cursor: pointer;
}

.side-rail-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

.side-rail-arrow {
  writing-mode: horizontal-tb;
  line-height: 1;
}

/* Projects tabs */
.proj-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.proj-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: color 0.15s, border-color 0.15s;
}

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

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

.proj-tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  overflow-y: auto;
}

.proj-tab-content.hidden { display: none; }

/* Projects list */
.projects-list {
  list-style: none;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 100px;
  max-height: 40vh;
  overflow-y: auto;
  padding: 4px;
}

.projects-list li {
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.projects-list li:hover { background: var(--bg-surface); }

.projects-list li.selected {
  background: var(--accent);
  color: var(--bg-toolbar);
}

.projects-list .empty-msg {
  padding: 6px 10px;
  color: var(--text-muted);
  font-size: 11px;
  font-style: italic;
  cursor: default;
}

/* Projects actions */
.projects-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.projects-name-row {
  display: flex;
  gap: 4px;
}

.projects-name-row input {
  flex: 1;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
  min-width: 0;
}

.projects-name-row input:focus { border-color: var(--accent); }

.projects-btn-row {
  display: flex;
  gap: 4px;
}

.projects-btn-row-primary #browser-load-btn {
  flex: 2;
}

.projects-btn-row-primary #browser-delete-btn {
  flex: 1;
}

.projects-btn-row-secondary button {
  flex: 1;
}

.projects-actions button {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex: 1;
}

.projects-actions button:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg-toolbar);
  border-color: var(--accent);
}

.projects-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.projects-actions button.btn-danger {
  background: rgba(243, 139, 168, 0.2);
  color: var(--red);
  border-color: rgba(243, 139, 168, 0.7);
}

.projects-actions button.btn-danger:hover:not(:disabled) {
  background: var(--red);
  color: var(--bg-toolbar);
  border-color: var(--red);
}

.projects-note {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  min-height: 16px;
}

/* --- Robot hardware panel --- */
#robot-panel {
  width: 300px;
  min-width: 0;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
}

.robot-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
  overflow: hidden;
}

#robot-file-list {
  min-height: 72px;
  max-height: 140px;
}

.robot-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.robot-tb-btn {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 6px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

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

.robot-tb-primary {
  font-weight: 600;
}

.robot-full-btn {
  width: 100%;
  margin-top: 4px;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 11px;
  cursor: pointer;
}

.robot-full-btn:hover {
  background: var(--bg-primary);
  border-color: var(--accent);
}

.robot-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  min-height: 14px;
}

.robot-note-warn {
  color: var(--amber, #d4a017);
}

.robot-add-row {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.robot-add-select {
  flex: 1;
  min-width: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 6px;
  font-size: 12px;
}

.robot-comp-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
}

.robot-comp-item {
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.robot-comp-item:last-child { border-bottom: none; }

.robot-comp-item:hover { background: var(--bg-surface); }

.robot-comp-item.selected {
  background: var(--accent);
  color: var(--bg-toolbar);
}

.robot-editor {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.robot-editor-empty {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

.robot-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.robot-editor-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.robot-remove-btn {
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 11px;
}

.robot-field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.robot-field-row label {
  font-size: 11px;
  color: var(--text-secondary);
}

.robot-field-row input,
.robot-field-row select {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 12px;
}

.robot-status {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  min-height: 14px;
}

.robot-status-error {
  color: var(--red);
}

.robot-file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  opacity: 0;
}

/* --- Blockly Overrides (dark theme) --- */
.blocklyMainBackground {
  fill: var(--bg-primary) !important;
}

.blocklyToolboxDiv {
  background: var(--bg-secondary) !important;
  border-right: 1px solid var(--border) !important;
}

.blocklyFlyoutBackground {
  fill: var(--bg-surface) !important;
}

.blocklyTreeRow:hover {
  background: var(--bg-surface) !important;
}

.blocklyTreeSelected {
  background: var(--accent) !important;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Utility --- */
.hidden { display: none !important; }

/* --- Flash Progress Overlay --- */
#flash-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#flash-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  width: 520px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#flash-modal h3 {
  margin: 0;
  color: var(--accent);
  font-size: 16px;
}

#flash-log {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 10px 12px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

#flash-progress-bar {
  height: 10px;
  background: var(--bg-secondary);
  border-radius: 5px;
  overflow: hidden;
}

#flash-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.2s ease;
}

#flash-progress-text {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

#flash-close {
  align-self: flex-end;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 20px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}

#flash-close:hover {
  background: var(--accent);
  color: var(--bg-toolbar);
  border-color: var(--accent);
}

/* --- Send code progress modal (Run / Save) --- */
#send-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#send-overlay.hidden {
  display: none !important;
}

#send-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 40px;
  width: 360px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

#send-modal h3 {
  margin: 0;
  color: var(--accent);
  font-size: 16px;
  text-align: center;
}

#send-modal #send-progress-bar {
  width: 100%;
  height: 10px;
  background: var(--bg-secondary);
  border-radius: 5px;
  overflow: hidden;
}

#send-modal #send-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.15s ease;
}

#send-modal #send-progress-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* --- Addons Manager Overlay --- */
#addons-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#addons-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  width: 440px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.addons-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.addons-header h3 {
  margin: 0;
  color: var(--accent);
  font-size: 16px;
}

.addons-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.addons-header button:hover {
  color: var(--text-primary);
}

.addons-description {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.addons-description code {
  background: var(--bg-secondary);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.addons-upload-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.addons-upload-row input[type="file"] {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
}

.addons-upload-row button {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.addons-upload-row button:hover {
  background: var(--accent);
  color: var(--bg-toolbar);
  border-color: var(--accent);
}

.addons-status {
  font-size: 12px;
  min-height: 18px;
  color: var(--text-muted);
}
.addons-status.status-ok { color: var(--green); }
.addons-status.status-err { color: var(--red); }
.addons-status.status-warn { color: var(--yellow); }

.addons-list {
  list-style: none;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 60px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
}

.addons-list .addons-empty {
  padding: 12px 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  text-align: center;
}

.addons-list .addons-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 4px;
}

.addons-list .addons-item:hover {
  background: var(--bg-surface);
}

.addons-item-name {
  font-size: 13px;
  color: var(--text-primary);
}

.addons-item-remove {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.addons-item-remove:hover {
  background: var(--red);
  color: var(--bg-toolbar);
  border-color: var(--red);
}

/* --- Toolbox Customizer Sidebar Panel --- */
#customizer-panel {
  width: 280px;
  min-width: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

#customizer-panel.hidden {
  display: none !important;
}

#customizer-panel .panel-body {
  overflow-y: auto;
}

.cust-done-btn {
  background: var(--accent);
  color: var(--bg-toolbar);
  border: none;
  border-radius: var(--radius);
  padding: 2px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  transition: opacity 0.15s;
}
.cust-done-btn:hover { opacity: 0.85; }

/* Preset controls */
.cust-presets {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cust-preset-row {
  display: flex;
  gap: 4px;
}

.cust-preset-row select,
.cust-preset-row input {
  flex: 1;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 6px;
  font-size: 11px;
  outline: none;
  min-width: 0;
}

.cust-preset-row select:focus,
.cust-preset-row input:focus {
  border-color: var(--accent);
}

.cust-preset-row button {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.cust-preset-row button:hover {
  background: var(--accent);
  color: var(--bg-toolbar);
  border-color: var(--accent);
}

.cust-preset-row button.btn-danger:hover {
  background: var(--red);
  border-color: var(--red);
}

/* Category/block tree */
.customizer-tree {
  overflow-y: auto;
  padding: 4px 6px;
  flex: 1;
}

.cust-cat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 4px;
  user-select: none;
  transition: opacity 0.15s;
}

.cust-cat:hover { background: var(--bg-surface); }

.cust-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.cust-cat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cust-expand {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  line-height: 1;
  flex-shrink: 0;
}
.cust-expand:hover {
  color: var(--text-primary);
  background: var(--bg-primary);
}

.cust-cb {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.cust-blocks {
  padding-left: 30px;
}

.cust-block-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: opacity 0.15s;
}

.cust-block-row:hover { background: var(--bg-surface); }

.cust-block-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cust-dimmed { opacity: 0.4; }

.cust-cb:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Active customize button highlight */
#btn-customize.active {
  background: var(--accent);
  color: var(--bg-toolbar);
  border-color: var(--accent);
}

/* --- Hex Upload Overlay (Arduino) --- */
#hex-upload-overlay,
#esp32-flash-overlay,
#microbit-flash-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#hex-upload-modal,
#esp32-flash-modal,
#microbit-flash-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  width: 460px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.board-select-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.board-select-header h3 {
  margin: 0;
  color: var(--accent);
  font-size: 16px;
}

.board-select-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.board-select-header button:hover {
  color: var(--text-primary);
}

.board-select-description {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.board-list {
  list-style: none;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 60px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
}

.board-list .board-empty {
  padding: 12px 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  text-align: center;
}

.board-list .board-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.1s;
}

.board-list .board-item:hover {
  background: var(--bg-surface);
}

.board-list .board-item.selected {
  background: var(--accent);
  color: var(--bg-toolbar);
}

.board-select-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.board-select-actions button {
  background: var(--accent);
  color: var(--bg-toolbar);
  border: none;
  border-radius: var(--radius);
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.board-select-actions button:hover {
  opacity: 0.85;
}

/* --- Hex Upload Modal fields --- */
.hex-upload-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
}

.hex-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hex-upload-fields select,
.hex-upload-fields input[type="file"] {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

.hex-upload-fields select:focus {
  border-color: var(--accent);
}

.hex-upload-status {
  font-size: 12px;
  min-height: 18px;
  color: var(--text-muted);
}
.hex-upload-status.status-err { color: var(--red); }
.hex-upload-status.status-ok { color: var(--green); }

/* --- Login / Auth --- */
.user-badge {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border);
}

#login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#login-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  width: 400px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.login-header h3 {
  margin: 0;
  color: var(--accent);
  font-size: 16px;
}

.login-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.login-header button:hover { color: var(--text-primary); }

.login-description {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.login-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.login-tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

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

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

.login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-field-label {
  font-size: 12px;
  color: var(--text-muted);
}

.login-form input {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}

.login-form input:focus { border-color: var(--accent); }

.login-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.login-actions button {
  background: var(--accent);
  color: var(--bg-toolbar);
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.login-actions button:hover:not(:disabled) { background: var(--accent-hover); }
.login-actions button:disabled { opacity: 0.6; cursor: default; }

.login-status {
  font-size: 12px;
  min-height: 18px;
  color: var(--text-muted);
}

.login-status.status-err { color: var(--red); }
.login-status.status-ok { color: var(--green); }

/* Toast shown when a teacher pushes blocks to a student */
.push-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  font-size: 13px;
  max-width: 320px;
  transition: opacity 0.25s ease;
}
.push-toast.hidden { display: none; }
