/* ===================================================================
   BUILDER PAGE — PromithicAI v1.1
   =================================================================== */

/* ── Builder Layout ── */
.builder-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  padding-top: var(--nav-height);
}

.builder-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left Sidebar (History) ── */
.builder-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width var(--transition-base), opacity var(--transition-base);
}

.builder-sidebar.collapsed {
  width: 0;
  opacity: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* History Items */
.history-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  border: 1px solid transparent;
  position: relative;
}

.history-item:hover {
  background: var(--bg-card);
  border-color: var(--border);
}

.history-item.active {
  background: var(--glow-cyan);
  border-color: var(--border-glow);
}

.history-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--gradient-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.history-icon svg { width: 14px; height: 14px; color: #fff; }

.history-info { flex: 1; min-width: 0; }
.history-prompt {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.history-time {
  font-size: 10px;
  color: var(--text-muted);
}

.history-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}

.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: var(--accent-red); background: var(--glow-red); }
.history-delete svg { width: 12px; height: 12px; }

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
}
.history-empty svg { width: 36px; height: 36px; opacity: 0.4; }
.history-empty p { font-size: var(--text-sm); }

/* ── Builder Main ── */
.builder-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Prompt Area ── */
.prompt-area {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.prompt-area-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.prompt-area-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.prompt-area-title .badge { font-size: 10px; padding: 2px 6px; }

.prompt-actions { display: flex; align-items: center; gap: 6px; }

.prompt-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 12px 14px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.prompt-input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--glow-cyan);
}

.prompt-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  resize: none;
  max-height: 160px;
  min-height: 22px;
  height: 22px;
  overflow-y: auto;
}

.prompt-textarea::placeholder { color: var(--text-muted); }

.prompt-send {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-lg);
  background: var(--gradient-btn);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-glow-cyan);
  transition: all var(--transition-fast);
}

.prompt-send:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,212,255,0.5); }
.prompt-send:active { transform: scale(0.95); }
.prompt-send:disabled { opacity: 0.5; transform: none; cursor: not-allowed; }
.prompt-send svg { width: 16px; height: 16px; }

.prompt-send.loading svg { display: none; }
.prompt-send.loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Quick templates */
.prompt-templates {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.template-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.template-chip:hover {
  color: var(--accent-cyan);
  border-color: var(--border-glow);
  background: var(--glow-cyan);
}

.template-chip svg { width: 12px; height: 12px; }

/* ── Agent Progress ── */
.agent-progress-area {
  padding: 12px 20px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: none;
}

.agent-progress-area.visible { display: block; }

.agent-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.agent-progress-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.agent-current-msg {
  font-size: var(--text-xs);
  color: var(--accent-cyan);
  font-family: var(--font-mono);
}

/* ── Output Tabs ── */
.output-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.output-tabs { display: flex; gap: 4px; }
.output-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
  cursor: pointer;
  border: 1px solid transparent;
}
.output-tab:hover { color: var(--text-primary); background: var(--bg-card); }
.output-tab.active {
  color: var(--accent-cyan);
  background: var(--glow-cyan);
  border-color: var(--border-glow);
}
.output-tab svg { width: 14px; height: 14px; }

.output-tab-actions { display: flex; gap: 6px; }

/* ── Output Content ── */
.output-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* Preview Panel */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.preview-url-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.preview-url-bar svg { width: 12px; height: 12px; flex-shrink: 0; }

.preview-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
  display: block;
}

/* Empty preview state */
.preview-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: var(--text-muted);
  text-align: center;
  padding: 48px;
}

.preview-empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: float 4s ease-in-out infinite;
}
.preview-empty-icon svg { width: 36px; height: 36px; color: var(--text-muted); }

.preview-empty h3 { font-size: var(--text-xl); color: var(--text-secondary); }
.preview-empty p  { font-size: var(--text-sm); max-width: 320px; }

/* Code Panel */
.code-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.code-panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-code);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.code-panel-lang {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.code-panel-lang-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-orange);
}

.monaco-wrapper {
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* Split Panel */
.split-panel {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}
.split-panel .preview-panel { border-right: 1px solid var(--border); }

/* ── Hidden States ── */
.output-pane { display: none; flex: 1; overflow: hidden; }
.output-pane.active { display: flex; }

/* ── Streaming Console ── */
.streaming-console {
  height: 120px;
  background: var(--bg-code);
  border-top: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 16px;
  flex-shrink: 0;
  display: none;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.7;
}

.streaming-console.visible { display: block; }

.console-line {
  display: block;
  animation: codeLineSlide 0.15s ease both;
}
.console-line.info    { color: var(--accent-cyan); }
.console-line.success { color: var(--accent-green); }
.console-line.warn    { color: var(--accent-orange); }
.console-line.error   { color: var(--accent-red); }
.console-prefix { color: var(--text-muted); margin-right: 8px; }

/* ── Sidebar Toggle Button ── */
.sidebar-toggle {
  position: absolute;
  top: calc(var(--nav-height) + 12px);
  left: var(--sidebar-width);
  width: 24px;
  height: 48px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  z-index: var(--z-raised);
  transition: color var(--transition-fast), background var(--transition-fast),
              left var(--transition-base);
}

.sidebar-toggle:hover { color: var(--accent-cyan); background: var(--glow-cyan); }
.sidebar-toggle svg { width: 14px; height: 14px; }

.sidebar-toggle.collapsed { left: 0; }

/* ── Status Bar ── */
.builder-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.status-bar-left, .status-bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-bar-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.status-bar-item svg { width: 12px; height: 12px; }

/* ── Mobile Builder ── */
@media (max-width: 768px) {
  .builder-sidebar { display: none; }
  .sidebar-toggle { display: none; }
  .split-panel { grid-template-columns: 1fr; }
  .split-panel .preview-panel { border-right: none; border-bottom: 1px solid var(--border); }
  .prompt-templates { display: none; }
}
