/* ═══ ChaosHelper Messenger — Mattermost-style ═══ */

/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ═══ DARK THEME ═══ */
:root {
    --bg:         #1a1d21;
    --bg2:        #1f2228;
    --bg3:        #252830;
    --surface:    #2d3039;
    --border:     #3a3d46;
    --text:       #dddfe2;
    --text2:      #8b8d94;
    --text3:      #5d5f66;
    --accent:     #4a90d9;
    --accent-hover: #5ba0e6;
    --accent-bg:  rgba(74, 144, 217, 0.12);
    --danger:     #e74c3c;
    --success:    #2ecc71;
    --warning:    #f39c12;
    --sidebar-bg: #14171a;
    --sidebar-text: #c8cacc;
    --sidebar-hover: #1f2329;
    --sidebar-active: #2a3040;
    --msg-hover:  rgba(255,255,255,0.04);
    --online:     #2ecc71;
    --radius:     8px;
    --radius-sm:  4px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ═══ LIGHT THEME ═══ */
[data-theme="light"] {
    --bg:         #ffffff;
    --bg2:        #f7f7f7;
    --bg3:        #f0f0f0;
    --surface:    #e8e8e8;
    --border:     #d0d0d0;
    --text:       #1a1a1a;
    --text2:      #666666;
    --text3:      #999999;
    --accent:     #3578c4;
    --accent-hover: #2a68b4;
    --accent-bg:  rgba(53, 120, 196, 0.08);
    --danger:     #d32f2f;
    --success:    #27ae60;
    --warning:    #e67e22;
    --sidebar-bg: #1a2233;
    --sidebar-text: #d0d4da;
    --sidebar-hover: #243044;
    --sidebar-active: #2a3a55;
    --msg-hover:  rgba(0,0,0,0.03);
    --online:     #27ae60;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

input, textarea, select, button { font-family: inherit; font-size: inherit; }

/* ═══ SCREENS ═══ */
.screen { display: none; height: 100vh; height: 100dvh; }
.screen.active { display: flex; }

/* ═══ LOGIN ═══ */
.login-container {
    margin: auto;
    width: 360px;
    padding: 48px 32px;
    background: var(--bg2);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-align: center;
}
.login-logo { margin-bottom: 32px; }
.login-logo .logo-icon { font-size: 48px; color: var(--accent); }
.login-logo h1 { font-size: 24px; font-weight: 700; margin-top: 8px; }
.login-subtitle { color: var(--text2); margin-top: 4px; font-size: 13px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

.input-group {
    position: relative;
    margin-bottom: 12px;
}
.input-group .input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    color: var(--text2);
}
.input-group input, .input-group textarea {
    width: 100%;
    padding: 10px 12px 10px 42px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    outline: none;
    transition: border-color .2s;
}
.input-group input:focus, .input-group textarea:focus {
    border-color: var(--accent);
}
.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: background .2s;
}
.btn-login:hover { background: var(--accent-hover); }

/* ═══ APP LAYOUT — 3 columns ═══ */
.app-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 20;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-logo { font-size: 24px; color: var(--accent); }
.sidebar-title { font-size: 16px; font-weight: 700; flex: 1; }
.sidebar-close-btn { display: none; }

.sidebar-section { flex: 1; overflow-y: auto; padding: 8px 0; min-height: 0; }
.sidebar-section:first-of-type { flex: 1.5; }
.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: rgba(255,255,255,0.4);
    letter-spacing: .5px;
}
.btn-icon-xs {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}
.btn-icon-xs .material-icons-round { font-size: 18px; }
.btn-icon-xs:hover { color: rgba(255,255,255,0.7); background: rgba(255,255,255,0.06); }

.sidebar-list { padding: 2px 8px; }
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--sidebar-text);
    transition: background .15s;
    position: relative;
}
.sidebar-item:hover { background: var(--sidebar-hover); }
.sidebar-item.active { background: var(--sidebar-active); color: #fff; font-weight: 500; }
.sidebar-item-icon { font-size: 18px; opacity: .6; width: 20px; text-align: center; }
.sidebar-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item-badge {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}
.sidebar-dm-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text2);
    overflow: hidden;
    flex-shrink: 0;
}
.sidebar-dm-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-dm-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.sidebar-dm-status.online { background: var(--online); }
.sidebar-dm-status.offline { background: var(--text3); }

.sidebar-browse-btn {
    display: block;
    padding: 6px 16px;
    font-size: 13px;
    color: rgba(255,255,255,0.4);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    width: 100%;
}
.sidebar-browse-btn:hover { color: rgba(255,255,255,0.7); }

/* Sidebar user */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
    cursor: pointer;
    transition: background .15s;
}
.sidebar-user:hover { background: var(--sidebar-hover); }
.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    flex-shrink: 0;
}
.sidebar-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-status { font-size: 11px; color: rgba(255,255,255,0.4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ═══ MAIN AREA ═══ */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
}

/* ═══ TOPBAR ═══ */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 50px;
    min-height: 50px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-menu-btn { display: none; }
.topbar-channel-info { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-channel-icon { font-size: 18px; color: var(--text2); font-weight: 700; }
.topbar-channel-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-channel-desc { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 4px; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.btn-icon .material-icons-round { font-size: 22px; }

.call-active-icon { color: var(--success) !important; animation: pulse-call 1.5s infinite; }
@keyframes pulse-call {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}

/* ═══ MESSAGES PAGE ═══ */
.page { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.page:not(.active) { display: none !important; }

.msg-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text2);
    font-size: 15px;
}

.msg-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.msg-messages::-webkit-scrollbar { width: 6px; }
.msg-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Message row — Mattermost style */
.msg-row {
    display: flex;
    gap: 12px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: background .1s;
    position: relative;
}
.msg-row:hover { background: var(--msg-hover); }
.msg-row:hover .msg-actions { opacity: 1; }
.msg-row-compact { padding: 1px 8px 1px 52px; }

.msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text2);
    flex-shrink: 0;
    overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-body { flex: 1; min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-sender { font-weight: 600; font-size: 14px; color: var(--text); }
.msg-time { font-size: 11px; color: var(--text3); }
.msg-edited { font-size: 11px; color: var(--text3); font-style: italic; }
.msg-text {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.msg-text .mention { color: var(--accent); font-weight: 600; background: var(--accent-bg); padding: 1px 4px; border-radius: 3px; }

.msg-file-attach {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    cursor: pointer;
    max-width: 400px;
}
.msg-file-attach:hover { background: var(--surface); }
.msg-file-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file-size { font-size: 11px; color: var(--text2); }

.msg-file-image {
    max-width: 400px;
    max-height: 300px;
    border-radius: var(--radius-sm);
    margin-top: 4px;
    cursor: pointer;
}

/* Message actions (edit/delete) */
.msg-actions {
    position: absolute;
    right: 8px;
    top: 4px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .15s;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
}
.msg-action-btn {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    padding: 3px;
    border-radius: 3px;
    display: flex;
}
.msg-action-btn:hover { color: var(--text); background: var(--bg3); }
.msg-action-btn .material-icons-round { font-size: 16px; }

/* System message */
.msg-system {
    text-align: center;
    padding: 6px;
    font-size: 12px;
    color: var(--text3);
}

/* Date separator */
.msg-date-sep {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
    font-size: 12px;
    color: var(--text3);
    font-weight: 600;
}
.msg-date-sep::before, .msg-date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Typing indicator */
.msg-typing {
    padding: 4px 20px 8px;
    font-size: 12px;
    color: var(--text2);
    font-style: italic;
}

/* Input area */
.msg-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 16px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.msg-input-wrapper { flex: 1; position: relative; }
.msg-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color .2s;
}
.msg-input:focus { border-color: var(--accent); }
.msg-send-btn { color: var(--accent) !important; }
.msg-send-btn:hover { background: var(--accent-bg) !important; }

/* @mention autocomplete */
.msg-mention-list {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    margin-bottom: 4px;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.2);
}
.mention-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
}
.mention-item:hover, .mention-item.active { background: var(--accent-bg); }
.mention-item-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text2);
    overflow: hidden;
}
.mention-item-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ═══ RIGHT PANEL ═══ */
.right-panel {
    width: 280px;
    min-width: 280px;
    background: var(--bg2);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.right-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
.right-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
}
.member-row:hover { background: var(--msg-hover); }
.member-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
}
.member-avatar img { width: 100%; height: 100%; object-fit: cover; }
.member-online-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--bg2);
}
.member-online-dot.online { background: var(--online); }
.member-online-dot.offline { background: var(--text3); }
.member-info { flex: 1; min-width: 0; }
.member-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-role { font-size: 11px; color: var(--text3); }

/* ═══ FILES PAGE ═══ */
.files-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}
.breadcrumb a { color: var(--accent); cursor: pointer; }
.breadcrumb span { color: var(--text2); }
.toolbar-actions { display: flex; gap: 8px; }

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg2);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.btn-action:hover { background: var(--bg3); border-color: var(--text3); }
.btn-action .material-icons-round { font-size: 18px; }
.btn-action.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-action.btn-accent:hover { background: var(--accent-hover); }
.btn-action.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.file-area { flex: 1; overflow-y: auto; padding: 0 20px; }
.file-list-header {
    display: grid;
    grid-template-columns: 1fr 100px 140px 80px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    border-bottom: 1px solid var(--border);
}
.file-list { }
.file-row {
    display: grid;
    grid-template-columns: 1fr 100px 140px 80px;
    padding: 10px 12px;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    cursor: pointer;
    transition: background .1s;
}
.file-row:hover { background: var(--msg-hover); }
.file-name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-name-cell .material-icons-round { font-size: 20px; color: var(--text2); flex-shrink: 0; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file-size { font-size: 12px; color: var(--text2); }
.file-date { font-size: 12px; color: var(--text2); }
.file-actions { display: flex; gap: 4px; }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 48px 0;
    color: var(--text2);
}
.empty-state .empty-icon { font-size: 48px; }

.upload-progress {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}
.upload-bar {
    height: 4px;
    background: var(--bg3);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 4px;
}
.upload-bar-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width .3s;
}

/* ═══ MODALS ═══ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}
.modal-content {
    position: relative;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-content.modal-small { max-width: 440px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-body-col { display: flex; flex-direction: column; gap: 12px; }
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* ═══ CHANNEL CREATE ═══ */
.slug-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg3);
    border-radius: var(--radius-sm);
    font-size: 12px;
}
.slug-label { color: var(--text2); }
.slug-value { color: var(--accent); font-family: monospace; }

.radio-group {
    display: flex;
    gap: 16px;
}
.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}
.radio-label .material-icons-round { font-size: 18px; color: var(--text2); }

.form-hint { font-size: 12px; color: var(--text2); }

.member-checklist {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
}
.member-check-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
}
.member-check-item:hover { background: var(--msg-hover); }

/* Browse channels */
.browse-channel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.browse-channel-info { flex: 1; }
.browse-channel-name { font-weight: 600; font-size: 14px; }
.browse-channel-meta { font-size: 12px; color: var(--text2); }

/* DM user list */
.dm-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background .15s;
}
.dm-user-item:hover { background: var(--msg-hover); }
.dm-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text2);
    overflow: hidden;
}
.dm-user-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Profile dialog */
.profile-avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    color: var(--text2);
    overflow: hidden;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Admin panel */
.admin-users-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}
.admin-user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg3);
    border-radius: var(--radius-sm);
}
.admin-user-info { flex: 1; }
.admin-user-name { font-weight: 600; font-size: 13px; }
.admin-user-meta { font-size: 11px; color: var(--text2); }
.admin-user-actions { display: flex; gap: 4px; }
.admin-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 3px;
    text-transform: uppercase;
}
.admin-badge.admin { background: var(--accent-bg); color: var(--accent); }
.admin-badge.blocked { background: rgba(231,76,60,0.15); color: var(--danger); }

/* Settings */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}
.settings-toggle { display: flex; gap: 4px; }
.settings-option {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    transition: background .15s;
}
.settings-option:hover { background: var(--surface); }
.settings-option.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ═══ VIDEO CALL ═══ */
.modal-videocall {
    max-width: 90vw;
    max-height: 90vh;
    width: 800px;
}
.videocall-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}
.videocall-title { font-size: 16px; font-weight: 600; }
.videocall-controls { display: flex; gap: 8px; }
.videocall-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}
.videocall-btn:hover { background: var(--surface); }
.videocall-btn-hangup { background: var(--danger) !important; color: #fff; }
.videocall-btn-accept { background: var(--success) !important; color: #fff; }
.videocall-btn.muted { background: var(--danger); color: #fff; }

.videocall-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 8px;
    padding: 12px;
    flex: 1;
    overflow-y: auto;
}
.videocall-participant {
    position: relative;
    background: #000;
    border-radius: var(--radius-sm);
    overflow: hidden;
    aspect-ratio: 16/9;
}
.videocall-participant video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.videocall-participant-name {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

/* Incoming call */
.incoming-call {
    position: fixed;
    top: 16px;
    right: 16px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 2000;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: slideIn .3s ease;
}
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
.incoming-call-info { display: flex; align-items: center; gap: 12px; }
.incoming-call-name { font-weight: 600; font-size: 14px; }
.incoming-call-text { font-size: 12px; color: var(--text2); }
.incoming-call-actions { display: flex; gap: 8px; }

/* ═══ SEARCH PANEL ═══ */
.search-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    height: 100vh;
    background: var(--bg2);
    border-left: 1px solid var(--border);
    z-index: 50;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 16px rgba(0,0,0,0.2);
}
.search-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.search-panel-header .input-group { flex: 1; margin-bottom: 0; }
.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.search-result-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 4px;
}
.search-result-item:hover { background: var(--msg-hover); }
.search-result-channel { font-size: 11px; color: var(--accent); font-weight: 600; }
.search-result-sender { font-size: 12px; font-weight: 600; }
.search-result-text { font-size: 13px; color: var(--text2); margin-top: 2px; }
.search-result-time { font-size: 11px; color: var(--text3); }

/* ═══ CONTEXT MENU ═══ */
.context-menu {
    position: fixed;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    z-index: 2000;
    min-width: 160px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: background .1s;
}
.ctx-item:hover { background: var(--accent-bg); }
.ctx-item .material-icons-round { font-size: 18px; color: var(--text2); }
.ctx-danger { color: var(--danger); }
.ctx-danger .material-icons-round { color: var(--danger); }

/* ═══ TOAST ═══ */
.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--bg2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    animation: toastIn .3s ease;
    pointer-events: auto;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ═══ WELCOME STATE ═══ */
.msg-welcome {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 24px 8px 20px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.msg-welcome-icon {
    font-size: 44px;
    color: var(--accent);
    background: var(--accent-bg);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}
.msg-welcome-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}
.msg-welcome-hint {
    font-size: 14px;
    color: var(--text2);
    margin: 0;
}

/* ═══ SCROLL TO BOTTOM BUTTON ═══ */
.msg-scroll-btn {
    position: absolute;
    bottom: 70px;
    right: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--text2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .2s, transform .2s;
    z-index: 5;
    pointer-events: none;
}
.msg-scroll-btn.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.msg-scroll-btn:hover { background: var(--bg3); color: var(--text); }
.msg-scroll-btn .material-icons-round { font-size: 22px; }

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══ RESPONSIVE ═══ */

/* --- Tablet & small desktop (≤900px) --- */
@media (max-width: 900px) {
    .right-panel { display: none !important; }
}

/* --- Mobile (≤768px) --- */
@media (max-width: 768px) {
    /* Sidebar: fixed off-screen, slides in */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        height: 100%;
        height: 100dvh;
        width: 300px;
        max-width: 85vw;
        transition: left .3s ease;
        z-index: 30;
    }
    .sidebar.open { left: 0; }
    .sidebar-close-btn { display: flex; }

    /* Topbar */
    .topbar {
        height: 48px;
        min-height: 48px;
        padding: 0 10px;
        gap: 8px;
    }
    .topbar-menu-btn { display: flex; }
    .topbar-channel-desc { display: none; }
    .topbar-channel-name { font-size: 15px; }
    .topbar-channel-icon { font-size: 16px; }

    /* Messages */
    .msg-messages { padding: 10px 10px 6px; }
    .msg-row { padding: 5px 6px; gap: 10px; }
    .msg-row-compact { padding: 1px 6px 1px 46px; }
    .msg-avatar { width: 30px; height: 30px; font-size: 13px; }
    .msg-sender { font-size: 13px; }
    .msg-text { font-size: 14px; }
    .msg-file-image { max-width: 100%; max-height: 200px; }
    .msg-file-attach { max-width: 100%; }

    /* Input area */
    .msg-input-area { padding: 6px 10px 8px; gap: 6px; }
    .msg-input-area .btn-icon { padding: 8px; }
    .msg-input { padding: 9px 12px; font-size: 16px; /* prevents iOS zoom */ }

    /* Welcome */
    .msg-welcome { padding: 20px 6px 16px; }
    .msg-welcome-icon { width: 52px; height: 52px; font-size: 36px; }
    .msg-welcome-title { font-size: 16px; }

    /* Scroll button */
    .msg-scroll-btn { bottom: 60px; right: 12px; }

    /* Search panel: full screen */
    .search-panel { width: 100%; }

    /* Files */
    .file-list-header { grid-template-columns: 1fr 60px; }
    .file-row { grid-template-columns: 1fr 60px; }
    .fh-size, .fh-date, .file-size, .file-date { display: none; }
    .file-actions { display: none; }
    .files-toolbar { padding: 10px 12px; }
    .btn-label { display: none; }

    /* Modals */
    .modal-content { width: 95%; max-width: 95vw; max-height: 90vh; border-radius: var(--radius-sm); }
    .modal-content.modal-small { max-width: 95vw; }
    .modal-header { padding: 12px 16px; }
    .modal-body { padding: 16px; }
    .modal-footer { padding: 10px 16px; }

    /* Video call: full screen */
    .modal-videocall { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: 100dvh; border-radius: 0; }
    .videocall-grid { grid-template-columns: 1fr; }

    /* Incoming call */
    .incoming-call { top: 8px; right: 8px; left: 8px; }
}

/* --- Small phones (≤480px) --- */
@media (max-width: 480px) {
    .sidebar { width: 100%; max-width: 100%; }

    .topbar { height: 44px; min-height: 44px; padding: 0 8px; }
    .topbar-channel-name { font-size: 14px; }
    .btn-icon { padding: 5px; }
    .btn-icon .material-icons-round { font-size: 20px; }

    .msg-messages { padding: 8px 8px 4px; }
    .msg-row { padding: 4px; gap: 8px; }
    .msg-row-compact { padding: 1px 4px 1px 40px; }
    .msg-avatar { width: 28px; height: 28px; font-size: 12px; }
    .msg-header { gap: 6px; }
    .msg-sender { font-size: 13px; }
    .msg-time { font-size: 10px; }

    .msg-input-area { padding: 6px 8px; }

    .msg-welcome { padding: 16px 4px 12px; }
    .msg-welcome-icon { width: 48px; height: 48px; font-size: 32px; }
    .msg-welcome-title { font-size: 15px; }
    .msg-welcome-hint { font-size: 13px; }

    .msg-date-sep { font-size: 11px; margin: 8px 0; }

    .sidebar-item { padding: 10px 14px; font-size: 15px; }
    .sidebar-browse-btn { padding: 10px 16px; font-size: 14px; }
    .sidebar-user { padding: 12px 14px; }
}

/* ═══ SAFE AREA (notch/home bar) ═══ */
@supports (padding: env(safe-area-inset-bottom)) {
    .msg-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    .sidebar {
        padding-top: env(safe-area-inset-top);
    }
    .sidebar-user {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}

/* ═══ TOUCH & SCROLL ═══ */
.msg-messages,
.sidebar-section,
.right-panel-body,
.modal-body,
.search-results,
.file-area {
    -webkit-overflow-scrolling: touch;
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 25;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.active { display: block; }

/* ═══ PAGE position relative for scroll btn ═══ */
.page { position: relative; }

/* ═══ SIDEBAR FILES BUTTON ═══ */
.sidebar-header-actions { display: flex; gap: 4px; align-items: center; }
.sidebar-files-btn { color: rgba(255,255,255,0.5) !important; }
.sidebar-files-btn:hover { color: rgba(255,255,255,0.8) !important; background: rgba(255,255,255,0.06); }

/* ═══ CATEGORIES ═══ */
.sidebar-category-header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px 6px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: rgba(255,255,255,0.4);
    letter-spacing: .5px;
    cursor: pointer;
    user-select: none;
    transition: background .15s;
    border-radius: var(--radius-sm);
    margin: 2px 8px;
}
.sidebar-category-header:hover { background: rgba(255,255,255,0.04); }
.sidebar-category-header.drag-over {
    background: var(--accent-bg);
    outline: 1px dashed var(--accent);
    outline-offset: -1px;
}
.sidebar-uncategorized-header { color: rgba(255,255,255,0.3); }
.collapse-icon {
    font-size: 16px !important;
    transition: transform .2s;
    cursor: pointer;
    color: rgba(255,255,255,0.3);
}
.sidebar-category-name { flex: 1; cursor: pointer; }
.sidebar-category-count {
    font-size: 10px;
    color: rgba(255,255,255,0.25);
    min-width: 16px;
    text-align: center;
}

/* Drag & drop */
.sidebar-item[draggable="true"] { cursor: grab; }
.sidebar-item[draggable="true"]:active { cursor: grabbing; }
.sidebar-item.dragging { opacity: 0.35; }

/* ═══ NEW CHAT DIALOG ═══ */
.newchat-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin: -20px -20px 16px;
    padding: 0 20px;
}
.newchat-tab {
    flex: 1;
    padding: 10px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    text-align: center;
    transition: color .2s, border-color .2s;
}
.newchat-tab:hover { color: var(--text); }
.newchat-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.newchat-tab-content { }

/* ═══ EMOJI PICKER ═══ */
.emoji-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    width: 320px;
    max-height: 360px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
}
.emoji-search-bar {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}
.emoji-search {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    outline: none;
}
.emoji-search:focus { border-color: var(--accent); }
.emoji-tabs {
    display: flex;
    overflow-x: auto;
    padding: 4px 8px;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
}
.emoji-tabs::-webkit-scrollbar { display: none; }
.emoji-cat-tab {
    padding: 4px 6px;
    font-size: 16px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0.5;
    transition: opacity .15s, background .15s;
    flex-shrink: 0;
}
.emoji-cat-tab:hover { opacity: 0.8; background: var(--bg3); }
.emoji-cat-tab.active { opacity: 1; background: var(--accent-bg); }
.emoji-grid {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 2px;
}
.emoji-item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background .1s;
    user-select: none;
}
.emoji-item:hover { background: var(--bg3); }
.emoji-section-label {
    width: 100%;
    font-size: 11px;
    font-weight: 600;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 8px 4px 4px;
}

/* ═══ FILE VIEW CONTROLS ═══ */
.file-view-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}
.file-view-btn { padding: 4px !important; }
.file-view-btn.active { color: var(--accent) !important; background: var(--accent-bg) !important; }
.file-size-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg3);
    border-radius: 2px;
    outline: none;
    margin-left: 8px;
    cursor: pointer;
}
.file-size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}
.file-size-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

/* ═══ FILE GRID VIEW ═══ */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--file-card-size, 160px), 1fr));
    gap: 12px;
    padding: 12px;
}
.file-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
}
.file-card:hover {
    background: var(--bg3);
    border-color: var(--text3);
    transform: translateY(-1px);
}
.file-card-preview {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg3);
    overflow: hidden;
}
.file-card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.file-card-preview .material-icons-round {
    font-size: 48px;
    color: var(--text3);
}
.file-card-name {
    padding: 8px 10px 4px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-card-meta {
    padding: 0 10px 8px;
    font-size: 11px;
    color: var(--text3);
    text-align: center;
}

/* ═══ OWN MESSAGES (right-aligned bubble) ═══ */
.msg-row.msg-own {
    flex-direction: row-reverse;
}
.msg-row.msg-own .msg-avatar {
    display: none;
}
.msg-row.msg-own .msg-body {
    align-items: flex-end;
}
.msg-row.msg-own .msg-header {
    justify-content: flex-end;
}
.msg-row.msg-own .msg-text {
    background: var(--accent-bg);
    border: 1px solid rgba(74, 144, 217, 0.2);
    padding: 6px 12px;
    border-radius: 12px 12px 2px 12px;
    display: inline-block;
    max-width: 100%;
}
.msg-row.msg-own.msg-row-compact {
    padding-left: 8px;
    padding-right: 8px;
    justify-content: flex-end;
}
.msg-row.msg-own .msg-actions {
    right: auto;
    left: 8px;
}

/* ═══ CHECKMARKS ═══ */
.msg-checkmark {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    vertical-align: middle;
}
.msg-checkmark .material-icons-round {
    font-size: 14px;
    color: var(--text3);
}
.msg-checkmark.read .material-icons-round {
    color: var(--text2);
}
.msg-checkmark.read-dm .material-icons-round {
    color: var(--accent);
}

/* ═══ REACTIONS ═══ */
.msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}
.msg-reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 13px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    color: var(--text);
    transition: background .15s;
}
.msg-reaction-chip:hover { background: var(--surface); }
.msg-reaction-chip.own {
    background: var(--accent-bg);
    border-color: var(--accent);
}

.reaction-picker {
    position: fixed;
    z-index: 100;
    display: flex;
    gap: 4px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.reaction-picker-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.reaction-picker-btn:hover { background: var(--bg3); }

/* ═══ REPLY PREVIEW (above input) ═══ */
.reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg3);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.reply-preview-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.reply-preview-sender {
    font-weight: 600;
    font-size: 12px;
    color: var(--accent);
}
.reply-preview-text {
    font-size: 12px;
    color: var(--text2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reply-preview-close {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    padding: 2px;
    display: flex;
}
.reply-preview-close:hover { color: var(--text); }
.reply-preview-close .material-icons-round { font-size: 18px; }

/* ═══ REPLY QUOTE (in message) ═══ */
.msg-reply-quote {
    padding: 4px 10px;
    margin-bottom: 4px;
    border-left: 3px solid var(--accent);
    background: var(--accent-bg);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    cursor: pointer;
    max-width: 400px;
}
.msg-reply-quote:hover { background: rgba(74, 144, 217, 0.18); }
.msg-reply-sender {
    font-weight: 600;
    font-size: 12px;
    color: var(--accent);
    display: block;
}
.msg-reply-text {
    font-size: 12px;
    color: var(--text2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

/* ═══ THREAD INDICATOR ═══ */
.msg-thread-indicator {
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.msg-thread-indicator:hover { text-decoration: underline; }

/* ═══ MESSAGE HIGHLIGHT (scroll-to) ═══ */
@keyframes msgHighlight {
    0%, 100% { background: transparent; }
    50% { background: var(--accent-bg); }
}
.msg-highlight {
    animation: msgHighlight 1s ease 2;
}

/* ═══ THREAD PANEL MESSAGES ═══ */
.thread-msg {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.thread-msg.msg-own {
    text-align: right;
}
.thread-msg .msg-text {
    display: inline-block;
}
.thread-msg.msg-own .msg-text {
    background: var(--accent-bg);
    padding: 4px 10px;
    border-radius: 10px 10px 2px 10px;
}
.thread-msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}
.thread-msg.msg-own .thread-msg-header {
    justify-content: flex-end;
}

/* ═══ VIDEO CALL — PiP (desktop) ═══ */
.videocall-pip {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 320px;
    height: 200px;
    background: #000;
    border-radius: 12px;
    z-index: 50;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
    display: flex;
    flex-direction: column;
}
.pip-video {
    flex: 1;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pip-video video { width: 100%; height: 100%; object-fit: cover; }
.pip-controls {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 6px;
    background: rgba(0,0,0,.7);
}
.pip-controls .videocall-btn {
    width: 32px;
    height: 32px;
}
.pip-controls .videocall-btn .material-icons-round {
    font-size: 18px;
}

/* ═══ VIDEO CALL — Top bar (mobile) ═══ */
.videocall-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 44px;
    background: var(--success);
    color: #fff;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.bar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
}
.bar-info .material-icons-round { font-size: 20px; }
.bar-info span:last-child { font-weight: 600; font-size: 14px; }
.bar-controls {
    display: flex;
    gap: 6px;
}
.bar-controls .videocall-btn {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,.2);
}
.bar-controls .videocall-btn .material-icons-round { font-size: 18px; }
.bar-controls .videocall-btn-hangup { background: var(--danger) !important; }

/* ═══ GLOBAL SEARCH MODAL ═══ */
.global-search-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    margin-bottom: 12px;
}
.global-search-input:focus { border-color: var(--accent); }
.global-search-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.global-search-tab {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text2);
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}
.global-search-tab:hover { color: var(--text); }
.global-search-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.global-search-results {
    max-height: 50vh;
    overflow-y: auto;
}
.global-search-section {
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text3);
    letter-spacing: .5px;
}
.global-search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background .1s;
}
.global-search-item:hover { background: var(--msg-hover); }
.global-search-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text2);
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}
.global-search-avatar img { width: 100%; height: 100%; object-fit: cover; }
.global-search-avatar .member-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
}
.global-search-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--text2);
    flex-shrink: 0;
}
.global-search-info { flex: 1; min-width: 0; }
.global-search-name { font-weight: 500; font-size: 14px; }
.global-search-meta { font-size: 12px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ═══ SIDEBAR ADMIN BUTTON ═══ */
.sidebar-admin-btn {
    color: var(--sidebar-text);
}
.sidebar-admin-btn:hover {
    color: #fff;
    background: var(--sidebar-hover);
}

/* ═══ NEWCHAT SEARCH INPUT ═══ */
.newchat-search-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    outline: none;
    margin-bottom: 8px;
}
.newchat-search-input:focus { border-color: var(--accent); }

/* ═══ RESPONSIVE — NEW FEATURES ═══ */

/* Tablet: emoji picker stays same, file grid adjusts */
@media (max-width: 900px) {
    .emoji-picker { width: 300px; }
}

/* Mobile (≤768px) */
@media (max-width: 768px) {
    /* Emoji picker */
    .emoji-picker {
        width: 280px;
        max-height: 320px;
    }
    .emoji-item {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    /* File view */
    .file-view-controls { gap: 2px; }
    .file-size-slider { width: 60px; }
    .file-grid { gap: 8px; padding: 8px; }
    .file-card-preview .material-icons-round { font-size: 36px; }
    .file-card-name { font-size: 11px; padding: 6px 6px 2px; }
    .file-card-meta { font-size: 10px; padding: 0 6px 6px; }

    /* Categories */
    .sidebar-category-header { padding: 8px 12px 8px 16px; font-size: 12px; }
    .sidebar-item[draggable="true"] { padding: 10px 14px; }

    /* PiP hidden on mobile, show bar instead */
    .videocall-pip { display: none !important; }

    /* Own messages */
    .msg-row.msg-own .msg-text { max-width: 85%; }
    .msg-reply-quote { max-width: 80vw; }
}

/* Small phones (≤480px) */
@media (max-width: 480px) {
    .emoji-picker {
        left: -40px;
        width: calc(100vw - 32px);
        max-height: 280px;
    }
    .emoji-item {
        width: 38px;
        height: 38px;
        font-size: 22px;
    }

    .file-grid { gap: 6px; padding: 6px; }
    .file-card-preview .material-icons-round { font-size: 32px; }

    .newchat-tabs { margin: -16px -16px 12px; padding: 0 16px; }

    .reaction-picker { gap: 2px; padding: 4px; }
    .reaction-picker-btn { width: 32px; height: 32px; font-size: 18px; }
}
