/* ============================================================
   tbx Studio — IDE Styles
   Dark theme matching the tbx design system
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #111827;
  --surface: #1f2937;
  --border: #374151;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
  --radius: 6px;
  --font-mono: 'SF Mono', Monaco, 'Consolas', 'Courier New', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --sidebar-width: 240px;
  --toolbar-height: 42px;
  --bottom-panel-height: 200px;
  --ai-panel-width: 350px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.4;
}

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

#toolbar {
  display: flex;
  align-items: center;
  height: var(--toolbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  gap: 12px;
  user-select: none;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-left { flex-shrink: 0; }
.toolbar-center { flex: 1; justify-content: center; }
.toolbar-right { flex-shrink: 0; }

.logo {
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.logo strong { color: var(--accent); }

.separator {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.toolbar-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

.toolbar-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  padding: 4px 8px;
  outline: none;
  cursor: pointer;
}
.toolbar-select:focus { border-color: var(--accent); }
.toolbar-select option { background: var(--surface); }

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.toolbar-btn:hover {
  background: var(--surface);
  border-color: var(--text-muted);
}

.build-btn {
  color: var(--success);
  border-color: var(--success);
}
.build-btn:hover { background: rgba(52, 211, 153, 0.1); }
.build-btn.building {
  animation: pulse-build 1.2s ease-in-out infinite;
}
@keyframes pulse-build {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.flash-btn {
  color: var(--accent);
  border-color: var(--accent);
}
.flash-btn:hover { background: rgba(59, 130, 246, 0.1); }

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
}
.icon-btn:hover { background: var(--border); color: var(--text); }

/* ============================================================
   Main Layout
   ============================================================ */

#main {
  display: flex;
  height: calc(100vh - var(--toolbar-height));
  overflow: hidden;
}

#main.bottom-open {
  height: calc(100vh - var(--toolbar-height) - var(--bottom-panel-height));
}

/* ============================================================
   Sidebar (file tree)
   ============================================================ */

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.tree-item {
  display: flex;
  align-items: center;
  padding: 3px 12px;
  cursor: pointer;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  transition: background 0.1s;
  white-space: nowrap;
}
.tree-item:hover { background: rgba(255,255,255,0.04); }
.tree-item.active { background: rgba(59,130,246,0.15); color: #fff; }

.tree-item .indent {
  display: inline-block;
  width: 16px;
  flex-shrink: 0;
}

.tree-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  font-size: 14px;
  text-align: center;
  line-height: 16px;
}

.tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.tree-modified {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* File icons by extension */
.file-icon-cpp  { color: #569cd6; }
.file-icon-h    { color: #9cdcfe; }
.file-icon-html { color: #e44d26; }
.file-icon-js   { color: #f7df1e; }
.file-icon-css  { color: #264de4; }
.file-icon-json { color: #fbbf24; }
.file-icon-ini  { color: #9ca3af; }
.file-icon-folder { color: #fbbf24; }
.file-icon-default { color: var(--text-muted); }

/* ============================================================
   Editor Area
   ============================================================ */

#editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Tab bar */
#tab-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  height: 34px;
}

#tab-bar:empty { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 34px;
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s;
}
.tab:hover { background: rgba(255,255,255,0.03); }
.tab.active {
  color: var(--text);
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
}

.tab .tab-modified {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.tab .tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 14px;
  color: var(--text-muted);
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.1s;
}
.tab:hover .tab-close,
.tab.active .tab-close { opacity: 1; }
.tab .tab-close:hover { background: rgba(255,255,255,0.1); color: var(--text); }

#monaco-container {
  flex: 1;
  overflow: hidden;
}

/* Placeholder when no file is open */
#monaco-container:empty::after {
  content: 'Open a file from the explorer to start editing';
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================================
   Bottom Panel (build output)
   ============================================================ */

#bottom-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height 0.15s ease;
}

#bottom-panel.collapsed {
  height: 32px !important;
}

#bottom-panel:not(.collapsed) {
  height: var(--bottom-panel-height);
}

#bottom-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
}

.build-output {
  flex: 1;
  margin: 0;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.build-output .log-error { color: var(--error); }
.build-output .log-warning { color: var(--warning); }
.build-output .log-success { color: var(--success); }

/* ============================================================
   AI Panel
   ============================================================ */

#ai-panel {
  width: var(--ai-panel-width);
  min-width: var(--ai-panel-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#ai-panel.hidden {
  display: none;
}

#ai-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.ai-msg {
  margin-bottom: 12px;
  padding: 10px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
}
.ai-msg.user {
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.25);
}
.ai-msg.assistant {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
}

.ai-msg pre {
  margin: 8px 0 0;
  padding: 8px;
  background: var(--bg);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
}

.ai-msg .ai-apply-bar {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.ai-apply-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  border: none;
  cursor: pointer;
}
.ai-apply-btn.apply {
  background: var(--accent);
  color: #fff;
}
.ai-apply-btn.apply:hover { background: var(--accent-hover); }
.ai-apply-btn.dismiss {
  background: var(--border);
  color: var(--text);
}
.ai-apply-btn.dismiss:hover { background: #4b5563; }

.ai-input-area {
  border-top: 1px solid var(--border);
  padding: 10px;
  flex-shrink: 0;
}

#ai-prompt {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  resize: none;
  outline: none;
}
#ai-prompt:focus { border-color: var(--accent); }
#ai-prompt::placeholder { color: var(--text-muted); }

.ai-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.ai-action-btn {
  flex: 1;
  padding: 6px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ai-action-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Project Modal
   ============================================================ */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 600; }

.modal-close {
  width: 28px; height: 28px;
  padding: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.modal-body h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px 0;
}

.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--text-muted); }
.form-group select option { background: var(--surface); }

.modal-body button {
  width: 100%;
  padding: 9px 16px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.modal-body button:hover { background: var(--accent-hover); }

.project-list { display: flex; flex-direction: column; gap: 6px; }
.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
}
.project-item:hover { border-color: var(--accent); }
.project-item-name { font-weight: 500; }
.project-item-meta { font-size: 11px; color: var(--text-muted); }
.project-item-delete {
  width: auto;
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--error);
  font-size: 11px;
  border-radius: 4px;
}
.project-item-delete:hover { background: rgba(248,113,113,0.1); border-color: var(--error); }

/* ============================================================
   Toast Notifications
   ============================================================ */

#toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--error); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ============================================================
   Loading States
   ============================================================ */

.loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Scrollbar styling
   ============================================================ */

::-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: #4b5563; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
  #sidebar { display: none; }
  #ai-panel { position: fixed; top: var(--toolbar-height); right: 0; bottom: 0; z-index: 100; }
  .toolbar-center { display: none; }
}
