* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

html, body {
  height: 100%;
  background: #0b0f1a;
  color: #e5e7eb;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ============ Header ============ */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #4338ca 0%, #6d28d9 50%, #9333ea 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

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

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
}

.brand h1 {
  font-size: 14px;
  font-weight: 600;
  color: white;
}

header button {
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

header button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.28);
}

header button:disabled {
  opacity: 0.5;
  cursor: default;
}

#status {
  margin-left: auto;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}

/* ============ Body layout: 3 panes ============ */
.body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.hint {
  color: #6b7280;
  font-size: 12.5px;
  padding: 16px;
}

/* ---- File tree (left) ---- */
#fileTree {
  width: 230px;
  min-width: 150px;
  max-width: 500px;
  background: #0f1424;
  overflow-y: auto;
  padding: 8px;
  flex-shrink: 0;
}

/* ---- Draggable dividers between panels ---- */
.resize-handle {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  position: relative;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: #6d28d9;
}

/* widen the invisible hit-area a little without changing the visible line */
.resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  right: -3px;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
  color: #d1d5db;
}

.tree-item:hover {
  background: #1a1f2e;
}

.tree-item.dir {
  color: #a5b4fc;
  font-weight: 600;
}

.tree-children {
  margin-left: 14px;
  display: none;
}

.tree-children.open {
  display: block;
}

/* ---- File preview (middle) ---- */
#filePreview {
  flex: 1;
  min-width: 200px;
  overflow-y: auto;
  background: #1e1e1e;
  display: flex;
  flex-direction: column;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: #171717;
  border-bottom: 1px solid #2a2a2a;
  position: sticky;
  top: 0;
}

.preview-filename {
  font-size: 12.5px;
  color: #d4d4d4;
  font-family: "Consolas", "Menlo", monospace;
}

.copy-btn {
  padding: 4px 10px;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  background: #262626;
  color: #d4d4d4;
  font-size: 11px;
  cursor: pointer;
}

.copy-btn:hover {
  background: #333333;
  border-color: #4a4a4a;
}

#filePreview .code-block {
  margin: 0;
  padding: 16px;
  background: transparent;
}

#filePreview code {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 12.5px;
  line-height: 1.7;
}

/* ---- Chat panel (right) ---- */
#chatPanel {
  width: 460px;
  min-width: 280px;
  max-width: 700px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0b0f1a;
}

#chatWindow {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: #6b7280;
  font-size: 12.5px;
}

.message-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-row.user { flex-direction: row-reverse; }

.avatar {
  min-width: 30px;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.avatar.user {
  background: linear-gradient(135deg, #4338ca, #9333ea);
  color: white;
}

.avatar.bot {
  background: #1f2937;
  border: 1px solid #374151;
  color: #9ca3af;
}

.bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 92%;
  word-wrap: break-word;
}

.msg-text {
  white-space: pre-wrap;
  margin: 4px 0;
}

.msg-text:first-child { margin-top: 0; }
.msg-text:last-child { margin-bottom: 0; }

/* Code blocks inside chat bubbles */
.code-block-wrapper {
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2a2a2a;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: #171717;
  font-size: 10.5px;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.code-block-header .copy-btn {
  padding: 3px 8px;
  font-size: 10.5px;
  text-transform: none;
}

.bubble .code-block {
  margin: 0;
  padding: 12px;
  background: #1e1e1e;
  overflow-x: auto;
}

.bubble .code-block code {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 11.5px;
  line-height: 1.6;
  white-space: pre;
}

.message-row.user .bubble {
  background: linear-gradient(135deg, #4338ca, #7c3aed);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-row.bot .bubble {
  background: #1a1f2e;
  color: #e5e7eb;
  border: 1px solid #262b3d;
  border-bottom-left-radius: 4px;
}

.bubble.error {
  background: #3f1d1d;
  border: 1px solid #7f1d1d;
  color: #fca5a5;
}

.typing-dots { display: flex; gap: 4px; padding: 4px 0; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9ca3af;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

#chatPanel footer {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: #101426;
  border-top: 1px solid #1f2437;
}

#questionInput {
  flex: 1;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid #262b3d;
  background: #1a1f2e;
  color: #e5e7eb;
  font-size: 12.5px;
  outline: none;
}

#questionInput:focus { border-color: #6d28d9; }
#questionInput:disabled { opacity: 0.5; }

#askBtn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #4338ca, #9333ea);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#askBtn:disabled { opacity: 0.4; cursor: default; }
