/* ============================================================
   AI 智慧村长「古小博」对话界面与悬浮组件
   与小程序 .ai-float / ai 页面风格保持一致，Premium 网页版
   ============================================================ */

/* ===== 悬浮 AI 村长挂件（与小程序 .ai-float 一致） ===== */
.floating-chief-widget {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-height) + 16px);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  padding: 6px 14px 6px 6px;
  box-shadow: 0 6px 24px rgba(47, 74, 60, 0.25);
  cursor: pointer;
  transition: all 0.3s var(--ease-spring);
}

@media (min-width: 768px) {
  .floating-chief-widget {
    bottom: 24px;
    right: 24px;
  }
}

.floating-chief-widget:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 8px 30px rgba(47, 74, 60, 0.35);
}

/* 脉冲光环（与小程序 .ai-float::after / floatPulse 一致） */
.floating-chief-widget::after {
  content: "";
  position: absolute;
  left: -2px;
  top: -2px;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  border-radius: var(--radius-full);
  border: 1.5px solid rgba(166, 66, 42, 0.4);
  animation: floatPulse 2.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes floatPulse {
  0% { transform: scale(1); opacity: 0.8; }
  70% { transform: scale(1.12); opacity: 0; }
  100% { transform: scale(1.12); opacity: 0; }
}

/* 头像（与小程序 .ai-float-ball 一致：渐变底色 + 纸色边框） */
.floating-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(160deg, #e8f0e6, #b9cdbb);
  border: 2px solid rgba(246, 236, 216, 0.9);
  box-shadow: 0 4px 12px rgba(47, 74, 60, 0.3);
  object-fit: cover;
}

.floating-chief-text {
  display: flex;
  flex-direction: column;
}

.floating-name {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

.floating-status {
  font-size: 10px;
  color: var(--ink-green-2);
  display: flex;
  align-items: center;
  gap: 4px;
}

.floating-status::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

/* ===== 对话容器 ===== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--tabbar-height) - 16px);
  max-width: 840px;
  margin: 0 auto;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

@media (min-width: 768px) {
  .chat-container {
    height: calc(100vh - var(--header-height) - 40px);
  }
}

.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-chief {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-chief-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid rgba(246, 236, 216, 0.9);
  background: linear-gradient(160deg, #e8f0e6, #b9cdbb);
  box-shadow: 0 3px 10px rgba(47, 74, 60, 0.2);
  object-fit: cover;
}

.chat-chief-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.chat-chief-desc {
  font-size: 11px;
  color: var(--ink-3);
}

.chat-header-tools {
  display: flex;
  gap: 8px;
}

/* ===== 分类主题快捷条 ===== */
.chat-topics-bar {
  padding: 10px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chat-topics-bar::-webkit-scrollbar {
  display: none;
}

.chat-topic-btn {
  flex-shrink: 0;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  background: var(--paper-2);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-2);
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.chat-topic-btn:hover {
  background: rgba(47, 74, 60, 0.06);
  color: var(--ink-green-2);
  border-color: var(--ink-green-3);
}

/* ===== 消息流 ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--paper);
}

/* 消息区纸纹背景 */
.chat-messages::before {
  content: "";
  position: fixed;
  pointer-events: none;
  inset: 0;
  background: url('../images/ink/wave.png') repeat;
  background-size: 80px 10px;
  opacity: 0.015;
  z-index: 0;
}

.msg-row {
  display: flex;
  gap: 10px;
  max-width: 88%;
  position: relative;
  z-index: 1;
}

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

.msg-row.chief {
  align-self: flex-start;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid var(--line);
  object-fit: cover;
}

.msg-bubble {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

/* 用户消息气泡（与小程序 ink-green 渐变一致） */
.msg-row.user .msg-bubble {
  background: linear-gradient(135deg, var(--ink-green), var(--ink-green-2));
  color: #fff8ec;
  border-bottom-right-radius: 3px;
  box-shadow: 0 3px 12px rgba(47, 74, 60, 0.2);
}

/* 村长消息气泡 */
.msg-row.chief .msg-bubble {
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
  box-shadow: var(--shadow-sm);
}

.msg-title {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 操作跳转卡片（与小程序 .story-link pot-brown 风格一致） */
.msg-action-card {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s ease;
}

.msg-action-card:hover {
  background: rgba(139, 90, 43, 0.05);
  border-color: var(--pot-brown);
}

.action-card-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--pot-brown);
}

.action-card-arrow {
  font-size: 14px;
  color: var(--pot-brown);
}

/* 快捷问题 */
.quick-questions-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.quick-q-btn {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  text-align: left;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quick-q-btn:hover {
  background: rgba(47, 74, 60, 0.05);
  color: var(--ink-green-2);
  border-color: var(--ink-green-3);
  transform: translateX(3px);
}

/* ===== 底部输入框 ===== */
.chat-input-bar {
  padding: 14px 16px;
  background: var(--paper-2);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-input-field {
  flex: 1;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  padding: 0 18px;
  font-size: 14px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-field:focus {
  border-color: var(--ink-green-2);
  background: var(--paper-2);
  box-shadow: 0 0 0 3px rgba(47, 74, 60, 0.08);
}

/* 发送按钮（与小程序朱砂渐变风格一致） */
.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cinnabar), #b5482c);
  color: #fff8ec;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(166, 66, 42, 0.25);
}

.chat-send-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 5px 16px rgba(166, 66, 42, 0.35);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== 输入中动画 ===== */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 8px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--ink-green-2);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== 流式回答光标 ===== */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--ink-green-2);
  animation: cursorBlink 0.8s step-end infinite;
}

@keyframes cursorBlink {
  50% { opacity: 0; }
}

.live-answer {
  min-height: 20px;
}

/* ===== Markdown 渲染体 ===== */
.msg-md-body {
  line-height: 1.7;
}

.msg-md-body p {
  margin-bottom: 8px;
}

.msg-md-body ul, .msg-md-body ol {
  padding-left: 20px;
  margin-bottom: 8px;
}

.msg-md-body li {
  margin-bottom: 4px;
}

.msg-md-body h1, .msg-md-body h2, .msg-md-body h3 {
  font-family: var(--font-serif);
  font-size: 15px;
  margin: 10px 0 6px 0;
  color: var(--ink);
}

.msg-md-body code {
  background: var(--paper);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid var(--line);
}

.msg-md-body blockquote {
  border-left: 3px solid var(--pot-brown);
  padding-left: 12px;
  color: var(--ink-2);
  margin: 8px 0;
  font-style: italic;
}

/* ===== Agent 检索步骤 ===== */
.live-trace-box {
  margin-bottom: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: rgba(245, 239, 224, 0.6);
  overflow: hidden;
}

.agent-trace-item {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--ink-2);
  border-bottom: 1px dashed var(--line);
}

.agent-trace-item:last-child {
  border-bottom: none;
}

.agent-trace-title {
  font-weight: 700;
  color: var(--ink-green-2);
  margin-bottom: 2px;
}

.agent-trace-detail {
  color: var(--ink-3);
}

.agent-trace-observation {
  margin-top: 2px;
  color: var(--ink-2);
  word-break: break-all;
}

/* ===== 来源标签 ===== */
.msg-sources {
  margin-top: 12px;
}

.msg-sources-label {
  font-size: 11px;
  color: var(--ink-3);
  margin-bottom: 5px;
}

.source-chip {
  display: inline-block;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink-green-2);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin: 2px 4px 2px 0;
}

/* ===== 停止按钮 ===== */
.chat-stop-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--paper-2);
  color: var(--cinnabar);
  border: 1.5px solid var(--cinnabar);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.chat-stop-btn:hover {
  background: var(--cinnabar);
  color: #fff;
}
