/* ═══════════════════════════════════════════════════════════
   RflySim 慧答 Chat Widget Styles
   通过 SSE 连接 guard 网关
   ═══════════════════════════════════════════════════════════ */

:root {
  --docai-primary: #2962FF;
  --docai-primary-light: #448AFF;
  --docai-primary-dark: #0039CB;
  --docai-accent: #00B0FF;
  --docai-bg: #ffffff;
  --docai-bg-secondary: #f8f9fb;
  --docai-text: #1a1a2e;
  --docai-text-secondary: #6b7280;
  --docai-border: #e5e7eb;
  --docai-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  --docai-radius: 16px;
  --docai-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ── 浮动按钮 ── */
#docai-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--docai-primary), var(--docai-accent));
  border: none;
  cursor: pointer;
  z-index: 99990;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(41, 98, 255, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#docai-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 28px rgba(41, 98, 255, 0.5);
}

#docai-fab svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s;
}

#docai-fab.open svg {
  transform: rotate(90deg);
}

/* ── 脉冲光环 ── */
#docai-pulse {
  position: fixed;
  bottom: 35px;
  right: 35px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(41, 98, 255, 0.3);
  z-index: 99989;
  pointer-events: none;
  animation: docai-pulse 2s infinite cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes docai-pulse {
  0% { transform: scale(0.8); opacity: 0.6; }
  100% { transform: scale(3.5); opacity: 0; }
}

/* ── 气泡提示 ── */
#docai-hint {
  position: fixed;
  bottom: 96px;
  right: 20px;
  background: linear-gradient(135deg, var(--docai-primary), var(--docai-accent));
  color: #fff;
  padding: 10px 18px;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 6px 18px rgba(41, 98, 255, 0.3);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--docai-font);
  z-index: 99991;
  cursor: pointer;
  animation: docai-float 3s ease-in-out infinite;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 200px;
  text-align: center;
}

#docai-hint:hover {
  transform: scale(1.05) translateY(-3px);
}

#docai-hint.hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.8);
  pointer-events: none;
}

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

/* ── 聊天面板 ── */
#docai-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  /* 固定宽度：不随窗口缩小而压窄回答文字，只有窗口比面板还窄时才让位 */
  width: var(--docai-panel-width, 500px);
  max-width: calc(100vw - 40px);
  height: min(var(--docai-panel-height, 920px), calc(100vh - 120px));
  max-height: calc(100vh - 120px);
  background: var(--docai-bg);
  border-radius: var(--docai-radius);
  box-shadow: var(--docai-shadow);
  z-index: 99992;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: var(--docai-font);
}

#docai-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── 头部 ── */
.docai-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--docai-primary), var(--docai-primary-light));
  color: white;
  flex-shrink: 0;
}

.docai-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.docai-header-text h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.docai-header-text p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.85;
}

.docai-header-close {
  margin-left: auto;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  padding: 4px;
  border-radius: 6px;
}

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

/* ── 消息区域 ── */
.docai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.docai-messages::-webkit-scrollbar {
  width: 4px;
}

.docai-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

/* ── 消息气泡 ── */
.docai-msg {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: docai-msg-in 0.3s ease-out;
}

@keyframes docai-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.docai-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

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

.docai-msg.bot .docai-msg-avatar {
  background: linear-gradient(135deg, var(--docai-primary), var(--docai-accent));
  color: white;
}

.docai-msg.user .docai-msg-avatar {
  background: #e5e7eb;
  color: #374151;
}

.docai-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 14px;
  word-break: break-word;
}

/* AI 回答占满面板可用宽度，文字不被挤窄；min-width:0 让内部代码块能正常换行 */
.docai-msg.bot {
  max-width: 100%;
}

.docai-msg.bot .docai-msg-bubble {
  background: var(--docai-bg-secondary);
  color: var(--docai-text);
  border-bottom-left-radius: 4px;
  flex: 1;
  min-width: 0;
}

.docai-msg.user .docai-msg-bubble {
  background: linear-gradient(135deg, var(--docai-primary), var(--docai-primary-light));
  color: white;
  border-bottom-right-radius: 4px;
}

/* ── Markdown 渲染 ── */
.docai-msg-bubble h1, .docai-msg-bubble h2, .docai-msg-bubble h3 {
  margin: 8px 0 4px;
  font-size: 15px;
  font-weight: 700;
}

.docai-msg-bubble p {
  margin: 4px 0;
}

.docai-msg-bubble code {
  background: #e2e8f0;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: "Fira Code", "Cascadia Code", Consolas, monospace;
}

.docai-msg-bubble pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 8px;
  /* 长代码自动换行，不再被面板右边截断、无需横向滚动 */
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 12.5px;
  margin: 6px 0;
}

.docai-msg-bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.docai-msg-bubble ul, .docai-msg-bubble ol {
  padding-left: 18px;
  margin: 4px 0;
}

.docai-msg-bubble a {
  color: var(--docai-primary);
  text-decoration: none;
}

.docai-msg-bubble a:hover {
  text-decoration: underline;
}

.docai-msg-bubble sup {
  color: var(--docai-primary);
  font-size: 10px;
  font-weight: 700;
  margin-left: 2px;
}

.docai-msg-bubble sup a {
  color: inherit;
  text-decoration: none;
}

/* ── 表格 (marked.js GFM tables) ── */
.docai-msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12.5px;
}

.docai-msg-bubble th,
.docai-msg-bubble td {
  border: 1px solid var(--docai-border);
  padding: 6px 10px;
  text-align: left;
}

.docai-msg-bubble th {
  background: #eef2ff;
  font-weight: 600;
}

.docai-msg-bubble tr:nth-child(even) {
  background: #f8fafc;
}

/* ── 引用块 ── */
.docai-msg-bubble blockquote {
  border-left: 3px solid var(--docai-primary-light);
  margin: 6px 0;
  padding: 4px 12px;
  color: var(--docai-text-secondary);
  background: #f8fafc;
  border-radius: 0 6px 6px 0;
}

/* ── 分隔线 ── */
.docai-msg-bubble hr {
  border: none;
  border-top: 1px solid var(--docai-border);
  margin: 8px 0;
}

/* ── 引用卡片 ── */
.docai-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.docai-citation {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: white;
  border: 1px solid var(--docai-border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--docai-primary);
  text-decoration: none;
  transition: all 0.2s;
}

.docai-citation:hover {
  background: #eef2ff;
  border-color: var(--docai-primary-light);
}

.docai-citation::before {
  content: "📄";
  font-size: 11px;
}

/* ── 推荐追问 ── */
.docai-followups {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--docai-border);
}

.docai-followups-title {
  font-size: 12px;
  color: var(--docai-text-secondary);
  font-weight: 600;
}

.docai-followup-btn {
  width: 100%;
  border: 1px solid var(--docai-border);
  background: white;
  color: var(--docai-text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  font-family: var(--docai-font);
  transition: all 0.2s;
}

.docai-followup-btn:hover {
  border-color: var(--docai-primary-light);
  background: #eef2ff;
  color: var(--docai-primary);
}

/* ── 状态指示器 ── */
.docai-status {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--docai-text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  animation: docai-msg-in 0.2s ease-out;
}

.docai-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--docai-primary);
  animation: docai-blink 1.2s infinite;
}

@keyframes docai-blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ── 输入区域 ── */
.docai-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--docai-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--docai-bg);
  flex-shrink: 0;
}

.docai-input-area textarea {
  flex: 1;
  border: 1px solid var(--docai-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--docai-font);
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  max-height: 120px;
  line-height: 1.4;
  background: var(--docai-bg-secondary);
}

.docai-input-area textarea:focus {
  border-color: var(--docai-primary);
  background: white;
}

.docai-input-area textarea::placeholder {
  color: #9ca3af;
}

.docai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--docai-primary), var(--docai-accent));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.docai-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(41, 98, 255, 0.3);
}

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

.docai-send-btn svg {
  width: 20px;
  height: 20px;
  fill: white;
}

/* ── 页脚 ── */
.docai-footer {
  padding: 6px 16px;
  text-align: center;
  font-size: 11px;
  color: var(--docai-text-secondary);
  background: var(--docai-bg-secondary);
  border-top: 1px solid var(--docai-border);
  flex-shrink: 0;
}

.docai-footer a {
  color: var(--docai-primary);
  text-decoration: none;
}

/* ── 欢迎消息 ── */
.docai-welcome {
  text-align: center;
  padding: 20px;
  color: var(--docai-text-secondary);
}

.docai-welcome-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.docai-welcome h4 {
  margin: 0 0 6px;
  color: var(--docai-text);
  font-size: 16px;
}

.docai-welcome p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.docai-quick-questions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.docai-quick-q {
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--docai-border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--docai-text);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.docai-quick-q:hover {
  border-color: var(--docai-primary);
  background: #eef2ff;
  color: var(--docai-primary);
}

/* ── 发送按钮：流式中切换为停止态 ── */
.docai-send-btn.streaming {
  background: linear-gradient(135deg, #ef4444, #f87171);
}

/* ── 消息操作条：重试 + 👍/👎 ── */
.docai-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.docai-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: 1px solid var(--docai-border);
  border-radius: 8px;
  background: var(--docai-bg);
  color: var(--docai-text-secondary);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.18s;
}

.docai-action-btn:hover {
  border-color: var(--docai-primary);
  color: var(--docai-primary);
  background: #eef2ff;
}

.docai-action-btn.active {
  border-color: var(--docai-primary);
  color: var(--docai-primary);
  background: #e0e7ff;
}

.docai-action-btn svg {
  fill: currentColor;
}

/* ── 「已停止」提示 ── */
.docai-stopped {
  margin-top: 6px;
  font-size: 12px;
  color: var(--docai-text-secondary);
}

/* ── 移动端适配 ── */
@media (max-width: 480px) {
  #docai-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}

/* 用量余额徽标（footer 左侧，弱化展示） */
.docai-usage { font-size: 11px; color: #94a3b8; margin-right: auto; }
