/* ============================================================
   chat.css
   Owns: chat shell · message feed · bubbles · reply indicator ·
         typing indicator · chat composer.

   This is a PEER to topics.css — topics.css covers the
   Topics board (list of topic cards + topic-level chat).
   chat.css covers any standalone or generic chat thread UI
   that does not belong to the Topics system specifically.

   Does NOT own:
     • Topics board / topic cards  → topics.css
     • Any popup / sheet            → dialog.css
     • Font imports                 → styles.css
     • Base tokens                  → styles.css
   ============================================================ */


/* ── 1. CHAT SHELL ───────────────────────────────────────────
   Full-height flex column.  Parent must set a definite height.
   ──────────────────────────────────────────────────────────── */

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}


/* ── 2. CHAT TOPBAR ──────────────────────────────────────────
   Filter chips row at the top of the chat panel.
   ──────────────────────────────────────────────────────────── */

.chat-topbar {
  flex-shrink: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--separator);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
}

.chat-filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chat-filter-row::-webkit-scrollbar { display: none; }

.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0.76rem;
  font-weight: 700;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.13s, background 0.13s, color 0.13s;
  -webkit-tap-highlight-color: transparent;
}

.chat-chip:hover  { border-color: var(--accent); color: var(--accent); }
.chat-chip.active { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }


/* ── 3. PINNED BANNER ────────────────────────────────────────
   Thin strip showing pinned messages above the feed.
   ──────────────────────────────────────────────────────────── */

.chat-pinned-strip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--separator);
  background: var(--warning-light);
}

.chat-pinned-strip:empty { display: none; }

.chat-pinned-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--warning);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-pinned-row:hover { opacity: 0.8; }
.chat-pinned-icon { font-size: 0.85rem; flex-shrink: 0; }
.chat-pinned-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }


/* ── 4. MESSAGE FEED ─────────────────────────────────────────
   Scrollable list of message bubbles.
   ──────────────────────────────────────────────────────────── */

.chat-feed {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 10px;
  padding: 40px 24px;
  text-align: center;
}

.chat-empty-icon { font-size: 2.2rem; opacity: 0.4; }
.chat-empty-text { font-size: 0.875rem; color: var(--text-tertiary); max-width: 240px; line-height: 1.5; }


/* ── 5. DATE SEPARATOR ───────────────────────────────────────
   "Today", "Yesterday", "Mon 10 Mar" etc.
   ──────────────────────────────────────────────────────────── */

.chat-date-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
}

.chat-date-sep::before,
.chat-date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--separator);
}

.chat-date-sep span {
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--text-tertiary);
  white-space: nowrap;
}


/* ── 6. MESSAGE WRAP + BUBBLE ────────────────────────────────
   ──────────────────────────────────────────────────────────── */

.msg-wrap {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 100%;
}

.msg-wrap--own { flex-direction: row-reverse; }

/* Avatar */
.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  border: 1.5px solid var(--border);
  align-self: flex-end;
}

.msg-avatar--initials {
  display: grid;
  place-items: center;
  font-size: 0.58rem;
  font-weight: 800;
  color: var(--accent-fg);
  background: var(--accent);
}

/* Avatar colour variants */
.msg-avatar--initials[data-color="blue"]   { background: #3b82f6; }
.msg-avatar--initials[data-color="green"]  { background: #22c55e; }
.msg-avatar--initials[data-color="purple"] { background: #a855f7; }
.msg-avatar--initials[data-color="orange"] { background: #f97316; }
.msg-avatar--initials[data-color="pink"]   { background: #ec4899; }
.msg-avatar--initials[data-color="teal"]   { background: #14b8a6; }

/* Bubble */
.msg-bubble {
  max-width: 70%;
  padding: 9px 13px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
  word-break: break-word;
}

.msg-wrap--own .msg-bubble {
  background: var(--accent);
  border-color: transparent;
}

.msg-bubble--pinned {
  border-color: var(--warning);
  background: var(--warning-light);
}

/* Sender name */
.msg-name {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.msg-wrap--own .msg-name { display: none; }

/* Reg number beside name */
.msg-regnum {
  font-size: 0.62rem;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-left: 4px;
}

/* Body text */
.msg-text {
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.msg-wrap--own .msg-text { color: var(--accent-fg); }

/* Inline hashtag / mention */
.msg-hashtag { color: var(--accent);  font-weight: 700; cursor: pointer; }
.msg-mention  { color: var(--success); font-weight: 700; }

.msg-wrap--own .msg-hashtag { color: rgba(255,255,255,0.85); }

/* Footer: timestamp + read tick */
.msg-foot {
  display: flex;
  align-items: center;
  gap: 5px;
  justify-content: flex-end;
}

.msg-time {
  font-size: 0.62rem;
  color: var(--text-tertiary);
}

.msg-wrap--own .msg-time { color: rgba(255,255,255,0.65); }

/* Attachment row */
.msg-attachment { margin-top: 6px; }

.msg-image {
  max-width: 220px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  cursor: pointer;
  display: block;
}

.msg-file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.06);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.12s;
}

.msg-file-link:hover { background: rgba(0, 0, 0, 0.1); }
.msg-wrap--own .msg-file-link { background: rgba(255,255,255,0.22); color: var(--accent-fg); }

/* Bubble action buttons */
.msg-actions {
  display: flex;
  gap: 3px;
  margin-top: 4px;
  justify-content: flex-end;
}

.msg-action-btn {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.msg-action-btn:hover      { background: var(--danger-light);  color: var(--danger); }
.msg-action-btn--pin:hover { background: var(--warning-light); color: var(--warning); }


/* ── 7. REPLY INDICATOR ──────────────────────────────────────
   Quoted message preview above the composer when replying.
   ──────────────────────────────────────────────────────────── */

.chat-reply-preview {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--separator);
  border-left: 3px solid var(--accent);
}

.chat-reply-preview:empty { display: none; }

.chat-reply-content {
  flex: 1;
  min-width: 0;
}

.chat-reply-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}

.chat-reply-text {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-reply-close {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 0.7rem;
  transition: background 0.12s, color 0.12s;
}

.chat-reply-close:hover { background: var(--danger-light); color: var(--danger); }


/* ── 8. TYPING INDICATOR ─────────────────────────────────────
   Animated three-dot pulse while another user types.
   ──────────────────────────────────────────────────────────── */

.chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.chat-typing-label {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-style: italic;
}

.chat-typing-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}

.chat-typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: chat-dot-bounce 1.2s ease-in-out infinite;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes chat-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}


/* ── 9. FILE PREVIEW CHIPS (above composer) ──────────────────
   ──────────────────────────────────────────────────────────── */

.chat-file-previews {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 14px 0;
}

.chat-file-previews:empty { display: none; }

.chat-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.chat-file-chip-thumb {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-file-chip-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-file-chip-rm {
  color: var(--text-tertiary);
  font-size: 0.7rem;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0 1px;
  line-height: 1;
  margin-left: 2px;
  transition: color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.chat-file-chip-rm:hover { color: var(--danger); }


/* ── 10. COMPOSER ────────────────────────────────────────────
   Input + icon buttons + send.
   ──────────────────────────────────────────────────────────── */

.chat-composer {
  flex-shrink: 0;
  border-top: 1px solid var(--separator);
  padding: 10px 14px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px 7px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-composer-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.chat-input-wrap { flex: 1; min-width: 0; }

.chat-input {
  width: 100%;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  display: block;
}

.chat-input:focus    { outline: none; }
.chat-input::placeholder { color: var(--text-placeholder); }

/* Icon action buttons */
.chat-action-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: none;
  background: none;
  color: var(--text-tertiary);
  flex-shrink: 0;
  cursor: pointer;
  transition: color 0.14s, background 0.14s;
  -webkit-tap-highlight-color: transparent;
}

.chat-action-btn:hover { color: var(--accent); background: var(--accent-light); }
.chat-action-btn.active { color: var(--warning); background: var(--warning-light); }

/* Send button */
.chat-send-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.14s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.chat-send-btn:hover  { background: var(--accent-hover); }
.chat-send-btn:active { transform: scale(0.9); }
.chat-send-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }


/* ── 11. RESPONSIVE ──────────────────────────────────────────
   ──────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .msg-bubble { max-width: 84%; }
  .chat-feed  { padding: 10px 10px 8px; }
  .chat-composer { padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing-dot { animation: none; opacity: 0.4; }
  .chat-chip,
  .msg-bubble,
  .chat-send-btn { transition: none; }
}
