/* 水利规范智能问答页样式 */
:root {
  --chat-bg: #f1f5f9;
  --chat-user: #0d9488;
  --chat-ai-bg: #ffffff;
  --chat-radius: 18px;
}

.chat-main {
  background: var(--chat-bg);
  min-height: calc(100vh - 64px);
  padding: var(--space-md) 0 var(--space-md);
}

.chat-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 var(--space-md);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px - 24px);
}

/* 顶部标题区 */
.chat-hero {
  text-align: center;
  padding: var(--space-lg) 0 var(--space-md);
}
.chat-hero h1 {
  font-size: var(--text-2xl);
  color: var(--color-text);
  margin: 0 0 var(--space-xs);
  font-weight: 700;
}
.chat-subtitle {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  margin: 0 0 var(--space-md);
}
.chat-stats {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  flex-wrap: wrap;
}
.stat-pill {
  background: var(--color-surface);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
}
.stat-pill strong {
  color: var(--color-accent);
}

/* 对话区 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  gap: var(--space-sm);
  max-width: 88%;
  animation: msgIn 0.3s ease;
}
.msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-ai {
  align-self: flex-start;
}

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

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}
.msg-user .msg-avatar {
  background: var(--color-accent);
  color: white;
}
.msg-ai .msg-avatar {
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
}

.msg-bubble {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--chat-radius);
  font-size: var(--text-sm);
  line-height: 1.7;
  word-break: break-word;
}
.msg-user .msg-bubble {
  background: var(--chat-user);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-ai .msg-bubble {
  background: var(--chat-ai-bg);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
}

/* AI回答内的Markdown渲染 */
.msg-ai .msg-bubble p { margin: 0 0 var(--space-sm); }
.msg-ai .msg-bubble p:last-child { margin-bottom: 0; }
.msg-ai .msg-bubble strong { color: var(--color-accent-dark); }
.msg-ai .msg-bubble ol,
.msg-ai .msg-bubble ul { margin: var(--space-xs) 0; padding-left: var(--space-lg); }
.msg-ai .msg-bubble code {
  background: var(--color-border-light);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* 推荐问题按钮 */
.suggest-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}
.suggest-btn {
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  border: 1px solid var(--color-accent);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: var(--text-xs);
  cursor: pointer;
  transition: all 0.15s;
}
.suggest-btn:hover {
  background: var(--color-accent);
  color: white;
}

/* 来源引用卡片 */
.sources-block {
  margin-top: var(--space-md);
  padding-top: var(--space-sm);
  border-top: 1px dashed var(--color-border);
}
.sources-title {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
  font-weight: 600;
}
.source-card {
  background: var(--color-border-light);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-sm);
  margin-bottom: 6px;
  font-size: var(--text-xs);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
}
.source-card-left {
  flex: 1;
  min-width: 0;
}
.source-std {
  font-weight: 600;
  color: var(--color-text);
}
.source-mandatory {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  margin-left: 4px;
}
.source-meta {
  color: var(--color-text-muted);
  margin-top: 2px;
}
.source-preview {
  color: var(--color-text-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-link {
  color: var(--color-accent);
  text-decoration: none;
  font-size: var(--text-xs);
  white-space: nowrap;
  flex-shrink: 0;
}
.source-link:hover { text-decoration: underline; }

/* 输入区 */
.chat-input-area {
  padding: var(--space-sm) 0 var(--space-md);
  background: var(--chat-bg);
}
.chat-status {
  font-size: var(--text-xs);
  color: var(--color-accent);
  text-align: center;
  min-height: 18px;
  margin-bottom: 6px;
}
.chat-input-row {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-sm);
  box-shadow: var(--shadow-sm);
}
.chat-input-row:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}
.chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  max-height: 120px;
  color: var(--color-text);
  background: transparent;
}
.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--color-accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.send-btn:disabled {
  background: var(--color-border);
  cursor: not-allowed;
}
.send-btn:not(:disabled):hover {
  background: var(--color-accent-dark);
  transform: scale(1.05);
}
.chat-hint {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 6px;
  flex-wrap: wrap;
  gap: 4px;
}
.chat-hint strong { color: var(--color-accent); }

/* 打字指示器 */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: var(--space-xs) 0;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  opacity: 0.4;
  animation: typingBounce 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* 额度用完提示 */
.quota-exhausted {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-top: var(--space-sm);
}
.quota-exhausted a {
  color: var(--color-accent-dark);
  font-weight: 600;
}

/* 移动端适配 */
@media (max-width: 640px) {
  .chat-container { padding: 0 var(--space-sm); }
  .chat-hero h1 { font-size: var(--text-xl); }
  .chat-stats { flex-direction: column; align-items: center; }
  .msg { max-width: 95%; }
  .msg-avatar { width: 30px; height: 30px; font-size: 10px; }
  .msg-bubble { padding: var(--space-xs) var(--space-sm); font-size: var(--text-xs); }
  .chat-hint { flex-direction: column; }
}
