/* ── Reset & base ────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:          #0f0f0f;
  --sidebar-bg:  #111;
  --surface:     #1a1a1a;
  --surface-2:   #222;
  --border:      #2a2a2a;
  --text:        #e8e8e8;
  --muted:       #666;
  --accent:      #7c6af7;
  --accent-dk:   #5c4fd4;
  --bubble-me:   #1d1b2e;
  --bubble-th:   #1a1a1a;
  --error:       #e05c5c;
  --sidebar-w:   200px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.view { display: none; height: 100%; }
.view.active { display: flex; }

/* ── LOGIN ───────────────────────────────────── */
#login-view {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card { width: 100%; max-width: 360px; }

.login-wordmark {
  font-size: 1.35rem;
  font-weight: 300;
  letter-spacing: 0.18em;
  margin-bottom: 36px;
  text-align: center;
}

.login-card label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.login-card input[type="text"],
.login-card input[type="email"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 16px;
}

.login-card input:focus { border-color: var(--accent); }

.login-avatar-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.login-avatar-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
  font-size: 22px;
  color: var(--muted);
  transition: border-color 0.15s;
}

.login-avatar-circle:hover { border-color: var(--accent); }
.login-avatar-circle img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.login-avatar-hint { font-size: 0.78rem; color: var(--muted); line-height: 1.5; }

.login-submit-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  margin-top: 4px;
}

.login-submit-btn:hover    { background: var(--accent-dk); }
.login-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#login-error {
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--error);
  text-align: center;
  min-height: 20px;
}

/* ── CHAT LAYOUT — sidebar + main ────────────── */
#chat-view {
  flex-direction: row;
  height: 100dvh;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.24s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 14px 11px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── WORDMARK ────────────────────────────────────────────────────────────────
   Applied to <span class="wordmark"> in the sidebar header.
   This is NOT a <code> element and is NOT a child of .msg-text or .msg-bubble,
   so .msg-text code / .msg-bubble code rules can never reach it. All properties
   are declared explicitly — nothing is inherited from code or pre rules.       */
.wordmark {
  /* reset anything a browser might inherit from a code/pre ancestor */
  font-style: normal;
  text-decoration: none;
  white-space: nowrap;
  /* wordmark-specific styling */
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  line-height: 1.3;
  display: inline-block;
}

#sidebar-close {
  display: none; /* shown only on mobile */
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

#sidebar-close:hover { color: var(--text); }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.channel-list {
  padding: 8px 6px 4px;
}

.channel-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.87rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.1s, background 0.1s;
}

.channel-item:hover  { color: var(--text); background: var(--surface); }
.channel-item.active { color: var(--text); background: #404040; font-weight: 600; border-left: 3px solid var(--accent); padding-left: 7px; }
.channel-item.unread { color: var(--text); font-weight: 700; position: relative; padding-right: 20px; }
.channel-item.unread::after { content: ''; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* Mobile sidebar overlay */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 39;
}

#sidebar-overlay.open { display: block; }

/* Main content column */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── HEADER ──────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
  gap: 10px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#hamburger-btn {
  display: none; /* shown only on mobile */
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
}

#hamburger-btn:hover { color: var(--text); background: var(--surface); }

#channel-title {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}

.header-avatar:hover { border-color: var(--accent); }
.header-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

#logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

#logout-btn:hover { border-color: var(--muted); color: var(--text); }

/* ── MESSAGES ────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
}

.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 2px 0;
  border-radius: 4px;
  transition: background 0.12s;
}

.msg-row:hover { background: rgba(255,255,255,0.03); }

.msg-row.new-sender  { margin-top: 14px; }
.msg-row.same-sender .msg-avatar { visibility: hidden; }

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  margin-top: 1px;
  box-shadow: 0 0 0 2px rgba(124, 106, 247, 0.3);
}

.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.avatar-fallback {
  width: 100%;
  height: 100%;
  background: #333;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
}

.msg-body { flex: 1; min-width: 0; }

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.msg-sender { font-size: 0.88rem; font-weight: 700; color: var(--text); }
.msg-time   { font-size: 0.66rem; font-weight: 400; color: var(--muted); transition: opacity 0.15s; }


.msg-bubble {
  display: inline-block;
  border-radius: 6px 14px 14px 14px;
  padding: 8px 12px;
  word-break: break-word;
  max-width: min(520px, 100%);
}

.msg-row.is-me   .msg-bubble { background: linear-gradient(145deg, #1d1b2e 0%, #221f38 100%); }
.msg-row.is-them .msg-bubble { background: linear-gradient(145deg, #1c1c1c 0%, #202020 100%); border: 1px solid var(--border); }

.msg-bubble b, .msg-bubble strong,
#msg-editor b, #msg-editor strong { font-weight: 700; }
.msg-bubble i, .msg-bubble em,
#msg-editor i, #msg-editor em     { font-style: italic; }

.msg-text code, .msg-bubble code {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  color: #FF8C00;
  background: #1a1a1a;
  border: 1px solid rgba(255, 140, 0, 0.3);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.9em;
}

.msg-text pre, .msg-bubble pre {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  color: #FF8C00;
  background: #1a1a1a;
  border: 1px solid rgba(255, 140, 0, 0.3);
  border-radius: 6px;
  padding: 12px 16px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9em;
}

.msg-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.msg-bubble .chat-img,
.msg-text img {
  display: block;
  max-width: 100%;
  max-height: 400px;
  width: auto;
  height: auto;
  border-radius: 8px;
  object-fit: contain;
  cursor: pointer;
  margin-bottom: 4px;
}

.msg-actions { margin-top: 4px; opacity: 0; transition: opacity 0.12s; }
.msg-row:hover .msg-actions { opacity: 1; }

.action-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: border-color 0.1s, color 0.1s;
}

.action-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── THREADS ─────────────────────────────────── */
.thread-section { margin-top: 5px; }

.thread-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 2px 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.thread-toggle:hover { text-decoration: underline; }

.thread-arrow { display: inline-block; transition: transform 0.15s; line-height: 1; }
.thread-toggle.open .thread-arrow { transform: rotate(90deg); }

.thread-replies {
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reply-row { display: flex; gap: 8px; align-items: flex-start; }
.reply-row .msg-avatar    { width: 24px; height: 24px; }
.reply-row .avatar-fallback { font-size: 0.62rem; }
.reply-row .msg-sender    { font-size: 0.8rem; }
.reply-row .msg-time      { font-size: 0.65rem; }
.reply-row .msg-bubble    { font-size: 0.92em; padding: 6px 10px; }

.reply-composer {
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.reply-input {
  flex: 1;
  min-height: 32px;
  max-height: 80px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  word-break: break-word;
  transition: border-color 0.15s;
}

.reply-input:focus { border-color: var(--accent); }

.reply-input:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
  display: block;
}

.reply-send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.reply-send-btn:hover { background: var(--accent-dk); }

.reply-cancel-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

.reply-cancel-btn:hover { color: var(--text); }

/* ── LATEST DIVIDER ──────────────────────────── */
.latest-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 12px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.latest-divider::before,
.latest-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--accent);
  opacity: 0.3;
}

/* ── EMPTY STATE ─────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

/* ── INPUT AREA ──────────────────────────────── */
.input-area {
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
}

.editor-toolbar {
  display: flex;
  gap: 2px;
  padding: 2px 2px 6px;
}

.toolbar-btn {
  background: none;
  border: none;
  color: var(--muted);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1.4;
  transition: color 0.1s, background 0.1s;
}

.toolbar-btn:hover { color: var(--text); background: var(--surface); }
.toolbar-btn b { font-weight: 700; font-size: 0.9em; }
.toolbar-btn i { font-style: italic; }

#msg-editor {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 16px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  word-break: break-word;
  transition: border-color 0.15s;
}

#msg-editor:focus { border-color: var(--accent); }

#msg-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
  display: block;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
  min-width: 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 7px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.icon-btn:hover  { color: var(--text); background: var(--surface); }
.icon-btn.active { color: var(--accent); }

#send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

#send-btn:hover    { background: var(--accent-dk); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

@keyframes send-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(0.78) rotate(-8deg); }
  65%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

#send-btn.sending { animation: send-pop 0.32s ease; }

#image-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 0 4px;
}

#image-preview img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

#remove-image-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#remove-image-btn:hover { color: var(--text); }

/* ── EMOJI PICKER ────────────────────────────── */
#emoji-picker-wrap {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 46px;
  z-index: 50;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

emoji-picker {
  --background:               #1a1a1a;
  --border-color:             #2a2a2a;
  --button-active-background: #2a2a2a;
  --button-hover-background:  #242424;
  --indicator-color:          #7c6af7;
  --input-border-color:       #2a2a2a;
  --input-border-radius:      6px;
  --input-font-color:         #e8e8e8;
  --input-placeholder-color:  #666;
  --outline-color:            #7c6af7;
  --search-background:        #222;
  --text-color:               #e8e8e8;
  --category-emoji-padding:   0.5rem;
  --emoji-padding:            0.5rem;
  --emoji-size:               1.5rem;
  --num-columns:              8;
  width: 320px;
  height: 380px;
}

/* ── LIGHTBOX ────────────────────────────────── */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 100;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

#lightbox.open { display: flex; }

#lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 10px;
  object-fit: contain;
}

/* ── SCROLLBARS ──────────────────────────────── */
#messages::-webkit-scrollbar,
.sidebar-scroll::-webkit-scrollbar     { width: 4px; }
#messages::-webkit-scrollbar-track,
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb,
.sidebar-scroll::-webkit-scrollbar-thumb { background: #2e2e2e; border-radius: 4px; }
#messages::-webkit-scrollbar-thumb:hover,
.sidebar-scroll::-webkit-scrollbar-thumb:hover { background: #3c3c3c; }

/* ── REACTIONS ──────────────────────────────── */
.reaction-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
  line-height: 1.5;
  transition: border-color 0.1s, background 0.1s;
}

.reaction-pill:hover { border-color: var(--accent); }
.reaction-pill.mine  { border-color: var(--accent); background: rgba(124,106,247,0.18); }

#reaction-emoji-wrap {
  position: fixed;
  z-index: 80;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

/* ── EDIT / DELETE ───────────────────────────── */
.action-btn.danger:hover { border-color: #e05c5c; color: #e05c5c; }

.inline-edit-input {
  max-width: min(520px, 100%);
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  min-height: 36px;
  max-height: 120px;
  overflow-y: auto;
  word-break: break-word;
  margin-top: 4px;
}

.inline-edit-btns { display: flex; gap: 6px; margin-top: 5px; }

.edit-save-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 4px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s;
}

.edit-save-btn:hover   { background: var(--accent-dk); }

.edit-cancel-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}

.edit-cancel-btn:hover { color: var(--text); }

.edited-label {
  font-size: 0.68rem;
  color: var(--muted);
  margin-left: 5px;
  font-style: italic;
}

/* ── MENTIONS ────────────────────────────────── */
.mention-chip { color: #7ec8c8; font-weight: 600; }

.msg-row.mentioned-me .msg-bubble {
  background: rgba(124,106,247,0.1) !important;
  border-color: rgba(124,106,247,0.3) !important;
}

#mention-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  z-index: 70;
  max-height: 180px;
  overflow-y: auto;
  display: none;
}

.mention-item { padding: 7px 13px; cursor: pointer; font-size: 0.88rem; transition: background 0.1s; }
.mention-item:hover,
.mention-item.active { background: var(--surface-2); }

/* ── DIRECT MESSAGES ────────────────────────── */
.dm-section {
  border-top: 1px solid var(--border);
  padding: 6px 0 8px;
}

.dm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px 4px 12px;
  margin-bottom: 2px;
}

.dm-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

#new-dm-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 1px 5px;
  border-radius: 4px;
  transition: color 0.1s, background 0.1s;
}

#new-dm-btn:hover { color: var(--text); background: var(--surface); }

.dm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.87rem;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.1s, background 0.1s;
  position: relative;
}

.dm-item:hover  { color: var(--text); background: var(--surface); }
.dm-item.active { color: var(--text); background: #404040; font-weight: 600; border-left: 3px solid var(--accent); padding-left: 7px; }
.dm-item.unread { color: var(--text); font-weight: 700; }
.dm-item.unread::after { content: ''; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.dm-item-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--surface-2);
  position: relative;
}

.dm-item-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dm-item-avatar .avatar-fallback { font-size: 0.58rem; width: 100%; height: 100%; }

.dm-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── DM PICKER MODAL ─────────────────────────── */
#dm-picker {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  align-items: center;
  justify-content: center;
}

#dm-picker.open { display: flex; }

.dm-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.dm-picker-modal {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 340px;
  max-height: 480px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  overflow: hidden;
}

.dm-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
  flex-shrink: 0;
}

#dm-picker-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.1s, background 0.1s;
}

#dm-picker-close:hover { color: var(--text); background: var(--surface-2); }

#dm-picker-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}

.dm-picker-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.1s;
  font-family: inherit;
}

.dm-picker-item:hover { background: var(--surface-2); }

.dm-picker-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--surface-2);
}

.dm-picker-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dm-picker-avatar .avatar-fallback { font-size: 0.72rem; width: 100%; height: 100%; }

.dm-picker-name  { font-size: 0.88rem; font-weight: 600; color: var(--text); }
.dm-picker-email { font-size: 0.74rem; color: var(--muted); margin-top: 1px; }

/* ── TYPING INDICATOR ───────────────────────── */
#typing-indicator {
  padding: 0 16px 4px;
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 18px;
  flex-shrink: 0;
}

.typing-dots { display: inline-flex; gap: 3px; vertical-align: middle; margin-left: 2px; }

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

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-3px); }
}

/* ── MOBILE ──────────────────────────────────── */
@media (max-width: 600px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    /* transition already on #sidebar */
  }

  #sidebar.open { transform: translateX(0); }

  #sidebar-close  { display: block; }
  #hamburger-btn  { display: flex; }
}

@media (max-width: 768px) {
  /* Native keyboard has a built-in emoji picker on iOS/Android */
  #emoji-btn { display: none; }

  /* Keep the entire input bar within the viewport */
  .input-area { padding-left: 8px; padding-right: 8px; }
  .input-row  { gap: 6px; }

  /* Editor fills remaining space without overflowing */
  #msg-editor { min-width: 0; padding: 9px 12px; }

  /* Send button must never be clipped */
  #send-btn { flex-shrink: 0; }
}
