/* AI 桌宠助手样式 */

/* 桌宠按钮 */
.ai-assistant-toggle {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: all 0.3s ease;
  animation: float 3s ease-in-out infinite;
}

.ai-assistant-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
}

.ai-avatar {
  font-size: 28px;
}

.ai-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ff6b6b;
  color: white;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* 对话窗口 */
.ai-assistant-window {
  position: fixed;
  right: 110px;
  top: 100px;
  width: 400px;
  height: 600px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  overflow: hidden;
  transition: all 0.3s ease;
}

/* 标题栏 */
.ai-window-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: grab;
  user-select: none;
}

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

.ai-avatar-small {
  font-size: 20px;
}

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

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

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

.ai-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

/* 聊天区域 */
.ai-chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.ai-chat-container::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.ai-welcome-message {
  text-align: center;
  padding: 20px;
  color: #718096;
  font-size: 14px;
  line-height: 1.6;
}

.ai-welcome-message p:first-child {
  font-size: 16px;
  font-weight: 600;
  color: #4a5568;
  margin-bottom: 8px;
}

/* 消息气泡 */
.ai-message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeIn 0.3s ease;
}

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

.ai-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-message-content {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

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

.ai-message-assistant .ai-message-content {
  background: white;
  color: #2d3748;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

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

/* Markdown样式 */
.ai-message-content h2,
.ai-message-content h3,
.ai-message-content h4 {
  margin: 12px 0 8px 0;
  font-weight: 600;
  color: #2d3748;
}

.ai-message-content h2 {
  font-size: 18px;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 4px;
}

.ai-message-content h3 {
  font-size: 16px;
}

.ai-message-content h4 {
  font-size: 14px;
}

.ai-message-content ul,
.ai-message-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.ai-message-content li {
  margin: 4px 0;
  line-height: 1.6;
}

.ai-message-content code {
  background: #f7fafc;
  color: #e53e3e;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
}

.ai-message-content pre {
  background: #2d3748;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.ai-message-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 13px;
}

.ai-message-content strong {
  font-weight: 600;
  color: #2d3748;
}

.ai-message-content em {
  font-style: italic;
}

.ai-message-content a {
  color: #667eea;
  text-decoration: underline;
}

.ai-message-content a:hover {
  color: #764ba2;
}

/* LaTeX公式样式 */
.ai-message-content .katex {
  font-size: 1.05em;
  line-height: 1;
}

.ai-message-content .katex-display {
  margin: 16px 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
  padding: 8px 0;
}

.ai-message-content .katex-display > .katex {
  display: inline-block;
  text-align: left;
}

/* 确保公式中的上下标正确显示 */
.ai-message-content .katex .mord,
.ai-message-content .katex .mbin,
.ai-message-content .katex .mrel,
.ai-message-content .katex .mop {
  line-height: 1;
}

/* 行内公式垂直对齐 */
.ai-message-content .katex {
  vertical-align: baseline;
  display: inline-block;
}

.ai-message-content .katex-display .katex {
  vertical-align: middle;
}

/* 公式渲染错误提示 */
.ai-message-content .latex-error {
  background: #fff5f5;
  color: #c53030;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  border: 1px dashed #fc8181;
  cursor: help;
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
}

.ai-message-content .latex-error:hover {
  background: #fed7d7;
  border-color: #f56565;
}

/* 公式占位符（流式渲染时的临时显示） */
.ai-message-content .latex-placeholder {
  background: #edf2f7;
  color: #718096;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  font-style: italic;
  display: inline-block;
}

/* 公式加载动画 */
.ai-message-content .katex.rendering {
  opacity: 0.5;
  animation: pulse 1s ease-in-out infinite;
}

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

/* 用户消息中的代码和公式样式调整 */
.ai-message-user .ai-message-content code {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.ai-message-user .ai-message-content pre {
  background: rgba(0, 0, 0, 0.2);
}

.ai-message-user .ai-message-content h2,
.ai-message-user .ai-message-content h3,
.ai-message-user .ai-message-content h4,
.ai-message-user .ai-message-content strong {
  color: white;
}

.ai-message-user .ai-message-content h2 {
  border-bottom-color: rgba(255, 255, 255, 0.3);
}

.ai-message-user .ai-message-content a {
  color: white;
  text-decoration: underline;
}

/* 加载动画 */
.ai-loading .ai-message-content {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-loading .ai-message-content::after {
  content: '';
  width: 20px;
  height: 4px;
  background: linear-gradient(90deg, #cbd5e0 0%, #4a5568 50%, #cbd5e0 100%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
  border-radius: 2px;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* 输入区域 */
.ai-input-container {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: white;
  border-top: 1px solid #e2e8f0;
  align-items: flex-end;
}

.ai-input {
  flex: 1;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.ai-input:focus {
  outline: none;
  border-color: #667eea;
}

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

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

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

/* 快捷问题 */
.ai-quick-questions {
  display: flex;
  gap: 8px;
  padding: 0 16px 16px;
  overflow-x: auto;
  background: white;
}

.ai-quick-questions::-webkit-scrollbar {
  height: 4px;
}

.ai-quick-questions::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 2px;
}

.ai-quick-btn {
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  background: white;
  color: #4a5568;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.ai-quick-btn:hover {
  border-color: #667eea;
  color: #667eea;
  background: #f7fafc;
}

/* 响应式 */
@media (max-width: 768px) {
  .ai-assistant-window {
    right: 0;
    left: 0;
    width: 100%;
    top: 0;
    bottom: 0;
    height: 100vh;
    border-radius: 0;
  }

  .ai-window-header {
    padding: 10px 14px;
  }

  .ai-assistant-name {
    font-size: 13px;
  }

  .ai-action-btn {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }

  .ai-header-actions {
    gap: 6px;
  }

  .ai-chat-container {
    padding: 10px;
    gap: 8px;
  }

  .ai-message-content {
    max-width: 80%;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.5;
  }

  .ai-message-avatar {
    width: 26px;
    height: 26px;
    font-size: 14px;
  }

  .ai-message {
    gap: 8px;
  }

  .ai-input-container {
    padding: 10px;
    gap: 8px;
  }

  .ai-input {
    font-size: 14px;
    padding: 8px 10px;
    min-height: 38px;
    max-height: 100px;
    border-radius: 10px;
  }

  /* 发送按钮缩小 */
  .ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 14px;
  }

  .ai-quick-questions {
    padding: 0 10px 10px;
    gap: 6px;
  }

  .ai-quick-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .ai-assistant-toggle {
    bottom: 14px;
    right: 14px;
    width: 52px;
    height: 52px;
  }

  .ai-avatar {
    font-size: 24px;
  }

  .ai-badge {
    font-size: 8px;
    padding: 2px 4px;
  }

  /* 代码块适配 */
  .ai-message-content pre {
    padding: 8px;
    font-size: 11px;
    overflow-x: auto;
  }

  .ai-message-content code {
    font-size: 11px;
    padding: 2px 4px;
  }

  /* 公式适配 */
  .ai-message-content .katex {
    font-size: 0.95em;
  }

  /* 标题适配 */
  .ai-message-content h2 {
    font-size: 15px;
    margin: 10px 0 6px 0;
  }

  .ai-message-content h3 {
    font-size: 14px;
    margin: 8px 0 5px 0;
  }

  .ai-message-content h4 {
    font-size: 13px;
    margin: 6px 0 4px 0;
  }

  /* 列表适配 */
  .ai-message-content ul,
  .ai-message-content ol {
    margin: 6px 0;
    padding-left: 20px;
  }

  .ai-message-content li {
    margin: 3px 0;
    font-size: 13px;
  }

  /* 欢迎消息 */
  .ai-welcome-message {
    padding: 16px;
    font-size: 13px;
  }

  .ai-welcome-message p:first-child {
    font-size: 15px;
  }
}

/* 超小屏幕优化 */
@media (max-width: 480px) {
  .ai-window-header {
    padding: 8px 12px;
  }

  .ai-assistant-name {
    font-size: 12px;
  }

  .ai-chat-container {
    padding: 8px;
  }

  .ai-message-content {
    max-width: 85%;
    padding: 7px 10px;
    font-size: 12px;
  }

  .ai-input {
    font-size: 14px;
    padding: 7px 9px;
  }

  /* 发送按钮进一步缩小 */
  .ai-send-btn {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }

  .ai-assistant-toggle {
    width: 48px;
    height: 48px;
    bottom: 12px;
    right: 12px;
  }

  .ai-avatar {
    font-size: 22px;
  }

  .ai-quick-btn {
    padding: 5px 8px;
    font-size: 10px;
  }
}
