/* Chat Page Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f1419;
  --bg-secondary: #1a1f2e;
  --bg-tertiary: #242b3d;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-muted: #5f6368;
  --accent-primary: #8b5cf6;
  --accent-secondary: #6366f1;
  --border-color: #2d3548;
  --sidebar-width: 280px;
  --user-bubble: #8b5cf6;
  --ai-bubble: #2d3548;
  --highlight-color: #fbbf24;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

.chat-page {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

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

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.chat-badge {
  display: inline-block;
  padding: 4px 12px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-icon {
  font-size: 18px;
}

.nav-text {
  font-size: 14px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  font-size: 12px;
}

.tip {
  color: var(--accent-primary);
  font-weight: 600;
  margin-bottom: 4px;
}

.tip-text {
  color: var(--text-muted);
  line-height: 1.5;
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

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

.header-info h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

.status-dot.connecting {
  background: #f59e0b;
  animation: pulse 1s infinite;
}

.status-dot.error {
  background: #ef4444;
}

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

/* Chat Container */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 30px;
}

/* Welcome Message */
.welcome-message {
  max-width: 600px;
  margin: 40px auto;
  text-align: center;
  padding: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.welcome-message h2 {
  font-size: 24px;
  margin-bottom: 12px;
}

.welcome-message p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.example-questions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.example-btn {
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
}

.example-btn:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

/* Messages */
.messages {
  max-width: 900px;
  margin: 0 auto;
}

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: fadeIn 0.3s ease-in;
}

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

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

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

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

.message.ai .message-avatar {
  background: var(--bg-tertiary);
}

.message-content {
  max-width: 70%;
}

.message.user .message-content {
  display: flex;
  justify-content: flex-end;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.6;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
}

.message.ai .message-bubble {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.message-name {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.message.ai .message-name {
  text-align: left;
}

/* Message formatting */
.message-bubble p {
  margin-bottom: 8px;
}

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

.message-bubble strong {
  color: var(--highlight-color);
  font-weight: 600;
}

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

.message-bubble a {
  color: var(--accent-primary);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent-primary);
}

.message-bubble a:hover {
  border-bottom-style: solid;
}

.message-bubble ul,
.message-bubble ol {
  margin-left: 20px;
  margin-bottom: 8px;
}

/* Source Tags */
.source-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.source-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.source-tag:hover {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.source-tag-icon {
  font-size: 14px;
}

.source-tag-text {
  color: var(--accent-primary);
  font-weight: 500;
}

/* Highlighting */
.highlight {
  background: rgba(251, 191, 36, 0.2);
  border-bottom: 2px solid var(--highlight-color);
  padding: 2px 4px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.2s;
}

.highlight:hover {
  background: rgba(251, 191, 36, 0.3);
}

/* Source Bubble */
.source-bubble {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(139, 92, 246, 0.1);
  z-index: 1000;
  min-width: 280px;
  max-width: 380px;
  animation: bubbleIn 0.2s ease-out;
}

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

.bubble-title {
  font-size: 14px;
  font-weight: 600;
}

.bubble-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.bubble-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.bubble-content {
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
}

.bubble-source {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 8px;
  transition: all 0.2s;
}

.bubble-source:last-child {
  margin-bottom: 0;
}

.bubble-source:hover {
  background: var(--accent-primary);
}

.bubble-source:hover .bubble-source-title {
  color: white;
}

.bubble-source-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.bubble-source-type {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.bubble-source-url {
  display: block;
  margin-top: 8px;
  color: var(--accent-primary);
  font-size: 13px;
  text-decoration: none;
}

.bubble-source:hover .bubble-source-url {
  color: white;
}

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

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

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

/* Retry message styling */
.retry-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.retry-icon {
  font-size: 18px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Input Area */
.input-area {
  padding: 20px 30px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.input-wrapper {
  display: flex;
  gap: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 4px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent-primary);
}

#messageInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  padding: 12px 16px;
  min-height: 24px;
  max-height: 150px;
}

#messageInput:focus {
  outline: none;
}

#messageInput::placeholder {
  color: var(--text-muted);
}

.send-button {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.2s;
}

.send-button:hover:not(:disabled) {
  transform: scale(1.05);
}

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

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .chat-header,
  .chat-container,
  .input-area {
    padding: 16px;
  }

  .message-content {
    max-width: 85%;
  }

  .example-questions {
    grid-template-columns: 1fr;
  }

  .source-bubble {
    left: 10px !important;
    right: 10px !important;
    min-width: auto;
  }
}

/* Source Highlighting - 高亮与信息源相关的文本 */
.source-highlight {
  background: linear-gradient(120deg, rgba(139, 92, 246, 0.25), rgba(59, 130, 246, 0.25));
  border-bottom: 2px solid rgba(139, 92, 246, 0.6);
  padding: 2px 4px;
  border-radius: 4px;
  cursor: help;
  transition: all 0.2s ease;
  position: relative;
}

.source-highlight:hover {
  background: linear-gradient(120deg, rgba(139, 92, 246, 0.4), rgba(59, 130, 246, 0.4));
  border-bottom-color: rgba(139, 92, 246, 1);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

/* Source hint */
.source-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Bubble Sections */
.bubble-section {
  margin-bottom: 16px;
}

.bubble-section:last-child {
  margin-bottom: 0;
}

.bubble-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

/* External source styling */
.bubble-source.external {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.15));
  border: 1px solid rgba(139, 92, 246, 0.3);
  padding: 14px;
}

.bubble-source.external:hover {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(59, 130, 246, 0.25));
  border-color: rgba(139, 92, 246, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.bubble-source-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  line-height: 1.5;
}

.bubble-source-url.external-link {
  color: #8b5cf6;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.bubble-source-url.external-link:hover {
  color: #a78bfa;
  text-decoration: underline;
}

/* Internal source styling */
.bubble-source.internal {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.bubble-source-url.internal-link {
  color: var(--accent-primary);
}

/* Animation for bubble appearance */
@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Citation mark styling */
.citation-mark {
  display: inline-block;
  cursor: pointer;
  margin-left: 2px;
  margin-right: 2px;
  font-size: 14px;
  vertical-align: super;
  line-height: 1;
  user-select: none;
  transition: all 0.2s ease;
  filter: grayscale(0.3);
}

.citation-mark:hover {
  filter: grayscale(0);
  transform: scale(1.2);
}

/* Improved bubble source layout */
.bubble-source {
  display: flex;
  gap: 12px;
  padding: 14px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 10px;
  transition: all 0.2s;
}

.bubble-source:last-child {
  margin-bottom: 0;
}

.bubble-source-number {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-primary);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
}

.bubble-source-content {
  flex: 1;
  min-width: 0;
}

.bubble-source-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
  line-height: 1.4;
}

.bubble-source-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.5;
}

.bubble-source-type {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bubble-source-url {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  text-decoration: none;
  font-weight: 500;
}

.bubble-source.external .bubble-source-number {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}
