/* AI Chat Component Styles */

/* Widget Container */
.ai-chat-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 400px;
  max-height: 600px;
  background: var(--bg-secondary, #1e1e2e);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  transition: all 0.3s ease;
}

.ai-chat-widget.minimized {
  height: 52px;
  min-height: 52px;
}

.ai-chat-widget.minimized .ai-chat-messages,
.ai-chat-widget.minimized .ai-chat-input-container,
.ai-chat-widget.minimized .ai-tier-badge {
  display: none;
}

/* Header */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
}

.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-title {
  display: flex;
  flex-direction: column;
}

.ai-name {
  font-weight: 600;
  font-size: 14px;
}

.ai-status {
  font-size: 11px;
  opacity: 0.8;
}

.ai-chat-header-actions {
  display: flex;
  gap: 4px;
}

.ai-chat-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  color: white;
  transition: background 0.2s;
}

.ai-chat-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Tier Badge */
.ai-tier-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-tertiary, rgba(255, 255, 255, 0.05));
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  font-size: 12px;
}

.ai-tier-badge .tier-name {
  font-weight: 600;
}

.ai-tier-badge .tier-usage {
  opacity: 0.7;
}

.ai-tier-badge.tier-free { color: #9ca3af; }
.ai-tier-badge.tier-basic { color: #fbbf24; }
.ai-tier-badge.tier-pro { color: #8b5cf6; }
.ai-tier-badge.tier-team { color: #06b6d4; }

/* Messages Container */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-primary, #0f0f17);
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

/* Messages */
.ai-message {
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}

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

.ai-message.user {
  align-self: flex-end;
}

.ai-message.assistant,
.ai-message.system,
.ai-message.error {
  align-self: flex-start;
}

.ai-message .message-content {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
}

.ai-message.user .message-content {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-message.assistant .message-content {
  background: var(--bg-secondary, #1e1e2e);
  color: var(--text-primary, #e2e8f0);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
}

.ai-message.system .message-content {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.ai-message.error .message-content {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.ai-message .message-content code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
}

/* Typing Indicator */
.ai-message.typing .typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.ai-message.typing .typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent-color, #6366f1);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.ai-message.typing .typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-message.typing .typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Input Container */
.ai-chat-input-container {
  padding: 12px 16px 16px;
  background: var(--bg-secondary, #1e1e2e);
  border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
}

.ai-chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-primary, #0f0f17);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.ai-chat-input-wrapper:focus-within {
  border-color: var(--accent-color, #6366f1);
}

#ai-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary, #e2e8f0);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 120px;
}

#ai-chat-input::placeholder {
  color: var(--text-muted, rgba(255, 255, 255, 0.4));
}

.ai-send-btn {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border: none;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  color: white;
  transition: transform 0.2s, opacity 0.2s;
}

.ai-send-btn:hover {
  transform: scale(1.05);
}

.ai-send-btn:active {
  transform: scale(0.95);
}

.ai-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Hint Buttons */
.ai-chat-hints {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.ai-hint-btn {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.ai-hint-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
}

/* Upgrade Button */
.ai-upgrade-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: transform 0.2s;
}

.ai-upgrade-btn:hover {
  transform: scale(1.02);
}

/* Responsive */
@media (max-width: 480px) {
  .ai-chat-widget {
    border-radius: 0;
    height: 100vh;
    max-height: none;
  }
  
  .ai-message {
    max-width: 90%;
  }
  
  .ai-chat-hints {
    display: none;
  }
}

/* Dashboard Integration */
.dashboard-ai-section {
  background: var(--bg-secondary, #1e1e2e);
  border-radius: 16px;
  overflow: hidden;
}

.dashboard-ai-section .ai-chat-widget {
  border-radius: 0;
  border: none;
}

/* Extension Popup Integration */
.popup-ai-chat {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  z-index: 1000;
  background: var(--bg-secondary);
  border-top: 2px solid var(--accent-color, #6366f1);
  border-radius: 16px 16px 0 0;
}

.popup-ai-chat .ai-chat-widget {
  border-radius: 16px 16px 0 0;
}

/* Floating Widget (Content Script) */
.smartnote-ai-floating {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  z-index: 2147483647;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.smartnote-ai-floating .ai-chat-widget {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.smartnote-ai-floating.minimized {
  width: 280px;
}

/* Floating Toggle Button */
.smartnote-ai-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: white;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
  z-index: 2147483646;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.smartnote-ai-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.smartnote-ai-toggle svg {
  width: 28px;
  height: 28px;
}

/* Dark Mode Adjustments */
@media (prefers-color-scheme: light) {
  .ai-chat-widget {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
  }
  
  .ai-message.assistant .message-content {
    background: #f1f5f9;
    color: #1e293b;
    border-color: #e2e8f0;
  }
  
  .ai-chat-messages {
    background: #ffffff;
  }
}
