/* AI Chat — dark CRM UI */
.ai-layout {
  display: flex;
  height: 100vh;
  background: var(--bg);
  font-family: var(--font-body);
}

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

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

.ai-logo {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent-dim);
  border: 1px solid rgba(139,92,246,0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 14px;
}

.ai-sidebar-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin: 20px 20px 8px;
}

.assistant-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 16px;
}

.assistant-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  margin-bottom: 4px;
}

.assistant-item:hover {
  background: var(--surface);
  border-color: var(--border);
}

.assistant-item.active {
  background: var(--accent-dim);
  border-color: rgba(139,92,246,0.4);
}

.assistant-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 3px;
}

.assistant-item-desc {
  font-size: 12px;
  color: var(--fg-3);
  line-height: 1.4;
}

.assistant-item-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--fg-2);
}

.assistant-item.active .assistant-item-badge {
  background: rgba(139,92,246,0.2);
  border-color: rgba(139,92,246,0.3);
  color: var(--accent);
}

/* ── Main Chat Area ─────────────────────────────────────── */
.ai-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.ai-chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-2);
}

.ai-chat-header-info { flex: 1; min-width: 0; }

.ai-chat-assistant-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}

.ai-chat-assistant-status {
  font-size: 12px;
  color: var(--fg-3);
  margin-top: 2px;
}

.ai-status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 5px;
  vertical-align: middle;
}

.ai-status-dot.inactive { background: var(--fg-3); }
.ai-status-dot.loading { background: var(--yellow); animation: pulse 1.5s infinite; }

/* Model selector */
.ai-model-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg-2);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-body);
}

/* OpenAI warning banner */
.ai-warning-banner {
  margin: 16px 24px 0;
  padding: 12px 16px;
  background: rgba(251,191,36,0.08);
  border: 1px solid rgba(251,191,36,0.2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #fbbf24;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.ai-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--fg-3);
  text-align: center;
  padding: 40px;
}

.ai-empty-icon {
  width: 56px;
  height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-3);
  font-size: 24px;
}

.ai-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-2);
}

.ai-empty-desc {
  font-size: 13px;
  color: var(--fg-3);
  max-width: 300px;
  line-height: 1.6;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 720px;
}

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(139,92,246,0.3);
}

.message.user .message-avatar {
  background: var(--surface-2);
  color: var(--fg-2);
  border-color: var(--border);
}

.message-avatar.steady { background: var(--surface-2); color: var(--fg-2); }

.message-body {
  flex: 1;
  min-width: 0;
}

.message-meta {
  font-size: 11px;
  color: var(--fg-3);
  margin-bottom: 5px;
  font-weight: 500;
}

.message.user .message-meta { text-align: right; }

.message-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
}

.message.user .message-bubble {
  background: var(--accent-dim);
  border-color: rgba(139,92,246,0.25);
  color: var(--fg);
}

.message-bubble p { margin: 0 0 8px; }
.message-bubble p:last-child { margin-bottom: 0; }

.message-bubble code {
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
}

.message-bubble pre {
  background: var(--bg-3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-bubble pre code {
  background: none;
  padding: 0;
}

.message-bubble strong { color: var(--green); }
.message.user .message-bubble strong { color: var(--accent); }

/* typing indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--fg-3);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Suggested prompts */
.ai-suggested {
  padding: 0 24px 16px;
}

.ai-suggested-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin-bottom: 8px;
}

.suggested-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-2);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.chip:hover {
  background: var(--accent-dim);
  border-color: rgba(139,92,246,0.3);
  color: var(--accent);
}

/* Input area */
.ai-input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

.ai-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--fg);
  font-size: 14px;
  font-family: var(--font-body);
  resize: none;
  min-height: 48px;
  max-height: 140px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}

.ai-input::placeholder { color: var(--fg-3); }
.ai-input:focus { border-color: rgba(139,92,246,0.5); }

.ai-send-btn {
  width: 48px;
  height: 48px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.ai-send-btn:hover { background: #7c3aed; transform: scale(1.05); }
.ai-send-btn:disabled { background: var(--surface-2); color: var(--fg-3); cursor: not-allowed; transform: none; }

/* ── Context Panel ─────────────────────────────────────── */
.ai-context-panel {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, opacity 0.2s ease;
}

.ai-context-panel.collapsed {
  width: 0;
  border: none;
  overflow: hidden;
  opacity: 0;
}

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

.context-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.context-toggle-btn {
  background: none;
  border: none;
  color: var(--fg-3);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  border-radius: 6px;
  transition: all 0.15s;
}

.context-toggle-btn:hover { background: var(--surface); color: var(--fg); }

.context-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.context-section { }

.context-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin-bottom: 8px;
}

.context-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}

.context-card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 4px;
}

.context-card-value {
  font-size: 12px;
  color: var(--fg-2);
  line-height: 1.5;
}

.context-card-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 6px;
}

.badge-green { background: rgba(52,211,153,0.12); color: var(--green); }
.badge-yellow { background: rgba(251,191,36,0.12); color: var(--yellow); }
.badge-purple { background: rgba(139,92,246,0.12); color: var(--accent); }

.context-empty {
  font-size: 12px;
  color: var(--fg-3);
  text-align: center;
  padding: 20px;
  line-height: 1.6;
}

/* Scrollbar */
.ai-messages::-webkit-scrollbar,
.context-panel-body::-webkit-scrollbar,
.assistant-list::-webkit-scrollbar {
  width: 5px;
}
.ai-messages::-webkit-scrollbar-track,
.context-panel-body::-webkit-scrollbar-track,
.assistant-list::-webkit-scrollbar-track { background: transparent; }
.ai-messages::-webkit-scrollbar-thumb,
.context-panel-body::-webkit-scrollbar-thumb,
.assistant-list::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

/* Responsive */
@media (max-width: 900px) {
  .ai-context-panel { display: none; }
}

@media (max-width: 640px) {
  .ai-sidebar { width: 220px; }
  .ai-layout { gap: 0; }
}