:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-input: #1a1a3e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #606078;
    --border: #2a2a4a;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --green: #4ade80;
    --msg-own: #1a2a4a;
    --msg-other: #222240;
    --msg-system: #2a2040;
    --msg-private: #2a1a3e;
    --scrollbar: #333355;
    --shadow: rgba(0,0,0,0.3);
}

[data-theme="light"] {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8ef;
    --bg-input: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #555570;
    --text-muted: #999;
    --border: #ddd;
    --accent: #d63447;
    --accent-hover: #e94560;
    --green: #22c55e;
    --msg-own: #e8f0fe;
    --msg-other: #f0f0f5;
    --msg-system: #f5f0ff;
    --msg-private: #fdf0ff;
    --scrollbar: #ccc;
    --shadow: rgba(0,0,0,0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg-primary); color: var(--text-primary); height: 100vh; overflow: hidden; }

/* Login required */
.chat-login-required { display: flex; align-items: center; justify-content: center; height: 100vh; }
.chat-login-box { text-align: center; padding: 3rem; background: var(--bg-secondary); border-radius: 16px; border: 1px solid var(--border); }
.chat-login-box i { font-size: 3rem; color: var(--accent); margin-bottom: 1rem; }
.chat-login-box h2 { margin-bottom: 0.5rem; }
.chat-login-box p { color: var(--text-secondary); margin-bottom: 1.5rem; }
.chat-login-btn { display: inline-block; padding: 0.75rem 2rem; background: var(--accent); color: #fff; text-decoration: none; border-radius: 8px; font-weight: 600; transition: background 0.2s; }
.chat-login-btn:hover { background: var(--accent-hover); }

/* App layout */
.chat-app { display: flex; flex-direction: column; height: 100vh; }

/* Header */
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 0 1.25rem; height: 56px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-header-left { display: flex; align-items: center; gap: 1rem; }
.chat-logo { color: var(--accent); font-weight: 800; font-size: 1.25rem; text-decoration: none; letter-spacing: -0.5px; }
.chat-title { color: var(--text-secondary); font-size: 0.9rem; }
.chat-header-right { display: flex; align-items: center; gap: 1rem; }
.chat-user-info { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.chat-avatar-small { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.chat-badge { font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; font-weight: 600; text-transform: uppercase; }
.chat-badge-admin { background: var(--accent); color: #fff; }
.chat-badge-moderator { background: #3b82f6; color: #fff; }
.chat-back-btn { color: var(--text-secondary); font-size: 1.1rem; text-decoration: none; padding: 0.5rem; transition: color 0.2s; }
.chat-back-btn:hover { color: var(--accent); }

/* Body */
.chat-body { display: flex; flex: 1; overflow: hidden; }

/* Sidebar */
.chat-sidebar { width: 260px; background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.chat-sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.chat-sidebar-header h3 { font-size: 0.9rem; color: var(--text-secondary); display: flex; align-items: center; gap: 0.5rem; }
#onlineCount { background: var(--green); color: #000; font-size: 0.7rem; padding: 1px 6px; border-radius: 10px; font-weight: 700; }
.chat-sidebar-toggle { display: none; background: none; border: none; color: var(--text-secondary); font-size: 1.2rem; cursor: pointer; }
.chat-user-list { list-style: none; overflow-y: auto; flex: 1; padding: 0.5rem 0; }
.chat-user-list li { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1.25rem; cursor: pointer; transition: background 0.15s; position: relative; }
.chat-user-list li:hover { background: var(--bg-tertiary); }
.chat-user-list li .user-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--bg-tertiary); }
.chat-user-list li .user-avatar-placeholder { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.8rem; }
.chat-user-list li .user-name { font-size: 0.9rem; font-weight: 500; }
.chat-user-list li .user-badge { font-size: 0.65rem; padding: 1px 5px; border-radius: 3px; font-weight: 600; margin-left: 4px; }
.chat-user-list li .online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); position: absolute; left: 44px; bottom: 10px; border: 2px solid var(--bg-secondary); }

/* Main */
.chat-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }

/* Tabs */
.chat-tabs { display: flex; align-items: center; gap: 0; padding: 0; background: var(--bg-secondary); border-bottom: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; }
.chat-tab { padding: 0.75rem 1.25rem; background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-secondary); font-size: 0.85rem; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 0.5rem; transition: all 0.15s; position: relative; }
.chat-tab:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.chat-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.chat-tab .tab-close { font-size: 0.7rem; opacity: 0.5; margin-left: 0.25rem; }
.chat-tab .tab-close:hover { opacity: 1; }
.chat-tab .tab-unread { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: none; }
.chat-tab .tab-unread.visible { display: block; }

/* Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.25rem; }
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

.chat-msg { display: flex; gap: 0.75rem; padding: 0.5rem 0.75rem; border-radius: 8px; max-width: 100%; transition: background 0.15s; position: relative; }
.chat-msg:hover { background: var(--bg-tertiary); }
.chat-msg:hover .msg-actions { opacity: 1; }
.chat-msg-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--bg-tertiary); }
.chat-msg-avatar-placeholder { width: 36px; height: 36px; border-radius: 50%; background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.75rem; flex-shrink: 0; }
.chat-msg-body { flex: 1; min-width: 0; }
.chat-msg-header { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 2px; }
.chat-msg-name { font-weight: 600; font-size: 0.85rem; cursor: pointer; }
.chat-msg-name:hover { text-decoration: underline; }
.chat-msg-name.role-admin { color: var(--accent); }
.chat-msg-name.role-moderator { color: #60a5fa; }
.chat-msg-time { font-size: 0.7rem; color: var(--text-muted); }
.chat-msg-text { font-size: 0.9rem; line-height: 1.45; word-wrap: break-word; overflow-wrap: break-word; }
.chat-msg-private-label { font-size: 0.7rem; color: #a78bfa; font-style: italic; }

.msg-actions { position: absolute; right: 0.5rem; top: 0.25rem; opacity: 0; display: flex; gap: 0.25rem; }
.msg-actions button { background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text-muted); padding: 2px 6px; border-radius: 4px; cursor: pointer; font-size: 0.7rem; }
.msg-actions button:hover { color: var(--accent); border-color: var(--accent); }

.chat-msg-system { justify-content: center; padding: 0.35rem; }
.chat-msg-system .system-text { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }

.chat-msg.deleted .chat-msg-text { color: var(--text-muted); font-style: italic; text-decoration: line-through; }

/* Typing */
.chat-typing { padding: 0 1rem; min-height: 1.5rem; display: flex; align-items: center; font-size: 0.8rem; color: var(--text-muted); font-style: italic; }

/* Input */
.chat-input-area { display: flex; gap: 0.5rem; padding: 0.75rem 1rem; background: var(--bg-secondary); border-top: 1px solid var(--border); flex-shrink: 0; }
.chat-input { flex: 1; padding: 0.75rem 1rem; background: var(--bg-input); border: 1px solid var(--border); border-radius: 24px; color: var(--text-primary); font-size: 0.9rem; outline: none; transition: border-color 0.2s; }
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }
.chat-send-btn { width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 1rem; cursor: pointer; transition: background 0.2s; display: flex; align-items: center; justify-content: center; }
.chat-send-btn:hover { background: var(--accent-hover); }

/* Context menu */
.chat-context-menu { position: fixed; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px var(--shadow); z-index: 1000; padding: 0.25rem 0; min-width: 180px; }
.chat-context-menu button { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.6rem 1rem; background: none; border: none; color: var(--text-primary); font-size: 0.85rem; cursor: pointer; text-align: left; }
.chat-context-menu button:hover { background: var(--bg-tertiary); }
.chat-context-menu button.chat-mod-action { color: var(--accent); }

/* Mobile users button (header) */
.chat-mobile-users-btn { display: none; background: var(--accent); border: none; color: #fff; font-size: 0.85rem; cursor: pointer; padding: 0.5rem 0.75rem; border-radius: 8px; gap: 0.5rem; align-items: center; }
.chat-mobile-users-btn span { background: rgba(255,255,255,0.25); color: #fff; font-size: 0.7rem; padding: 2px 6px; border-radius: 8px; font-weight: 700; min-width: 18px; text-align: center; }

/* Mobile */
@media (max-width: 768px) {
    .chat-sidebar { position: fixed; left: -280px; top: 56px; bottom: 0; z-index: 100; width: 280px; transition: left 0.3s; box-shadow: 4px 0 16px var(--shadow); }
    .chat-sidebar.open { left: 0; }
    .chat-sidebar-toggle { display: block; }
    .chat-mobile-users-btn { display: flex; }
    .chat-tabs { padding-left: 0.5rem; }
}
