/* ============================================================
   小T · 天机智能助手（tianji-ai-chat v1.3 自绘前端）
   入口：header 语言框右侧头像；面板：贴合头像弹出
   设计变量取自官网设计语言：主色 #00478D
   ============================================================ */

:root {
  --tjac-primary: #00478D;
  --tjac-primary-lt: #E6F0F9;
  --tjac-text: #424752;
  --tjac-text-lt: #98A4B3;
  --tjac-panel: #F2F6FA;
  --tjac-border: #C4D2E0;
  --tjac-radius: 8px;
}

/* ---------- 入口：header 小T头像 ---------- */
.header__ai-chat {
  margin-left: 0.857em; /* 与语言框 12px 间距（跟随 header 字号） */
  display: flex;
  align-items: center;
  position: relative;
}

.tjac-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: var(--tjac-primary-lt);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.2s ease;
  /* 触控热区扩展（视觉 32px 热区 44px） */
  box-shadow: 0 0 0 6px rgba(0, 0, 0, 0);
  outline: none;
}

.tjac-avatar:hover,
.tjac-avatar:focus-visible {
  transform: scale(1.08);
}

.tjac-avatar.is-open {
  /* 激活态：主色描边环 */
  box-shadow: 0 0 0 2px var(--tjac-primary);
}

/* 首页深色 Banner 阶段（header 透明）：白描边保证可见 */
.white-header:not(.fixed-header) .tjac-avatar,
.home-transparent-header .tjac-avatar {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

.tjac-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* 微动效（项3）：悬停播放动画时叠加轻微呼吸缩放，增强"活"感、
   掩盖 10fps 帧间跳变（transform 合成层动画，不触发重绘） */
.tjac-avatar.is-hover {
  animation: tjac-breath 2.6s ease-in-out infinite;
}
@keyframes tjac-breath {
  0%, 100% { transform: scale(1.05); }
  50%      { transform: scale(1.14); }
}

/* 静态帧默认显示；hover 帧仅悬停时插入（JS 控制） */
.tjac-avatar .tjac-gif {
  display: none;
  position: absolute;
  inset: 0;
}
.tjac-avatar.is-hover .tjac-gif {
  display: block;
}

/* 未读红点 */
.tjac-avatar .tjac-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 15px;
  height: 15px;
  border-radius: 8px;
  background: #E24B4A;
  color: #fff;
  font-size: 10px;
  line-height: 15px;
  text-align: center;
  padding: 0 3px;
  display: none;
}
.tjac-avatar.has-unread .tjac-badge {
  display: block;
}

/* tooltip：有什么问题，问小T（头像下方） */
.tjac-tip {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: #fff;
  border: 0.5px solid var(--tjac-border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--tjac-text);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  z-index: 10;
}
.tjac-avatar:hover .tjac-tip,
.tjac-avatar:focus-visible .tjac-tip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* caret 指向头像 */
.tjac-tip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 6px;
  height: 6px;
  background: #fff;
  border-top: 0.5px solid var(--tjac-border);
  border-left: 0.5px solid var(--tjac-border);
}

/* ---------- 聊天面板：贴合头像弹出 ---------- */
/* 注：面板与头像下方的 tooltip 共存时，打开面板会隐藏 tooltip（JS 侧
   打开时头像 is-open 已有描边环指示），避免两者层叠。 */
.tjac-panel {
  position: fixed;
  top: var(--tjac-header-h, 64px);
  right: 12px;
  width: 400px;   /* 固定宽度，不跟随视口 */
  height: 600px;  /* 固定高度，不跟随视口 */
  background: #fff;
  border: 0.5px solid #D6DEE8;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.16);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 600; /* header z-index 500 之上 */
  opacity: 0;
  transform: translateY(-8px);
}
.tjac-panel.is-open {
  display: flex;
  animation: tjac-in 0.18s ease-out forwards;
}
/* 面板打开时隐藏 tooltip（同区域防层叠） */
.header__ai-chat .tjac-avatar.is-open .tjac-tip {
  opacity: 0 !important;
}
@keyframes tjac-in {
  to { opacity: 1; transform: translateY(0); }
}

/* caret 指向头像 */
.tjac-panel::before {
  content: "";
  position: absolute;
  top: -6px;
  right: 22px;
  width: 12px;
  height: 12px;
  background: var(--tjac-primary);
  transform: rotate(45deg);
  border-radius: 2px;
}

/* 面板头部 */
.tjac-panel-head {
  background: var(--tjac-primary);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.tjac-panel-head .tjac-mini-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tjac-panel-head .tjac-mini-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.tjac-panel-head-info {
  flex: 1;
  min-width: 0;
}
.tjac-panel-head-name {
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
}
.tjac-panel-head-status {
  color: #9FC5EC;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.tjac-panel-head-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3DC75A;
}
.tjac-panel-head-status.is-busy::before {
  background: #F59E0B;
  animation: tjac-dot-pulse 1s ease-in-out infinite;
}
@keyframes tjac-dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.65); }
}
.tjac-panel-close {
  background: none;
  border: none;
  color: #9FC5EC;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.tjac-panel-close:hover {
  color: #fff;
}

/* 消息区 */
.tjac-msgs {
  flex: 1;
  min-height: 0;        /* flex 子项可收缩：溢出时 overflow-y: auto 才会真正滚动 */
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; /* mac Safari 顺滑滚动 */
}
/* 滚动条始终可见（细灰条），让访客感知可滚动 */
.tjac-msgs::-webkit-scrollbar {
  width: 6px;
}
.tjac-msgs::-webkit-scrollbar-track {
  background: transparent;
}
.tjac-msgs::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 3px;
}
.tjac-msgs::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}
.tjac-msgs {
  scrollbar-width: thin;              /* Firefox */
  scrollbar-color: #CBD5E1 transparent;
}

.tjac-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  flex-shrink: 0;   /* 关键：消息保持自然高度不被压缩，内容超出才触发滚动 */
}
.tjac-msg.self {
  align-self: flex-end;
  max-width: 72%;
  flex-direction: row-reverse;
}
.tjac-msg .tjac-msg-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  background: var(--tjac-primary-lt);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tjac-msg .tjac-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tjac-bubble {
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  border-radius: 2px 8px 8px 8px;
  background: var(--tjac-panel);
  color: var(--tjac-text);
  word-break: break-word;
}
.tjac-msg.self .tjac-bubble {
  background: var(--tjac-primary);
  color: #fff;
  border-radius: 8px 2px 8px 8px;
}

/* dev 模式回答：知识库内联引用标签（可点击下载文档） */
.tjac-kbref {
  display: inline-block;
  font-size: 11px;
  color: #00478D;
  background: #E8F0F9;
  border-radius: 4px;
  padding: 1px 6px;
  margin: 0 2px;
  vertical-align: 1px;
  max-width: 100%;
  white-space: normal;
  word-break: break-all;
  line-height: 1.5;
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dashed #9FC5EC;
}
a.tjac-kbref:hover {
  background: #D6E6F7;
  border-bottom-color: #00478D;
}

/* dev 模式回答：网页链接引用（<web> 标签） */
.tjac-webref {
  display: inline-block;
  font-size: 11px;
  color: #00478D;
  background: #E8F0F9;
  border-radius: 4px;
  padding: 1px 6px;
  margin: 0 2px;
  vertical-align: 1px;
  text-decoration: none;
  cursor: pointer;
}
a.tjac-webref:hover { background: #D6E6F7; }

/* dev 模式回答：OSS 下载链接（点击此处下载按钮样式） */
.tjac-dlbtn {
  display: inline-block;
  font-size: 12px;
  color: #fff;
  background: linear-gradient(135deg, #3B82F6, #2563EB);
  border-radius: 6px;
  padding: 6px 14px;
  margin: 4px 2px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}
a.tjac-dlbtn:hover {
  background: linear-gradient(135deg, #2563EB, #1D4ED8);
  text-decoration: none;
}

/* dev 模式回答：知识库图片 */
.tjac-img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 6px 0;
  border: 0.5px solid #E4EAF1;
  cursor: zoom-in;
}

/* Markdown 渲染样式（回答气泡内） */
.tjac-bubble h1, .tjac-bubble h2, .tjac-bubble h3, .tjac-bubble h4 {
  font-size: 14px;
  font-weight: 600;
  margin: 10px 0 4px;
  line-height: 1.5;
}
.tjac-bubble p { margin: 4px 0; }
.tjac-bubble ul, .tjac-bubble ol { padding-left: 18px; margin: 4px 0; }
.tjac-bubble li { margin: 2px 0; }
.tjac-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #EEF2F7;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.tjac-bubble pre {
  background: #F1F5F9;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}
.tjac-bubble pre code { background: none; padding: 0; }
.tjac-bubble blockquote {
  border-left: 3px solid #CBD5E1;
  padding-left: 10px;
  color: #64748B;
  margin: 6px 0;
}
.tjac-bubble hr { border: none; border-top: 1px solid #E2E8F0; margin: 10px 0; }
.tjac-bubble a { color: #00478D; text-decoration: none; }
.tjac-bubble a:hover { text-decoration: underline; }
/* 表格：窄面板适配（标准表格布局，边框完整，内容换行） */
.tjac-bubble table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  margin: 6px 0;
}
.tjac-bubble th, .tjac-bubble td {
  border: 1px solid #E2E8F0;
  padding: 4px 7px;
  font-size: 11px;
  text-align: left;
  white-space: normal;
  word-break: break-word;
  line-height: 1.45;
}
.tjac-bubble th { background: #F1F5F9; font-weight: 600; }
/* 首列（通常为机型/型号）保持不换行，避免短词被拆成单字符 */
.tjac-bubble th:first-child, .tjac-bubble td:first-child {
  white-space: nowrap;
}
/* 单元格里的链接：超长文件名截断，避免撑爆表格 */
.tjac-bubble td a {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* 图片放大查看遮罩 */
#tjac-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  touch-action: none;
}
#tjac-lightbox.is-open {
  display: flex;
}
#tjac-lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease-out;
  transform-origin: center;
  cursor: grab;
  touch-action: none;
}
#tjac-lightbox img.is-dragging {
  cursor: grabbing;
  transition: none;
}
.tjac-lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  z-index: 2001;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tjac-lightbox-close:active {
  background: rgba(255, 255, 255, 0.35);
}

/* 流式光标 */
.tjac-caret {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--tjac-primary);
  vertical-align: -2px;
  margin-left: 1px;
  animation: tjac-blink 0.8s step-end infinite;
}
@keyframes tjac-blink { 50% { opacity: 0; } }

/* 正在输入三点 */
.tjac-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.tjac-typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #98A4B3;
  animation: tjac-bounce 1.2s infinite;
}
.tjac-typing i:nth-child(2) { animation-delay: 0.15s; }
.tjac-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes tjac-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* 引用来源 */
.tjac-refs {
  margin-top: 8px;
  border-top: 0.5px dashed var(--tjac-border);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tjac-ref {
  font-size: 11px;
  color: var(--tjac-primary);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 2px 0;
  text-align: left;
}
.tjac-ref::before {
  content: "🔖";
  font-size: 10px;
}

/* 未命中兜底卡片 */
.tjac-fallback {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tjac-fb-btn {
  background: #fff;
  border: 0.5px solid var(--tjac-border);
  border-left: 2px solid var(--tjac-primary);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--tjac-text);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
}
.tjac-fb-btn:hover {
  background: var(--tjac-primary-lt);
}
.tjac-fb-btn b {
  color: var(--tjac-primary);
  font-weight: 500;
}

/* 快捷问题 chips */
.tjac-chips {
  padding: 8px 12px 0;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.tjac-chip {
  background: var(--tjac-primary-lt);
  color: var(--tjac-primary);
  border: none;
  border-radius: 12px;
  padding: 4px 12px;
  font-size: 11px;
  cursor: pointer;
  transition: filter 0.15s;
}
.tjac-chip:hover {
  filter: brightness(0.95);
}
.tjac-chip-lead {
  background: var(--tjac-primary);
  color: #fff;
  font-weight: 500;
}
.tjac-chip-lead:hover {
  filter: brightness(0.9);
}

/* 线索录入表单弹窗 */
.tjac-lead-form {
  position: absolute;
  inset: 0;
  background: #fff;
  z-index: 10;
  display: none;
  flex-direction: column;
  border-radius: 12px;
}
.tjac-lead-form.is-open {
  display: flex;
}
.tjac-lead-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 0.5px solid #E4EAF1;
  flex-shrink: 0;
}
.tjac-lead-form-title {
  font-size: 14px;
  font-weight: 500;
  color: #1E293B;
}
.tjac-lead-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #94A3B8;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}
.tjac-lead-close:hover { color: #475569; }
.tjac-lead-form-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tjac-lead-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tjac-lead-field label {
  font-size: 12px;
  color: #475569;
}
.tjac-lead-field label em {
  color: #E24B4A;
  font-style: normal;
}
.tjac-lead-field input,
.tjac-lead-field select,
.tjac-lead-field textarea {
  border: 1px solid #D6DEE8;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: #1E293B;
  outline: none;
  font-family: inherit;
  resize: none;
  background: #fff;
}
.tjac-lead-field input:focus,
.tjac-lead-field select:focus,
.tjac-lead-field textarea:focus {
  border-color: var(--tjac-primary);
}
.tjac-lead-submit {
  margin: 0 14px 14px;
  background: var(--tjac-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
}
.tjac-lead-submit:hover { filter: brightness(0.92); }

/* 输入区 */
.tjac-inputbar {
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-top: 0.5px solid #E4EAF1;
  flex-shrink: 0;
}
/* 语音输入按钮（与发送按钮同款：圆形蓝色底 + 白色图标） */
.tjac-mic {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--tjac-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  transition: opacity 0.15s, background 0.15s;
}
.tjac-mic:hover { opacity: 0.9; }
.tjac-mic svg { width: 13px; height: 13px; }
.tjac-mic.recording {
  background: #EF4444;
  animation: tjac-mic-pulse 1s infinite;
}
@keyframes tjac-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
}
/* 微信式录音条（按住说话时显示） */
.tjac-recbar {
  display: none;
  padding: 10px 12px;
  gap: 12px;
  align-items: center;
  border-top: 0.5px solid #E4EAF1;
  background: #fff;
  flex-shrink: 0;
}
.tjac-recbar.show { display: flex; }
.tjac-recwave {
  display: flex;
  gap: 3px;
  align-items: center;
  height: 28px;
}
.tjac-recwave i {
  width: 3px;
  height: 8px;
  border-radius: 2px;
  background: #3B82F6;
  animation: tjac-wave 1s ease-in-out infinite;
}
.tjac-recwave i:nth-child(1) { animation-delay: 0s; }
.tjac-recwave i:nth-child(2) { animation-delay: 0.1s; }
.tjac-recwave i:nth-child(3) { animation-delay: 0.2s; }
.tjac-recwave i:nth-child(4) { animation-delay: 0.3s; }
.tjac-recwave i:nth-child(5) { animation-delay: 0.4s; }
.tjac-recwave i:nth-child(6) { animation-delay: 0.5s; }
.tjac-recwave i:nth-child(7) { animation-delay: 0.6s; }
@keyframes tjac-wave {
  0%, 100% { height: 7px; }
  50% { height: 26px; }
}
.tjac-recbar-tip {
  font-size: 12px;
  color: #64748B;
  flex: 1;
  text-align: center;
}
/* 上滑取消状态 */
.tjac-recbar.cancel {
  background: #FEF2F2;
}
.tjac-recbar.cancel .tjac-recbar-tip {
  color: #EF4444;
}
.tjac-recbar.cancel .tjac-recwave i {
  background: #EF4444;
}
.tjac-input {
  flex: 1;
  border: 0.5px solid var(--tjac-border);
  border-radius: 16px;
  padding: 9px 14px;
  font-size: 12.5px;
  color: var(--tjac-text);
  outline: none;
  background: #fff;
  font-family: inherit;
}
.tjac-input:focus {
  border-color: var(--tjac-primary);
}
.tjac-input::placeholder {
  color: var(--tjac-text-lt);
}
.tjac-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--tjac-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.tjac-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.tjac-send svg {
  width: 13px;
  height: 13px;
}

/* AI 声明 */
.tjac-disclaimer {
  text-align: center;
  font-size: 10.5px;
  color: var(--tjac-text-lt);
  padding: 4px 0 8px;
  flex-shrink: 0;
}

/* ---------- 移动端 ---------- */
@media (max-width: 1024px) {
  .tjac-avatar {
    width: 26px;
    height: 26px;
  }
  .header__ai-chat {
    margin-left: 0.5em;
  }
}
@media (max-width: 640px) {
  .tjac-avatar {
    width: 24px;
    height: 24px;
  }
  .tjac-tip {
    display: none; /* 触屏无 hover */
  }
  /* 面板占满 header 以下 */
  .tjac-panel {
    top: var(--tjac-header-h, 56px);
    right: 0;
    left: 0;
    width: auto;
    height: calc(100vh - var(--tjac-header-h, 56px));
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  .tjac-panel::before {
    display: none;
  }
  .tjac-msg {
    max-width: 92%;
  }
  .tjac-msg.self {
    max-width: 80%;
  }
}
