/* --- 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;
}

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;
}

.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-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));
}

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

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

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

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

#code-panel, #terminal-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.panel-header {
  background: var(--bg-secondary);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* --- 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;
}

/* --- Terminal --- */
#terminal-panel {
  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);
}

/* --- 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);
}

/* --- Flash Progress Overlay --- */
.hidden { display: none !important; }

#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);
}
