/* ========================
   AI Chat Assistant Styles
   Suparious Portfolio Chat
   Based on working TechFusion implementation
   ======================== */

/* Chat Widget Container */
.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--z-chat, 400);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Toggle Button */
.chat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
  color: white;
  position: relative;
}

.chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
}

.chat-toggle:focus-visible {
  outline: 3px solid #22d3ee;
  outline-offset: 3px;
}

.chat-toggle i {
  font-size: 1.5rem;
  color: white;
  transition: transform 0.3s ease;
}

.chat-toggle.active i {
  transform: rotate(90deg);
}

/* Notification Badge */
.chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: white;
  font-weight: 600;
}

.chat-badge.hidden {
  display: none;
}

/* Chat Window */
.chat-window {
  position: absolute !important;
  bottom: 80px !important;
  right: 0 !important;
  width: 380px !important;
  max-width: calc(100vw - 40px) !important;
  height: 500px !important;
  max-height: calc(100vh - 150px) !important;
  background: #ffffff !important;
  border-radius: 16px !important;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Chat Header */
.chat-header {
  order: 1 !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.chat-avatar i {
  font-size: 1.25rem;
}

.chat-header-text h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.chat-header-text p {
  font-size: 0.75rem;
  opacity: 0.9;
  margin: 0;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
}

.chat-status-indicator {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  animation: status-pulse 2s infinite;
}

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

.chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background 0.2s ease;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chat-close:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* Chat Messages Container */
.chat-messages {
  order: 2 !important;
  flex: 1 1 auto !important;
  min-height: 100px !important;
  overflow-y: auto !important;
  padding: 16px;
  display: flex !important;
  flex-direction: column !important;
  gap: 12px;
  background: #f8fafc;
  scroll-behavior: smooth;
}

/* Individual Message */
.chat-message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: message-in 0.3s ease;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.assistant {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.875rem;
}

.chat-message.user .message-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.chat-message.assistant .message-avatar {
  background: #e2e8f0;
  color: #667eea;
}

.message-content {
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 0.9rem;
}

.chat-message.user .message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant .message-content {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

/* Message Links */
.message-content a {
  color: inherit;
  text-decoration: underline;
  font-weight: 500;
}

.chat-message.assistant .message-content a {
  color: #667eea;
}

/* Typing Indicator */
.chat-message.typing .typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  width: fit-content;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Quick Suggestions */
.chat-suggestions {
  order: 3 !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  padding: 12px 16px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: #ffffff;
}

.suggestion-btn {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #475569;
  white-space: nowrap;
}

.suggestion-btn:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: #667eea;
}

.suggestion-btn:focus-visible {
  outline: 2px solid #22d3ee;
  outline-offset: 2px;
}

/* Chat Input Area */
.chat-input-area {
  order: 4 !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  padding: 16px;
  border-top: 1px solid #e2e8f0;
  background: #ffffff;
}

.chat-input-container {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.9rem;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  font-family: inherit;
  background: #ffffff;
  color: #1e293b;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input::placeholder {
  color: #94a3b8;
}

.chat-send {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.chat-send:focus-visible {
  outline: 3px solid #22d3ee;
  outline-offset: 3px;
}

/* API Key Notice / Footer */
.chat-api-notice {
  order: 5 !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  padding: 10px 16px;
  background: #f8fafc;
  font-size: 0.7rem;
  color: #94a3b8;
  text-align: center;
  border-top: 1px solid #e2e8f0;
}

.chat-api-notice a {
  color: #667eea;
  text-decoration: none;
}

.chat-api-notice a:hover {
  text-decoration: underline;
}

/* Error State */
.chat-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid #ef4444;
  color: #ef4444;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.85rem;
  margin: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-error i {
  flex-shrink: 0;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* System Preference Dark Mode - applies when user hasn't explicitly set light theme */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .chat-window {
        background: #1e293b;
    }

    :root:not([data-theme="light"]) .chat-messages {
        background: #0f172a;
    }

    :root:not([data-theme="light"]) .chat-message.assistant .message-content {
        background: #334155;
        color: #f1f5f9;
        border-color: #475569;
    }

    :root:not([data-theme="light"]) .chat-message.assistant .message-avatar {
        background: #334155;
    }

    :root:not([data-theme="light"]) .chat-suggestions {
        background: #1e293b;
        border-color: #334155;
    }

    :root:not([data-theme="light"]) .suggestion-btn {
        background: #334155;
        border-color: #475569;
        color: #e2e8f0;
    }

    :root:not([data-theme="light"]) .chat-input-area {
        background: #1e293b;
        border-color: #334155;
    }

    :root:not([data-theme="light"]) .chat-input {
        background: #334155;
        border-color: #475569;
        color: #f1f5f9;
    }

    :root:not([data-theme="light"]) .chat-input::placeholder {
        color: #64748b;
    }

    :root:not([data-theme="light"]) .chat-api-notice {
        background: #0f172a;
        border-color: #334155;
    }

    :root:not([data-theme="light"]) .typing-indicator {
        background: #334155;
        border-color: #475569;
    }

    :root:not([data-theme="light"]) .typing-indicator span {
        background: #64748b;
    }
}

/* Dark Mode - Using data-theme attribute (explicit user preference) */
[data-theme="dark"] .chat-window {
  background: #1e293b;
}

[data-theme="dark"] .chat-messages {
  background: #0f172a;
}

[data-theme="dark"] .chat-message.assistant .message-content {
  background: #334155;
  color: #f1f5f9;
  border-color: #475569;
}

[data-theme="dark"] .chat-message.assistant .message-avatar {
  background: #334155;
}

[data-theme="dark"] .chat-suggestions {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .suggestion-btn {
  background: #334155;
  border-color: #475569;
  color: #e2e8f0;
}

[data-theme="dark"] .chat-input-area {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .chat-input {
  background: #334155;
  border-color: #475569;
  color: #f1f5f9;
}

[data-theme="dark"] .chat-input::placeholder {
  color: #64748b;
}

[data-theme="dark"] .chat-api-notice {
  background: #0f172a;
  border-color: #334155;
}

[data-theme="dark"] .typing-indicator {
  background: #334155;
  border-color: #475569;
}

[data-theme="dark"] .typing-indicator span {
  background: #64748b;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .chat-widget {
    bottom: 16px;
    right: 16px;
  }

  .chat-window {
    width: calc(100vw - 32px);
    height: calc(100vh - 120px);
    bottom: 70px;
    right: -8px;
  }

  .chat-toggle {
    width: 50px;
    height: 50px;
  }

  .chat-toggle i {
    font-size: 1.25rem;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .chat-window,
  .chat-toggle,
  .chat-message,
  .typing-indicator span {
    animation: none;
    transition: opacity 0.1s ease;
  }

  .chat-status-indicator {
    animation: none;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .chat-window {
    border: 2px solid #1e293b;
  }

  .chat-message.assistant .message-content {
    border-width: 2px;
  }

  .chat-input {
    border-width: 2px;
  }
}

/* Print - Hide chat widget */
@media print {
  .chat-widget {
    display: none;
  }
}
