/* گفتگو / پیام‌رسان (views/chat.js) — فقط توکن‌های موجود؛ PC و موبایل
   ارتفاع: صفحه کل ناحیه .view را پر می‌کند (با zoom نمایش فشرده هم درست می‌ماند؛ به vh وابسته نیست). */
.view > .chat-page.page { height: 100%; box-sizing: border-box; display: flex; flex-direction: column; max-width: none; padding: var(--s-4) var(--s-5) var(--s-4); }
.chat-shell { flex: 1; min-height: 0; display: grid; grid-template-columns: clamp(300px, 28%, 380px) minmax(0, 1fr);
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px -12px rgba(0, 0, 0, .18); }
.chat-msgs, .chat-items, .chat-pick-list { scrollbar-width: thin; }

/* ---------- فهرست گفتگوها ---------- */
.chat-list { display: flex; flex-direction: column; min-height: 0; border-inline-end: 1px solid var(--border); background: var(--surface); }
.chat-list-head { display: flex; align-items: center; gap: var(--s-2); min-height: 64px; padding: 0 var(--s-4); font-size: var(--fs-lg); }
.chat-search { padding: 0 var(--s-3) var(--s-3); }
.chat-search .input { border-radius: var(--r-full); background: var(--surface-2); padding-inline: var(--s-4); }
.chat-items { flex: 1; overflow-y: auto; padding: 0 var(--s-2) var(--s-3); display: flex; flex-direction: column; gap: 2px; }
.chat-item { position: relative; display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: 10px var(--s-3); border: 0; border-radius: var(--r-md); background: transparent; color: var(--text); text-align: start; cursor: pointer; font: inherit; transition: background var(--t-fast); }
.chat-item:hover { background: var(--surface-hover); }
.chat-item.on { background: var(--primary-soft); }
.chat-item.on::before { content: ''; position: absolute; inset-block: 14px; inset-inline-start: 0; width: 3px; border-radius: 3px; background: var(--primary); }
.chat-item.unread .semi { font-weight: 800; }
.chat-item.unread .small.muted { color: var(--text); }
.chat-item.unread .xs.dim { color: var(--primary-text); font-weight: 700; }
.chat-badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: var(--r-full); background: var(--primary); color: var(--primary-fg); font-size: 12px; line-height: 22px; text-align: center; font-weight: 700; }
.chat-badge.muted { background: var(--border-strong); color: var(--surface); }
.av.av-group { display: flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--primary-text); border: 1px solid var(--primary-border); }

/* ---------- ستون گفتگو ---------- */
.chat-thread { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: linear-gradient(180deg, var(--surface-2), var(--surface-3)); }
.chat-thread.drop::after { content: 'فایل را اینجا رها کنید'; position: absolute; inset: 8px; z-index: 5; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--primary); border-radius: var(--r-lg); background: var(--primary-soft); color: var(--primary-text); font-weight: 700; font-size: var(--fs-lg); pointer-events: none; }
.chat-thread-head { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-4); min-height: 64px; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-head-main { display: flex; align-items: center; gap: var(--s-3); min-width: 0; padding: var(--s-1) var(--s-2); border: 0; border-radius: var(--r-md); background: transparent; color: var(--text); cursor: pointer; font: inherit; }
.chat-head-main:hover { background: var(--surface-hover); }
.chat-msgs-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.chat-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  padding: var(--s-4) max(var(--s-5), calc((100% - 920px) / 2)) var(--s-4); }
.chat-placeholder, .chat-empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: var(--s-2); color: var(--text-3); text-align: center; padding: var(--s-6); }
.chat-placeholder { height: 100%; justify-content: center; background: var(--surface-2); }
.chat-day { display: flex; justify-content: center; margin: var(--s-3) 0 var(--s-2); pointer-events: none; }
.chat-day span { padding: 3px 14px; border-radius: var(--r-full); background: var(--surface); border: 1px solid var(--border); color: var(--text-2); font-size: var(--fs-xs); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.chat-pill { position: absolute; bottom: var(--s-3); inset-inline-start: 50%; transform: translateX(50%); display: flex; align-items: center; gap: 4px; padding: 7px 16px;
  border: 0; border-radius: var(--r-full); background: var(--primary); color: var(--primary-fg); font: inherit; font-size: var(--fs-xs); font-weight: 600; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, .3); }
.chat-pill[hidden] { display: none; }

/* پیام‌ها: «من» سمت راست، بقیه سمت چپ (آواتار کنار لبه‌ی بیرونی)؛ گوشه‌ی دم‌دار روی آخرین پیام هر ردیف */
.chat-row { display: flex; align-items: flex-end; gap: var(--s-2); max-width: min(76%, 600px); margin-top: 2px; }
.chat-row.run-start { margin-top: 12px; }
.chat-row.mine { align-self: flex-start; }
.chat-row.theirs { align-self: flex-end; flex-direction: row-reverse; }
.chat-row .av-gap { width: 32px; flex: none; }
.chat-row .av { flex: none; }
.chat-bubble { position: relative; min-width: 76px; max-width: 100%; padding: 7px 12px 5px; border-radius: 17px; border: 1px solid var(--border); background: var(--surface); color: var(--text); overflow-wrap: anywhere; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.chat-row.mine .chat-bubble { background: var(--primary); border-color: transparent; color: var(--primary-fg); }
.chat-row.mine .chat-bubble.tail { border-end-start-radius: 5px; }
.chat-row.theirs .chat-bubble.tail { border-end-end-radius: 5px; }
.chat-bubble a { color: var(--primary-text); text-decoration: underline; }
.chat-row.mine .chat-bubble a { color: inherit; }
.chat-bubble.gone { opacity: .7; box-shadow: none; }
.chat-body { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0 12px; }
.chat-text { flex: 0 1 auto; min-width: 0; white-space: pre-wrap; line-height: 1.75; font-size: var(--fs-md); }
.chat-text.deleted { font-style: italic; opacity: .85; font-size: var(--fs-sm); }
.chat-sender { font-size: var(--fs-xs); font-weight: 700; margin-bottom: 1px; }
.chat-meta { flex: none; margin-inline-start: auto; display: flex; align-items: center; gap: 5px; font-size: 11.5px; line-height: 1.9; opacity: .72; white-space: nowrap; }
.chat-tick { letter-spacing: -2px; }
.chat-tick.seen { color: #8be9a8; opacity: 1; font-weight: 700; }
.chat-quote { display: flex; flex-direction: column; align-items: flex-start; width: 100%; margin: 2px 0 5px; padding: 4px 10px; border: 0; border-inline-start: 3px solid currentColor; border-radius: 8px;
  background: rgba(127, 127, 127, .16); color: inherit; font: inherit; font-size: var(--fs-xs); text-align: start; cursor: pointer; }
.chat-quote span { max-width: 100%; opacity: .85; }
.chat-more { position: absolute; top: 3px; inset-inline-end: 5px; display: none; width: 22px; height: 22px; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: rgba(127, 127, 127, .3); color: inherit; cursor: pointer; }
.chat-bubble:hover .chat-more { display: flex; }
.chat-row.flash .chat-bubble { box-shadow: 0 0 0 3px var(--primary-border); }

/* ---------- نوشتن پیام ---------- */
.chat-bar { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-4); border-top: 1px solid var(--border); background: var(--surface); border-inline-start: 3px solid var(--primary); }
.chat-bar[hidden], .chat-emoji[hidden] { display: none; }
.chat-emoji { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; padding: var(--s-2) var(--s-3); border-top: 1px solid var(--border); background: var(--surface); max-height: 132px; overflow-y: auto; }
.chat-emoji button { height: 38px; border: 0; border-radius: var(--r-sm); background: transparent; font-size: 21px; cursor: pointer; }
.chat-emoji button:hover { background: var(--surface-hover); }
.chat-composer { display: flex; align-items: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border); background: var(--surface); }
.chat-composer .icon-btn { width: 42px; height: 42px; flex: none; justify-content: center; color: var(--text-2); }
.chat-input { flex: 1; min-height: 44px; max-height: 140px; resize: none; padding: 10px 16px; border: 1px solid var(--border-2); border-radius: 22px; background: var(--surface-2); color: var(--text);
  font: inherit; line-height: 1.6; outline: none; overflow-y: auto; scrollbar-width: none; }
.chat-input::-webkit-scrollbar { display: none; }
.chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.chat-send { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 50%; flex: none; box-shadow: 0 4px 12px -3px rgba(0, 0, 0, .35); }
.chat-send svg { transform: scaleX(-1); }
.chat-send.busy { opacity: .6; cursor: progress; }

/* ---------- مودال‌ها ---------- */
.chat-pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-1); }
.chat-pick-list.tall { max-height: 380px; }
.chat-pick-row { display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: var(--s-2) var(--s-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text); font: inherit; text-align: start; cursor: pointer; }
.chat-pick-row:hover { background: var(--surface-hover); }
.chat-member { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--border); }

/* ---------- موبایل: یا فهرست یا گفتگو (بدون zoom؛ ارتفاع با dvh) ---------- */
.is-mobile .view > .chat-page.page { height: calc(100dvh - var(--topbar-h) - 78px); padding: var(--s-2); }
.is-mobile .chat-shell { grid-template-columns: minmax(0, 1fr); border-radius: var(--r-md); }
.is-mobile .chat-shell.has-sel .chat-list { display: none; }
.is-mobile .chat-shell:not(.has-sel) .chat-thread { display: none; }
.is-mobile .chat-list { border-inline-end: 0; }
.is-mobile .chat-row { max-width: 88%; }
.is-mobile .chat-msgs { padding: var(--s-3) var(--s-3) var(--s-3); }
.is-mobile .chat-bubble { padding-inline-end: 36px; }
.is-mobile .chat-more { display: flex; width: 28px; height: 28px; }
.is-mobile .chat-file { min-width: 0; }
.is-mobile .chat-composer .chat-input { min-width: 0; }
.is-mobile .chat-composer { padding: var(--s-2) var(--s-3) calc(var(--s-2) + env(safe-area-inset-bottom, 0px)); }

/* ---------- پیوست فایل ---------- */
.chat-img { display: block; position: relative; max-width: 320px; min-width: 140px; min-height: 90px; margin: 2px 0 5px; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: rgba(127, 127, 127, .18); cursor: zoom-in; }
.chat-img img { display: block; width: 100%; max-height: 300px; object-fit: cover; }
.chat-img.loading::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .25), transparent); background-size: 200% 100%; animation: chat-shimmer 1.2s infinite; }
.chat-img.failed::after { content: 'تصویر بارگذاری نشد'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: var(--fs-xs); opacity: .8; }
@keyframes chat-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.chat-file { display: flex; align-items: center; gap: var(--s-3); min-width: 230px; max-width: 340px; margin: 2px 0 5px; padding: 8px 10px; border-radius: 12px; background: rgba(127, 127, 127, .16); }
.chat-file .icon-btn { color: inherit; }
.chat-file-ico { position: relative; flex: none; width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: rgba(127, 127, 127, .25); }
.chat-file-ico span { position: absolute; bottom: 2px; font-size: 8.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .3px; }
.chat-file-ico svg { margin-bottom: 6px; }
.chat-lightbox-wrap { display: flex; justify-content: center; max-height: 70vh; overflow: auto; }
.chat-lightbox { max-width: 100%; max-height: 66vh; border-radius: var(--r-sm); }
.chat-row.mine .chat-bubble .dim, .chat-row.mine .chat-bubble .muted { color: inherit; opacity: .78; }
