/* ============================================================
   💬 MODERN AI CHAT - Clean & Minimal
   ============================================================
   Inspired by: ChatGPT, Claude, Perplexity
   Design: Conversational, lightweight, professional
*/

:root {
  --chat-bg: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  --chat-surface: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  --chat-border: #2e5092;
  --chat-text: #ececec;
  --chat-text-secondary: #b4b4b4;
  --chat-user-bg: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  --chat-assistant-bg: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  --chat-primary: #10a37f;
  --chat-primary-light: rgba(16, 163, 127, 0.15);
  --chat-accent: #6366f1;
  --chat-error: #ff6b6b;
  --chat-success: #51cf66;

  
  /* Prefer dark mode for dashboard */
  @media (prefers-color-scheme: dark) {
    --chat-bg: #1a1a1a;
    --chat-surface: #2d2d2d;
    --chat-border: #404040;
    --chat-text: #ececec;
    --chat-text-secondary: #b4b4b7;
    --chat-user-bg: #404040;
    --chat-assistant-bg: #404040;
    --chat-text: #ececec;
  }

  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* Dark mode by default */
body.dark-theme,
body[data-theme="dark"] {
  --chat-bg: #1a1a1a;
  --chat-surface: #2d2d2d;
  --chat-border: #404040;
  --chat-text: #ececec;
  --chat-text-secondary: #b4b4b7;
  --chat-user-bg: #404040;
  --chat-assistant-bg: #404040;
  --chat-text: #ececec;
}

/* ============================================================
   CHAT PANEL - Sidebar/Dock Container
============================================================ */

#ai-chat-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 100%;
  max-width: 400px;
  height: 0;
  background: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  border-left: 1px solid var(--chat-border);
  border-top: 1px solid var(--chat-border);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
  font-family: var(--font-family);
  color: var(--chat-text);
  transition: height 0.3s ease, max-height 0.3s ease;
  overflow: hidden;
}

#ai-chat-panel.expanded {
  height: 600px;
  max-height: 80vh;
}

@media (max-width: 768px) {
  #ai-chat-panel {
    max-width: 100%;
  }
  
  #ai-chat-panel.expanded {
    height: 70vh;
  }
}

/* ============================================================
   CHAT HEADER
============================================================ */

#ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--chat-border);
  background: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  flex-shrink: 0;
  cursor: pointer;
  /* user-select: none; */
}

#ai-chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--chat-text);
}

.chat-title-icon {
  font-size: 18px;
}

#ai-chat-controls {
  display: flex;
  gap: 6px;
}

.chat-control-btn {
  /* background: none; */
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  font-size: 14px;
  color: var(--chat-text-secondary);
  transition: color 0.15s ease;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
}

.chat-control-btn:hover {
  color: var(--chat-text);
  background: var(--chat-surface);
}

/* ============================================================
   MESSAGES CONTAINER
============================================================ */

#ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

#ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

#ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--chat-text-secondary);
}

/* Empty state */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  opacity: 0.6;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.chat-empty-state h3 {
  margin: 0 0 8px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--chat-text);
}

.chat-empty-state p {
  margin: 0;
  font-size: 13px;
  color: var(--chat-text-secondary);
}

/* ============================================================
   MESSAGE BUBBLES
============================================================ */

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: slideIn 0.3s ease;
}

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

/* User messages - right */
.chat-message-user {
  align-items: flex-end;
}

.chat-message-user .message-bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-radius: 12px 12px 4px 12px;
  margin-left: 32px;
}

/* Assistant messages - left */
.chat-message-assistant {
  align-items: flex-start;
}

.chat-message-assistant .message-bubble {
  background: var(--assistant-bg);
  color: var(--assistant-text);
  border-radius: 12px 12px 12px 4px;
  margin-right: 32px;
}

.message-bubble {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  max-width: 100%;
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 14px;
  border-radius: 12px;
}

.message-avatar {
  flex-shrink: 0;
  font-size: 14px;
  display: flex;
  align-items: center;
}

.message-content {
  flex: 1;
}

.message-time {
  font-size: 11px;
  color: var(--chat-text-secondary);
  padding: 0 8px;
  opacity: 0.6;
}

.chat-message-user .message-time {
  text-align: right;
}

.chat-message-assistant .message-time {
  text-align: left;
}

/* Message Metadata - Provider Info & Reasoning */
.message-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px;
  font-size: 11px;
  opacity: 0.75;
}

.provider-badge {
  background: rgba(16, 163, 127, 0.15);
  color: #10a37f;
  padding: 3px 8px;
  border-radius: 4px;
  display: inline-block;
  font-weight: 500;
}

.reasoning-badge {
  background: rgba(100, 150, 255, 0.15);
  color: #6496ff;
  padding: 3px 8px;
  border-radius: 4px;
  display: inline-block;
  cursor: help;
  border-bottom: 1px dotted #6496ff;
}

.loading-indicator {
  display: inline-block;
  animation: pulse 1.5s ease-in-out infinite;
  margin-left: 6px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============================================================
   INPUT AREA
============================================================ */

#ai-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--chat-border);
  background: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  flex-shrink: 0;
}

#ai-chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#ai-chat-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--chat-border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  color: var(--chat-text);
  font-size: 14px;
  font-family: var(--font-family);
  outline: none;
  transition: all 0.15s ease;
  min-height: 36px;
  resize: none;
  max-height: 100px;
}

#ai-chat-input::placeholder {
  color: var(--chat-text-secondary);
  opacity: 0.7;
}

#ai-chat-input:focus {
  border-color: var(--chat-accent);
  background: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.1);
}

#ai-chat-send {
  padding: 8px 14px;
  min-width: 40px;
  height: 36px;
  background: linear-gradient(135deg, #090f18 0%, #1d253d 100%);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* #ai-chat-send:hover:not(:disabled) {
   background: #0d9970; 
} */

#ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   LEGACY MODAL (Deprecated - kept for compatibility)
============================================================ */

#ai-control-center-modal {
  display: none !important;
}

/* ============================================================
   RESPONSIVE
============================================================ */

@media (max-width: 640px) {
  #ai-chat-panel {
    max-width: 100%;
  }
  
  #ai-chat-header {
    padding: 12px;
  }
  
  #ai-chat-messages {
    padding: 12px;
  }
  
  #ai-chat-input-area {
    padding: 12px;
  }
  
  .message-bubble {
    padding: 8px 12px;
  }
  
  .chat-message-user .message-bubble {
    margin-left: 16px;
  }
  
  .chat-message-assistant .message-bubble {
    margin-right: 16px;
  }
}
