/* ===== AI Chat Widget ===== */

/* 悬浮按钮 */
#ai-chat-fab {
  position: fixed !important;
  bottom: 34%;
  right:0px;
  width: 52px;
  height: 46px;
  border-radius: 3px;
  background: #1a73e8;
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(26, 115, 232, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  z-index: -9999999;
  transition: transform 0.2s, box-shadow 0.2s;
  line-height: 1;
  padding: 0;
}

#ai-chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 18px rgba(26, 115, 232, 0.5);
}

#ai-chat-fab.active {
  background: #5f6368;
  font-size: 18px;
}

/* 聊天窗口容器 */
#ai-chat-window {
  position: fixed;
  bottom: calc(32% + 60px);
  right: 24px;
  width: 440px;
  height: 560px;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483646;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  background: #fff;
}

#ai-chat-window.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* 顶栏 */
.ai-chat-header {
  background: #1a73e8;
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ai-chat-header-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.ai-chat-header-info {
  flex: 1;
}

.ai-chat-header-title {
  font-weight: 600;
  font-size: 15px;
}

.ai-chat-header-status {
  font-size: 11px;
  opacity: 0.85;
}

.ai-chat-header-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  opacity: 0.7;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: opacity 0.15s;
}

.ai-chat-header-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

/* 消息区域 */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8f9fa;
}

/* 单条消息行 */
.ai-chat-msg {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: flex-start;
}

.ai-chat-msg.user {
  justify-content: flex-end;
}

/* AI 头像 */
.ai-chat-msg-avatar {
  width: 30px;
  height: 30px;
  background: #1a73e8;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* 消息气泡 */
.ai-chat-msg-bubble {
  max-width: 75%;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}

.ai-chat-msg.ai .ai-chat-msg-bubble {
  background: #fff;
  color: #333;
  border: 1px solid #e8e8e8;
  border-radius: 0 12px 12px 12px;
}

.ai-chat-msg.user .ai-chat-msg-bubble {
  background: #1a73e8;
  color: #fff;
  border-radius: 12px 0 12px 12px;
}

/* AI 消息上方小标签 */
.ai-chat-msg-label {
  font-size: 11px;
  color: #999;
  margin-bottom: 4px;
  margin-left: 42px;
}

/* 打字光标 */
.ai-chat-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: #1a73e8;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: ai-chat-blink 0.8s infinite;
}

@keyframes ai-chat-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 错误消息 */
.ai-chat-error {
  text-align: center;
  padding: 10px 14px;
  font-size: 12px;
  color: #d93025;
  background: #fce8e6;
  border-radius: 8px;
  margin-bottom: 14px;
}

.ai-chat-error-retry {
  display: inline-block;
  color: #1a73e8;
  cursor: pointer;
  text-decoration: underline;
  margin-left: 6px;
  font-weight: 600;
}

/* 输入区域 */
.ai-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 8px;
  align-items: center;
  background: #fff;
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.ai-chat-input:focus {
  border-color: #1a73e8;
}

.ai-chat-input:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
}

.ai-chat-send {
  width: 36px;
  height: 36px;
  background: #1a73e8;
  border-radius: 8px;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  padding: 0;
}

.ai-chat-send:hover {
  background: #1557b0;
}

.ai-chat-send:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
}

/* Loading 动画 */
.ai-chat-send.loading {
  position: relative;
  pointer-events: none;
}

.ai-chat-send.loading::after {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ai-chat-spin 0.6s linear infinite;
}

.ai-chat-send.loading svg {
  display: none;
}

@keyframes ai-chat-spin {
  to { transform: rotate(360deg); }
}

/* 移动端适配 */
@media screen and (max-width: 480px) {
  #ai-chat-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    right: 8px;
    bottom: 76px;
  }
}

/* ===== Markdown 渲染样式 ===== */

/* 标题 */
.md-h1 { font-size: 16px; font-weight: 700; margin: 6px 0 2px; color: #1a1a1a; }
.md-h2 { font-size: 15px; font-weight: 700; margin: 5px 0 2px; color: #1a1a1a; }
.md-h3 { font-size: 14px; font-weight: 600; margin: 4px 0 2px; color: #333; }
.md-h4 { font-size: 13px; font-weight: 600; margin: 4px 0 2px; color: #333; }

/* 代码块 */
.md-code-block {
  background: #f1f3f4;
  border-radius: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  font-size: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  margin: 4px 0;
  line-height: 1.4;
  border: 1px solid #e8e8e8;
}

/* 行内代码 */
.md-code-inline {
  background: #f1f3f4;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: #d63384;
}

/* 引用 */
.md-quote {
  border-left: 3px solid #1a73e8;
  padding: 2px 10px;
  margin: 4px 0;
  color: #666;
  background: #f8f9fa;
  border-radius: 0 4px 4px 0;
}

/* 分隔线 */
.md-hr {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 6px 0;
}

/* 链接 */
.md-link {
  color: #1a73e8;
  text-decoration: none;
}
.md-link:hover {
  text-decoration: underline;
}

/* 列表项 */
.md-li {
  padding-left: 8px;
  margin: 1px 0;
  line-height: 1.4;
}
.md-li-ol .md-li-num {
  color: #1a73e8;
  font-weight: 600;
  margin-right: 2px;
}

/* 表格 */
.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0;
  font-size: 12px;
  line-height: 1.3;
}
.md-table th {
  background: #f1f3f4;
  font-weight: 600;
  text-align: left;
  padding: 4px 8px;
  border: 1px solid #e0e0e0;
}
.md-table td {
  padding: 3px 8px;
  border: 1px solid #e0e0e0;
}
.md-table tr:nth-child(even) td {
  background: #fafbfc;
}
