atagen

malice

public
Star0
Watch0
6381c09db9bfd2f6f31341eb87efa1dfcf65d2e0
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git
web/src/lib/MessageRow.svelteSvelte618 lines25.5 KB
1
<script lang="ts">
2
  import MediaAttachmentView from './MediaAttachmentView.svelte';
3
  import MxcAvatar from './MxcAvatar.svelte';
4
  import Emoji from './Emoji.svelte';
5
  import EmojiText from './EmojiText.svelte';
6
  import MessageText from './MessageText.svelte';
7
  import ReactionPicker from './ReactionPicker.svelte';
8
  import LinkCard from './LinkCard.svelte';
9
  import { mediaUrl, messageMediaUrl } from './api';
10
  import type { ImagePack, LinkPreview, Person, QuickReaction, ReplyReference, SendState, TimelineContent, TimelineEvent } from './types';
11
  import { senderLabel } from './types';
12
  import { formatClock, formatDay, initialsOf, senderHue } from './format';
13
  import { findUrls } from './urls';
14
  import { mentionsFromHtml, resolveMentions, stripMarkdownPills } from './mentions';
15
16
  export let itemId: string;
17
  export let event: TimelineEvent;
18
  export let showSender: boolean;
19
  export let reacting: boolean;
20
  export let onReact: (eventId: string, key: string, shortcode?: string) => void;
21
  export let senderAvatar: string | null = null;
22
  export let quickReactions: QuickReaction[] = [];
23
  export let packs: ImagePack[] = [];
24
  export let onQuickChange: (list: QuickReaction[]) => void = () => {};
25
  export let linkPreviews: Record<string, LinkPreview | null> = {};
26
  export let loadPreview: ((url: string) => void) | null = null;
27
  export let people: Record<string, Person> = {};
28
  export let onReply: ((target: ReplyReference) => void) | null = null;
29
  export let onJump: ((eventId: string) => void) | null = null;
30
  export let onEdit: ((eventId: string, body: string) => void) | null = null;
31
  export let editing = false;
32
  export let showSent = true;
33
  export let readOnly = false;
34
  export let self: string | null = null;
35
  export let onUser: ((userId: string, x: number, y: number, menu: boolean) => void) | null = null;
36
  export let onCloneSticker: ((eventId: string, body: string, x: number, y: number) => void) | null = null;
37
  export let onMore: ((event: TimelineEvent, x: number, y: number) => void) | null = null;
38
39
  $: lag = lagLabel(event);
40
41
  function lagLabel(event: TimelineEvent): string | null {
42
    const lag = event.delivery_lag_ms;
43
    if (!lag) return null;
44
    if (lag < 60 * 60 * 1000) return `${Math.max(1, Math.floor(lag / 60000))}m`;
45
    if (lag < 24 * 60 * 60 * 1000) return `${Math.floor(lag / 3600000)}h`;
46
    return `${Math.floor(lag / 86400000)}d`;
47
  }
48
49
  function openUser(ev: MouseEvent, menu: boolean): void {
50
    if (!onUser) return;
51
    const rect = (ev.currentTarget as HTMLElement).getBoundingClientRect();
52
    onUser(event.sender.user_id, menu ? ev.clientX : rect.left, menu ? ev.clientY : rect.bottom + 4, menu);
53
  }
54
55
  const PICKER_WIDTH = 320;
56
  const PICKER_HEIGHT = 380;
57
  const PICKER_MARGIN = 8;
58
  const MAX_READERS = 3;
59
  const STATE_LABELS: Record<string, string> = {
60
    'm.room.pinned_events': 'changed the pinned messages',
61
    'm.room.power_levels': 'changed the room permissions',
62
    'm.room.join_rules': 'changed who can join',
63
    'm.room.history_visibility': 'changed who can read history',
64
    'm.room.guest_access': 'changed guest access',
65
    'm.room.canonical_alias': 'changed the room address',
66
    'm.room.server_acl': 'changed the server access list',
67
    'm.space.child': 'changed the rooms in this space',
68
    'm.space.parent': 'changed the parent space',
69
    'im.ponies.room_emotes': 'updated a sticker pack'
70
  };
71
72
  let row: HTMLDivElement;
73
  let pickerPop: HTMLDivElement | undefined;
74
  let selected = false;
75
  let pickerOpen = false;
76
  let pickerStyle = '';
77
78
  const MEMBERSHIP_LABELS: Record<string, string> = {
79
    Joined: 'joined the room',
80
    Left: 'left the room',
81
    Banned: 'was banned',
82
    Unbanned: 'was unbanned',
83
    Kicked: 'was kicked',
84
    KickedAndBanned: 'was kicked and banned',
85
    Invited: 'was invited',
86
    InvitationAccepted: 'accepted the invite',
87
    InvitationRejected: 'rejected the invite',
88
    InvitationRevoked: 'had the invite revoked',
89
    Knocked: 'requested to join',
90
    KnockAccepted: 'was let in',
91
    KnockRetracted: 'withdrew the request to join',
92
    KnockDenied: 'had the request to join denied'
93
  };
94
95
  $: name = event.sender.display_name ?? people[event.sender.user_id]?.name ?? event.sender.user_id;
96
  $: displayName = event.sender.name_ambiguous ? `${name} (${event.sender.user_id})` : name;
97
  $: readers = event.read_by.map((id) => people[id] ?? { user_id: id, name: id, avatar: null });
98
  $: interactive = event.content.kind === 'Message' || event.content.kind === 'Sticker' || event.content.kind === 'Poll';
99
  $: message = event.content.kind === 'Message' ? event.content.message : null;
100
  $: stripped = stripMarkdownPills(message ? (message.media ? message.media.caption : message.body) ?? '' : '');
101
  $: linked = message ? [...mentionsFromHtml(message.formatted_body), ...stripped.mentions] : [];
102
  $: mentions = resolveMentions(stripped.text, linked);
103
  $: mentionsMe = self !== null && [...linked, ...mentions].some((m) => m.user_id === self);
104
  $: previews = findUrls(stripped.text);
105
  $: bundled = message ? message.link_previews : [];
106
  $: cards = previews
107
    .map((link) => ({ link, preview: bundled.find((b) => b.url === link.href) ?? linkPreviews[link.href] ?? null }))
108
    .filter((c) => c.preview && (c.preview.title || c.preview.description || c.preview.image));
109
  $: if (loadPreview) {
110
    for (const link of previews) {
111
      if (!bundled.some((b) => b.url === link.href) && !(link.href in linkPreviews)) loadPreview(link.href);
112
    }
113
  }
114
115
  $: sent = interactive && showSent && event.own && event.send_state.kind === 'Sent' && event.event_id !== null;
116
117
  function sendLabel(state: SendState): string {
118
    if (state.kind === 'Failed') return state.will_retry ? 'failed — will retry' : 'failed — not delivered';
119
    if (state.kind === 'Sending') return 'sending…';
120
    return '';
121
  }
122
123
  function toggleSelected(e: MouseEvent) {
124
    if (readOnly || !interactive || (e.target as Element).closest('a, button, input, video, audio, .picker-pop')) return;
125
    selected = !selected;
126
  }
127
128
  function deselectOutside(e: PointerEvent) {
129
    if (selected && !pickerOpen && !row.contains(e.target as Node)) selected = false;
130
  }
131
132
  function openPicker(e: MouseEvent) {
133
    if (pickerOpen) {
134
      pickerOpen = false;
135
      return;
136
    }
137
    const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
138
    const height = Math.min(PICKER_HEIGHT, window.innerHeight - 2 * PICKER_MARGIN);
139
    const below = window.innerHeight - rect.bottom - PICKER_MARGIN >= height;
140
    const top = below ? rect.bottom + 4 : Math.max(PICKER_MARGIN, rect.top - height - 4);
141
    const maxLeft = window.innerWidth - PICKER_WIDTH - PICKER_MARGIN;
142
    const left = Math.max(PICKER_MARGIN, Math.min(rect.right - PICKER_WIDTH, maxLeft));
143
    pickerStyle = `top:${top}px;left:${left}px;height:${height}px`;
144
    selected = true;
145
    pickerOpen = true;
146
  }
147
148
  function closePicker() {
149
    pickerOpen = false;
150
  }
151
152
  function isImageKey(key: string): boolean {
153
    return key.startsWith('mxc://') || packs.some((p) => p.images.some((i) => i.reaction_key === key));
154
  }
155
156
  function react(key: string, shortcode: string | null) {
157
    if (shortcode && isImageKey(key)) onReact(event.event_id ?? '', key, shortcode);
158
    else onReact(event.event_id ?? '', key);
159
  }
160
161
  function reply() {
162
    if (!event.event_id || !onReply) return;
163
    onReply({
164
      event_id: event.event_id,
165
      details: { kind: 'Ready', sender: event.sender, content: event.content, timestamp_ms: event.timestamp_ms }
166
    });
167
  }
168
169
  $: editableBody =
170
    event.own && event.editable && event.event_id && event.content.kind === 'Message' && event.content.message.kind === 'Text'
171
      ? event.content.message.body
172
      : null;
173
174
  function edit() {
175
    if (!event.event_id || editableBody === null || !onEdit) return;
176
    onEdit(event.event_id, editableBody);
177
  }
178
179
  function reactorNames(senders: string[]): string {
180
    const names = senders.map((id) => people[id]?.name ?? id);
181
    if (names.length <= 12) return names.join(', ');
182
    return `${names.slice(0, 12).join(', ')} and ${names.length - 12} more`;
183
  }
184
185
  function pick(key: string, shortcode: string | null) {
186
    pickerOpen = false;
187
    react(key, shortcode);
188
  }
189
190
  function closeOnScroll(e: Event) {
191
    if (pickerOpen && !pickerPop?.contains(e.target as Node)) pickerOpen = false;
192
  }
193
194
  function actorLabel(userId: string, name: string | null): string {
195
    return name ?? people[userId]?.name ?? userId;
196
  }
197
198
  function replyPreview(content: TimelineContent): string {
199
    if (content.kind === 'Message') return stripMarkdownPills(content.message.body).text;
200
    if (content.kind === 'Sticker') return content.body || 'Sticker';
201
    if (content.kind === 'Poll') return `Poll: ${content.question}`;
202
    if (content.kind === 'Redacted') return 'Message deleted';
203
    if (content.kind === 'UnableToDecrypt') return 'Unable to decrypt';
204
    return systemLine(content);
205
  }
206
207
  function systemLine(content: TimelineContent, actor = displayName): string {
208
    switch (content.kind) {
209
      case 'Redacted':
210
        return 'Message deleted';
211
      case 'UnableToDecrypt':
212
        return `Message from ${actor} could not be decrypted`;
213
      case 'Membership': {
214
        const who = actorLabel(content.user_id, content.display_name);
215
        return `${who} ${MEMBERSHIP_LABELS[content.change] ?? 'updated their membership'}`;
216
      }
217
      case 'Profile': {
218
        const who = actorLabel(content.user_id, null);
219
        const parts: string[] = [];
220
        if (content.display_name) {
221
          parts.push(
222
            content.display_name.new
223
              ? `changed their display name to "${content.display_name.new}"`
224
              : 'removed their display name'
225
          );
226
        }
227
        if (content.avatar) parts.push('changed their avatar');
228
        return `${who} ${parts.length > 0 ? parts.join(' and ') : 'updated their profile'}`;
229
      }
230
      case 'RoomName':
231
        return content.name
232
          ? `${actor} changed the room name to "${content.name}"`
233
          : `${actor} removed the room name`;
234
      case 'RoomTopic':
235
        return content.topic
236
          ? `${actor} changed the topic to "${content.topic}"`
237
          : `${actor} removed the topic`;
238
      case 'RoomAvatar':
239
        return content.avatar ? `${actor} changed the room avatar` : `${actor} removed the room avatar`;
240
      case 'EncryptionEnabled':
241
        return `${actor} enabled encryption in this room`;
242
      case 'RoomCreated':
243
        return `${actor} created the room`;
244
      case 'RoomUpgraded':
245
        return `${actor} upgraded the room to a new version`;
246
      case 'OtherState':
247
        return `${actor} ${STATE_LABELS[content.event_type] ?? `sent a state event (${content.event_type})`}`;
248
      case 'Other':
249
        return `${actor} sent an event (${content.event_type})`;
250
      default:
251
        return actor;
252
    }
253
  }
254
</script>
255
256
<svelte:window
257
  on:pointerdown={deselectOutside}
258
  on:keydown={(e) => e.key === 'Escape' && (selected = false)}
259
  on:scroll|capture={closeOnScroll}
260
  on:resize={closePicker}
261
/>
262
263
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
264
<div
265
  class="msg"
266
  class:own={event.own}
267
  class:editing
268
  class:mentioned={mentionsMe}
269
  class:system={!interactive}
270
  class:has-readers={interactive && readers.length > 0}
271
  class:selected
272
  data-item={itemId}
273
  data-event={event.event_id}
274
  bind:this={row}
275
  on:click={toggleSelected}
276
>
277
  {#if !readOnly && interactive && event.event_id}
278
    <div class="actions" role="toolbar" aria-label={`Actions for message from ${displayName}`}>
279
      {#each quickReactions as r (r.key)}
280
        {@const label = r.shortcode ? `:${r.shortcode}:` : r.key}
281
        <button
282
          type="button"
283
          title={`React ${label}`}
284
          aria-label={`React ${label} to message from ${displayName}`}
285
          disabled={reacting}
286
          on:click={() => react(r.key, r.shortcode)}
287
        >
288
          {#if r.key.startsWith('mxc://')}
289
            <img class="emote" src={mediaUrl(r.key, 64) ?? ''} alt="" />
290
          {:else}
291
            <Emoji emoji={r.key} size={18} />
292
          {/if}
293
        </button>
294
      {/each}
295
      <button
296
        type="button"
297
        title="Add reaction"
298
        aria-label={`Add reaction to message from ${displayName}`}
299
        aria-haspopup="dialog"
300
        aria-expanded={pickerOpen}
301
        on:pointerdown|stopPropagation
302
        on:click={openPicker}
303
      >
304
        ☺+
305
      </button>
306
      {#if onCloneSticker && event.content.kind === 'Sticker'}
307
        {@const stickerBody = event.content.body}
308
        {@const stickerId = event.event_id}
309
        <button
310
          type="button"
311
          title="Clone sticker"
312
          aria-label="Clone sticker to one of your packs"
313
          on:click|stopPropagation={(ev) => onCloneSticker?.(stickerId, stickerBody, ev.clientX, ev.clientY)}
314
        >
315
          ⧉
316
        </button>
317
      {/if}
318
      {#if onReply}
319
        <button
320
          type="button"
321
          title="Reply"
322
          aria-label={`Reply to message from ${displayName}`}
323
          on:click|stopPropagation={reply}
324
        >
325
          ↩
326
        </button>
327
      {/if}
328
      {#if onEdit && editableBody !== null}
329
        <button type="button" title="Edit" aria-label="Edit your message" on:click|stopPropagation={edit}>
330
          ✎
331
        </button>
332
      {/if}
333
      {#if onMore}
334
        <button
335
          type="button"
336
          title="More"
337
          aria-label={`More actions for message from ${displayName}`}
338
          aria-haspopup="menu"
339
          on:click|stopPropagation={(ev) => onMore?.(event, ev.clientX, ev.clientY)}
340
        >
341
          ⋯
342
        </button>
343
      {/if}
344
    </div>
345
    {#if pickerOpen}
346
      <div class="picker-pop" style={pickerStyle} bind:this={pickerPop}>
347
        <ReactionPicker {packs} quick={quickReactions} onPick={pick} {onQuickChange} onClose={closePicker} />
348
      </div>
349
    {/if}
350
  {/if}
351
  {#if showSender}
352
    <button
353
      type="button"
354
      class="user-hit"
355
      disabled={!onUser}
356
      tabindex="-1"
357
      aria-hidden="true"
358
      on:click|stopPropagation={(ev) => openUser(ev, false)}
359
      on:contextmenu|preventDefault|stopPropagation={(ev) => openUser(ev, true)}
360
    >
361
      {#if senderAvatar}
362
        <MxcAvatar mxc={senderAvatar} label={name} size={34} />
363
      {:else}
364
        <span class="avatar" style={`background:hsl(${senderHue(event.sender.user_id)} 35% 32%)`}>
365
          <span><EmojiText text={initialsOf(name)} /></span>
366
        </span>
367
      {/if}
368
    </button>
369
  {:else}
370
    <div class="avatar-spacer" aria-hidden="true">
371
      <span class="hover-time">{formatClock(event.timestamp_ms)}</span>
372
    </div>
373
  {/if}
374
  <div class="msg-body">
375
    {#if showSender}
376
      <div class="msg-head">
377
        <button
378
          type="button"
379
          class="sender"
380
          disabled={!onUser}
381
          style={`color:hsl(${senderHue(event.sender.user_id)} 70% var(--name-lightness))`}
382
          on:click|stopPropagation={(ev) => openUser(ev, false)}
383
          on:contextmenu|preventDefault|stopPropagation={(ev) => openUser(ev, true)}
384
        >
385
          <EmojiText text={displayName} />
386
        </button>
387
        {#if lag}
388
          <span class="federation-lag" title="Possibly delayed by federation" aria-label={`Arrived ${lag} late, possibly delayed by federation`}>
389
            <span aria-hidden="true">◷</span><span>{lag}</span>
390
          </span>
391
        {/if}
392
        <time class="time" datetime={new Date(event.timestamp_ms).toISOString()}>
393
          {formatDay(event.timestamp_ms)} {formatClock(event.timestamp_ms)}
394
        </time>
395
        {#if event.content.kind === 'Message' && event.content.message.edited}
396
          <span class="edited" title="Edited">(edited)</span>
397
        {/if}
398
      </div>
399
    {/if}
400
    {#if event.reply_to}
401
      {@const target = event.reply_to.event_id}
402
      <button
403
        type="button"
404
        class="reply-quote"
405
        disabled={!onJump}
406
        title="Jump to the original message"
407
        on:click|stopPropagation={() => onJump?.(target)}
408
      >
409
        {#if event.reply_to.details.kind === 'Ready'}
410
          <span class="reply-sender"><EmojiText text={event.reply_to.details.sender.display_name ?? people[event.reply_to.details.sender.user_id]?.name ?? senderLabel(event.reply_to.details.sender)} /></span>
411
          <span class="reply-text"><EmojiText text={replyPreview(event.reply_to.details.content)} /></span>
412
        {:else if event.reply_to.details.kind === 'Pending'}
413
          Loading reply…
414
        {:else}
415
          Reply unavailable
416
        {/if}
417
      </button>
418
    {/if}
419
420
    {#if event.content.kind === 'Message'}
421
      {@const m = event.content.message}
422
      {#if stripped.text}
423
        <div class="text" class:emote={m.kind === 'Emote'} class:notice={m.kind === 'Notice' || m.kind === 'ServerNotice'}>{#if m.kind === 'Emote'}* <EmojiText text={displayName} /> {/if}<MessageText text={stripped.text} html={m.formatted_body} jumbo={m.kind === 'Text'} {mentions} {self} nameOf={(id) => people[id]?.name ?? null} />{#if m.edited && !showSender}<span class="edited" title="Edited">(edited)</span>{/if}</div>
424
      {/if}
425
      {#if m.media}
426
        <MediaAttachmentView attachment={m.media} />
427
      {/if}
428
      {#if cards.length > 0}
429
        <div class="link-previews">
430
          {#each cards as card (card.link.href)}
431
            <LinkCard link={card.link} preview={card.preview} />
432
          {/each}
433
        </div>
434
      {/if}
435
    {:else if event.content.kind === 'Sticker'}
436
      {#if event.content.media}
437
        <MediaAttachmentView attachment={event.content.media} />
438
      {:else if event.content.body}<p class="text"><EmojiText text={event.content.body} /></p>{/if}
439
    {:else if event.content.kind === 'Poll'}
440
      <p class="text"><EmojiText text={`📊 ${event.content.question}`} /></p>
441
    {:else}
442
      <p class="system-line"><EmojiText text={systemLine(event.content, displayName)} /></p>
443
    {/if}
444
445
    {#if interactive && event.reactions.length > 0}
446
      <div class="reactions" aria-label="Reactions">
447
        {#each event.reactions as r (r.key)}
448
          <button
449
            type="button"
450
            class="reaction"
451
            class:mine={r.own}
452
            aria-label={`${r.shortcode ? `:${r.shortcode}:` : r.key.startsWith('mxc://') ? 'custom emote' : r.key}, ${r.count} reaction${r.count === 1 ? '' : 's'}`}
453
            disabled={readOnly || !event.event_id || reacting}
454
            on:click={() => event.event_id && onReact(event.event_id, r.key)}
455
          >
456
            {#if r.image}
457
              <img class="emote" src={messageMediaUrl(r.image, 'Thumbnail')} alt={r.shortcode ?? ''} title={r.shortcode ?? ''} />
458
            {:else if r.key.startsWith('mxc://')}
459
              <img class="emote" src={mediaUrl(r.key, 64) ?? ''} alt="" />
460
            {:else}
461
              <Emoji emoji={r.key} size={16} />
462
            {/if}
463
            <span class="count">{r.count}</span>
464
            <span class="reactors" role="tooltip" id={`${itemId}-reactors-${r.key}`}>
465
              <span class="reactors-key"><EmojiText text={r.shortcode ? `:${r.shortcode}:` : r.key.startsWith('mxc://') ? 'custom emote' : r.key} /></span>
466
              <EmojiText text={reactorNames(r.senders)} />
467
            </span>
468
          </button>
469
        {/each}
470
      </div>
471
    {/if}
472
    {#if sent}<span class="sent-tick" title="Sent" aria-label="Sent">✓</span>{/if}
473
    {#if interactive && sendLabel(event.send_state)}
474
      <div class="msg-foot">
475
        <span class="sendstate" class:failed={event.send_state.kind === 'Failed'}>{sendLabel(event.send_state)}</span>
476
      </div>
477
    {/if}
478
    {#if interactive && readers.length > 0}
479
      {@const seenBy = `Seen by ${readers.map((r) => r.name).join(', ')}`}
480
      <div class="readby" title={seenBy} aria-label={seenBy} role="img">
481
        {#each readers.slice(0, MAX_READERS) as r (r.user_id)}
482
          <MxcAvatar mxc={r.avatar} label={r.name} size={16} />
483
        {/each}
484
        {#if readers.length > MAX_READERS}<span class="more">+{readers.length - MAX_READERS}</span>{/if}
485
      </div>
486
    {/if}
487
  </div>
488
</div>
489
490
<style>
491
  .msg { position: relative; display: flex; gap: 10px; padding: var(--msg-gap, 3px) 0; }
492
  .msg:hover, .msg.selected { background: var(--hover-faint); }
493
  .msg:hover .hover-time, .msg.selected .hover-time { opacity: 1; }
494
  .msg-foot { display: flex; align-items: center; gap: 8px; }
495
  .sendstate { font-size: 11px; color: var(--muted); }
496
  .sent-tick { position: absolute; right: 12px; bottom: 4px; font-size: 11px; color: var(--muted); }
497
  .sendstate.failed { color: var(--danger); }
498
  .link-previews { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-width: 420px; }
499
  .avatar {
500
    flex: none;
501
    width: 34px; height: 34px;
502
    border-radius: 50%;
503
    display: grid; place-items: center;
504
    font-size: 12px; font-weight: 700; color: #fff;
505
  }
506
  .avatar-spacer { flex: none; width: 34px; padding-top: 2px; text-align: center; }
507
  .hover-time { opacity: 0; font-size: 10.5px; color: var(--muted); }
508
  .msg-body { min-width: 0; flex: 1; }
509
  .msg-head { display: flex; align-items: baseline; gap: 8px; }
510
  .federation-lag { display: inline-flex; align-items: center; gap: 3px; color: var(--danger); font-size: 11px; font-weight: 650; }
511
  .federation-lag > span:last-child { display: inline-grid; place-items: center; min-width: 24px; height: 18px; padding: 0 4px; border: 1px solid currentColor; border-radius: 999px; }
512
  .sender { font-weight: 650; font-size: 13.5px; padding: 0; border: none; background: none; font-family: inherit; cursor: pointer; }
513
  .sender:hover { text-decoration: underline; }
514
  .user-hit { flex: none; align-self: flex-start; padding: 0; border: none; background: none; border-radius: 50%; cursor: pointer; }
515
  .time, .edited { color: var(--muted); font-size: 11.5px; }
516
  .text .edited { margin-left: 6px; }
517
  .msg.editing { background: color-mix(in srgb, var(--accent) 10%, transparent); }
518
  .msg.mentioned { background: color-mix(in srgb, var(--warn) 8%, transparent); box-shadow: inset 2px 0 0 var(--warn); }
519
  .reply-quote {
520
    display: flex; gap: 6px; align-items: baseline;
521
    max-width: min(100%, 520px);
522
    border: none;
523
    border-left: 2px solid var(--accent);
524
    padding: 2px 8px;
525
    margin: 2px 0 4px;
526
    color: var(--muted);
527
    font-size: 12.5px;
528
    text-align: left;
529
    background: var(--bg-soft);
530
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
531
    cursor: pointer;
532
  }
533
  .reply-quote:disabled { cursor: default; }
534
  .reply-quote:hover:not(:disabled) { color: var(--text); }
535
  .reply-sender { flex: none; font-weight: 650; }
536
  .reply-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
537
  :global(.msg.flash) { animation: reply-flash 1.2s ease-out; }
538
  @keyframes -global-reply-flash { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } }
539
  .text {
540
    margin: 1px 0 2px;
541
    font-size: 14px;
542
    line-height: var(--msg-line-height, 1.5);
543
    white-space: pre-wrap;
544
    overflow-wrap: anywhere;
545
  }
546
  .text.emote { font-style: italic; color: var(--muted); }
547
  .text.notice { color: var(--muted); }
548
  .system-line { color: var(--muted); font-size: 12.5px; font-style: italic; margin: 1px 0; }
549
  .msg.system { opacity: 0.85; --msg-gap: 1.5px; }
550
  .msg.system .avatar-spacer { height: 0; padding-top: 0; }
551
  .reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: max(4px, var(--msg-gap, 3px)); }
552
  .reaction {
553
    display: inline-flex; align-items: center; gap: 4px;
554
    background: var(--bg-soft);
555
    border: 1px solid var(--border);
556
    border-radius: var(--r-sm);
557
    padding: 1px 8px;
558
    font-size: 13px;
559
    color: var(--text);
560
    cursor: pointer;
561
  }
562
  .reaction { position: relative; }
563
  .reactors {
564
    position: absolute;
565
    left: 0;
566
    bottom: calc(100% + 6px);
567
    z-index: 15;
568
    display: none;
569
    width: max-content;
570
    max-width: 260px;
571
    padding: 6px 9px;
572
    border: 1px solid var(--border);
573
    border-radius: var(--r-md);
574
    background: var(--panel-2);
575
    box-shadow: 0 6px 18px rgb(0 0 0 / 0.3);
576
    color: var(--text);
577
    font-size: 12px;
578
    line-height: 1.35;
579
    text-align: left;
580
    white-space: normal;
581
    pointer-events: none;
582
  }
583
  .reactors-key { display: block; color: var(--muted); font-size: 11px; }
584
  .reaction:hover .reactors, .reaction:focus-visible .reactors { display: block; }
585
  .reaction.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
586
  .reaction:disabled { cursor: default; opacity: 0.85; }
587
  .msg.has-readers .msg-body { padding-right: 72px; }
588
  .readby { position: absolute; right: 12px; bottom: 4px; display: flex; align-items: center; }
589
  .readby > :global(* + *) { margin-left: -4px; }
590
  .readby :global(.mxc-avatar), .readby :global(.mxc-fallback) { box-shadow: 0 0 0 1.5px var(--bg); }
591
  .readby .more { margin-left: 3px; font-size: 10.5px; color: var(--muted); }
592
  .actions {
593
    position: absolute; top: -12px; right: 10px; z-index: 2;
594
    display: flex; gap: 2px;
595
    padding: 2px;
596
    background: var(--bg-soft);
597
    border: 1px solid var(--border);
598
    border-radius: var(--r-md);
599
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
600
    opacity: 0;
601
    visibility: hidden;
602
    pointer-events: none;
603
  }
604
  .msg:hover .actions, .msg:focus-within .actions, .msg.selected .actions { opacity: 1; visibility: visible; pointer-events: auto; }
605
  :global(.timeline-inner:has(.msg.selected)) .msg:not(.selected) .actions { opacity: 0; visibility: hidden; pointer-events: none; }
606
  .actions button {
607
    background: transparent;
608
    border: 1px solid transparent;
609
    border-radius: var(--r-sm);
610
    cursor: pointer;
611
    font-size: 14px;
612
    padding: 1px 5px;
613
  }
614
  .actions button:hover:not(:disabled) { border-color: var(--border); background: var(--hover); }
615
  .actions button:disabled { opacity: 0.4; cursor: default; }
616
  .emote { width: 1.3em; height: 1.3em; object-fit: contain; vertical-align: middle; }
617
  .picker-pop { position: fixed; z-index: 60; width: 320px; max-width: calc(100vw - 16px); animation: pop-in var(--pop); }
618
</style>