:root {
    --bg: #111;
    --surface: #1a1a1a;
    --surface2: #222;
    --border: #2e2e2e;
    --orange: #ff6a00;
    --orange2: #ff9900;
    --orange-dim: #7a3200;
    --orange-glow: rgba(255, 106, 0, 0.15);
    --text: #f5e6d0;
    --text-dim: #8a7a6a;
    --text-muted: #3a3028;
    --diamond: #4dd9e8;
    --dg: rgba(77, 217, 232, 0.2);
    --danger: #e74c3c;
    --success: #2ecc71;
    --r: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: 'Nunito', sans-serif; height: 100vh; display: flex; flex-direction: column; overflow: hidden; position: relative; }

body::before { 
    content:''; position:fixed; inset:0; 
    background-image:linear-gradient(rgba(255,106,0,0.04) 1px,transparent 1px), linear-gradient(90deg,rgba(255,106,0,0.04) 1px,transparent 1px); 
    background-size:32px 32px; pointer-events:none; z-index:0; 
    animation: gridDriftX 60s ease-in-out infinite alternate, gridDriftY 43s ease-in-out infinite alternate; 
}
@keyframes gridDriftX { 0% { background-position-x: 0px; } 100% { background-position-x: 1024px; } }
@keyframes gridDriftY { 0% { background-position-y: 0px; } 100% { background-position-y: 1024px; } }

.topbar { position: relative; z-index: 50; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 11px 20px; background: rgba(17,17,17,0.96); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.mc-title { font-family: 'Press Start 2P', monospace; font-size: 0.6rem; color: var(--orange); text-shadow: 0 0 10px var(--orange); }
.mc-sub { font-size: 0.73rem; color: var(--text-dim); margin-top: 2px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-link { background: transparent; border: 1px solid var(--border); border-radius: var(--r); padding: 7px 12px; color: var(--text-dim); font-size: 0.78rem; font-weight: 700; cursor: pointer; transition: 0.15s; text-decoration: none; white-space: nowrap; }
.topbar-link:hover { border-color: var(--orange); color: var(--orange); }
.user-pill { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 6px 12px; font-size: 0.8rem; font-weight: 700; color: var(--text-dim); display: flex; align-items: center; gap: 6px; text-decoration: none; transition: 0.15s; }
.user-pill:hover { border-color: var(--orange); }

.sidebar-toggle { display: none; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: var(--r); cursor: pointer; font-size: 1.2rem; }
.sidebar-close { display: none; background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.2rem; }

.bell-btn { position: relative; cursor: pointer; font-size: 1.3rem; text-decoration: none; }
.bell-badge { position: absolute; top: -5px; right: -8px; background: var(--danger); color: #fff; font-size: 0.5rem; font-family: 'Press Start 2P', monospace; padding: 3px 5px; border-radius: 10px; display: none; }

.chat-layout { display: flex; flex: 1; min-height: 0; position: relative; z-index: 1; }

.sidebar { width: 280px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.sidebar-title { font-family: 'Press Start 2P', monospace; font-size: 0.7rem; color: var(--text); }
.groups-list { flex: 1; overflow-y: auto; padding: 10px; }
.group-item { padding: 15px; border-radius: var(--r); margin-bottom: 8px; cursor: pointer; transition: 0.15s; border: 1px solid transparent; }
.group-item:hover { background: var(--surface2); }
.group-item.active { background: var(--orange-glow); border-color: var(--orange); }
.group-name { font-weight: 800; font-size: 0.95rem; color: var(--text); margin-bottom: 4px; }
.group-desc { font-size: 0.75rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-main { flex: 1; display: flex; flex-direction: column; background: rgba(0,0,0,0.2); position: relative; min-width: 0; }
.chat-placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); text-align: center; padding: 40px; }
.chat-placeholder-icon { font-size: 4rem; margin-bottom: 20px; opacity: 0.2; }

.chat-header { padding: 15px 25px; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.chat-title { font-family: 'Press Start 2P', monospace; font-size: 0.8rem; color: var(--orange); }
.chat-desc { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; }

.messages-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }
.message { display: flex; gap: 12px; max-width: 85%; }
.message.own { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar { width: 32px; height: 32px; border-radius: 4px; flex-shrink: 0; image-rendering: pixelated; border: 1px solid var(--border); }
.msg-content { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.message.own .msg-content { align-items: flex-end; }
.msg-info { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; font-weight: 800; }
.msg-author { color: var(--diamond); }
.message.own .msg-author { color: var(--orange); }
.msg-time { color: var(--text-muted); font-weight: 600; font-size: 0.65rem; }
.msg-bubble { background: var(--surface); border: 1px solid var(--border); padding: 10px 14px; border-radius: 12px; font-size: 0.92rem; line-height: 1.4; color: var(--text); word-break: break-word; box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
.message.own .msg-bubble { background: var(--orange-glow); border-color: var(--orange); }

.msg-bubble a { color: var(--diamond); text-decoration: underline; text-underline-offset: 3px; }
.msg-bubble a:hover { filter: brightness(1.2); }

.reply-preview { background: rgba(0,0,0,0.2); border-left: 3px solid var(--diamond); padding: 6px 10px; border-radius: 4px; font-size: 0.75rem; margin-bottom: 8px; color: var(--text-dim); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.message.own .reply-preview { border-left-color: var(--orange); }
.reply-author { font-weight: 800; color: var(--diamond); font-size: 0.7rem; }
.message.own .reply-author { color: var(--orange); }
.reply-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 250px; }

.reply-bar { background: var(--surface2); padding: 8px 15px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 0.8rem; position: relative; z-index: 10; }
.reply-bar-info { display: flex; align-items: center; gap: 8px; color: var(--text-dim); }
.btn-cancel-reply { background: transparent; border: none; color: var(--danger); cursor: pointer; font-family: 'Press Start 2P', monospace; font-size: 0.5rem; }

.btn-reply { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.7rem; font-weight: 800; transition: 0.15s; }
.btn-reply:hover { color: var(--diamond); }
.message.own .btn-reply:hover { color: var(--orange); }
.msg-actions { display: flex; gap: 8px; margin-top: 2px; opacity: 0; transition: 0.15s; }
.message:hover .msg-actions { opacity: 1; }
.message.own .msg-actions { justify-content: flex-end; }

.chat-input-area { padding: 20px; background: var(--surface); border-top: 1px solid var(--border); display: flex; gap: 12px; position: relative; z-index: 10; }
.chat-input { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 15px; color: var(--text); font-family: inherit; font-size: 0.95rem; outline: none; transition: 0.15s; min-width: 0; }
.chat-input:focus { border-color: var(--orange); box-shadow: 0 0 10px var(--orange-glow); }
.btn-send { background: var(--orange); color: #fff; border: none; border-radius: var(--r); padding: 0 25px; font-family: 'Press Start 2P', monospace; font-size: 0.6rem; cursor: pointer; transition: 0.15s; text-transform: uppercase; }
.btn-send:hover { background: var(--orange2); transform: translateY(-2px); box-shadow: 0 4px 15px var(--orange-glow); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

@media (max-width: 768px) {
    .topbar { padding: 10px; }
    .mc-sub { display: none; }
    .topbar-right { gap: 8px; }
    .topbar-link, .user-pill { padding: 6px 8px; font-size: 0.7rem; }
    
    .sidebar-toggle { display: block; }
    .sidebar-close { display: block; }
    
    .sidebar { position: absolute; left: 0; top: 0; bottom: 0; z-index: 1000; transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: 10px 0 30px rgba(0,0,0,0.8); width: 85%; }
    .sidebar.open { transform: translateX(0); }
    
    .chat-header { padding: 10px 15px; }
    .chat-title { font-size: 0.6rem; }
    .chat-desc { font-size: 0.7rem; }
    
    .messages-container { padding: 15px 10px; }
    .message { max-width: 95%; gap: 8px; }
    .msg-avatar { width: 28px; height: 28px; }
    .msg-bubble { font-size: 0.85rem; padding: 8px 12px; }
    
    .chat-input-area { padding: 10px; gap: 8px; }
    .chat-input { padding: 10px; font-size: 0.85rem; }
    .btn-send { padding: 0 15px; font-size: 0.5rem; }
    
    .reply-preview { max-width: 200px; }
}

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(60px); background: var(--surface); border: 1px solid var(--orange); border-radius: var(--r); padding: 10px 20px; font-size: 0.86rem; font-weight: 700; color: var(--orange); z-index: 999; opacity: 0; transition: transform 0.25s, opacity 0.25s; pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* --- Context Menu --- */
.context-menu {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 1000;
    width: 200px;
    padding: 5px;
    display: none;
    animation: menuFade 0.15s ease-out;
}
@keyframes menuFade { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.menu-item {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    border-radius: 4px;
    transition: 0.1s;
}
.menu-item:hover { background: var(--orange-glow); color: var(--orange); }
.menu-item.danger:hover { background: rgba(231,76,60,0.1); color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 5px; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
