/* =============================================================================
   ui/chat.css — بخش پیام‌ها، برگردان ۱به۱ استایل اندروید:
   MessagesScreen.kt · DmThread.kt · ChannelChat.kt · ChatMedia.kt · Groups.kt
   همهٔ اندازه‌ها دقیقاً همان dp اندروید هستند.
   ========================================================================== */

/* ------------------------------------------------ قالب کلی صفحه --- */
.mg { display: flex; flex-direction: column; min-height: 0; gap: 0; }
.mg-scroll { display: flex; flex-direction: column; gap: 4px; padding-bottom: 90px; }

/* سرتیتر اینباکس: «پیام‌ها» + «گفتگو با رفقای درس‌خون» */
.mg-head { padding: 18px 4px 10px; }
.mg-title { font-size: 1.45rem; font-weight: 800; letter-spacing: -.01em; }
.mg-sub { margin-top: 2px; font-size: .82rem; color: var(--muted); }

/* GlowSearchField — حلقهٔ نورانی دور فیلد جستجو */
.mg-search { position: relative; margin: 2px 0 10px; }
.mg-search input {
  width: 100%; border: 1px solid var(--line); background: var(--surf);
  color: var(--fg); border-radius: var(--r-full); padding: 12px 42px 12px 14px;
  font: inherit; font-size: .92rem; transition: border-color var(--t-fast), box-shadow var(--t-med);
}
.mg-search input:focus {
  outline: none; border-color: color-mix(in srgb, var(--primary) 65%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}
.mg-search > svg { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.mg-res { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }

/* PinnedRow — سه کانال عمومی */
.mg-pins { display: flex; flex-direction: column; gap: 2px; }
.mg-pin {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px;
  background: none; border: 0; border-radius: 18px; color: var(--fg);
  text-align: start; cursor: pointer; transition: background var(--t-fast);
}
.mg-pin:hover { background: var(--elev); }
.mg-pin-ic {
  width: 46px; height: 46px; flex: none; display: grid; place-items: center;
  border-radius: 16px; font-size: 1.25rem;
  background: color-mix(in srgb, var(--tint) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--tint) 22%, transparent);
}
.mg-pin b { display: block; font-size: .95rem; font-weight: 700; }
.mg-pin .sub { font-size: .78rem; color: var(--muted); }
.mg-pin .pin-g { font-size: 13px; color: var(--muted); opacity: .75; }
.mg-pill {
  min-width: 22px; padding: 2px 7px; border-radius: var(--r-full);
  font-size: .72rem; font-weight: 800; text-align: center;
  background: var(--tint, var(--primary)); color: #08150F;
}

.mg-sect { padding: 14px 6px 6px; font-size: .8rem; font-weight: 700; color: var(--muted); }

/* ConversationRow / GroupInboxRow */
.mg-conv {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
  background: none; border: 0; border-radius: 18px; color: var(--fg);
  text-align: start; cursor: pointer; transition: background var(--t-fast);
}
.mg-conv:hover { background: var(--elev); }
.mg-conv .who { display: flex; align-items: center; gap: 5px; font-weight: 700; font-size: .95rem; }
.mg-conv .last { font-size: .8rem; color: var(--muted); }
.mg-conv .mark { font-size: .78rem; opacity: .8; }
.mg-conv .side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: none; }
.mg-conv .time { font-size: .72rem; color: var(--muted); }
.mg-conv.unread .time { color: var(--primary); font-weight: 700; }
.mg-badge {
  min-width: 20px; padding: 2px 6px; border-radius: var(--r-full);
  background: var(--primary); color: var(--on-primary);
  font-size: .7rem; font-weight: 800; text-align: center;
}
.mg-badge.grape { background: #A78BFA; color: #14101F; }
.mg-ment {
  padding: 1px 7px; border-radius: var(--r-full); font-size: .7rem; font-weight: 800;
  background: color-mix(in srgb, #A78BFA 20%, transparent); color: #A78BFA;
}
.mg-gtile {
  width: 52px; height: 52px; flex: none; display: grid; place-items: center;
  border-radius: 16px; font-size: 1.3rem;
  background: color-mix(in srgb, #A78BFA 13%, transparent);
}

/* FAB گروه‌ها — پایین سمت start
   قبلاً absolute بود و به تهِ طومار می‌رفت؛ حالا در لایهٔ شناور روی body
   می‌نشیند و دقیقاً بالای منوی پایین قرار می‌گیرد. */
.mg-fab {
  position: fixed; z-index: 44;
  inset-inline-start: 18px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 22px);
  width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; padding: 15px;
  background: var(--secondary-c); color: var(--on-secondary-c); box-shadow: var(--sh-md);
  transition: transform var(--t-fast);
}
.mg-fab:active { transform: scale(.94); }

/* ---------------------------------------------- ترانزیشن مسیرها --- */
/* AnimatedContent: ورود slideIn 260ms + fadeIn / خروج slideOut 200ms + fadeOut */
.mg-in { animation: mgIn 260ms var(--e-decel) both; }
.mg-out { animation: mgOut 200ms var(--e-accel) both; }
@keyframes mgIn { from { opacity: 0; transform: translateX(16%); } to { opacity: 1; transform: none; } }
@keyframes mgOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(-12%); } }
@media (prefers-reduced-motion: reduce) { .mg-in, .mg-out { animation: none; } }

/* ------------------------------------------------------ سرتیتر چت --- */
.ch-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - var(--top-h, var(--topbar-h)) - var(--nav-h)); }
.ch-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px 10px;
  position: sticky; top: 0; z-index: 4; background: var(--bg);
}
.ch-head .grow { min-width: 0; }
.ch-head b { display: block; font-size: 1rem; font-weight: 800; }
.ch-head .sub { font-size: .74rem; color: var(--muted); animation: mgFade 200ms var(--e-standard) both; }
@keyframes mgFade { from { opacity: 0 } to { opacity: 1 } }
.ch-head .bell.on { color: var(--error); }

.ch-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px 10px; overflow-anchor: none; }
/* نوار نوشتن باید بالای منوی شناور پایین بماند، نه زیرِ آن. */
.ch-foot {
  position: sticky; z-index: 5; background: var(--bg);
  bottom: calc(var(--nav-h) + var(--safe-b) + 6px);
  padding-bottom: 6px;
}
@media (min-width: 900px) {
  .ch-foot { bottom: 0; padding-bottom: var(--safe-b); }
}

/* ------------------------------------------------------------- حباب --- */
.ch-row { display: flex; direction: ltr; align-items: flex-end; gap: 6px; transition: transform 180ms var(--e-spring); }
.ch-row.mine { justify-content: flex-end; }
.ch-row > .ch-bub, .ch-row > .ch-plain { direction: rtl; }
.ch-av { background: none; border: 0; padding: 0; cursor: pointer; flex: none; }

.ch-bub {
  max-width: min(300px, 78%); display: flex; flex-direction: column; gap: 4px;
  padding: 8px 11px; position: relative;
  border-start-start-radius: 6px; border-start-end-radius: 20px;
  border-end-end-radius: 20px; border-end-start-radius: 20px;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--surface-v) 92%, transparent),
    color-mix(in srgb, var(--surface-v) 78%, transparent));
  border: 1px solid color-mix(in srgb, var(--outline-v) 45%, transparent);
}
.ch-row.mine .ch-bub {
  border-start-start-radius: 20px; border-start-end-radius: 6px;
  background: linear-gradient(180deg, var(--primary-c),
    color-mix(in srgb, var(--secondary-c) 65%, var(--primary-c)));
  border-color: transparent; color: var(--on-primary-c);
}
.ch-plain { max-width: min(300px, 78%); display: flex; flex-direction: column; gap: 4px; }
.ch-row.mine .ch-plain { align-items: flex-end; }

.ch-text { font-size: .93rem; line-height: 1.75; overflow-wrap: anywhere; white-space: pre-wrap; }
.ch-cap { font-size: .88rem; line-height: 1.7; overflow-wrap: anywhere; }
.ch-cap.sm { font-size: .78rem; color: var(--muted); }
.ch-who { background: none; border: 0; padding: 0; font-size: .78rem; font-weight: 800; cursor: pointer; text-align: start; }

.ch-quote {
  display: flex; flex-direction: column; gap: 1px; padding: 5px 8px;
  border-radius: 10px; border-inline-start: 3px solid var(--primary);
  background: color-mix(in srgb, var(--on-surface) 7%, transparent);
  font-size: .78rem; max-width: 100%;
}
.ch-quote b { color: var(--primary); font-size: .74rem; }
.ch-quote span { color: var(--muted); }

.ch-meta { display: flex; align-items: center; gap: 5px; align-self: flex-end; font-size: .68rem; color: var(--muted); }
.ch-row.mine .ch-meta { color: color-mix(in srgb, var(--on-primary-c) 72%, transparent); }
.ch-ed { opacity: .8; }
.ch-tick { display: inline-flex; opacity: .75; }
.ch-tick.on { color: var(--primary); opacity: 1; }

.ch-reacts { display: flex; flex-wrap: wrap; gap: 4px; }
.ch-react {
  border-radius: var(--r-full); padding: 2px 8px; font-size: .78rem; cursor: pointer;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border: 1px solid rgba(255,255,255,.12); color: inherit;
}
.ch-react.mine { background: color-mix(in srgb, var(--primary) 28%, transparent); border-color: rgba(255,255,255,.30); }

/* فلش هایلایت پیام پاسخ/منشن دیده‌نشده (tween 500ms · 2500ms) */
.ch-row.flash .ch-bub { animation: chFlash 3000ms var(--e-standard) both; }
@keyframes chFlash {
  0% { box-shadow: 0 0 0 0 transparent; }
  17% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
  83% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.ch-newpill {
  align-self: center; font-size: .72rem; font-weight: 700; padding: 3px 10px;
  border-radius: var(--r-full); background: color-mix(in srgb, var(--primary) 18%, transparent);
  color: var(--primary);
}

/* سوایپ برای پاسخ */
.ch-row.swiping::after {
  content: ''; position: absolute; inset-inline-end: -30px; top: 50%;
  width: 20px; height: 20px; transform: translateY(-50%);
  background: currentColor; opacity: .35;
  clip-path: polygon(45% 0,45% 30%,100% 30%,100% 100%,80% 100%,80% 50%,45% 50%,45% 80%,0 40%);
}
.ch-row { position: relative; }

/* ------------------------------------------------------------- رسانه --- */
.ch-img { display: block; max-width: 240px; max-height: 240px; border-radius: 14px; cursor: zoom-in; }
.ch-sticker { display: block; width: 140px; height: 140px; object-fit: contain; }
.ch-video { width: 240px; height: 190px; border-radius: 14px; background: #000; }
.ch-tile {
  width: 200px; height: 120px; border-radius: 14px; cursor: pointer;
  display: grid; place-items: center; gap: 2px; color: var(--fg);
  background: color-mix(in srgb, var(--on-surface) 8%, transparent); border: 0;
}
.ch-tile b { font-size: .8rem; } .ch-tile span { font-size: .7rem; color: var(--muted); }

.ch-audio { display: flex; align-items: center; gap: 8px; min-width: 170px; }
.ch-play {
  width: 34px; height: 34px; flex: none; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--primary); color: var(--on-primary);
}
.ch-track { height: 4px; border-radius: var(--r-full); background: color-mix(in srgb, var(--on-surface) 18%, transparent); overflow: hidden; }
.ch-track i { display: block; height: 100%; width: 0; background: var(--primary); transition: width 120ms linear; }
.ch-time { margin-top: 4px; font-size: .7rem; color: var(--muted); }

.ch-file { display: flex; align-items: center; gap: 8px; min-width: 190px; }
.ch-file-main { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; color: inherit; text-decoration: none; }
.ch-file-ic { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.ch-file-main b { display: block; font-size: .84rem; }
.ch-file-main .tiny { font-size: .7rem; color: var(--muted); }
.ch-dl { flex: none; color: var(--muted); }

/* DateChip */
.ch-date { align-self: center; margin: 6px 0; }
.ch-date span {
  display: inline-block; padding: 3px 12px; border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface-v) 70%, transparent);
  font-size: .72rem; color: var(--muted);
}

/* JumpToBottom */
.ch-jump {
  position: absolute; inset-inline-end: 14px; bottom: calc(var(--nav-h) + var(--safe-b) + 92px); z-index: 6;
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; border: 1px solid var(--line);
  background: var(--surf); color: var(--fg); box-shadow: var(--sh-sm);
  animation: mgFade 180ms var(--e-standard) both;
}

/* UploadBar */
.ch-up { display: flex; flex-direction: column; gap: 4px; padding: 6px 12px; font-size: .76rem; color: var(--muted); }
.ch-up-t { height: 3px; border-radius: var(--r-full); background: var(--line); overflow: hidden; }
.ch-up-t i { display: block; height: 100%; background: var(--primary); transition: width 160ms linear; }

/* نوار پاسخ / نوار ضبط */
.ch-replybar, .ch-recbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-top: 1px solid var(--line); font-size: .8rem;
}
.ch-replybar b { color: var(--primary); }
.ch-replybar .trunc { color: var(--muted); }
.ch-recbar .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--error); animation: recPulse 1s infinite; }
@keyframes recPulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

/* چیپ‌های پیشنهاد منشن در گروه */
.ch-ments { display: flex; gap: 6px; overflow-x: auto; padding: 6px 10px; }
.ch-ments button {
  flex: none; border-radius: var(--r-full); padding: 5px 12px; cursor: pointer;
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 26%, transparent);
  color: var(--primary); font-size: .8rem; font-weight: 700;
}

/* ------------------------------------------------------- نوار ورودی --- */
.ch-input {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 6px 10px;
  border-top: 1px solid var(--line);
}
.ch-attach {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--elev); color: var(--fg);
}
.ch-field {
  flex: 1 1 auto; min-width: 0; max-height: 132px; resize: none;
  border: 1px solid var(--line); background: var(--surf); color: var(--fg);
  border-radius: 22px; padding: 11px 14px; font: inherit; font-size: .92rem; line-height: 1.6;
}
.ch-field:focus { outline: none; border-color: color-mix(in srgb, var(--primary) 60%, transparent); }
/* دکمهٔ هشت‌ضلعی نارنجی مانند اندروید */
.ch-send {
  width: 46px; height: 46px; flex: none; border: 0; cursor: pointer;
  display: grid; place-items: center; color: var(--on-primary);
  background: linear-gradient(135deg, var(--primary), var(--grad-a));
  clip-path: polygon(30% 0,70% 0,100% 30%,100% 70%,70% 100%,30% 100%,0 70%,0 30%);
}
.ch-send.pop { animation: sendPop 150ms var(--e-spring); }
@keyframes sendPop { from { transform: scale(.7); opacity: .4 } to { transform: none; opacity: 1 } }
.ch-note { padding: 12px; text-align: center; font-size: .82rem; color: var(--muted); border-top: 1px solid var(--line); }

/* ------------------------------------------------------- شیت پیوست --- */
.at-row { display: flex; justify-content: space-evenly; gap: 8px; padding: 6px 0 4px; }
.at-circle { background: none; border: 0; cursor: pointer; display: grid; justify-items: center; gap: 8px; color: var(--fg); }
.at-ic { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; color: #071410; box-shadow: var(--sh-sm); }
.at-lb { font-size: .78rem; }
.at-more { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.at-line {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px;
  border: 0; border-radius: 16px; background: var(--elev); color: var(--fg);
  cursor: pointer; font: inherit; font-size: .88rem; text-align: start;
}

.st-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-height: 52dvh; overflow-y: auto; }
.st-grid button { border: 0; background: none; padding: 0; cursor: pointer; }
.st-grid img { width: 100%; aspect-ratio: 1; object-fit: contain; }

.mu-list { display: flex; flex-direction: column; gap: 4px; max-height: 52dvh; overflow-y: auto; }
.mu-list button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  border: 0; border-radius: 16px; background: var(--elev); color: var(--fg);
  cursor: pointer; font: inherit; text-align: start;
}
.mu-list .tiny { font-size: .72rem; color: var(--muted); }

/* --------------------------------------------------- منوی شیشه‌ای --- */
.gm-scrim {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: var(--scrim); opacity: 0; transition: opacity 140ms var(--e-standard);
}
.gm-scrim.on { opacity: 1; }
.gm-card {
  min-width: 250px; max-width: 320px; border-radius: 26px; padding: 8px 0;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid transparent;
  border-image: linear-gradient(135deg, rgba(255,255,255,.35), rgba(255,255,255,.06)) 1;
  box-shadow: var(--sh-lg);
  transform: scale(.82); transition: transform 200ms var(--e-spring);
}
.gm-scrim.on .gm-card { transform: none; }
.gm-reacts {
  margin: 6px 12px; padding: 4px 6px; border-radius: 24px;
  background: color-mix(in srgb, var(--surface-v) 45%, transparent);
  border: 1px solid rgba(255,255,255,.14);
}
.gm-rrow { display: flex; justify-content: space-evenly; align-items: center; padding: 2px 0; }
.gm-em {
  width: 36px; height: 36px; border: 0; background: none; cursor: pointer;
  font-size: 1.12rem; border-radius: 50%; animation: emIn 220ms var(--e-spring) both;
}
.gm-em.mine { background: color-mix(in srgb, var(--primary) 26%, transparent); }
.gm-em:active { transform: scale(.86); }
@keyframes emIn { from { opacity: 0; transform: scale(.4) } to { opacity: 1; transform: none } }
.gm-div { height: 1px; margin: 4px 14px; background: color-mix(in srgb, var(--on-surface) 12%, transparent); }
.gm-act {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 18px;
  border: 0; background: none; color: var(--fg); cursor: pointer; font: inherit;
  font-size: .9rem; text-align: start;
}
.gm-act:hover { background: color-mix(in srgb, var(--on-surface) 6%, transparent); }
.gm-act.danger { color: var(--error); }

/* ------------------------------------------------------------- گروه‌ها --- */
.gr-head { display: flex; align-items: center; gap: 10px; padding: 10px 4px; }
.gr-actions { display: flex; gap: 8px; padding: 6px 4px 12px; }
.gr-actions .btn { flex: 1 1 0; }
.gr-card {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px;
  border: 1px solid var(--line); border-radius: 20px; background: var(--surf);
  color: var(--fg); cursor: pointer; text-align: start; margin-bottom: 8px;
}
.gr-card:hover { background: var(--elev); }
.gr-av { width: 46px; height: 46px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 1.2rem; overflow: hidden; }
.gr-av img { width: 100%; height: 100%; object-fit: cover; }
.gr-card b { display: block; font-size: .95rem; }
.gr-card .at { font-size: .78rem; color: var(--primary); }
.gr-card .cnt { font-size: .76rem; color: var(--muted); flex: none; }

.gr-detail { display: flex; flex-direction: column; gap: 4px; }
.gr-hero { display: grid; justify-items: center; gap: 6px; padding: 14px 0 8px; }
.gr-hero .big { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; font-size: 1.9rem; overflow: hidden; }
.gr-hero .name { display: flex; align-items: center; gap: 6px; font-size: 1.15rem; font-weight: 800; }
.gr-hero .at { font-size: .82rem; color: var(--primary); }
.gr-hero .meta { font-size: .78rem; color: var(--muted); }
.gr-member { display: flex; align-items: center; gap: 10px; padding: 8px 4px; }
.gr-member .grow { min-width: 0; }
.gr-member b { font-size: .9rem; }
.gr-member .min { font-size: .74rem; color: var(--muted); }

/* --- overflow hardening: long text must never widen the page --- */
.ch-body, .ch-wrap { min-width: 0; max-width: 100%; }
.ch-row { max-width: 100%; min-width: 0; }
.ch-row > * { min-width: 0; }
.ch-bub, .ch-plain { min-width: 0; }
.ch-text, .ch-cap, .ch-who, .ch-quote { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.ch-quote b, .ch-quote span { overflow-wrap: anywhere; word-break: break-word; }
.ch-text a, .ch-cap a { overflow-wrap: anywhere; word-break: break-all; }
.ch-img, .ch-video, .ch-sticker, .ch-tile { max-width: 100%; }
.ch-audio { min-width: 0; width: min(170px, 100%); }
.ch-file { min-width: 0; width: min(190px, 100%); }
.ch-file-main b, .ch-file-main .tiny, .ch-cap.trunc { white-space:normal; overflow:visible; overflow-wrap:anywhere; }
.ch-head b, .ch-head .sub { white-space:normal; overflow-wrap:anywhere; }
.ch-head .grow { max-height:30dvh; overflow-y:auto; }
.mg-conv > .grow, .mg-pin > .grow, .mg-conv .who, .mg-conv .last, .mg-pin b, .mg-pin .sub { min-width: 0; }
.mg-conv .last, .mg-pin .sub, .mg-conv .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-search input { max-width: 100%; }
.ch-ments, .ch-replybar { min-width: 0; max-width: 100%; }
.ch-replybar .trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
