* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --text: #e0e0e0;
  --text-muted: #888;
  --primary: #6c5ce7;
  --primary-hover: #7c6df7;
  --human: #2d9cdb;
  --success: #00b894;
  --error: #e74c3c;
  --mention: #fdcb6e;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--primary);
}

.topic-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.topic-item {
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.2s;
}

.topic-item:hover { background: var(--surface2); }
.topic-item.active { background: var(--primary); color: white; }

.topic-item h3 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-item .meta {
  font-size: 12px;
  color: var(--text-muted);
}

.topic-item.active .meta { color: rgba(255,255,255,0.7); }

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

.empty-state h2 { margin-bottom: 8px; }

/* Chat */
.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.chat-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.chat-agents {
  display: flex;
  gap: 6px;
  flex: 1;
}

.agent-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.agent-badge.lead { background: var(--primary); color: white; }
.agent-badge.assistant { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }

.status-badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 500;
}

.status-badge.active { background: rgba(0,184,148,0.15); color: var(--success); }
.status-badge.completed { background: rgba(108,92,231,0.15); color: var(--primary); }

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 14px;
  position: relative;
}

.message.human {
  background: var(--human);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.ai {
  background: var(--surface2);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message .sender {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.message .sender .avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.message .content {
  word-break: break-word;
}

.message.human .content {
  white-space: pre-wrap;
}

/* Markdown inside AI messages */
.message.ai .content h1, .message.ai .content h2, .message.ai .content h3 {
  margin: 8px 0 4px;
  font-size: 14px;
  font-weight: 700;
}

.message.ai .content h2 { font-size: 15px; }
.message.ai .content h3 { font-size: 14px; }

.message.ai .content p { margin: 4px 0; }

.message.ai .content ul, .message.ai .content ol {
  margin: 4px 0;
  padding-left: 20px;
}

.message.ai .content table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}

.message.ai .content th, .message.ai .content td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}

.message.ai .content th { background: var(--surface); }

.message.ai .content code {
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}

.message.ai .content pre {
  background: var(--bg);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

.message.ai .content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.message.ai .content strong { color: #fff; }

.message .content .mention {
  color: var(--mention);
  font-weight: 600;
}

.message .time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.message.human .time { color: rgba(255,255,255,0.6); }

/* Thinking indicator */
.thinking {
  padding: 8px 20px;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s ease-in-out infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Input */
.chat-input {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
}

.chat-input textarea:focus { border-color: var(--primary); }
.chat-input textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
}

.btn-secondary:hover { background: var(--border); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}

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

.modal-header h2 { font-size: 16px; }

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

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

.modal-body label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
  margin-top: 16px;
}

.modal-body label:first-child { margin-top: 0; }

.modal-body input, .modal-body textarea, .modal-body select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.modal-body input:focus, .modal-body textarea:focus { border-color: var(--primary); }

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Templates */
.template-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-template {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.btn-template:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Agent config */
.agents-config {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.agent-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.agent-card-header {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.agent-card-header input { flex: 1; }

.agent-card-header select { width: 120px; }

.agent-card textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  min-height: 60px;
  outline: none;
}

.btn-remove-agent {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
