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

:root {
  --bg:       #0d0d0d;
  --surface:  #141414;
  --surface2: #1c1c1c;
  --border:   #2a2a2a;
  --accent:   #4cff88;
  --accent2:  #b26bff;
  --accent-rgb: 76, 255, 136;
  --accent2-rgb: 178, 107, 255;
  --text:     #e8e8e8;
  --muted:    #666;
  --danger:   #ff4747;
  --radius:   6px;
  --font-mono: 'IBM Plex Mono', monospace;
  --font-sans: 'IBM Plex Sans', sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

/* ── SCREENS ───────────────────────────────────────── */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* ── LOGIN ─────────────────────────────────────────── */
#login-screen {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(var(--accent-rgb), 0.06) 0%, transparent 70%),
    var(--bg);
}

.login-box {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.login-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.logo-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  margin-bottom: 8px;
}

.login-header h1 {
  font-family: var(--font-mono);
  font-size: 24px;
  letter-spacing: 4px;
  color: var(--accent);
}

.login-header p {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--muted);
}

.field input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--muted); }

#login-form { display: flex; flex-direction: column; gap: 12px; }

button {
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  border: none;
  border-radius: var(--radius);
  transition: all 0.15s;
}

#login-btn {
  background: var(--accent);
  color: #0d0d0d;
  font-weight: 600;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 1px;
  margin-top: 4px;
}
#login-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
#login-btn:active { transform: translateY(0); }

.secondary-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 10px 16px;
  letter-spacing: 1px;
}
.secondary-btn:hover { border-color: var(--text); color: var(--text); }

.error-msg { color: var(--danger); font-size: 12px; min-height: 16px; }

/* ── CHAT LAYOUT ───────────────────────────────────── */
#chat-screen { flex-direction: row; }

.chat-layout { display: flex; width: 100%; height: 100vh; }

/* ── SIDEBAR ───────────────────────────────────────── */
.sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 12px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.room-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 1px;
}

.logout-btn {
  background: transparent;
  color: var(--muted);
  padding: 4px;
  border-radius: 4px;
  display: flex;
}
.logout-btn:hover { color: var(--danger); background: rgba(255,71,71,0.08); }

.me-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #0d0d0d;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.me-tag span:not(.online-dot) {
  font-size: 12px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.9);
}

.online-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--muted);
  padding: 0 4px;
}

.online-users { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; flex: 1; }

.online-user-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
}

.online-user-item .avatar {
  width: 24px; height: 24px;
  font-size: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}

.online-user-item span { font-size: 12px; color: var(--muted); }

/* ── CHAT MAIN ─────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

/* ── MESSAGES AREA ─────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.day-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  color: var(--muted);
}
.day-divider::before, .day-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.day-divider span {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
}

/* ── MESSAGE BUBBLE ────────────────────────────────── */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 10px;
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-group.mine { align-items: flex-end; }
.msg-group.theirs { align-items: flex-start; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 2px;
}

.msg-meta .avatar { width: 22px; height: 22px; font-size: 9px; }

.msg-meta .name {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent2);
  font-family: var(--font-mono);
}

.msg-meta.mine .name { color: var(--accent); }

.msg-meta .ts {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 68%;
  position: relative;
}

.msg-group.mine .msg-row { flex-direction: row-reverse; }
.msg-group.theirs .msg-row { flex-direction: row; }

.bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
  cursor: pointer;
  transition: background 0.1s;
  max-width: 100%;
}

.bubble:hover { background: var(--surface2); }

.msg-group.mine .bubble {
  background: rgba(var(--accent-rgb), 0.07);
  border-color: rgba(var(--accent-rgb), 0.2);
}
.msg-group.mine .bubble:hover { background: rgba(var(--accent-rgb), 0.12); }

/* deleted message */
.bubble.deleted {
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
  cursor: default;
}

/* edited tag */
.edited-tag {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
  margin-left: 6px;
}

/* ── REPLY QUOTE ───────────────────────────────────── */
.reply-quote {
  border-left: 2px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--muted);
  border-radius: 0 4px 4px 0;
  background: rgba(var(--accent-rgb), 0.04);
  cursor: pointer;
}

.reply-quote .rq-name {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  margin-bottom: 2px;
  display: block;
}

/* ── IMAGE MESSAGE ─────────────────────────────────── */
.msg-img {
  max-width: 240px;
  max-height: 200px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: opacity 0.15s;
}
.msg-img:hover { opacity: 0.85; }

/* ── VOICE MESSAGE ─────────────────────────────────── */
.voice-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.voice-play-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #0d0d0d;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter 0.15s;
}
.voice-play-btn:hover { filter: brightness(1.15); }

.voice-waveform {
  flex: 1;
  height: 24px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.voice-waveform span {
  display: block;
  width: 3px;
  background: var(--muted);
  border-radius: 2px;
  transition: background 0.1s;
}

.voice-duration {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

/* ── REACTIONS ─────────────────────────────────────── */
.reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 6px 2px;
}

.react-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
.react-chip:hover { border-color: var(--accent); background: rgba(var(--accent-rgb), 0.06); }
.react-chip.mine { border-color: var(--accent); background: rgba(var(--accent-rgb), 0.1); }
.react-chip .count { font-family: var(--font-mono); font-size: 10px; color: var(--muted); }

/* ── REPLY BAR ─────────────────────────────────────── */
.reply-bar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: 10px;
}
.reply-bar.hidden { display: none; }

.reply-bar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  color: var(--muted);
  font-size: 12px;
}

#cancel-reply {
  background: transparent;
  color: var(--muted);
  padding: 2px 6px;
  font-size: 13px;
  border-radius: 4px;
}
#cancel-reply:hover { color: var(--danger); }

/* ── INPUT BAR ─────────────────────────────────────── */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.attach-btn, .voice-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.attach-btn:hover, .voice-btn:hover { color: var(--text); border-color: var(--text); }
.voice-btn.recording {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(255,71,71,0.1);
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,71,71,0.4); } 50% { box-shadow: 0 0 0 6px rgba(255,71,71,0); } }

.voice-recording-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--danger);
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.voice-recording-indicator.hidden { display: none; }

.rec-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.2; } }

#msg-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.15s;
  overflow-y: auto;
}
#msg-input:focus { border-color: var(--accent); }
#msg-input::placeholder { color: var(--muted); }

.send-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #0d0d0d;
  border-radius: var(--radius);
  flex-shrink: 0;
  padding: 0;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn:active { transform: scale(0.96); }

/* ── CONTEXT MENU ──────────────────────────────────── */
.ctx-menu {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 1000;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 140px;
}
.ctx-menu.hidden { display: none; }

.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  border-radius: 0;
  letter-spacing: 0.3px;
}
.ctx-menu button:hover { background: var(--surface); }
.ctx-menu .delete-action { color: var(--danger); }

/* ── EMOJI PICKER ──────────────────────────────────── */
.emoji-picker {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 1001;
  padding: 8px;
  display: flex;
  gap: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.emoji-picker.hidden { display: none; }

.emoji-picker button {
  font-size: 20px;
  padding: 4px 6px;
  background: transparent;
  border-radius: 4px;
  line-height: 1;
}
.emoji-picker button:hover { background: var(--surface); }

/* ── IMAGE LIGHTBOX ────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox.hidden { display: none; }

.lightbox-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.9);
}

#lightbox-img {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  object-fit: contain;
}

#lightbox-close {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* ── MODAL ─────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-box label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--muted);
}

#edit-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  resize: vertical;
  outline: none;
}
#edit-input:focus { border-color: var(--accent); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .secondary-btn { padding: 8px 14px; }
.modal-actions .send-btn { width: auto; padding: 8px 16px; font-size: 13px; font-weight: 600; }

/* ── UTILITIES ─────────────────────────────────────── */
.hidden { display: none !important; }

/* scrollbar */
textarea::-webkit-scrollbar { width: 4px; }
textarea::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ═══════════════════════════════════════════════════
   MOBILE — slim top header replaces full sidebar
   TABLET — minor sidebar shrink
═══════════════════════════════════════════════════ */

/* Fix font-size to 16px on inputs to prevent iOS zoom */
.field input { font-size: 16px; }
#msg-input   { font-size: 16px; }
#edit-input  { font-size: 16px; }

/* Use dynamic viewport height everywhere */
.screen, .chat-layout { height: 100dvh; }

/* Modal padding so it clears keyboard on mobile */
.modal { padding: 16px; }
.modal-box { width: 100%; max-width: 380px; }

/* Input bar always flexes correctly */
.input-bar {
  flex-wrap: nowrap;
  align-items: flex-end;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}

/* reply bar never shrinks */
.reply-bar { flex-shrink: 0; }

/* Tablet — minor sidebar shrink */
@media (min-width: 641px) and (max-width: 900px) {
  .sidebar { width: 170px; min-width: 170px; padding: 14px 12px; }
  .msg-row  { max-width: 78%; }
}

/* ── MOBILE (≤640px) — Messenger-style screen navigation ── */
@media (max-width: 640px) {

  /* ── LAYOUT: full screen stacking ── */
  #chat-screen { flex-direction: column; }
  .chat-layout { flex-direction: column; height: 100dvh; }

  /* ── SIDEBAR becomes the CHAT LIST SCREEN ── */
  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    min-width: 0;
    height: 100dvh;
    flex-direction: column;
    padding: 0;
    gap: 0;
    border-right: none;
    background: var(--bg);
    z-index: 200;
    overflow: hidden;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    overflow: auto;
  }

  /* When chat is open, slide sidebar off-screen left */
  .sidebar.mobile-hidden {
    transform: translateX(-100%);
    pointer-events: none;
  }

  /* ── MOBILE SIDEBAR TOP BAR ── */
  .sidebar-top {
    display: flex;
    align-items: center;
    padding: 14px 16px 10px;
    padding-top: max(14px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 10px;
  }

  .app-name {
    font-size: 18px;
    letter-spacing: 3px;
    flex: 1;
  }

  /* me-tag in sidebar */
  .me-tag {
    margin: 12px 16px 0;
    padding: 10px 14px;
  }
  .me-tag .avatar { width: 30px; height: 30px; font-size: 12px; }

  /* Section labels */
  .sidebar-section-label {
    padding: 14px 16px 6px;
    font-size: 9px;
    letter-spacing: 2px;
  }

  /* Room tab button — full width list item */
  .room-tab-btn {
    margin: 0 8px;
    padding: 12px 16px;
    font-size: 14px;
    border-radius: 10px;
  }

  /* Online users — vertical list style */
  .online-users {
    flex-direction: column !important;
    max-height: none !important;
    flex: none !important;
    overflow: visible !important;
    gap: 2px;
    padding: 0 8px;
  }

  .online-user-item {
    padding: 10px 16px;
    border-radius: 10px;
    gap: 12px;
  }
  .online-user-item:hover { background: var(--surface2); }
  .online-user-item .avatar { width: 36px; height: 36px; font-size: 14px; }
  .online-user-item > span:not(.online-dot) { font-size: 14px; color: var(--text); }
  .online-user-item .online-dot { margin-left: auto; }
  .dm-start-btn { opacity: 1; width: 32px; height: 32px; justify-content: center; }

  /* DM convo list */
  .dm-convo-list {
    max-height: none;
    padding: 0 8px;
    gap: 2px;
  }
  .dm-convo-item {
    padding: 10px 16px;
    border-radius: 10px;
    gap: 12px;
  }
  .dm-convo-item .avatar { width: 40px; height: 40px; font-size: 15px; }
  .dm-convo-name { font-size: 14px; }
  .dm-convo-preview { font-size: 12px; }

  /* ── CHAT MAIN — full screen ── */
  .chat-main {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    z-index: 100;
    background: var(--bg);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  }

  /* When on list view, push chat off-screen right */
  .chat-main.mobile-hidden {
    transform: translateX(100%);
    pointer-events: none;
  }

  /* ── MOBILE CHAT HEADER ── */
  .chat-header {
    padding: 0 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    height: auto;
    min-height: 56px;
    gap: 10px;
    flex-shrink: 0;
  }

  /* Back button */
  .mobile-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    color: var(--accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 18px;
    padding: 0;
  }
  .mobile-back-btn:hover { background: var(--surface2); }

  .chat-header-title { font-size: 15px; }
  .chat-header-sub   { font-size: 11px; }

  /* Messages */
  .messages-area { padding: 10px 10px 8px; flex: 1; min-height: 0; }
  .msg-row        { max-width: 84%; }
  .bubble { padding: 8px 11px; font-size: 14px; }
  .msg-meta { padding: 0 4px 2px; }
  .msg-meta .name { font-size: 10px; }
  .msg-meta .ts   { font-size: 9px; }
  .msg-img { max-width: 68vw; max-height: 200px; }

  /* Reply bar */
  .reply-bar { padding: 6px 10px; flex-shrink: 0; }

  /* Input bar */
  .input-bar {
    padding: 8px 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 6px;
    flex-shrink: 0;
  }
  .attach-btn, .voice-btn, .send-btn { width: 40px; height: 40px; }
  #msg-input { flex: 1; min-width: 0; min-height: 40px; max-height: 100px; }

  /* Voice indicator */
  .voice-recording-indicator {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 16px;
    white-space: nowrap;
    z-index: 300;
    pointer-events: none;
  }

  /* Emoji picker */
  .emoji-picker {
    left: 50% !important;
    transform: translateX(-50%) !important;
    bottom: 72px !important;
    top: auto !important;
    padding: 10px;
    gap: 4px;
    border-radius: 12px;
    z-index: 400;
  }
  .emoji-picker button { font-size: 26px; padding: 6px 7px; }

  /* Context menu */
  .ctx-menu { min-width: 160px; z-index: 400; }
  .ctx-menu button { padding: 14px 18px; font-size: 15px; }

  /* Login */
  .login-box {
    width: 92vw;
    max-width: 400px;
    padding: 28px 22px;
    gap: 22px;
  }
  .login-header h1 { font-size: 20px; letter-spacing: 3px; }
  #login-btn     { padding: 13px 16px; }
  .secondary-btn { padding: 12px 16px; }

  /* Lightbox */
  #lightbox-close { top: 10px; right: 10px; width: 36px; height: 36px; }

  /* Voice msg */
  .voice-msg      { min-width: 140px; }
  .voice-waveform { height: 20px; }
}

/* ── Desktop: hide back button ── */
@media (min-width: 641px) {
  .mobile-back-btn { display: none; }
}
/* ══════════════════════════════════════════════════════
   DM & NEW SIDEBAR ADDITIONS
   ══════════════════════════════════════════════════════ */

/* App name replaces room-tag */
.app-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 2px;
  font-weight: 500;
}

/* Section labels */
.sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--muted);
  padding: 4px 4px 0;
  margin-top: 4px;
}

/* Room tab button */
.room-tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border: none;
  width: 100%;
}
.room-tab-btn:hover { background: var(--surface2); color: var(--text); }
.room-tab-btn.active { background: var(--surface2); color: var(--accent); }

/* DM start button on online users */
.dm-start-btn {
  background: transparent;
  color: var(--muted);
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.online-user-item:hover .dm-start-btn { opacity: 1; }
.dm-start-btn:hover { color: var(--accent2); }

/* DM conversation list */
.dm-convo-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  max-height: 180px;
}
.dm-convo-list::-webkit-scrollbar { width: 3px; }
.dm-convo-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.dm-convo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}
.dm-convo-item:hover { background: var(--surface2); }
.dm-convo-item.active { background: var(--surface2); border-left: 2px solid var(--accent2); }

.dm-convo-item .avatar {
  width: 26px; height: 26px;
  font-size: 10px;
  background: rgba(var(--accent2-rgb), 0.15);
  color: var(--accent2);
  border: 1px solid rgba(var(--accent2-rgb), 0.3);
  flex-shrink: 0;
}

.dm-convo-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.dm-convo-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-convo-preview {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-empty {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 8px;
  font-style: italic;
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  gap: 12px;
}
.chat-header-info {
  display: flex;
  flex-direction: column;
}
.chat-header-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.5px;
}
.chat-header-sub {
  font-size: 11px;
  color: var(--muted);
}

/* DM bubble accent */
.dm-bubble-hint {
  border-left: 2px solid var(--accent2);
}

/* Sidebar overflow — make it scroll as needed */
.sidebar {
  overflow-y: auto;
  gap: 8px !important;
}
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); }

/* Online users — limit height so DMs are visible */
.online-users {
  max-height: 140px !important;
  flex: none !important;
}
/* ═══════════════════════════════════════════════════════
   CALLING SYSTEM STYLES
   ═══════════════════════════════════════════════════════ */

/* ── Call header buttons ─────────────────────────────── */
.chat-header-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
}
.call-header-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.call-header-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Incoming call modal ─────────────────────────────── */
.call-incoming-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 28px;
  text-align: center;
  border-radius: 16px;
}
.call-avatar-ring {
  border-radius: 50%;
  padding: 4px;
  border: 2px solid var(--accent);
  animation: call-ring-pulse 1.2s ease-in-out infinite;
}
@keyframes call-ring-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb, 100,100,220), 0.5); }
  50% { box-shadow: 0 0 0 10px rgba(var(--accent-rgb, 100,100,220), 0); }
}
.call-avatar-lg {
  width: 56px !important;
  height: 56px !important;
  font-size: 22px !important;
  border-radius: 50%;
}
.call-incoming-name {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.call-incoming-type {
  font-size: 13px;
  color: var(--muted);
}
.call-incoming-actions {
  display: flex;
  gap: 24px;
  margin-top: 8px;
}
.call-reject-btn, .call-accept-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.call-reject-btn {
  background: #e53e3e;
  color: #fff;
}
.call-accept-btn {
  background: #38a169;
  color: #fff;
}
.call-reject-btn:hover { transform: scale(1.08); background: #c53030; }
.call-accept-btn:hover { transform: scale(1.08); background: #2f855a; }

/* ── Call overlay ────────────────────────────────────── */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #0a0a0f;
  display: flex;
  align-items: center;
  justify-content: center;
}
.call-overlay.hidden { display: none; }
.call-overlay-inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.call-remote-video-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#call-remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.call-no-video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0d14;
}
.call-local-video {
  position: absolute;
  bottom: 100px;
  right: 16px;
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--border);
  z-index: 10;
  background: #1a1a2e;
}
@media (max-width: 640px) {
  .call-local-video { width: 88px; height: 66px; bottom: 90px; }
}
.call-overlay-info {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 10;
}
.call-overlay-name {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}
.call-overlay-timer {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  margin-top: 4px;
}
.call-overlay-actions {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 10;
}
.call-action-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  transition: background 0.15s;
}
.call-action-btn:hover { background: rgba(255,255,255,0.28); }
.call-action-btn.active { background: rgba(255,255,255,0.35); }
.call-end-btn {
  background: #e53e3e !important;
}
.call-end-btn:hover { background: #c53030 !important; }
