/* ============================================================
   همفکران — کوچک‌سازی آواتار و لوگو در گفتگوها
   باگ: تصویرها بدون ابعاد رندر می‌شوند و تمام قاب را می‌گیرند
   ============================================================ */

/* آواتار پیام و فهرست */
html body .ch-av,
html body .ch-msg .ch-av,
html body .ch-item-ico,
html body .chat-avatar,
html body .chat-msg-avatar,
html body .nw-comment-av,
html body .ch-member img,
html body .ch-pick img,
html body .chat-who-avatar {
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  min-height: 36px !important;
  max-height: 36px !important;
  flex: 0 0 36px !important;
  border-radius: 50% !important;
  overflow: hidden !important;
  display: grid !important;
  place-items: center !important;
  font-size: 13px !important;
  line-height: 1 !important;
  padding: 0 !important;
}

html body .ch-item-ico { border-radius: 12px !important; }

/* تصویر داخل آواتار */
html body .ch-av img,
html body .ch-item-ico img,
html body .chat-avatar img,
html body .chat-msg-avatar img,
html body .nw-comment-av img,
html body .chat-who-avatar img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
  border: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* هر تصویر بی‌ابعاد درون قاب پیام‌ها — سقف امن */
html body .ch-feed img,
html body #chatFeed img,
html body .chat-feed img {
  max-width: 100% !important;
  max-height: 260px !important;
  height: auto !important;
  width: auto !important;
  border-radius: 12px !important;
}

/* آواتارها از قاعدهٔ بالا مستثنا */
html body .ch-feed .ch-av img,
html body .ch-feed .chat-avatar img,
html body #chatFeed .chat-msg-avatar img {
  max-height: 100% !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0 !important;
}

/* لوگوی واترمارک: پشت متن، کوچک و محو */
html body .ch-feed > img[src*="logo"],
html body #chatFeed > img[src*="logo"],
html body .chat-feed > img[src*="logo"],
html body .ch-feed > img[src*="watermark"],
html body [class*="watermark"] img {
  position: absolute !important;
  inset: 50% auto auto 50% !important;
  transform: translate(-50%, -50%) !important;
  width: 190px !important;
  max-width: 40% !important;
  height: auto !important;
  max-height: 190px !important;
  opacity: .05 !important;
  z-index: 0 !important;
  pointer-events: none !important;
  border-radius: 0 !important;
}

html body .ch-feed, html body #chatFeed, html body .chat-feed { 
  position: relative !important; 
}

/* =========================================================
   CHANNEL CHAT — FINAL MESSAGE ORDER + AVATAR FIX
   ========================================================= */

/* پیام‌ها همیشه از بالا به پایین باشند */
html body .ch-feed {
  display: flex !important;
  flex-direction: column !important;
  justify-content: flex-start !important;
  align-items: stretch !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

/* هر پیام یک ردیف مستقل باشد */
html body .ch-feed > .ch-msg {
  display: flex !important;
  flex: 0 0 auto !important;
  order: initial !important;
  min-height: 0 !important;
}

/* پیام خود کاربر همچنان سمت خودش باشد */
html body .ch-feed > .ch-msg.mine,
html body .ch-feed > .ch-msg.is-mine {
  margin-inline-start: auto !important;
  flex-direction: row-reverse !important;
}

/* آواتار: اندازه کاملاً ثابت */
html body .ch-feed > .ch-msg > .ch-av {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
  max-width: 34px !important;
  min-height: 34px !important;
  max-height: 34px !important;
  flex: 0 0 34px !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  position: relative !important;
  display: grid !important;
  place-items: center !important;
  overflow: hidden !important;
  border-radius: 50% !important;
  box-sizing: border-box !important;
}

/* خود عکس آواتار هم ثابت */
html body .ch-feed > .ch-msg > .ch-av > img {
  position: absolute !important;
  inset: 0 !important;
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  border: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* حباب پیام اجازه ندارد آواتار را بکشد */
html body .ch-feed > .ch-msg > .ch-bub {
  min-width: 0 !important;
  max-width: calc(100% - 45px) !important;
  flex: 0 1 auto !important;
}

/* مدیاهای داخل پیام جدا از آواتار */
html body .ch-feed > .ch-msg .ch-bubble img,
html body .ch-feed > .ch-msg .ch-bubble video {
  max-width: 100% !important;
  height: auto !important;
}

/* آخرین پیام همیشه در انتهای لیست طبیعی باشد */
html body .ch-feed > .ch-msg:last-child {
  margin-bottom: 2px !important;
}

/* موبایل */
@media (max-width: 480px) {
  html body .ch-feed > .ch-msg > .ch-av {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    max-width: 30px !important;
    min-height: 30px !important;
    max-height: 30px !important;
    flex-basis: 30px !important;
  }

  html body .ch-feed > .ch-msg > .ch-bub {
    max-width: calc(100% - 40px) !important;
  }
}

/* ============================================================
   رفع نهایی: آواتارهای کوچک در پنجره ساخت (چت)
   ============================================================ */
html body .ch-member img,
html body .ch-pick img {
  width: 30px !important;
  height: 30px !important;
  min-width: 30px !important;
  max-width: 30px !important;
  flex: 0 0 30px !important;
  object-fit: cover !important;
  border-radius: 50% !important;
}