/**
 * 微信对话标签 {% wechat %}
 * ------------------------------------------------------------------
 * 复刻微信 PC 版聊天窗口：左边白色气泡（对方）、右边绿色气泡（自己）、
 * 中间的时间戳和系统提示。
 *
 * 颜色全部走 CSS 变量，跟站点主题一致：
 *   浅色模式 → 白气泡 + 微信绿气泡
 *   暗色模式 → 灰气泡 + 微信绿气泡
 *   暗色 + 背景图案 → 气泡半透明，线稿从底下透出来
 */

.wechat {
  /* ---------- 颜色令牌 ---------- */
  --wechat-self-bg: #95ec69;
  /* 聊天窗口宽度上限。100% = 跟文章栏一样宽（和代码块一致）。
     下面 max-width 那行默认注释掉了，所以聊天窗口永远跟代码块一样宽。
     想限宽（比如只占 720px），把 max-width 那行取消注释，
     再把这里的值改成具体像素数就行。 */
  --wechat-max: 100%;
  /* 聊天窗口底色 */
  --wechat-bg: #ededed;
  /* 对方气泡 */
  --wechat-other-bg: #ffffff;
  /* 文字 */
  --wechat-text: #191919;
  /* 时间戳 / 系统提示 */
  --wechat-time-bg: rgba(0, 0, 0, .1);
  --wechat-time-text: rgba(0, 0, 0, .45);
  /* 气泡圆角 */
  --wechat-radius: 8px;

  box-sizing: border-box;
  width: 100%;
  /* max-width: var(--wechat-max); */
  margin: 0 0 20px;
  padding: 18px 16px;
  border-radius: 12px;
  background: var(--wechat-bg);
  font-size: .95rem;
  line-height: 1.65;

}

.wechat * {
  box-sizing: border-box;
}

/* ---------- 中间的时间戳 ---------- */

.wechat-time {
  margin: 2px 0 16px;
  text-align: center;
}

.wechat-time span {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--wechat-time-bg);
  color: var(--wechat-time-text);
  font-size: .78rem;
}

/* ---------- 中间的系统提示 ---------- */

.wechat-system {
  margin: 8px 0 16px;
  color: var(--wechat-time-text);
  font-size: .8rem;
  text-align: center;
}

/* ---------- 一行消息 ---------- */

.wechat-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.wechat-row:last-child {
  margin-bottom: 0;
}

/* 自己的消息：气泡在左，头像在右 */
.wechat-row-self {
  flex-direction: row-reverse;
}

/* ---------- 头像 ---------- */

.wechat-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--wechat-other-bg);
}

.wechat-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 没有头像时，用名字首字当占位头像 */
.wechat-avatar-text {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
}

.wechat-avatar-self {
  background: var(--btf-theme, #425aef);
}

.wechat-avatar-other {
  background: #7d8496;
}

/* ---------- 气泡 ---------- */

.wechat-bubble {
  position: relative;
  max-width: 68%;
  padding: 9px 13px;
  border-radius: var(--wechat-radius);
  background: var(--wechat-other-bg);
  color: var(--wechat-text);
  font-size: .95rem;
  word-break: break-word;
  white-space: pre-wrap;
}

/* 自己的气泡：微信绿，文字始终用深色，两种模式下都清晰 */
.wechat-bubble-self {
  background: var(--wechat-self-bg);
  color: #191919;
}

/* 气泡上那个小尖角（指向头像）
   ------------------------------------------------------------------
   跟微信 PC 版保持一致：
   - 对方（左边）的气泡有一个朝头像的小三角；
   - 自己（右边）的绿气泡同样有一个朝头像的小三角。

   ⚠️ 关键：对方那枚三角用 `left: -12px`，**底边正好贴在气泡左边缘、
   一像素都不重叠**。
   暗色模式 + 背景图案下气泡是半透明的（rgba(255,255,255,.14)），
   如果尖角跟气泡叠上一部分，两层半透明叠在一起会在接缝处
   冒出一条更亮的竖线（就是之前那个「灰箭头 + 亮竖线」的元凶）。
   零重叠就只剩一层颜色，接缝自然消失，三角看着也跟气泡长在一起。
   绿气泡是不透明的，尖角压住气泡 2px 也看不出来，所以保持原样。
   */
.wechat-bubble::before {
  position: absolute;
  top: 11px;
  width: 0;
  height: 0;
  border: 6px solid transparent;
  content: '';
}

.wechat-row-other .wechat-bubble::before {
  /* 底边贴住气泡左边，尖端朝左指向头像（不跟气泡重叠） */
  left: -12px;
  border-right-color: var(--wechat-other-bg);
}

.wechat-row-self .wechat-bubble::before {
  /* 自己（绿气泡）的小三角，朝右指向头像 */
  right: -10px;
  border-left-color: var(--wechat-self-bg);
}

/* 图片气泡 */
.wechat-bubble-img {
  padding: 4px;
}

.wechat-bubble-img::before {
  display: none;
}

.wechat-bubble-img a {
  display: block;
}

.wechat-bubble-img img {
  display: block;
  max-width: 240px;
  max-height: 320px;
  border-radius: 6px;
  object-fit: cover;
}

/* ---------- 暗色模式 ---------- */

[data-theme="dark"] .wechat {
  --wechat-bg: #1b1c20;
  --wechat-other-bg: #2c2c2c;
  --wechat-text: #e6e6e6;
  --wechat-time-bg: rgba(255, 255, 255, .08);
  --wechat-time-text: rgba(255, 255, 255, .45);
}

/* ---------- 暗色模式 + 背景图案 ----------
   气泡改成半透明，让线稿从底下透出来，跟整站的玻璃卡片观感一致。 */

html.has-dark-bg-pattern .wechat {
  --wechat-bg: rgba(0, 0, 0, .26);
  --wechat-other-bg: rgba(255, 255, 255, .14);
}

/* ---------- 移动端 ---------- */

@media screen and (max-width: 600px) {
  .wechat {
    padding: 14px 12px;
    border-radius: 10px;
    font-size: .9rem;
  }

  .wechat-avatar {
    width: 34px;
    height: 34px;
  }

  .wechat-bubble {
    max-width: 76%;
    padding: 8px 11px;
    font-size: .9rem;
  }
}
