/* =============================================================================
   buildchat.css — Full-screen AI chat page styles
   Uses CSS variables defined in styles.css
   ============================================================================= */

/* =============================================================================
   Page Layout
   ============================================================================= */

.build-chat-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-light);
}

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

.build-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--gray-200);
  z-index: 10;
}

.build-toolbar-left {
  display: flex;
  align-items: center;
}

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

.build-toolbar-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--dark);
}

/* =============================================================================
   Body: Chat + Sidebar
   ============================================================================= */

.build-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  margin-top: 48px; /* offset for fixed toolbar */
}

/* =============================================================================
   Messages Area
   ============================================================================= */

.build-messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

#build-messages {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.build-msg {
  max-width: 75%;
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 0.9375rem;
  word-wrap: break-word;
}

.build-msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.build-msg-assistant {
  align-self: flex-start;
  background: var(--bg-surface);
  color: var(--dark);
  border: 1px solid var(--gray-200);
  border-bottom-left-radius: 4px;
}

/* =============================================================================
   Code Blocks in Assistant Messages
   ============================================================================= */

.build-msg-assistant pre {
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.8125rem;
}

.build-msg-assistant code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.85em;
}

.build-msg-assistant pre code {
  background: none;
  padding: 0;
}

.build-msg-assistant code:not(pre code) {
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
}

/* =============================================================================
   Sidebar
   ============================================================================= */

.build-sidebar {
  width: 300px;
  border-left: 1px solid var(--gray-200);
  background: var(--bg-surface);
  overflow-y: auto;
  padding: 16px;
  flex-shrink: 0;
}

.build-sidebar-inner {
  display: flex;
  flex-direction: column;
}

.build-sidebar-heading {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin: 0 0 8px 0;
}

.build-sidebar-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0;
  font-size: 0.8125rem;
}

.build-sidebar-label {
  color: var(--gray-500);
  font-weight: 500;
}

.build-sidebar-value {
  color: var(--dark);
  text-align: right;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.build-sidebar-section {
  margin-bottom: 16px;
}

.build-sidebar-title {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--gray-500);
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.build-sidebar-item {
  font-size: 0.875rem;
  color: var(--dark);
  padding: 4px 0;
}

.build-sidebar-item .label {
  color: var(--gray-500);
}

/* =============================================================================
   Input Bar
   ============================================================================= */

.build-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--gray-200);
}

#build-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--bg-light);
  color: var(--dark);
  min-height: 44px;
  max-height: 120px;
}

#build-send-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
}

#build-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.build-stop-btn {
  background: var(--danger, #ef4444) !important;
  color: white !important;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  animation: stop-pulse 1.5s ease-in-out infinite;
}

.build-stop-btn:hover {
  opacity: 0.85;
}

@keyframes stop-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* =============================================================================
   Streaming Indicator
   ============================================================================= */

.build-msg-streaming .build-msg-content::after {
  content: '▊';
  animation: blink 1s step-end infinite;
  color: var(--primary);
}

@keyframes blink {
  50% { opacity: 0; }
}

/* =============================================================================
   Empty State
   ============================================================================= */

.build-empty {
  text-align: center;
  color: var(--gray-400);
  margin-top: 40vh;
  font-size: 1.125rem;
}

/* =============================================================================
   Tool Cards — API execution status indicators
   ============================================================================= */

.tool-cards-container {
  align-self: flex-start;
  max-width: 75%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.tool-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border-left: 3px solid var(--gray-300);
  background: var(--bg-surface);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.tool-card-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--gray-500);
}

.tool-card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.tool-card-label {
  color: var(--dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-card-summary {
  color: var(--gray-500);
  font-size: 0.75rem;
}

/* Calling state — blue accent + spinner */
.tool-card-calling {
  border-left-color: var(--primary);
}

.tool-card-calling .tool-card-icon {
  color: var(--primary);
}

.tool-spinner {
  animation: tool-spin 0.8s linear infinite;
}

@keyframes tool-spin {
  to { transform: rotate(360deg); }
}

/* Success state — green accent + checkmark */
.tool-card-success {
  border-left-color: var(--success, #22c55e);
}

.tool-card-success .tool-card-icon {
  color: var(--success, #22c55e);
}

/* Error state — red accent + X */
.tool-card-error {
  border-left-color: var(--danger, #ef4444);
}

.tool-card-error .tool-card-icon {
  color: var(--danger, #ef4444);
}

/* =============================================================================
   Project Files Section
   ============================================================================= */

.build-files-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.build-file-item {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  background: var(--bg-light);
}

.build-file-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  cursor: pointer;
  user-select: none;
}

.build-file-link:hover .build-file-name {
  color: var(--primary);
}

.build-file-link:hover .build-file-download {
  opacity: 1;
}

.build-file-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.build-file-icon {
  flex-shrink: 0;
  font-size: 0.875rem;
}

.build-file-name {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}

.build-file-download {
  flex-shrink: 0;
  font-size: 0.875rem;
  color: var(--primary);
  opacity: 0.5;
  transition: opacity 0.15s;
}

.build-file-ref {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--gray-400);
}

.build-file-desc {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 2px;
  padding-left: 22px;
}

.build-file-warning {
  font-size: 0.6875rem;
  color: var(--warning, #f59e0b);
  margin-top: 2px;
  padding-left: 22px;
}

.build-file-pending {
  border-style: dashed;
  opacity: 0.85;
}

.build-file-empty {
  font-size: 0.8125rem;
  color: var(--gray-400);
  padding: 8px 0;
  text-align: center;
}

/* =============================================================================
   Tree-View Collapsible Sections
   ============================================================================= */

.tree-section {
  border-top: 1px solid var(--gray-200);
  padding-top: 0;
}

.tree-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  cursor: pointer;
  user-select: none;
}

.tree-header:hover {
  opacity: 0.8;
}

.tree-chevron {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  transition: transform 0.15s ease;
}

.tree-chevron::before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid var(--gray-500);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}

.tree-section:not(.collapsed) .tree-chevron::before {
  transform: rotate(90deg);
}

.tree-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--dark);
}

.tree-count {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--gray-500);
  background: var(--gray-100);
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.tree-body {
  padding: 0 0 8px 22px;
}

.tree-section.collapsed .tree-body {
  display: none;
}

.tree-leaf {
  font-size: 0.8125rem;
  color: var(--dark);
  padding: 3px 0;
  border-bottom: 1px solid var(--gray-100);
}

.tree-leaf:last-child {
  border-bottom: none;
}

.tree-tag {
  font-size: 0.75rem;
  color: var(--dark);
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 500;
}

.tree-empty {
  font-size: 0.8125rem;
  color: var(--gray-400);
  font-style: italic;
  padding: 3px 0;
}

.tree-action {
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--gray-100);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  user-select: none;
}

.tree-action:hover {
  background: var(--gray-200);
}

/* Files inside tree body need no extra left padding */
.tree-body.build-files-body {
  padding-left: 4px;
}

/* =============================================================================
   Dark Mode Overrides
   Most styles inherit correctly via CSS variables; these need explicit overrides.
   ============================================================================= */

[data-theme="dark"] .build-msg-assistant pre {
  background: var(--gray-200);
}

[data-theme="dark"] .build-msg-assistant code:not(pre code) {
  background: var(--gray-200);
}

[data-theme="dark"] .tool-card {
  background: var(--bg-surface);
  border-left-color: var(--gray-400);
}

[data-theme="dark"] .tool-card-calling {
  border-left-color: var(--primary);
}

[data-theme="dark"] .tool-card-success {
  border-left-color: var(--success, #22c55e);
}

[data-theme="dark"] .tool-card-error {
  border-left-color: var(--danger, #ef4444);
}

[data-theme="dark"] .build-file-item {
  background: var(--bg-light);
  border-color: var(--gray-400);
}

[data-theme="dark"] .tree-section {
  border-top-color: var(--gray-400);
}

[data-theme="dark"] .tree-count {
  background: var(--gray-300);
  color: var(--gray-100);
}

[data-theme="dark"] .tree-tag {
  background: var(--gray-300);
  color: var(--gray-600);
}

[data-theme="dark"] .tree-action {
  background: var(--gray-300);
}

[data-theme="dark"] .tree-leaf {
  border-bottom-color: var(--gray-400);
}

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

@media (max-width: 768px) {
  .build-sidebar {
    display: none;
  }

  .build-msg {
    max-width: 90%;
  }

  .tool-cards-container {
    max-width: 90%;
  }
}

/* Streaming cursor */
.build-msg-content.streaming::after {
  content: '▋';
  display: inline;
  animation: blink-cursor 0.6s steps(2) infinite;
  color: var(--primary);
  font-weight: 300;
  margin-left: 1px;
}

@keyframes blink-cursor {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
