/* =====================================================================
   Messages, bubbles, composer
   ===================================================================== */

/* ---- day separator ---- */
.day-sep {
  display: flex;
  justify-content: center;
  padding: var(--sp-4) 0 var(--sp-3);
  position: sticky;
  top: 0;
  z-index: 3;
  pointer-events: none;
}
.day-sep span {
  padding: 4px 13px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  box-shadow: var(--shadow-xs);
}

/* ---- system notice ---- */
.msg-system {
  display: flex;
  justify-content: center;
  padding: var(--sp-2) 0;
}
.msg-system span {
  max-width: 76%;
  padding: 5px 13px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

/* ---- row ---- */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: 1px 0;
  animation: bubbleIn var(--t-base) var(--ease-out);
  position: relative;
}
.msg-row.is-out { flex-direction: row-reverse; }
.msg-row.is-highlight { animation: highlightFlash 1.5s var(--ease-out); border-radius: var(--r-md); }

.msg-avatar { width: 30px; height: 30px; flex: none; margin-bottom: 2px; }
.msg-avatar.is-hidden { visibility: hidden; }
.msg-row.is-out .msg-avatar { display: none; }

/* selection mode */
.msg-select {
  flex: none;
  width: 21px; height: 21px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: none;
  place-items: center;
  align-self: center;
  transition: all var(--t-fast);
  color: #fff;
}
.chat-active.is-selecting .msg-select { display: grid; }
.msg-row.is-picked .msg-select { background: var(--bubble-out-solid); border-color: var(--bubble-out-solid); }
.chat-active.is-selecting .msg-row { cursor: pointer; }
.chat-active.is-selecting .msg-row.is-picked {
  background: color-mix(in srgb, var(--brand-500) 9%, transparent);
  border-radius: var(--r-md);
}

/* ---- bubble ---- */
.bubble {
  position: relative;
  max-width: var(--bubble-max);
  min-width: 84px;
  padding: 7px 11px 6px;
  border-radius: var(--r-md);
  background: var(--bubble-in-bg);
  color: var(--bubble-in-text);
  box-shadow: var(--shadow-bubble);
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-row.is-out .bubble {
  background: var(--bubble-out-bg);
  color: var(--bubble-out-text);
}

/* tail corners, tightened on grouped runs */
.msg-row.is-in  .bubble { border-start-start-radius: var(--r-xs); }
.msg-row.is-out .bubble { border-start-end-radius: var(--r-xs); }
.msg-row.is-grouped .bubble { border-radius: var(--r-md); }
.msg-row.is-last-of-run.is-in  .bubble { border-end-start-radius: var(--r-xs); }
.msg-row.is-last-of-run.is-out .bubble { border-end-end-radius: var(--r-xs); }

.bubble.is-media { padding: 4px 4px 6px; min-width: 160px; }
.bubble.is-sticker { background: none !important; box-shadow: none; padding: 0; }

/* sender name in groups */
.msg-sender {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--brand-500);
}
.msg-sender.c1 { color: var(--accent-violet); }
.msg-sender.c2 { color: var(--accent-teal); }
.msg-sender.c3 { color: var(--accent-amber); }
.msg-sender.c4 { color: var(--accent-rose); }
.msg-sender.c5 { color: var(--success); }

/* forwarded banner */
.msg-forward {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  font-style: italic;
  opacity: .8;
  margin-bottom: 3px;
}
.msg-forward svg { flex: none; }

/* reply quote */
.msg-reply {
  display: flex;
  gap: var(--sp-2);
  padding: 5px 8px;
  margin-bottom: 4px;
  border-radius: var(--r-xs);
  background: color-mix(in srgb, currentColor 8%, transparent);
  border-inline-start: 2.5px solid currentColor;
  cursor: pointer;
  transition: background var(--t-fast);
  text-align: start;
  width: 100%;
}
.msg-reply:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
.msg-reply-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.msg-reply-name { font-size: var(--fs-xs); font-weight: 700; }
.msg-reply-text {
  font-size: var(--fs-sm);
  opacity: .82;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}

/* text */
.msg-text {
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  white-space: pre-wrap;
}
.msg-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg-row.is-in .msg-text a { color: var(--text-link); }
.msg-text.is-emoji-only { font-size: 42px; line-height: 1.25; }
.msg-text code {
  font-family: var(--font-mono);
  font-size: .88em;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  background: color-mix(in srgb, currentColor 12%, transparent);
  direction: ltr;
  unicode-bidi: isolate;
}

.msg-deleted {
  font-style: italic;
  opacity: .62;
  font-size: var(--fs-md);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* ---- media ---- */
.msg-image, .msg-video {
  position: relative;
  border-radius: var(--r-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-sunken);
  max-width: 100%;
  line-height: 0;
}
.msg-image img, .msg-video video {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
  transition: transform var(--t-slow) var(--ease-out), filter var(--t-base);
}
.msg-image:hover img { transform: scale(1.024); }
.msg-image img.is-loading { filter: blur(9px); }

.play-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .26);
  transition: background var(--t-base);
  pointer-events: none;
}
.play-overlay span {
  width: 52px; height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, .58);
  color: #fff;
  backdrop-filter: blur(3px);
}
.msg-video:hover .play-overlay { background: rgba(0, 0, 0, .16); }

.media-duration {
  position: absolute;
  inset-block-end: 7px;
  inset-inline-start: 7px;
  padding: 2px 7px;
  border-radius: var(--r-full);
  background: rgba(0, 0, 0, .66);
  color: #fff;
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.msg-caption { padding: 5px 7px 0; font-size: var(--fs-base); line-height: var(--lh-normal); white-space: pre-wrap; }

/* ---- file ---- */
.msg-file {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 5px 3px;
  min-width: 210px;
}
.file-icon {
  flex: none;
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, currentColor 15%, transparent);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.file-meta { min-width: 0; flex: 1; }
.file-name {
  font-size: var(--fs-md);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-size { font-size: var(--fs-xs); opacity: .74; }
.file-dl {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  color: inherit;
  transition: background var(--t-fast);
}
.file-dl:hover { background: color-mix(in srgb, currentColor 15%, transparent); }

/* ---- voice / audio ---- */
.msg-voice {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 4px 2px;
  min-width: 216px;
}
.voice-play {
  flex: none;
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, currentColor 17%, transparent);
  color: inherit;
  transition: transform var(--t-fast), background var(--t-fast);
}
.voice-play:hover { transform: scale(1.07); background: color-mix(in srgb, currentColor 26%, transparent); }
.voice-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }

.voice-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
  cursor: pointer;
}
.voice-wave i {
  flex: 1;
  min-width: 2px;
  max-width: 3px;
  background: currentColor;
  opacity: .34;
  border-radius: var(--r-full);
  transition: opacity var(--t-fast), transform var(--t-fast);
}
.voice-wave i.is-played { opacity: .95; }
.voice-time { font-size: var(--fs-xs); opacity: .78; font-variant-numeric: tabular-nums; }

/* ---- meta line ---- */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 2px;
  font-size: var(--fs-xs);
  color: var(--bubble-meta-in);
  line-height: 1;
  user-select: none;
}
.msg-row.is-out .msg-meta { color: var(--bubble-meta-out); }
.bubble.is-media .msg-meta {
  position: absolute;
  inset-block-end: 9px;
  inset-inline-end: 10px;
  padding: 2px 7px;
  border-radius: var(--r-full);
  background: rgba(0, 0, 0, .5);
  color: #fff !important;
  backdrop-filter: blur(3px);
}
.msg-time { font-variant-numeric: tabular-nums; }
.msg-edited { font-style: italic; opacity: .8; }

.msg-ticks { display: inline-flex; align-items: center; }
.msg-ticks svg { display: block; }
.msg-ticks.is-read { color: #7fd4ff; }
.msg-row.is-out .msg-ticks.is-read { color: #a5e5ff; }
.msg-ticks.is-pending { opacity: .55; }

.msg-pin-mark { display: inline-flex; opacity: .82; }

/* ---- hover actions ---- */
.msg-actions {
  position: absolute;
  inset-block-start: 50%;
  transform: translateY(-50%) scale(.9);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-full);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast), transform var(--t-fast);
  z-index: 4;
}
.msg-row.is-in  .msg-actions { inset-inline-start: calc(var(--bubble-max) + 42px); }
.msg-row.is-out .msg-actions { inset-inline-end: calc(var(--bubble-max) + 10px); }
.msg-row:hover .msg-actions { opacity: 1; pointer-events: auto; transform: translateY(-50%) scale(1); }
.chat-active.is-selecting .msg-actions { display: none; }

.msg-action {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.msg-action:hover { background: var(--bg-hover); color: var(--brand-500); }

/* ---- upload progress ---- */
.msg-progress {
  position: absolute;
  inset-block-end: 0;
  inset-inline: 0;
  height: 3px;
  background: color-mix(in srgb, currentColor 20%, transparent);
  border-radius: 0 0 var(--r-md) var(--r-md);
  overflow: hidden;
}
.msg-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: currentColor;
  transition: width 160ms linear;
}
.msg-row.is-sending .bubble { opacity: .72; }
.msg-row.is-failed .bubble { border: 1px solid var(--danger); }

/* =====================================================================
   Composer
   ===================================================================== */
.composer {
  flex: none;
  padding: var(--sp-2) var(--sp-4) var(--sp-3);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  position: relative;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  max-width: 1080px;
  margin-inline: auto;
}

.composer-input {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 var(--sp-3);
  background: var(--bg-sunken);
  border: 1.5px solid transparent;
  border-radius: var(--r-lg);
  transition: border-color var(--t-fast), background var(--t-fast);
  min-height: 42px;
}
.composer-input:focus-within { border-color: var(--brand-400); background: var(--bg-surface); }

.composer-input textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font-size: var(--fs-base);
  line-height: 1.55;
  padding: 10px 0;
  max-height: 168px;
  overflow-y: auto;
  color: var(--text);
}
.composer-input textarea::placeholder { color: var(--text-faint); }

.send-btn {
  flex: none;
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bubble-out-solid);
  color: #fff;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--bubble-out-solid) 34%, transparent);
  transition: transform var(--t-fast) var(--ease-spring), background var(--t-fast);
  animation: popIn var(--t-fast) var(--ease-spring);
}
.send-btn:hover { transform: scale(1.07); background: var(--brand-600); }
.send-btn:active { transform: scale(.94); }
html[dir="rtl"] .send-btn svg { transform: scaleX(-1); }

.mic-btn.is-recording {
  color: var(--danger);
  animation: pulseRing 1.6s var(--ease-out) infinite;
}

/* reply / edit context strip */
.composer-context {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: 1080px;
  margin: 0 auto var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  animation: slideUp var(--t-fast) var(--ease-out);
}
.context-bar { flex: none; width: 3px; align-self: stretch; border-radius: var(--r-full); background: var(--brand-500); }
.context-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.context-title { font-size: var(--fs-xs); font-weight: 700; color: var(--brand-500); }
.context-text {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* attachment tray */
.attach-preview {
  display: flex;
  gap: var(--sp-2);
  max-width: 1080px;
  margin: 0 auto var(--sp-2);
  padding-bottom: 4px;
  overflow-x: auto;
}
.attach-item {
  position: relative;
  flex: none;
  width: 76px; height: 76px;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  animation: popIn var(--t-fast) var(--ease-spring);
}
.attach-item img { width: 100%; height: 100%; object-fit: cover; }
.attach-item .attach-generic {
  display: grid;
  place-items: center;
  height: 100%;
  gap: 3px;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  padding: 4px;
  text-align: center;
}
.attach-remove {
  position: absolute;
  inset-block-start: 3px;
  inset-inline-end: 3px;
  width: 20px; height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  backdrop-filter: blur(3px);
}
.attach-remove:hover { background: var(--danger); }
.attach-progress {
  position: absolute;
  inset-block-end: 0;
  inset-inline: 0;
  height: 3px;
  background: rgba(0, 0, 0, .3);
}
.attach-progress span { display: block; height: 100%; width: 0; background: var(--brand-400); transition: width 160ms linear; }

/* recorder */
.recorder {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: 1080px;
  margin-inline: auto;
  padding: var(--sp-1) 0;
  animation: slideUp var(--t-fast) var(--ease-out);
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: recBlink 1.1s var(--ease-inout) infinite;
  flex: none;
}
@keyframes recBlink { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-size: var(--fs-md); font-weight: 600; color: var(--danger); flex: none; }
.rec-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 30px; overflow: hidden; }
.rec-wave i {
  flex: none;
  width: 3px;
  min-height: 3px;
  border-radius: var(--r-full);
  background: var(--brand-400);
  transition: height 80ms linear;
}
.recorder-cancel:hover { color: var(--danger); }

/* blocked / read-only notice */
.composer-blocked {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  font-size: var(--fs-md);
  color: var(--text-muted);
  text-align: center;
}

/* selection action bar */
.selection-bar {
  position: absolute;
  inset-block-end: 0;
  inset-inline: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  animation: slideUp var(--t-base) var(--ease-out);
  z-index: 5;
}
.selection-count { flex: 1; font-size: var(--fs-md); font-weight: 600; color: var(--text-strong); }

/* =====================================================================
   Info panel content
   ===================================================================== */
.info-hero { padding: var(--sp-6) var(--sp-5); text-align: center; border-bottom: 1px solid var(--border); }
.info-hero .avatar-wrap { margin: 0 auto var(--sp-3); width: fit-content; }
.info-name { font-size: var(--fs-xl); font-weight: 700; color: var(--text-strong); margin-bottom: 2px; }
.info-sub { font-size: var(--fs-md); color: var(--text-muted); }
.info-actions { display: flex; justify-content: center; gap: var(--sp-2); margin-top: var(--sp-4); flex-wrap: wrap; }

.info-section { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.info-section:last-child { border-bottom: 0; }
.info-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}
.info-value { font-size: var(--fs-md); color: var(--text); line-height: var(--lh-normal); word-break: break-word; }

.info-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
}
.info-toggle-text { flex: 1; min-width: 0; }
.info-toggle-title { font-size: var(--fs-md); color: var(--text); }
.info-toggle-sub { font-size: var(--fs-xs); color: var(--text-faint); }

.member-list { display: flex; flex-direction: column; }
.member-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5);
  transition: background var(--t-fast);
  cursor: pointer;
  width: 100%;
  text-align: start;
}
.member-row:hover { background: var(--bg-hover); }
.member-main { flex: 1; min-width: 0; }
.member-name { font-size: var(--fs-md); font-weight: 500; color: var(--text-strong); }
.member-sub { font-size: var(--fs-xs); color: var(--text-muted); }

.media-tabs { display: flex; gap: 2px; padding: var(--sp-2) var(--sp-4) 0; border-bottom: 1px solid var(--border); }
.media-tab {
  flex: 1;
  padding: var(--sp-2) 0 var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2.5px solid transparent;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.media-tab.is-active { color: var(--brand-500); border-bottom-color: var(--brand-500); }

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
}
.media-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-xs);
  overflow: hidden;
  background: var(--bg-sunken);
  cursor: pointer;
}
.media-cell img { width: 100%; height: 100%; object-fit: cover; transition: transform var(--t-base); }
.media-cell:hover img { transform: scale(1.07); }

.file-list { display: flex; flex-direction: column; }
.file-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  transition: background var(--t-fast);
  color: inherit;
}
.file-row:hover { background: var(--bg-hover); text-decoration: none; }
