/* ============================================
   CHAT.CSS - AI Chat Interface
   Google-Inspired Clean Chat Design
   ============================================ */

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 600px;
  background: var(--color-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

/* ========== CHAT PAGE STYLES ========== */
.chat-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 64px); /* Subtract topbar height */
  overflow: hidden;
  background: var(--color-background);
}

/* Sidebar (History) */
.chat-sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-sidebar-header h2 {
  font-size: 1.125rem;
  margin: 0;
  font-weight: 600;
}

.new-chat-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-medium);
  background: var(--color-surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.new-chat-btn:hover {
  background: var(--google-blue);
  color: white;
  border-color: var(--google-blue);
  box-shadow: var(--shadow-sm);
}

.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary);
  text-decoration: none;
  border: 1px solid transparent;
}

.history-item:hover {
  background: var(--color-surface-subtle);
  color: var(--text-primary);
}

.history-item.active {
  background: var(--google-blue-subtle);
  color: var(--google-blue);
  border-color: rgba(66, 133, 244, 0.2);
  font-weight: 500;
}

.history-item i {
  font-size: 0.875rem;
  opacity: 0.7;
}

.history-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
}

/* Main Chat Area */
.chat-main {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  background: var(--color-background);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  gap: 1rem;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  animation: fadeIn 0.3s ease;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
}

.message.user .message-avatar {
  background: var(--google-blue);
  color: white;
}

.message.ai .message-avatar {
  background: var(--color-surface);
  border: 1px solid var(--border-medium);
  color: var(--google-green);
}

.message-content {
  background: var(--color-surface);
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  line-height: 1.6;
  color: var(--text-primary);
  position: relative;
  min-width: 200px;
}

.message.user .message-content {
  background: var(--google-blue);
  color: white;
  border-color: var(--google-blue);
  border-top-right-radius: 4px;
}

.message.ai .message-content {
  border-top-left-radius: 4px;
}

.message-meta {
  font-size: 0.75rem;
  margin-top: 0.5rem;
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.message.user .message-meta {
  justify-content: flex-end;
  color: rgba(255, 255, 255, 0.9);
}

/* Input Area */
.chat-input-area {
  padding: 1.5rem 2rem;
  background: var(--color-surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: center;
}

.input-wrapper {
  max-width: 800px;
  width: 100%;
  position: relative;
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  background: var(--color-surface-subtle);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
  border-color: var(--google-blue);
  box-shadow: var(--shadow-focus);
  background: var(--color-surface);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.5rem;
  resize: none;
  max-height: 150px;
  min-height: 24px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  outline: none;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--google-blue);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--google-blue-dark);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--text-disabled);
  cursor: not-allowed;
  transform: none;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-tertiary);
  padding: 2rem;
}

.empty-state i {
  font-size: 4rem;
  margin-bottom: 1.5rem;
  opacity: 0.2;
}

.empty-state h3 {
  font-size: 1.5rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Chat Header */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--border-light);
  gap: 1rem;
  flex-wrap: wrap;
}

.chat-header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 400;
  color: var(--text-primary);
}

/* Toggle Switch */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  user-select: none;
  position: relative;
}

.toggle-switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: relative;
  width: 40px;
  height: 20px;
  background: var(--border-medium);
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: all var(--transition-fast);
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--google-blue);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-switch:hover .toggle-slider {
  opacity: 0.85;
}

.toggle-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--color-background);
}

.message {
  display: flex;
  gap: 0.875rem;
  animation: messageSlideIn 0.3s ease-out;
  opacity: 1 !important;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
  font-weight: 500;
}

.user-message .message-avatar {
  background: var(--google-blue);
  color: white;
}

.assistant-message .message-avatar {
  background: var(--google-yellow);
  color: var(--text-primary);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-text {
  background: var(--color-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  font-size: 0.9375rem;
}

.user-message .message-text {
  background: var(--google-blue-subtle);
  border-color: var(--google-blue-light);
}

.message-text p {
  margin: 0 0 0.625rem 0;
}

.message-text p:last-child {
  margin-bottom: 0;
}

.message-text ul {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.message-text li {
  margin: 0.25rem 0;
}

.message-time {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  margin-top: 0.375rem;
  font-weight: 400;
}

/* Message Documents */
.message-documents {
  margin-top: 0.875rem;
  padding-top: 0.875rem;
  border-top: 1px solid var(--border-light);
}

.document-reference {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: var(--google-blue-subtle);
  border: 1px solid var(--google-blue-light);
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.document-reference:hover {
  background: var(--google-blue-subtle);
  border-color: var(--google-blue);
  transform: translateX(2px);
}

.doc-preview {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.doc-relevance {
  font-size: 0.6875rem;
  color: var(--google-blue);
  font-weight: 600;
  margin-top: 0.25rem;
}

/* Typing Indicator */
.typing-indicator {
  opacity: 0.7;
}

.typing-dots {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--google-blue);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Chat Input */
.chat-input-container {
  padding: 1.25rem 1.5rem;
  background: var(--color-surface);
  border-top: 1px solid var(--border-light);
}

.chat-input-wrapper {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--text-primary);
  font-size: 0.9375rem;
  line-height: 1.5;
  resize: none;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.chat-input:hover {
  border-color: var(--border-dark);
}

.chat-input:focus {
  outline: none;
  border-color: var(--google-blue);
  box-shadow: var(--shadow-focus);
}

.chat-send-button {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--google-blue);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.chat-send-button:hover:not(:disabled) {
  background: var(--google-blue-dark);
  box-shadow: var(--shadow-md);
}

.chat-send-button:active:not(:disabled) {
  transform: scale(0.96);
}

.chat-send-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Chat Suggestions */
.chat-suggestions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  background: var(--color-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.suggestion-chip:hover {
  background: var(--google-blue-subtle);
  border-color: var(--google-blue);
  color: var(--google-blue);
}

.suggestion-chip i {
  font-size: 0.875rem;
}

/* Chat Input Actions */
.chat-input-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.chat-voice-btn {
  border: 1px solid var(--border-light);
  background: var(--color-surface);
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.875rem;
}

.chat-voice-btn:hover {
  background: var(--google-blue-subtle);
  color: var(--google-blue);
  border-color: var(--google-blue-light);
}

.chat-voice-btn.voice-listening {
  background: rgba(217,48,37,0.08);
  color: #d93025;
  border-color: rgba(217,48,37,0.5);
}

/* Responsive */
@media (max-width: 768px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }
  
  .chat-sidebar {
    display: none; /* Hide sidebar on mobile for now, or add toggle */
  }
  
  .chat-messages {
    padding: 1rem;
  }
  
  .message {
    max-width: 100%;
  }

  .chat-container {
    height: calc(100vh - 150px);
    border-radius: var(--radius-lg);
  }

  .chat-header {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
  }

  .message {
    gap: 0.625rem;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.9375rem;
  }

  .chat-input-container {
    padding: 1rem;
  }

  .chat-suggestions {
    gap: 0.5rem;
  }

  .suggestion-chip {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
  }
}
