/* ================= 钉钉风格聊天界面（覆盖层） =================
   统一作用于：模型聊天 / 群聊 / 私聊
   说明：本文件在 style.css 之后加载，仅覆盖视觉样式，不改动任何结构或逻辑 */

/* 全局字体平滑：让 WebView 里的文字更锐利，接近原生 App 观感 */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ---------- 消息区底色 ---------- */
.chat-messages {
  background: #F5F6F8;
}

/* ---------- 头像：圆形、无阴影、无边框（28px，靠边） ---------- */
.msg-item .msg-avatar,
.msg-row .msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 11px;
  box-shadow: none;
  border: none;
  flex-shrink: 0;
}

/* ---------- 对方气泡：白底、细边、统一圆角（钉钉还原版） ---------- */
.msg-item.msg-left .msg-bubble,
.msg-row.ai .msg-bubble {
  background: #FFFFFF;
  color: #1A1A1A;
  border: 1px solid #EBEDEF;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* ---------- 自己气泡：钉钉浅蓝、深色文字（钉钉还原版） ---------- */
.msg-item.msg-right .msg-bubble,
.msg-row.user .msg-bubble {
  background: #D2E7FC;
  color: #1A1A1A;
  border: none;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.msg-item .msg-bubble,
.msg-row .msg-bubble {
  padding: 8px 11px;
  font-size: 14px;
  line-height: 1.5;
  text-align: justify;           /* 文字两端对齐，消除右侧锯齿 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 气泡内链接、代码在浅色底上保持可读 */
.msg-item.msg-right .msg-bubble a,
.msg-row.user .msg-bubble a {
  color: #1E6FFF;
}

/* ---------- 昵称与时间：更接近钉钉的小灰字 ---------- */
.msg-sender-name {
  font-size: 12px;
  color: #8A9099;
  margin-bottom: 4px;
}

.msg-time-row {
  font-size: 11px;
  color: #B7BCC4;
}

/* ---------- 系统消息 ---------- */
.msg-system span {
  background: rgba(0, 0, 0, 0.05);
  color: #8A9099;
}

/* ---------- 群聊 / 私聊输入区：胶囊输入框 ---------- */
.im-chat-input-bar {
  background: #F5F6F8;
  border-top: none;
  padding: 6px 12px 8px;
}

.im-chat-input-wrap {
  background: #FFFFFF;
  border: 1px solid #E7E9ED;
  border-radius: 22px;
  margin: 0 0 6px;
  padding: 8px 12px;
  min-height: 40px;
  border-bottom: 1px solid #E7E9ED;
}

/* ---------- 钉钉工具栏（输入框下方一排） ---------- */
.im-chat-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 2px;
}

.im-tool-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  color: #5A6270;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  transition: background 0.15s;
}

.im-tool-btn:active {
  background: #EBEEF2;
}

.im-tool-btn.im-chat-emoji-btn,
.im-tool-btn.im-chat-add-btn {
  width: 32px;
  height: 32px;
  font-size: 18px;
}

.im-chat-toolbar .im-chat-send-btn {
  margin-left: auto;
}

.im-chat-input-wrap:focus-within {
  background: #FFFFFF;
  border-color: #C9D6E8;
}

.im-chat-send-btn {
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: #1E6FFF;
  box-shadow: none;
  font-size: 13px;
}

.im-chat-send-btn:active {
  background: #145EDB;
  transform: scale(0.97);
  box-shadow: none;
}

/* ---------- 模型聊天输入区：同款胶囊 + 工具栏 ---------- */
.chat-input-bar {
  background: #F5F6F8;
  border-top: none;
  padding: 6px 12px 8px;
}

.chat-input-wrap {
  background: #FFFFFF;
  border: 1px solid #E7E9ED;
  border-radius: 22px;
  margin: 0 0 6px;
  padding: 8px 12px;
  min-height: 40px;
}

.chat-input-wrap:focus-within {
  background: #FFFFFF;
  border-color: #C9D6E8;
}

/* + 号按钮在工具栏中的尺寸 */
.im-chat-toolbar .chat-image-btn {
  width: 32px;
  height: 32px;
  font-size: 20px;
  background: transparent;
  border: none;
  color: #5A6270;
}

/* 模型聊天表情面板（内嵌，与群聊一致） */
.chat-emoji-panel {
  margin: 0 -12px -8px;
  background: #FFFFFF;
  border-top: 1px solid #E7E9ED;
  padding: 10px 12px 14px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 190px;
  overflow-y: auto;
}

.chat-emoji-panel.hidden {
  display: none;
}

.chat-emoji-item {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.chat-emoji-item:active {
  background: #EBEEF2;
}

@media (max-width: 768px) {
  .im-chat-input-bar {
    padding: 6px 10px 8px;
  }
  .chat-input-bar {
    padding: 6px 10px 8px;
  }
  .chat-input-wrap {
    margin: 0 0 6px;
  }
}

/* ================= 修复：输入栏被固定高度挤出 ================= */
/* 模型聊天输入栏原为固定 55px，加工具栏后内容被裁切 */
#chatView .chat-input-bar {
  height: auto;
  min-height: 0;
  flex-shrink: 0;
}

/* 覆盖 #chatView 下的旧胶囊样式，保证与群聊一致 */
#chatView .chat-input-wrap {
  padding: 8px 12px;
  border-radius: 22px;
  gap: 0;
  align-items: center;
  background: #FFFFFF;
  border: 1px solid #E7E9ED;
}

#chatView .chat-input {
  height: auto;
  min-height: 24px;
  max-height: 96px;
  line-height: 24px;
  padding: 0;
  overflow-y: auto;
}

/* 消息区允许收缩，避免输入栏变高后内容被裁切 */
#chatView .chat-messages,
#imChatView .chat-messages {
  min-height: 0;
}

/* 输入栏整体不允许被压缩 */
#imChatView .im-chat-input-bar,
#chatView .chat-input-bar {
  flex-shrink: 0;
}

/* 平板断点下的旧 padding / min-height 一并覆盖 */
@media (max-width: 1100px) {
  #chatView .chat-input-bar,
  #imChatView .im-chat-input-bar {
    padding: 6px 12px 8px;
    min-height: 0;
  }
}

@media (max-width: 768px) {
  #chatView .chat-input-bar,
  #imChatView .im-chat-input-bar {
    padding: 6px 10px 8px;
  }
}

/* ================= 首页温和压缩：6 个模型完整显示 ================= */
/* 备案号保留原位，只稍微缩 padding */
.icp-footer {
  padding: 3px 0 2px !important;
}
.icp-footer a {
  font-size: 10px !important;
}

/* 顶部切换栏稍微紧一点 */
.home-top-tabs {
  padding: 2px 8px 2px !important;
}
.home-top-tab {
  padding: 3px 10px !important;
  font-size: 13px !important;
}

/* 分页指示器稍微紧一点 */
.model-pagination {
  padding: 3px 0 3px !important;
  gap: 6px !important;
}

/* 模型卡片温和缩小（不是极端缩小，只是稍微小一号）*/
.model-item {
  padding: 11px 15px !important;
  margin: 4px 12px !important;
}
.model-item .model-icon {
  width: 36px !important;
  height: 36px !important;
}
.model-item .model-desc {
  font-size: 11px !important;
}

/* ================= 卷宗馆上传区域压缩 ================= */
.kb-upload-area {
  padding: 12px 14px !important;
  margin-bottom: 8px !important;
  border-radius: 9px !important;
}
.kb-upload-category {
  margin-bottom: 5px !important;
}
.kb-upload-icon {
  margin-bottom: 3px !important;
}
.kb-upload-icon svg {
  width: 24px !important;
  height: 24px !important;
}
.kb-upload-text {
  font-size: 11px !important;
}
.kb-upload-hint {
  font-size: 9px !important;
}

/* ================= 模型聊天气泡贴合头像（钉钉式布局） ================= */
/* 原 .msg-content-wrap 为 flex:1 撑满剩余宽度、.msg-bubble 为块级，
   导致 AI 气泡几乎占满整行，内容看起来"很靠右"。
   改为气泡随内容宽度、紧贴头像：AI 靠左、用户靠右 */
#chatView .msg-row {
  max-width: 100% !important;
  gap: 6px;
}
#chatView .msg-row.ai {
  justify-content: flex-start;
}
#chatView .msg-row.user {
  width: 100%;                  /* 固定宽度基准，避免 align-self:flex-end 下宽度塌缩导致气泡被挤窄 */
  justify-content: flex-start;  /* row-reverse 下 flex-start = 靠右 */
}
#chatView .chat-messages {
  padding: 10px 8px;
}
#chatView .msg-content-wrap {
  flex: 0 1 auto !important;   /* 不撑满剩余宽度，随气泡内容 */
  max-width: calc(100% - 68px);  /* 头像侧留34px(28+6)，对侧也留34px，两边对称 */
  overflow: visible;
}
#chatView .msg-row.user .msg-content-wrap {
  text-align: right;
}
#chatView .msg-row .msg-bubble {
  display: inline-block !important;  /* 气泡贴合文字宽度 */
  max-width: 100%;
  word-break: break-word;           /* 优先在空格/标点处换行，长单词才硬拆 */
  overflow-wrap: break-word;
}
/* 参考资料块跟随气泡一起靠左，且不溢出气泡 */
#chatView .msg-row.ai .kb-sources {
  text-align: left;
  max-width: 100%;
  box-sizing: border-box;
}
#chatView .kb-source-tag {
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
  vertical-align: top;
}

/* ================= 精致感微打磨（加法，不动气泡配色/圆角/尺寸） ================= */
/* 1. 群聊消息也加上与模型聊天一致的进场动画（复用 style.css 的 msgIn） */
#imChatMessages .msg-item {
  animation: msgIn 0.25s ease;
}

/* 2. 聊天操作按钮按下时轻微缩放（钉钉式触感反馈） */
.im-chat-send-btn:active,
.im-tool-btn:active,
#chatEmojiBtn:active,
#imEmojiBtn:active {
  transform: scale(0.94);
  transition: transform 0.1s ease;
}

/* 3. 两处聊天区消息间距统一为 14px */
#imChatMessages {
  gap: 14px;
}

/* ================= 钉钉式气泡小尾巴（指向头像） ================= */
.msg-row.ai .msg-bubble,
.msg-row.user .msg-bubble,
.msg-item.msg-left .msg-bubble,
.msg-item.msg-right .msg-bubble {
  position: relative;
}

/* 左气泡（AI/对方）：靠近头像侧圆角收小 */
.msg-row.ai .msg-bubble,
.msg-item.msg-left .msg-bubble {
  border-top-left-radius: 4px;
}
/* 尾巴：实心小三角，颜色=气泡底色，不描边（钉钉的尾巴没有边框线） */
.msg-row.ai .msg-bubble::before,
.msg-item.msg-left .msg-bubble::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 13px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 6px solid #FFFFFF;
}

/* 右气泡（用户/自己）：靠近头像侧圆角收小 */
.msg-row.user .msg-bubble,
.msg-item.msg-right .msg-bubble {
  border-top-right-radius: 4px;
}
/* 尾巴：实心小三角，颜色=气泡底色 */
.msg-row.user .msg-bubble::before,
.msg-item.msg-right .msg-bubble::before {
  content: '';
  position: absolute;
  right: -5px;
  top: 13px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid #D2E7FC;
}
