/**
 * 亚觅智库 AI 对话窗口 —— 前端样式
 * Version: 1.0.0
 */

/* ===== CSS 变量（由 JS 动态注入 --yami-primary） ===== */
:root {
  --yami-primary: #2563eb;
  --yami-primary-dark: #1d4ed8;
  --yami-bg: #ffffff;
  --yami-surface: #f8fafc;
  --yami-text: #1e293b;
  --yami-text-muted: #64748b;
  --yami-border: #e2e8f0;
  --yami-user-bubble: #2563eb;
  --yami-user-text: #ffffff;
  --yami-ai-bubble: #f1f5f9;
  --yami-ai-text: #1e293b;
  --yami-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --yami-radius: 16px;
}

/* ===== 浮动触发按钮 ===== */
.yami-chat-fab {
  position: fixed;
  bottom: 24px;
  z-index: 999998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--yami-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: yami-pulse 2s ease-in-out infinite;
}

.yami-pos-right .yami-chat-fab { right: 24px; }
.yami-pos-left .yami-chat-fab  { left: 24px; }

.yami-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(37, 99, 235, 0.5);
}

.yami-chat-fab svg {
  width: 28px;
  height: 28px;
}

.yami-chat-fab.is-open {
  animation: none;
}

@keyframes yami-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3); }
  50% { box-shadow: 0 4px 20px rgba(37, 99, 235, 0.5), 0 0 0 8px rgba(37, 99, 235, 0.08); }
}

/* ===== 对话窗口面板 ===== */
.yami-chat-panel {
  position: fixed;
  bottom: 96px;
  z-index: 999999;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--yami-bg);
  border-radius: var(--yami-radius);
  box-shadow: var(--yami-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--yami-border);
}

.yami-pos-right .yami-chat-panel { right: 24px; }
.yami-pos-left  .yami-chat-panel { left: 24px; }

.yami-chat-panel.is-open {
  display: flex;
  animation: yami-slide-up 0.25s ease;
}

@keyframes yami-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== 头部 ===== */
.yami-chat-header {
  background: var(--yami-primary);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.yami-chat-header-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.yami-chat-header-icon svg { width: 22px; height: 22px; }

.yami-chat-header-info { flex: 1; min-width: 0; }

.yami-chat-header-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
}

.yami-chat-header-subtitle {
  font-size: 12px;
  opacity: 0.85;
  margin: 0;
  line-height: 1.3;
}

.yami-chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  opacity: 0.8;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.yami-chat-close:hover { opacity: 1; background: rgba(255,255,255,0.15); }
.yami-chat-close svg { width: 20px; height: 20px; }

/* ===== 消息区域 ===== */
.yami-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: var(--yami-surface);
}

.yami-chat-messages::-webkit-scrollbar { width: 5px; }
.yami-chat-messages::-webkit-scrollbar-track { background: transparent; }
.yami-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* ===== 消息气泡 ===== */
.yami-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  animation: yami-fade-in 0.2s ease;
}

@keyframes yami-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.yami-msg-user {
  align-self: flex-end;
  background: var(--yami-user-bubble);
  color: var(--yami-user-text);
  border-bottom-right-radius: 4px;
}

.yami-msg-ai {
  align-self: flex-start;
  background: var(--yami-ai-bubble);
  color: var(--yami-ai-text);
  border-bottom-left-radius: 4px;
}

.yami-msg-ai p:first-child { margin-top: 0; }
.yami-msg-ai p:last-child  { margin-bottom: 0; }
.yami-msg-ai ul, .yami-msg-ai ol { margin: 6px 0; padding-left: 20px; }
.yami-msg-ai li { margin: 2px 0; }
.yami-msg-ai code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}
.yami-msg-ai strong { font-weight: 600; }
.yami-msg-ai h1, .yami-msg-ai h2, .yami-msg-ai h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 8px 0 4px;
}

/* ===== 引用来源 ===== */
.yami-citations {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,0.06);
}

.yami-citations-label {
  font-size: 11px;
  color: var(--yami-text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.yami-citation-chip {
  display: inline-block;
  font-size: 11px;
  color: var(--yami-text-muted);
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
  margin: 2px 4px 2px 0;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== 推荐问题 ===== */
.yami-suggestions {
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--yami-surface);
  flex-shrink: 0;
}

.yami-suggestion-btn {
  text-align: left;
  font-size: 13px;
  color: var(--yami-primary);
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.12);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.yami-suggestion-btn:hover {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(37, 99, 235, 0.25);
}

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

.yami-chat-input {
  flex: 1;
  border: 1px solid var(--yami-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
  max-height: 100px;
  min-height: 42px;
  line-height: 1.4;
}

.yami-chat-input:focus {
  border-color: var(--yami-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.yami-chat-send {
  background: var(--yami-primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  flex-shrink: 0;
}

.yami-chat-send:hover:not(:disabled) { background: var(--yami-primary-dark); }
.yami-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.yami-chat-send svg { width: 20px; height: 20px; }

/* ===== 打字指示器 ===== */
.yami-typing {
  align-self: flex-start;
  background: var(--yami-ai-bubble);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
}

.yami-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--yami-text-muted);
  animation: yami-bounce 1.2s ease-in-out infinite;
}

.yami-typing span:nth-child(2) { animation-delay: 0.15s; }
.yami-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes yami-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== 内嵌模式（短代码） ===== */
.yami-chat-inline {
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
}

.yami-chat-inline .yami-chat-panel {
  position: relative;
  bottom: auto;
  right: auto;
  left: auto;
  width: 100%;
  height: 500px;
  max-height: 70vh;
  display: flex;
  border: 1px solid var(--yami-border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

/* ===== 移动端适配 ===== */
@media (max-width: 480px) {
  .yami-pos-right .yami-chat-fab,
  .yami-pos-left .yami-chat-fab {
    right: 16px;
    left: auto;
    bottom: 16px;
    width: 52px;
    height: 52px;
  }
  .yami-pos-left .yami-chat-fab {
    right: auto;
    left: 16px;
  }

  .yami-chat-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    bottom: 80px;
  }
  .yami-pos-right .yami-chat-panel,
  .yami-pos-left .yami-chat-panel {
    right: 8px;
    left: 8px;
  }

  .yami-chat-inline .yami-chat-panel {
    height: 400px;
  }
}
