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

:root {
  --bg: #0f0f11;
  --bg2: #18181b;
  --bg3: #1e1e22;
  --border: #2e2e34;
  --text: #e8e8ed;
  --text2: #a1a1aa;
  --text3: #71717a;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-light: #a78bfa;
  --sidebar-w: 260px;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.25s ease;
  z-index: 100;
}
.sidebar.hidden { transform: translateX(-100%); }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: white;
}
.logo-title { display: block; font-weight: 700; font-size: 15px; line-height: 1.2; }
.logo-sub { display: block; font-size: 11px; color: var(--text3); }
.sidebar-toggle {
  background: none; border: none; color: var(--text3); cursor: pointer;
  font-size: 16px; padding: 4px; border-radius: 4px;
}
.sidebar-toggle:hover { color: var(--text); background: var(--border); }

.new-chat-btn {
  margin: 12px; padding: 10px 14px;
  background: var(--accent); color: white;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.new-chat-btn:hover { background: var(--accent-hover); }
.btn-icon { font-size: 18px; line-height: 1; }

/* ── Sidebar scrollable area ── */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-scroll::-webkit-scrollbar { width: 3px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.agents-section { padding: 8px 8px 4px; }
.section-label {
  font-size: 11px; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 8px 8px 6px;
}

.agent-list { list-style: none; }
.agent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; color: var(--text2);
  transition: background 0.1s, color 0.1s;
}
.agent-item:hover, .agent-item.active { background: var(--bg3); color: var(--text); }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-cmo    { background: #7c3aed; }
.dot-bi     { background: #0ea5e9; }
.dot-seo    { background: #10b981; }
.dot-copy   { background: #f59e0b; }
.dot-arte   { background: #ec4899; }
.dot-social { background: #f97316; }
.dot-trafego{ background: #ef4444; }
.dot-ux     { background: #06b6d4; }
.dot-dev    { background: #84cc16; }

/* ── Section divider ── */
.section-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 12px 0;
  flex-shrink: 0;
}

/* ── Conversation list ── */
.history-section { padding: 4px 8px 8px; flex: 1; }

.conv-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-empty {
  font-size: 12px;
  color: var(--text3);
  padding: 8px 10px;
  font-style: italic;
}

.conv-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg3); }

.conv-item-content {
  flex: 1;
  min-width: 0;
}

.conv-title-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.conv-agent-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.conv-title {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.conv-meta {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-delete {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { color: #ef4444; background: rgba(239,68,68,0.1); }

/* ── Sidebar footer ── */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.powered-by { font-size: 11px; color: var(--text3); text-align: center; }

/* ── Main ── */
.main {
  margin-left: var(--sidebar-w);
  height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left 0.25s ease;
}
.main.expanded { margin-left: 0; }

/* ── Topbar ── */
.topbar {
  display: flex; align-items: center;
  padding: 0 16px; height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.menu-btn {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 20px; padding: 6px 8px; border-radius: var(--radius-sm);
  margin-right: 8px;
}
.menu-btn:hover { color: var(--text); background: var(--border); }
.topbar-center { flex: 1; display: flex; align-items: center; gap: 10px; }
.topbar-title { font-weight: 700; font-size: 15px; }
.topbar-status { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text3); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #10b981; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.4;} }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn { background: none; border: none; color: var(--text3); cursor: pointer; padding: 6px 8px; border-radius: var(--radius-sm); font-size: 16px; }
.icon-btn:hover { color: var(--text); background: var(--border); }

/* ── Agent target banner ── */
.agent-target-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: rgba(124, 58, 237, 0.08);
  border-bottom: 1px solid rgba(124, 58, 237, 0.2);
  font-size: 13px;
  color: var(--accent-light);
  flex-shrink: 0;
}
.agent-target-banner strong { color: var(--accent-light); font-weight: 600; }
.banner-icon { font-size: 16px; }

/* ── Chat Container ── */
.chat-container {
  flex: 1; overflow-y: auto; padding: 0;
  display: flex; flex-direction: column;
}
.chat-container::-webkit-scrollbar { width: 4px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Welcome Screen ── */
.welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; padding: 40px 24px; text-align: center;
}
.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-title { font-size: 28px; font-weight: 300; margin-bottom: 12px; }
.welcome-title strong { font-weight: 700; background: linear-gradient(135deg, #a78bfa, #60a5fa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.welcome-desc { color: var(--text2); max-width: 480px; line-height: 1.6; margin-bottom: 28px; }
.agent-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; max-width: 400px; width: 100%; margin-bottom: 28px;
}
.agent-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 8px; font-size: 12px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; cursor: default;
}
.agent-card:hover { border-color: var(--accent); }
.start-btn {
  padding: 13px 28px; background: var(--accent); color: white;
  border: none; border-radius: var(--radius); cursor: pointer;
  font-size: 15px; font-weight: 600; transition: background 0.15s, transform 0.1s;
}
.start-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.start-btn:active { transform: translateY(0); }

/* ── Messages ── */
.messages { display: flex; flex-direction: column; gap: 0; padding: 0; }
.messages.has-messages { padding: 20px 0 8px; }

.message {
  display: flex; gap: 14px; padding: 16px 24px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message:hover { background: rgba(255,255,255,0.015); }

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

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0; margin-top: 2px;
}
.message.user .avatar { background: linear-gradient(135deg, #7c3aed, #4f46e5); color: white; }
.message.assistant .avatar { background: var(--bg3); border: 1px solid var(--border); color: var(--accent-light); font-size: 16px; }

.bubble { flex: 1; min-width: 0; }
.message.user .bubble { display: flex; flex-direction: column; align-items: flex-end; }

/* ── Target tag on user messages ── */
.target-tag {
  font-size: 11px;
  color: var(--accent-light);
  background: rgba(124, 58, 237, 0.12);
  border: 1px solid rgba(124, 58, 237, 0.25);
  border-radius: 10px;
  padding: 2px 8px;
  margin-bottom: 4px;
  display: inline-block;
}

.user-text {
  background: var(--accent); color: white;
  padding: 11px 16px; border-radius: 18px 18px 4px 18px;
  font-size: 14px; line-height: 1.5; max-width: 75%; word-break: break-word;
}

.assistant-text {
  font-size: 14px; line-height: 1.7; color: var(--text); max-width: 100%;
}
.assistant-text h1,.assistant-text h2,.assistant-text h3 {
  margin: 18px 0 8px; font-weight: 600; color: var(--text);
}
.assistant-text h1 { font-size: 20px; }
.assistant-text h2 { font-size: 17px; color: var(--accent-light); }
.assistant-text h3 { font-size: 15px; }
.assistant-text p { margin-bottom: 10px; }
.assistant-text ul, .assistant-text ol { padding-left: 20px; margin-bottom: 10px; }
.assistant-text li { margin-bottom: 5px; }
.assistant-text strong { color: var(--accent-light); font-weight: 600; }
.assistant-text em { color: var(--text2); }
.assistant-text code {
  background: var(--bg3); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px;
}
.assistant-text pre {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; overflow-x: auto;
  margin: 10px 0;
}
.assistant-text pre code { background: none; border: none; padding: 0; }
.assistant-text table {
  width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px;
}
.assistant-text th, .assistant-text td {
  padding: 8px 12px; border: 1px solid var(--border); text-align: left;
}
.assistant-text th { background: var(--bg3); color: var(--accent-light); font-weight: 600; }
.assistant-text blockquote {
  border-left: 3px solid var(--accent); padding-left: 14px; color: var(--text2); margin: 10px 0;
}
.assistant-text a { color: var(--accent-light); }
.assistant-text hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* Agent badge */
.agent-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px 3px 8px;
  font-size: 11px; font-weight: 600; color: var(--text2);
  margin-bottom: 8px;
}
.agent-badge-dot { width: 7px; height: 7px; border-radius: 50%; }

/* Typing indicator */
.typing { display: flex; align-items: center; gap: 5px; padding: 4px 0 8px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text3);
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%,60%,100%{transform:translateY(0);} 30%{transform:translateY(-6px);} }

/* ── Input Area ── */
.input-area {
  padding: 12px 20px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px 10px 16px;
  transition: border-color 0.15s;
}
.input-wrapper:focus-within { border-color: var(--accent); }
.chat-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: 14px; line-height: 1.5;
  resize: none; max-height: 140px; overflow-y: auto;
}
.chat-input::placeholder { color: var(--text3); }
.send-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--accent); border: none; cursor: pointer;
  color: white; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s, opacity 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; opacity: 0.5; }
.input-hint { font-size: 11px; color: var(--text3); text-align: center; margin-top: 6px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { width: 240px; }
  .main { margin-left: 0; }
  .sidebar { transform: translateX(-100%); }
  .sidebar:not(.hidden) { transform: translateX(0); }
  .agent-grid { grid-template-columns: repeat(3, 1fr); }
}
