/* ============================================================
   智能问答页样式（参照资讯主页：固定视口 + 内部滚动）
   ============================================================ */

.rag-layout {
  height: calc(100vh - 94px - var(--safe-top));
  margin-top: calc(64px + var(--safe-top));
  padding: 1rem max(1.5rem, var(--safe-right)) 1rem max(1.5rem, var(--safe-left));
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

/* ============ 头部 ============ */
.rag-header {
  text-align: center;
  padding: 0.8rem 0 0.5rem;
  flex-shrink: 0;
}
.rag-header h1 {
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}
.rag-header h1 i { color: #06b6d4; }
.rag-header p {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.4rem;
}

/* ============ 聊天区 ============ */
.rag-chat {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm), var(--shadow-md);
  padding: 1.2rem;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

/* 欢迎屏 */
.rag-welcome { text-align: center; padding: 2rem 1rem; }
.rag-welcome-icon { font-size: 3.5rem; margin-bottom: 0.8rem; }
.rag-welcome-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 0.5rem; }
.rag-welcome-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}
.rag-samples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.sample-q {
  padding: 0.45rem 1rem;
  border-radius: 30px;
  border: 1px solid var(--border-color);
  background: var(--bg-app);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}
.sample-q:hover {
  border-color: #06b6d4;
  color: #0891b2;
  background: rgba(6, 182, 212, 0.08);
}

/* 消息 */
.rag-msg { margin-bottom: 1.2rem; display: flex; gap: 0.8rem; }
.rag-msg.user { flex-direction: row-reverse; }
.rag-msg-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}
.rag-msg.bot .rag-msg-avatar {
  background: linear-gradient(135deg, #06b6d4, #2563eb);
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.25);
}
.rag-msg-body { flex: 1; min-width: 0; max-width: 80%; }
.rag-msg.user .rag-msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.rag-msg-text {
  padding: 0.7rem 1rem;
  border-radius: 4px 12px 12px 12px;
  font-size: 0.88rem;
  line-height: 1.65;
  background: var(--bg-app);
  white-space: pre-wrap;
  word-break: break-word;
}
.rag-msg.user .rag-msg-text {
  background: var(--accent);
  color: #fff;
  border-radius: 12px 4px 12px 12px;
}
.rag-msg.bot .rag-msg-text {
  background: linear-gradient(180deg, #f0f9ff, #e0f2fe);
  border: 1px solid rgba(6, 182, 212, 0.25);
  color: #0f172a;
}
[data-theme="dark"] .rag-msg.bot .rag-msg-text {
  background: linear-gradient(180deg, #0c2a3a, #0a1f2e);
  border-color: rgba(6, 182, 212, 0.4);
  color: #e0f7ff;
}
.rag-msg-text .cite { color: #0891b2; font-weight: 700; }

/* 引用卡片 */
.rag-refs {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed rgba(6, 182, 212, 0.35);
}
.rag-refs-title {
  font-size: 0.72rem;
  color: #0891b2;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.rag-ref-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: 8px;
  margin-bottom: 0.35rem;
  text-decoration: none;
  color: inherit;
  font-size: 0.78rem;
  transition: all 0.15s;
  cursor: pointer;
}
.rag-ref-item:hover {
  background: rgba(6, 182, 212, 0.08);
  border-color: #06b6d4;
}
[data-theme="dark"] .rag-ref-item { background: rgba(6, 182, 212, 0.06); }
[data-theme="dark"] .rag-ref-item:hover { background: rgba(6, 182, 212, 0.15); }
.rag-ref-idx { color: #0891b2; font-weight: 700; }
.rag-ref-title {
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.35;
}
.rag-ref-meta {
  color: var(--text-muted);
  font-size: 0.65rem;
  margin-top: 2px;
}

/* 打字动画 */
.rag-typing { display: inline-flex; gap: 4px; padding: 0.7rem 1rem; }
.rag-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #06b6d4;
  animation: dot-bounce 1.2s infinite ease-in-out;
}
.rag-typing i:nth-child(2) { animation-delay: 0.15s; }
.rag-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ============ 输入框 ============ */
.rag-input-wrap {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 40px;
  padding: 0.4rem 0.4rem 0.4rem 1rem;
  box-shadow: var(--shadow-sm), var(--shadow-md);
  flex-shrink: 0;
}
.rag-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.5rem 0;
  outline: none;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.rag-input-wrap button {
  padding: 0.55rem 1.5rem;
  border-radius: 40px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.15s;
}
.rag-input-wrap button:hover { background: #1d4ed8; }
.rag-input-wrap button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ 响应式 ============ */
@media (max-width: 1024px) {
  .rag-layout {
    height: auto;
    min-height: calc(100vh - 50px - var(--safe-top));
    margin-top: calc(50px + var(--safe-top));
    padding: 0.6rem;
    overflow: visible;
  }
  .rag-chat { min-height: 60vh; }
}
@media (max-width: 640px) {
  .rag-header h1 { font-size: 1.1rem; }
  .rag-msg-body { max-width: 88%; }
}