/* ═══ CHAT CSS ═══════════════════════════════════════════════ */

.chat-layout { display:flex; height:calc(100vh - 64px); overflow:hidden; }

/* ── SIDEBAR ── */
.chat-sidebar { width:240px; background:var(--bg-secondary); border-right:1px solid var(--border); display:flex; flex-direction:column; flex-shrink:0; }
.chat-server-header { display:flex; align-items:center; gap:10px; padding:1rem; border-bottom:1px solid var(--border); }
.chat-server-header img { width:32px; height:32px; border-radius:8px; object-fit:cover; }
.chat-server-header span { font-family:'Space Grotesk',sans-serif; font-weight:700; font-size:0.9rem; }
.chat-channels { flex:1; overflow-y:auto; padding:0.5rem 0; }
.channel-category { margin-bottom:0.25rem; }
.channel-category-label { padding:0.5rem 1rem 0.2rem; font-size:0.68rem; font-weight:700; letter-spacing:0.08em; text-transform:uppercase; color:var(--text-muted); cursor:pointer; }
.channel-item { display:flex; align-items:center; gap:8px; padding:0.35rem 0.75rem; margin:0 0.5rem; border-radius:6px; cursor:pointer; color:var(--text-muted); font-size:0.88rem; font-weight:500; transition:all 0.15s; }
.channel-item:hover { background:rgba(255,255,255,0.04); color:var(--text-secondary); }
.channel-item.active { background:rgba(255,255,255,0.07); color:var(--text-primary); }
.channel-icon { font-size:0.9rem; flex-shrink:0; }
.channel-name { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.chat-user-bar { padding:0.6rem 0.75rem; border-top:1px solid var(--border); display:flex; align-items:center; gap:8px; background:rgba(0,0,0,0.2); }
.user-avatar-wrap { position:relative; cursor:pointer; flex-shrink:0; }
.user-avatar { width:32px; height:32px; border-radius:50%; background:var(--purple-primary); display:flex; align-items:center; justify-content:center; font-size:0.8rem; font-weight:700; color:#fff; }
.user-status-dot { position:absolute; bottom:-1px; right:-1px; width:10px; height:10px; border-radius:50%; border:2px solid var(--bg-secondary); }
.user-status-dot.online { background:var(--success); }
.user-status-dot.idle { background:#f59e0b; }
.user-status-dot.dnd { background:var(--error); }
.user-status-dot.offline, .user-status-dot.invisible { background:var(--gray-600); }
.user-info { flex:1; min-width:0; }
.user-name { font-size:0.82rem; font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-status-label { font-size:0.68rem; color:var(--text-muted); }
.icon-btn { background:none; border:none; cursor:pointer; font-size:0.9rem; padding:4px; border-radius:5px; color:var(--text-muted); transition:all 0.15s; display:flex; align-items:center; }
.icon-btn:hover { background:rgba(255,255,255,0.06); color:var(--text-primary); }

/* ── MAIN CHAT ── */
.chat-main { flex:1; display:flex; flex-direction:column; overflow:hidden; min-width:0; }
.chat-header { padding:0 1rem; height:52px; display:flex; align-items:center; gap:10px; border-bottom:1px solid var(--border); background:var(--bg-secondary); flex-shrink:0; }
.chat-channel-icon { font-size:1.1rem; }
.chat-header-name { font-weight:700; font-size:0.95rem; flex:1; }
.chat-header-actions { display:flex; gap:4px; }
.chat-messages { flex:1; overflow-y:auto; padding:1rem 1rem 0.5rem; display:flex; flex-direction:column; gap:0; }
.chat-messages::-webkit-scrollbar { width:5px; }
.chat-messages::-webkit-scrollbar-thumb { background:var(--border); border-radius:3px; }

/* ── MESSAGES ── */
.msg-group { display:flex; gap:12px; padding:4px 8px; border-radius:6px; position:relative; }
.msg-group:hover { background:rgba(255,255,255,0.02); }
.msg-group:hover .msg-actions { opacity:1; pointer-events:all; }
.msg-avatar-wrap { cursor:pointer; flex-shrink:0; margin-top:2px; }
.msg-avatar { width:36px; height:36px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:0.85rem; font-weight:700; color:#fff; }
.msg-avatar-img { width:36px; height:36px; border-radius:50%; object-fit:cover; }
.msg-content { flex:1; min-width:0; }
.msg-header { display:flex; align-items:baseline; gap:8px; margin-bottom:2px; flex-wrap:wrap; }
.msg-author { font-weight:700; font-size:0.88rem; color:var(--purple-light); cursor:pointer; }
.msg-author.owner { color:#f59e0b; }
.msg-time { font-size:0.68rem; color:var(--text-muted); }
.msg-edited { font-size:0.68rem; color:var(--text-muted); font-style:italic; }
.msg-pinned-badge { font-size:0.7rem; }
.msg-text { font-size:0.9rem; line-height:1.5; color:var(--text-primary); word-break:break-word; }
.msg-text a { color:var(--purple-light); }
.msg-text strong { font-weight:700; }
.msg-text em { font-style:italic; }
.msg-text del { text-decoration:line-through; opacity:0.7; }
.msg-text u { text-decoration:underline; }
.msg-highlight { background:rgba(124,58,237,0.15) !important; transition:background 0.5s; }

/* Markdown elements */
.code-block { background:#0d0d0f; border:1px solid var(--border); border-radius:6px; padding:0.75rem 1rem; font-family:monospace; font-size:0.83rem; overflow-x:auto; margin:4px 0; white-space:pre; }
.inline-code { background:rgba(0,0,0,0.4); border:1px solid var(--border); border-radius:4px; padding:1px 5px; font-family:monospace; font-size:0.85em; }
.blockquote { border-left:3px solid var(--border-bright); padding-left:0.75rem; margin:4px 0; color:var(--text-secondary); }
.spoiler { background:var(--gray-800); color:transparent; border-radius:3px; cursor:pointer; padding:0 3px; transition:all 0.2s; user-select:none; }
.spoiler.revealed { color:var(--text-primary); background:rgba(255,255,255,0.05); }
.timestamp { background:rgba(255,255,255,0.07); border-radius:4px; padding:1px 5px; font-size:0.82em; color:var(--text-secondary); }

/* Message actions */
.msg-actions { position:absolute; top:-14px; right:8px; display:flex; gap:2px; background:var(--bg-card); border:1px solid var(--border); border-radius:8px; padding:3px; opacity:0; pointer-events:none; transition:opacity 0.15s; z-index:10; }
.msg-action-btn { background:none; border:none; cursor:pointer; font-size:0.85rem; padding:3px 5px; border-radius:5px; color:var(--text-muted); transition:all 0.15s; }
.msg-action-btn:hover { background:rgba(255,255,255,0.08); color:var(--text-primary); }
.msg-action-btn.danger:hover { background:rgba(239,68,68,0.1); color:var(--error); }

/* Reactions */
.msg-reactions { display:flex; flex-wrap:wrap; gap:4px; margin-top:4px; min-height:0; }
.reaction-pill { display:flex; align-items:center; gap:4px; padding:2px 8px; background:rgba(255,255,255,0.05); border:1px solid var(--border); border-radius:12px; cursor:pointer; font-size:0.82rem; transition:all 0.15s; }
.reaction-pill:hover { background:rgba(255,255,255,0.09); border-color:var(--border-bright); }
.reaction-pill.reacted { background:rgba(124,58,237,0.15); border-color:var(--purple-primary); }
.reaction-count { color:var(--text-secondary); font-size:0.78rem; }
.reaction-add-btn { background:none; border:1px dashed var(--border); border-radius:12px; padding:2px 8px; cursor:pointer; color:var(--text-muted); font-size:0.82rem; transition:all 0.15s; }
.reaction-add-btn:hover { border-color:var(--purple-primary); color:var(--purple-light); }

/* Embeds */
.embed { border-left:4px solid var(--purple-primary); background:var(--bg-card); border-radius:0 6px 6px 0; padding:0.75rem 1rem; margin:4px 0; max-width:520px; }
.embed-author { display:flex; align-items:center; gap:6px; font-size:0.78rem; color:var(--text-secondary); margin-bottom:6px; font-weight:600; }
.embed-author-icon { width:18px; height:18px; border-radius:50%; }
.embed-body { display:flex; gap:1rem; }
.embed-main { flex:1; min-width:0; }
.embed-title { font-weight:700; font-size:0.9rem; margin-bottom:4px; }
.embed-title a { color:var(--text-primary); text-decoration:none; }
.embed-title a:hover { text-decoration:underline; }
.embed-desc { font-size:0.85rem; color:var(--text-secondary); line-height:1.5; }
.embed-thumbnail { width:72px; height:72px; border-radius:6px; object-fit:cover; flex-shrink:0; }
.embed-image { max-width:100%; border-radius:6px; margin-top:8px; }
.embed-fields { display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
.embed-field { flex:1; min-width:120px; }
.embed-field.inline { flex:0 0 calc(33% - 8px); }
.embed-field-name { font-size:0.78rem; font-weight:700; color:var(--text-primary); margin-bottom:2px; }
.embed-field-value { font-size:0.82rem; color:var(--text-secondary); }
.embed-footer { display:flex; align-items:center; gap:6px; font-size:0.72rem; color:var(--text-muted); margin-top:8px; padding-top:8px; border-top:1px solid var(--border); }
.embed-footer-icon { width:16px; height:16px; border-radius:50%; }

/* Input area */
.chat-input-area { padding:0.75rem 1rem; flex-shrink:0; }
.chat-input-wrap { display:flex; align-items:flex-end; gap:8px; background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius); padding:0.5rem 0.75rem; transition:border-color 0.2s; }
.chat-input-wrap:focus-within { border-color:var(--purple-primary); }
.chat-input { flex:1; background:transparent; border:none; outline:none; color:var(--text-primary); font-size:0.9rem; font-family:'Inter',sans-serif; resize:none; max-height:150px; line-height:1.5; padding:2px 0; }
.chat-input::placeholder { color:var(--text-muted); }
.chat-send-btn { width:30px; height:30px; background:var(--purple-primary); border:none; border-radius:7px; color:#fff; cursor:pointer; display:flex; align-items:center; justify-content:center; flex-shrink:0; transition:all 0.2s; }
.chat-send-btn:hover { background:var(--purple-light); }
.chat-send-btn:disabled { opacity:0.4; cursor:not-allowed; }
.chat-send-btn svg { width:14px; height:14px; }

/* Typing dots */
.typing-dots { display:inline-flex; align-items:center; gap:3px; }
.typing-dots span { width:5px; height:5px; background:var(--text-muted); border-radius:50%; animation:typing-bounce 1.2s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation-delay:0.2s; }
.typing-dots span:nth-child(3) { animation-delay:0.4s; }
@keyframes typing-bounce { 0%,60%,100% { transform:translateY(0); } 30% { transform:translateY(-4px); } }

/* ── MEMBERS PANEL ── */
.members-panel { width:220px; background:var(--bg-secondary); border-left:1px solid var(--border); overflow-y:auto; flex-shrink:0; padding:0.75rem 0; transition:width 0.2s; }
.members-panel.hidden { width:0; overflow:hidden; padding:0; }
.members-panel::-webkit-scrollbar { width:4px; }
.members-panel::-webkit-scrollbar-thumb { background:var(--border); border-radius:2px; }
.members-header { padding:0.5rem 1rem 0.25rem; display:flex; justify-content:space-between; font-size:0.72rem; font-weight:700; letter-spacing:0.06em; text-transform:uppercase; color:var(--text-muted); }
.members-count { color:var(--purple-light); }
.member-role-label { padding:0.5rem 1rem 0.2rem; font-size:0.67rem; font-weight:700; letter-spacing:0.07em; text-transform:uppercase; color:var(--text-muted); }
.member-item { display:flex; align-items:center; gap:8px; padding:0.3rem 0.75rem; cursor:pointer; border-radius:5px; margin:0 0.4rem; transition:background 0.12s; }
.member-item:hover { background:rgba(255,255,255,0.05); }
.member-avatar-wrap { position:relative; flex-shrink:0; }
.member-avatar { width:28px; height:28px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:0.75rem; font-weight:700; color:#fff; }
.member-avatar-img { width:28px; height:28px; border-radius:50%; object-fit:cover; }
.member-status { position:absolute; bottom:-1px; right:-1px; width:9px; height:9px; border-radius:50%; border:2px solid var(--bg-secondary); background:var(--gray-600); }
.member-status.online { background:var(--success); }
.member-status.idle { background:#f59e0b; }
.member-status.dnd { background:var(--error); }
.member-name { font-size:0.83rem; font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:var(--text-secondary); }
.role-icon { font-size:0.8rem; }

/* ── EMOJI PICKER ── */
.emoji-search-wrap { position:sticky; top:0; background:var(--bg-card); padding:8px; border-bottom:1px solid var(--border); }
.emoji-search { width:100%; background:var(--bg-secondary); border:1px solid var(--border); border-radius:6px; padding:5px 10px; color:var(--text-primary); font-size:0.82rem; outline:none; }
.emoji-cat-label { padding:6px 10px 3px; font-size:0.68rem; font-weight:700; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.06em; }
.emoji-grid { display:flex; flex-wrap:wrap; padding:2px 6px; }
.emoji-btn { background:none; border:none; cursor:pointer; font-size:1.2rem; padding:4px; border-radius:5px; transition:background 0.1s; line-height:1; }
.emoji-btn:hover { background:rgba(255,255,255,0.07); }

/* ── USER PROFILE POPUP ── */
.profile-popup { background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius-lg); width:300px; overflow:hidden; position:relative; box-shadow:0 24px 60px rgba(0,0,0,0.6); }
.profile-close { position:absolute; top:10px; right:10px; background:rgba(0,0,0,0.4); border:none; color:var(--text-muted); cursor:pointer; width:26px; height:26px; border-radius:50%; font-size:0.8rem; }
.profile-header { height:80px; background:linear-gradient(135deg,#1a0a2e,#2d1b4e); display:flex; align-items:flex-end; padding:0 1rem 0; }
.profile-avatar { width:64px; height:64px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:1.5rem; font-weight:700; color:#fff; border:3px solid var(--bg-card); margin-bottom:-32px; }
.profile-avatar-img { width:64px; height:64px; border-radius:50%; object-fit:cover; border:3px solid var(--bg-card); margin-bottom:-32px; }
.profile-body { padding:2.5rem 1rem 1rem; }
.profile-name { font-family:'Space Grotesk',sans-serif; font-size:1.1rem; font-weight:700; margin-bottom:2px; }
.profile-joined { font-size:0.75rem; color:var(--text-muted); margin-bottom:0.75rem; }
.profile-roles { display:flex; flex-wrap:wrap; gap:5px; margin-bottom:0.75rem; }
.profile-role { padding:2px 8px; border-radius:20px; border:1px solid; font-size:0.72rem; font-weight:600; }
.profile-status-badge { padding:4px 10px; border-radius:6px; font-size:0.78rem; font-weight:600; margin-bottom:0.5rem; }
.profile-status-badge.ban { background:rgba(239,68,68,0.1); color:var(--error); border:1px solid rgba(239,68,68,0.3); }
.profile-status-badge.mute { background:rgba(245,158,11,0.1); color:#f59e0b; border:1px solid rgba(245,158,11,0.3); }
.profile-actions { display:flex; gap:0.5rem; flex-wrap:wrap; margin-top:0.75rem; }
.btn-outline.danger { border-color:rgba(239,68,68,0.4); color:var(--error); }
.btn-outline.danger:hover { border-color:var(--error); background:rgba(239,68,68,0.08); }

/* ── MOD POPUP ── */
.mod-popup { background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius-lg); padding:1.5rem; width:360px; box-shadow:0 24px 60px rgba(0,0,0,0.6); }

/* ── PINNED / SEARCH ITEMS ── */
.pinned-item { padding:0.5rem 0; border-bottom:1px solid var(--border); font-size:0.83rem; color:var(--text-secondary); }
.search-result-item { padding:0.5rem 0; border-bottom:1px solid var(--border); cursor:pointer; }
.search-result-item:hover { background:rgba(255,255,255,0.02); }

/* ── CODE VERIFY PASTE FIX ── */
.code-inputs input { text-align:center; }

@media (max-width:900px) {
  .members-panel { display:none; }
  .chat-sidebar { width:200px; }
}
@media (max-width:640px) {
  .chat-layout { position:relative; }
  .chat-sidebar {
    position:fixed; left:0; top:64px; bottom:0; z-index:200;
    width:260px; transform:translateX(-100%);
    transition:transform .25s cubic-bezier(.4,0,.2,1);
    box-shadow:4px 0 20px rgba(0,0,0,.5);
  }
  .chat-sidebar.sidebar-open { transform:translateX(0); }
  .sidebar-overlay {
    display:none; position:fixed; inset:0; top:64px; z-index:199;
    background:rgba(0,0,0,.55);
  }
  .sidebar-overlay.show { display:block; }
  .chat-mobile-header { display:flex !important; }
  .chat-header { display:none; }
  .chat-messages { padding:0.5rem 0.75rem; }
  .msg-group { padding:0.4rem 0; }
  .chat-input-area { padding:0.5rem 0.75rem; }
  .chat-input-wrap { gap:6px; }
  .chat-input { font-size:0.95rem; }
  .icon-btn { width:34px; height:34px; font-size:0.9rem; }
  .chat-send-btn { width:38px; height:38px; }
  .dm-panel { position:fixed !important; inset:0 !important; top:64px !important;
    right:0 !important; bottom:0 !important; left:0 !important;
    width:100% !important; height:calc(100vh - 64px) !important;
    border-radius:0 !important; z-index:250 !important; }
  .emoji-picker { width:calc(100vw - 16px) !important; left:8px !important; right:8px !important; }
  #emoji-picker { width:calc(100vw - 16px) !important; left:8px !important; }
  .msg-actions { opacity:1 !important; }
  .forum-thread-card { flex-direction:column; }
}
/* Mobile header bar shown only on small screens */
.chat-mobile-header {
  display:none; align-items:center; gap:10px; padding:0.5rem 1rem;
  background:var(--bg-secondary); border-bottom:1px solid var(--border);
  position:sticky; top:0; z-index:10;
}
.chat-mobile-menu-btn {
  background:none; border:none; cursor:pointer; color:var(--text-secondary);
  width:34px; height:34px; display:flex; align-items:center; justify-content:center;
  border-radius:6px; font-size:1.2rem; flex-shrink:0;
}
.chat-mobile-menu-btn:hover { background:var(--bg-hover); }
.chat-mobile-channel-name { font-weight:600; font-size:0.95rem; flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ── FILE PREVIEWS ─────────────────────────────────── */
.att-preview-grid { display:flex; flex-direction:column; gap:8px; margin-top:6px; max-width:420px; }

.att-img-preview {
  position:relative; display:inline-block; border-radius:10px; overflow:hidden;
  cursor:pointer; max-width:360px; max-height:260px; background:var(--bg-primary);
  border:1px solid var(--border);
}
.att-img-preview img { display:block; max-width:100%; max-height:260px; object-fit:cover; border-radius:9px; }
.att-img-overlay {
  position:absolute; bottom:0; left:0; right:0; background:linear-gradient(transparent,rgba(0,0,0,.7));
  padding:8px 10px 8px; display:flex; align-items:center; justify-content:space-between;
  opacity:0; transition:opacity .18s;
}
.att-img-preview:hover .att-img-overlay { opacity:1; }
.att-img-overlay span { color:#fff; font-size:0.78rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1; }
.att-dl-btn {
  background:rgba(255,255,255,.18); color:#fff; border:1px solid rgba(255,255,255,.35);
  border-radius:6px; padding:3px 9px; font-size:0.75rem; cursor:pointer; text-decoration:none;
  flex-shrink:0; margin-left:8px; white-space:nowrap;
}
.att-dl-btn:hover { background:rgba(255,255,255,.3); }

.att-file-card {
  display:flex; align-items:center; gap:10px; padding:10px 14px;
  background:var(--bg-primary); border:1px solid var(--border); border-radius:10px;
  max-width:380px;
}
.att-file-icon { font-size:1.6rem; flex-shrink:0; width:36px; text-align:center; }
.att-file-info { flex:1; min-width:0; }
.att-file-name { font-size:0.85rem; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--text-primary); }
.att-file-meta { font-size:0.72rem; color:var(--text-muted); margin-top:2px; }
.att-file-dl {
  background:var(--purple-primary); color:#fff; border:none; border-radius:7px;
  padding:5px 12px; font-size:0.78rem; font-weight:600; cursor:pointer; text-decoration:none;
  white-space:nowrap; flex-shrink:0;
}
.att-file-dl:hover { background:var(--purple-hover,#5b3fcc); }

/* ── DOWNLOAD WARNING MODAL ────────────────────────── */
.dl-warn-overlay {
  position:fixed; inset:0; z-index:9000; background:rgba(0,0,0,.65);
  display:none; align-items:center; justify-content:center; padding:1rem;
}
.dl-warn-overlay.show { display:flex; }
.dl-warn-box {
  background:var(--bg-secondary); border:1px solid var(--border); border-radius:16px;
  padding:2rem 1.75rem; max-width:420px; width:100%; display:flex; flex-direction:column; gap:0.75rem;
  box-shadow:0 20px 60px rgba(0,0,0,.6);
}
.dl-warn-icon { font-size:2.2rem; text-align:center; }
.dl-warn-title { font-size:1.1rem; font-weight:700; text-align:center; color:var(--text-primary); }
.dl-warn-file {
  background:var(--bg-primary); border:1px solid var(--border); border-radius:8px;
  padding:8px 12px; font-size:0.82rem; font-family:monospace; word-break:break-all;
  color:var(--text-secondary); text-align:center;
}
.dl-warn-text { font-size:0.83rem; color:var(--text-muted); line-height:1.55; text-align:center; }
.dl-warn-actions { display:flex; gap:10px; margin-top:0.5rem; }

/* ── OFFLINE MEMBERS ───────────────────────────────── */
.member-item.member-offline { opacity: 0.55; }
.member-item.member-offline .member-name { color: var(--text-muted) !important; }

/* ── MENTION DROPDOWN MOBILE FIX ──────────────────── */
.mention-dropdown {
  position: absolute; bottom: 100%; left: 0; right: 0; z-index: 300;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 8px; max-height: 220px; overflow-y: auto;
  box-shadow: 0 -4px 20px rgba(0,0,0,.4);
  margin-bottom: 6px;
}
.mention-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  cursor: pointer; font-size: 0.85rem; min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}
.mention-item:hover, .mention-item:active { background: var(--bg-hover); }
