/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #252525;
    --text-primary: #e0e0e0;
    --text-secondary: #888;
    --accent: #4fc3f7;
    --accent-hover: #1976d2;
    --danger: #f44336;
    --success: #4caf50;
    --warning: #ff9800;
    --mention: #ffeb3b;
    --border: #444;
    --shadow: rgba(0,0,0,0.5);
    --msg-own-bg: #2b5278;
    --msg-other-bg: #2d2d2d;
    --msg-own-text: #fff;
    --msg-other-text: #e0e0e0;
    --msg-time: rgba(255,255,255,0.45);
    --sidebar-w: clamp(240px, 14vw, 320px);
}

body {
    font-family: 'Consolas', 'Courier New', monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-size: clamp(13px, 0.3vw + 8px, 15px);
}

/* === Auth === */
.auth-container {
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh; background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    padding: 20px;
}
.auth-box {
    background: var(--bg-tertiary); padding: 30px 20px; border-radius: 12px;
    border: 1px solid var(--border); width: 100%; max-width: 400px;
    box-shadow: 0 10px 40px var(--shadow);
}
.auth-box h2 { color: var(--accent); margin-bottom: 25px; text-align: center; font-size: 1.4em; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text-secondary); font-size: 0.9em; }
.form-group input {
    width: 100%; padding: 12px; background: var(--bg-primary); border: 1px solid var(--border);
    color: var(--text-primary); border-radius: 6px; font-family: inherit; font-size: 1rem;
}
.btn-primary {
    width: 100%; padding: 14px; background: #2196f3; border: none; color: white;
    border-radius: 6px; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 1em;
}
.error-message { color: var(--danger); margin-top: 15px; text-align: center; font-size: 0.9em; display: none; }

/* === Chat Layout === */
.chat-container { display: flex; height: 100vh; height: 100dvh; position: relative; }
.sidebar {
    width: var(--sidebar-w); background: var(--bg-secondary); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; transition: transform 0.3s ease; z-index: 100;
}
.sidebar-header { padding: 15px; border-bottom: 1px solid var(--border); }
.sidebar-header h1 { color: var(--accent); font-size: 1.2em; margin-bottom: 5px; }
.user-info { font-size: 0.75em; color: var(--text-secondary); display: flex; justify-content: space-between; align-items: center; }
.user-info-name { cursor: pointer; transition: color 0.2s; }
.user-info-name:hover { color: var(--accent); }
.profile-label { display: block; font-size: 0.85em; color: var(--text-secondary); margin: 10px 0 4px; }
.logout-btn {
    background: transparent; border: 1px solid var(--danger); color: var(--danger);
    padding: 2px 8px; border-radius: 4px; cursor: pointer; font-size: 0.85em;
}
.admin-btn {
    margin: 10px 15px; padding: 8px; background: var(--success); border: none;
    color: white; border-radius: 6px; cursor: pointer; display: none; font-family: inherit; font-size: 0.9em;
}
.dm-search-container { padding: 10px; border-bottom: 1px solid var(--border); }
.dm-search {
    width: 100%; padding: 8px; background: var(--bg-primary); border: 1px solid var(--border);
    color: var(--text-primary); border-radius: 6px; font-family: inherit;
}
.channel-list { flex: 1; overflow-y: auto; padding: 10px; }

/* === Channel Items === */
.channel {
    padding: 10px 12px;
    cursor: pointer;
    margin: 2px 0;
    border-radius: 6px;
    font-size: 0.95em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.channel:hover { background: #3d3d3d; }
.channel.active { background: #404040; border-left: 3px solid var(--accent); }

.channel-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.channel-ro-icon {
    margin-right: 4px;
    font-size: 0.8em;
    flex-shrink: 0;
}


@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.95); }
}

.dm-user { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-left: 3px solid transparent; }
.dm-user.active { background: #404040; border-left-color: #9c27b0; }
.dm-user-icon { font-size: 1.2em; }
.dm-user-name { flex: 1; font-weight: 500; }
.role-badge { font-size: 0.8em; margin-left: 4px; }
.empty-list { padding: 30px 20px; text-align: center; color: var(--text-secondary); font-size: 0.9em; }
.empty-list-icon { font-size: 2em; margin-bottom: 10px; opacity: 0.5; }

.main { flex: 1; display: flex; flex-direction: column; background: var(--bg-primary); min-width: 0; position: relative; }
.chat-tabs {
    display: flex; background: var(--bg-secondary); border-bottom: 1px solid var(--border);
    flex-shrink: 0; position: relative; overflow: hidden;
}
.chat-tab {
    flex: 1; padding: 14px 12px; background: transparent; border: none;
    color: var(--text-secondary); cursor: pointer; font-family: inherit;
    font-size: 0.9em; font-weight: 500; position: relative; z-index: 1;
    transition: color 0.2s ease, background 0.2s ease;
    -webkit-tap-highlight-color: transparent; user-select: none;
}
.chat-tab:hover { background: rgba(255,255,255,0.03); }
.chat-tab:active { background: rgba(255,255,255,0.06); }
.chat-tab.active { color: var(--accent); }
.tab-unread {
    display: none;
    background: var(--accent);
    color: #fff;
    font-size: 0.7em;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 9px;
    padding: 0 5px;
    margin-left: 4px;
    vertical-align: middle;
}
.tab-unread.visible { display: inline-block; }

.tab-indicator {
    position: absolute; bottom: 0; height: 3px; background: var(--accent);
    border-radius: 3px 3px 0 0; transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1; pointer-events: none;
}
.chat-header {
    padding: 12px 15px; background: var(--bg-tertiary); border-bottom: 1px solid var(--border);
    color: var(--accent); font-weight: bold; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.search-toggle-btn {
    margin-left: auto; background: none; border: none; color: var(--text-secondary);
    font-size: 1.1em; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.search-toggle-btn:active { background: rgba(255,255,255,0.1); }
.menu-toggle {
    display: none; background: transparent; border: none; color: var(--text-primary);
    font-size: 1.5rem; cursor: pointer; padding: 4px 8px; border-radius: 6px; flex-shrink: 0;
}
.menu-toggle:active { background: rgba(255,255,255,0.1); }
.messages { flex: 1; overflow-y: auto; padding: 8px 15px; scroll-behavior: smooth; min-height: 0; font-size: clamp(14px, 0.3vw + 9px, 16px); }

.message {
    display: flex;
    margin: 3px 0;
    padding: 0;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.message-own { justify-content: flex-start; }
.message-other { justify-content: flex-start; }

.message-centered { justify-content: center !important; }
.message-centered .message-bubble {
    max-width: 90%;
    background: linear-gradient(135deg, rgba(79, 195, 247, 0.06) 0%, rgba(79, 195, 247, 0.02) 100%) !important;
    color: var(--text-primary);
    text-align: center;
    border-radius: 12px;
    padding: 10px 18px;
    font-size: 0.95em;
    border: 1px solid rgba(79, 195, 247, 0.12);
    border-left: 3px solid var(--accent);
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    border-bottom-right-radius: 12px !important;
    border-bottom-left-radius: 12px !important;
}
.message-centered .message-user {
    display: block;
    font-size: 0.75em;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
    text-align: center;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.message-centered .message-text {
    font-size: 1em;
    line-height: 1.5;
    margin-bottom: 6px;
}
.message-centered .message-text a {
    color: var(--accent);
    text-decoration: underline;
}
.message-centered .message-time {
    text-align: right;
    font-size: 0.6em;
    opacity: 0.5;
    margin-top: 2px;
}
.message-centered .message-bubble { border-left: 3px solid var(--accent) !important; }

.message-bubble {
    max-width: 80%;
    padding: 7px 12px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.message-own .message-bubble {
    background: var(--msg-own-bg);
    color: var(--msg-own-text);
    border-bottom-left-radius: 4px;
}
.message-other .message-bubble {
    background: var(--msg-other-bg);
    color: var(--msg-other-text);
    border-bottom-left-radius: 4px;
}

.message-user {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 2px;
}
.message-text { margin-bottom: 3px; }
.message-text a { color: var(--accent); text-decoration: underline; word-break: break-all; }
.message-text strong { font-weight: 700; }
.message-text em { font-style: italic; }
.message-text s { opacity: 0.7; }
.message-text code {
    background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px;
    font-family: 'Consolas', monospace; font-size: 0.9em;
}
.message-text pre {
    background: rgba(0,0,0,0.3); padding: 8px; border-radius: 6px;
    overflow-x: auto; margin: 4px 0; font-size: 0.85em;
}
.message-text pre code { background: none; padding: 0; }
.message-text blockquote {
    border-left: 3px solid var(--accent); padding-left: 8px; margin: 4px 0;
    opacity: 0.8; font-style: italic;
}
.message-time {
    font-size: 0.65em;
    color: var(--msg-time);
    text-align: right;
    margin-top: 1px;
}


.mention { color: var(--mention); background: rgba(255, 235, 59, 0.15); padding: 1px 4px; border-radius: 4px; font-weight: bold; }
.mention.me { color: var(--warning); background: rgba(255, 152, 0, 0.2); }
.message.mentioned .message-bubble { border-left: 3px solid var(--warning); }

.channel-unread {
    background: #f44336 !important;
    color: white !important;
    padding: 2px 8px !important;
    border-radius: 10px !important;
    font-size: 0.75em !important;
    font-weight: bold !important;
    min-width: 20px !important;
    text-align: center !important;
    margin-left: 8px !important;
    flex-shrink: 0 !important;
    animation: pulse 2s infinite;
    display: inline-block !important;
}


.reply-quote {
    background: rgba(79, 195, 247, 0.08);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 4px 8px;
    margin-bottom: 4px;
    font-size: 0.85em;
}
.reply-quote-user {
    font-weight: 600;
    color: var(--accent);
    display: block;
    margin-bottom: 1px;
    font-size: 0.85em;
}
.reply-quote-text {
    color: var(--text-secondary);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-preview {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
}
.reply-preview-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.reply-preview-name {
    font-weight: 600;
    color: var(--accent);
    font-size: 0.8em;
    display: block;
}
.reply-preview-text {
    color: var(--text-secondary);
    font-size: 0.8em;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reply-preview-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
}
.reply-preview-close:hover { color: var(--text-primary); }

.input-area {
    padding: 8px 10px; background: var(--bg-tertiary); border-top: 1px solid var(--border);
    display: flex; gap: 6px; align-items: flex-end; position: relative; flex-shrink: 0;
}
.message-form { flex: 1; display: flex; gap: 6px; min-width: 0; align-items: flex-end; }
.message-form textarea {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    min-height: 42px;
    max-height: 150px;
    outline: none;
}
.message-form textarea:focus { border-color: var(--accent); }
.message-form textarea::placeholder { color: #666; }
.send-btn {
    padding: 10px 16px; background: #2196f3; border: none; color: white;
    border-radius: 12px; cursor: pointer; white-space: nowrap; font-size: 0.9em;
    min-height: 42px; flex-shrink: 0;
}

.record-btn, .emoji-btn, .image-btn {
    width: 42px; height: 42px; border-radius: 50% !important; display: flex; align-items: center;
    justify-content: center; font-size: 18px; padding: 0 !important; flex-shrink: 0; border: none; cursor: pointer;
}
.record-btn { background: var(--danger) !important; }
.emoji-btn { background: transparent !important; border: 1px solid var(--border) !important; }
.image-btn { background: #9c27b0 !important; }
.record-btn.recording { animation: pulse 1.5s infinite; }

audio { max-width: 100%; margin: 8px 0; }
.message-image { max-width: 100%; max-height: 250px; border-radius: 8px; cursor: pointer; margin: 8px 0; display: block; border: 1px solid var(--border); }

/* === EMOJI PICKER === */
.emoji-picker {
    position: absolute;
    bottom: 70px;
    left: 10px;
    width: 340px;
    height: 380px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 30px var(--shadow);
    display: none;
    flex-direction: column;
    z-index: 500;
    overflow: hidden;
}

.emoji-picker.show { display: flex; }

.emoji-picker-header {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.emoji-search {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
}

.emoji-search:focus { outline: none; border-color: var(--accent); }

.emoji-categories {
    display: flex;
    padding: 8px;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
    justify-content: space-around;
}

.emoji-category-btn {
    flex: 1;
    padding: 6px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-category-btn:hover, .emoji-category-btn.active { background: #404040; }

.emoji-grid {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    align-content: start;
}

.emoji-grid::-webkit-scrollbar { width: 6px; }
.emoji-grid::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

.emoji-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
    user-select: none;
}

.emoji-item:hover { background: #404040; transform: scale(1.1); }

/* === Mention Dropdown === */
.mention-dropdown {
    position: fixed; left: 50%; transform: translateX(-50%); width: 90%; max-width: 320px;
    background: var(--bg-secondary); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    z-index: 9999; overflow: hidden; animation: slideUpTelegram 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border);
}

@keyframes slideUpTelegram {
    from { opacity: 0; transform: translateX(-50%) translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@media (min-width: 769px) { .mention-dropdown { bottom: auto; top: auto; } }

@media (max-width: 768px) {
    .mention-dropdown {
        bottom: 80px !important; left: 10px !important; right: 10px !important;
        width: auto !important; max-width: none !important; transform: none !important;
        border-radius: 16px; max-height: 45vh;
    }
    @keyframes slideUpTelegram {
        from { opacity: 0; transform: translateY(30px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

.mention-item {
    display: flex; align-items: center; padding: 12px 16px; cursor: pointer;
    color: var(--text-primary); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.95rem; font-weight: 500; transition: background 0.15s ease;
    border-bottom: 1px solid rgba(255,255,255,0.05); min-height: 48px;
}
.mention-item:last-child { border-bottom: none; }
.mention-item:hover, .mention-item:active { background: rgba(79, 195, 247, 0.1); }
.mention-item::before { content: '@'; color: var(--accent); margin-right: 12px; font-weight: 600; font-size: 1rem; opacity: 0.8; }
.mention-item.selected { background: rgba(79, 195, 247, 0.15); }
.mention-dropdown::-webkit-scrollbar { width: 4px; }
.mention-dropdown::-webkit-scrollbar-thumb { background: #555; border-radius: 2px; }

/* === Context Menu & Modals === */
.context-menu {
    position: fixed; background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: 8px; padding: 6px 0; min-width: 180px; box-shadow: 0 4px 20px var(--shadow);
    z-index: 1000; display: none;
}
.context-menu-item { padding: 10px 18px; cursor: pointer; font-size: 0.95rem; }
.context-menu-item:hover { background: #404040; }
.context-menu-item.delete { color: var(--danger); }
.modal {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    z-index: 2000; align-items: center; justify-content: center; padding: 20px;
}
.modal.show { display: flex; }
.modal-content {
    background: var(--bg-secondary); padding: 25px; border-radius: 12px;
    width: 100%; max-width: 350px; border: 1px solid var(--border);
}
.modal-content h3 { margin-bottom: 15px; color: var(--accent); }
.modal-content input {
    width: 100%; padding: 10px; background: var(--bg-primary); border: 1px solid var(--border);
    color: var(--text-primary); border-radius: 6px; margin-bottom: 15px; font-size: 1rem;
}
.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }
.modal-buttons button { padding: 8px 16px; background: #2196f3; border: none; color: white; border-radius: 6px; cursor: pointer; }
.btn-cancel { background: #555 !important; }

.notification-hint {
    position: fixed; top: 10px; right: 10px; left: 10px; background: var(--bg-secondary);
    border: 1px solid var(--accent); padding: 15px; border-radius: 8px; z-index: 3000; display: none; max-width: none;
}
.notification-hint.show { display: block; animation: slideIn 0.3s ease; }
.notification-buttons { margin-top: 10px; display: flex; gap: 8px; }
.notification-buttons button { padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer; }
.notification-buttons button:first-child { background: var(--accent); color: white; }
.notification-buttons button:last-child { background: #555; color: white; }

.image-modal {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.95);
    z-index: 4000; align-items: center; justify-content: center; padding: 10px;
}
.image-modal.show { display: flex; }
.image-modal-content { max-width: 90vw; max-height: 90vh; border-radius: 8px; }
.image-modal-close {
    position: absolute; top: 15px; right: 15px; font-size: 2rem; color: white; cursor: pointer;
    background: rgba(0,0,0,0.5); border: none; width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}

.image-preview {
    position: fixed !important; bottom: 80px !important; left: 10px !important; right: 10px !important;
    width: auto !important; max-width: none !important; z-index: 700; background: var(--bg-secondary);
    border: 1px solid var(--border); border-radius: 12px; padding: 15px; box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}
.image-preview img { max-width: 100% !important; max-height: 200px !important; width: auto !important; display: block; margin: 0 auto 10px auto; border-radius: 8px; }
.image-preview-info { text-align: center; margin-bottom: 12px; color: var(--text-secondary); font-size: 0.9em; }
.image-preview-buttons { display: flex; gap: 10px; justify-content: center; }
.image-preview-buttons button { flex: 1; padding: 12px; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 1em; }
.image-preview-buttons .btn-send { background: var(--success); color: white; }
.image-preview-buttons .btn-cancel-preview { background: #555; color: white; }

/* === Message status checkmarks === */
.message-status {
    display: inline-flex; align-items: center; margin-left: 4px;
    vertical-align: middle; float: right;
}
.message-status svg { width: 16px; height: 16px; }
.message-status.read svg { color: #4fc3f7; }
.message-status.delivered svg, .message-status.sent svg { color: rgba(255,255,255,0.45); }

/* === Forwarded from === */
.forwarded-from {
    font-size: 0.78em; color: var(--accent); font-weight: 600;
    margin-bottom: 2px; font-style: italic;
    display: flex; align-items: center; gap: 4px;
}

/* === Message reactions === */
.message-reactions {
    display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px;
}
.reaction-badge {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 8px; border-radius: 12px; font-size: 0.8em;
    background: rgba(79,195,247,0.1); border: 1px solid rgba(79,195,247,0.2);
    cursor: pointer; transition: all 0.15s; user-select: none;
}
.reaction-badge:active { transform: scale(0.95); }
.reaction-badge.active {
    background: rgba(79,195,247,0.25); border-color: var(--accent);
}
.reaction-badge .reaction-count { font-size: 0.85em; color: var(--text-secondary); }
.reaction-badge.active .reaction-count { color: var(--accent); }

/* === Scroll-to-bottom FAB === */
.scroll-to-bottom-btn {
    position: absolute; bottom: 80px; right: 16px; z-index: 50;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--bg-secondary); border: 1px solid var(--border);
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s; color: var(--accent);
}
.scroll-to-bottom-btn:active { transform: scale(0.9); }
.scroll-badge {
    position: absolute; top: -4px; right: -4px;
    background: var(--danger); color: white; font-size: 0.65em;
    min-width: 18px; height: 18px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}

/* === Typing indicator === */
.typing-indicator {
    padding: 4px 15px; font-size: 0.8em; color: var(--accent);
    font-style: italic; flex-shrink: 0;
}

/* === Search bar === */
.search-bar {
    padding: 8px 12px; background: var(--bg-tertiary); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.search-bar input {
    flex: 1; padding: 8px; background: var(--bg-primary); border: 1px solid var(--border);
    color: var(--text-primary); border-radius: 8px; font-family: inherit; font-size: 0.9em;
}
.search-bar input:focus { outline: none; border-color: var(--accent); }
.search-count { font-size: 0.8em; color: var(--text-secondary); white-space: nowrap; }
.search-nav {
    background: none; border: none; color: var(--text-secondary);
    font-size: 1em; cursor: pointer; padding: 4px 6px;
}
.search-nav:active { color: var(--accent); }
.search-close {
    background: none; border: none; color: var(--text-secondary);
    font-size: 1.1em; cursor: pointer; padding: 4px;
}
.search-match .message-bubble { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-match.current .message-bubble { outline-color: var(--warning); }

/* === Highlight flash === */
@keyframes flashHighlight {
    0% { background: rgba(79,195,247,0.3); }
    100% { background: transparent; }
}
.highlight-flash { animation: flashHighlight 2s ease-out; }

/* === Reply quote clickable === */
.reply-quote { cursor: pointer; transition: background 0.15s; }
.reply-quote:active { background: rgba(79,195,247,0.15); }

/* === Message grouping === */
.message.consecutive { margin-top: 0 !important; }
.message.consecutive .message-user { display: none; }

/* === User avatars === */
.message-avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 0.85em;
    margin-top: 2px; overflow: hidden; font-family: -apple-system, sans-serif;
}
.message-avatar span {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
}
.message-avatar img { width: 100%; height: 100%; object-fit: cover; }
.message.consecutive .message-avatar { visibility: hidden; }

/* === Bottom sheet reactions === */
.bs-reaction-bar {
    display: flex; gap: 2px; padding: 12px 16px 8px; justify-content: center;
    flex-wrap: wrap;
}
.bs-reaction {
    width: 44px; height: 44px; border-radius: 50%; border: none;
    background: transparent; font-size: 24px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.bs-reaction:active { transform: scale(1.2); background: rgba(255,255,255,0.1); }
.bs-reaction-more { font-size: 18px; color: var(--text-secondary); font-weight: 600; }

/* === Link previews === */
.link-preview {
    margin-top: 6px; border: 1px solid var(--border); border-radius: 8px;
    overflow: hidden; max-width: 320px; cursor: pointer;
}
.link-preview-img { width: 100%; height: 120px; object-fit: cover; display: block; }
.link-preview-title { padding: 6px 8px 2px; font-weight: 600; font-size: 0.85em; line-height: 1.3; }
.link-preview-desc { padding: 0 8px 6px; font-size: 0.8em; color: var(--text-secondary); line-height: 1.3; }

/* === Select mode === */
.select-toolbar {
    display: flex; align-items: center; gap: 12px; flex: 1;
}
.select-toolbar-close {
    background: none; border: none; color: white; font-size: 1.3em; cursor: pointer; padding: 4px;
}
.select-count {
    font-size: 1.1em; font-weight: 600; flex: 1;
}
.select-toolbar-actions {
    display: flex; gap: 8px;
}
.select-action-btn {
    background: none; border: none; color: white; font-size: 1.2em;
    cursor: pointer; padding: 6px 10px; border-radius: 6px;
}
.select-action-btn:active { background: rgba(255,255,255,0.15); }
#chatHeaderNormal { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.select-mode .message { position: relative; cursor: pointer; }
.select-mode .message::before {
    content: ''; position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
    width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border);
    transition: all 0.15s; z-index: 5;
}
.select-mode .message.selected::before {
    background: var(--accent); border-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'%3E%3Cpolyline points='6 12 10 16 18 8'/%3E%3C/svg%3E");
    background-size: 14px; background-position: center; background-repeat: no-repeat;
}

/* === Per-channel mute === */
.channel-muted::after {
    content: '🔇'; font-size: 0.7em; margin-left: 4px;
}

/* === Forward channel list === */
.forward-channel-list {
    max-height: 50vh; overflow-y: auto; margin: 10px 0;
}
.forward-channel-item {
    padding: 12px 16px; cursor: pointer; border-radius: 8px;
    display: flex; align-items: center; gap: 10px;
    transition: background 0.15s;
}
.forward-channel-item:active { background: rgba(255,255,255,0.06); }
.forward-channel-item .fc-icon { font-size: 1.2em; }
.forward-channel-item .fc-name { flex: 1; font-size: 0.95em; }

/* === Read/Unread Messages === */
.unread-marker {
    text-align: center;
    margin: 15px 0;
    position: relative;
}

.unread-marker::before,
.unread-marker::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: var(--border);
}

.unread-marker::before { left: 0; }
.unread-marker::after { right: 0; }

.unread-marker span {
    background: var(--bg-secondary);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 500;
    display: inline-block;
    position: relative;
    z-index: 1;
}

.unread-badge {
    background: var(--danger);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7em;
    margin-left: 8px;
    animation: pulse 2s infinite;
}

.message.read { opacity: 0.7; }

.message:not(.read) .message-bubble {
    border-left: 3px solid var(--accent);
    animation: newMessage 0.3s ease;
}

@keyframes newMessage {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

/* === PULL TO REFRESH === */
.ptr-indicator {
    display: none; text-align: center; padding: 12px 0; color: var(--text-secondary);
    font-size: 0.85em; transition: opacity 0.2s;
}
.ptr-indicator.visible { display: block; }
.ptr-spinner {
    display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%; animation: ptr-spin 0.7s linear infinite;
    vertical-align: middle; margin-right: 6px;
}
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* === MOBILE ADAPTATION === */
@media (max-width: 768px) {
    body { font-size: 13px; }
    .chat-container { flex-direction: column; }

    .menu-toggle { display: block; }

    .sidebar {
        position: fixed; top: 0; left: 0; width: 280px; height: 100dvh; height: 100vh;
        border-right: 1px solid var(--border); border-bottom: none;
        transform: translateX(-100%); z-index: 1000;
        box-shadow: 4px 0 20px rgba(0,0,0,0.4);
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
        z-index: 999;
    }
    .sidebar-backdrop.show { display: block; }

    .channel-list { padding: 5px 10px; max-height: none; flex: 1; }
    .chat-container { height: 100dvh; }
    .main { flex: 1; min-height: 0; }

    /* === Telegram-style messages === */
    .messages { padding: 4px 6px; min-height: 0; font-size: 15px; }
    .message { margin: 1px 0; }
    .message-bubble {
        max-width: 88% !important; padding: 6px 10px !important;
        border-radius: 12px !important;
    }
    .message-own .message-bubble {
        background: #2b5278 !important;
        border-bottom-left-radius: 12px !important;
        border-bottom-right-radius: 4px !important;
    }
    .message-other .message-bubble {
        background: #2d2d2d !important;
        border-bottom-left-radius: 4px !important;
        border-bottom-right-radius: 12px !important;
    }
    .message-user { font-size: 0.78em; margin-bottom: 1px; }
    .message-time { font-size: 0.6em; }
    .message-image { max-height: 200px; border-radius: 10px; }

    /* === Telegram-style input area === */
    .input-area {
        padding: 6px 6px !important;
        gap: 4px !important;
        background: var(--bg-secondary) !important;
        border-top: none !important;
        align-items: flex-end !important;
    }
    .message-form {
        flex: 1; display: flex; gap: 0; min-width: 0;
        background: var(--bg-primary); border-radius: 22px;
        border: 1px solid var(--border); align-items: flex-end;
        padding: 2px 2px 2px 10px;
    }
    .message-form textarea {
        flex: 1; border: none !important; background: transparent !important;
        padding: 8px 4px !important; min-height: 38px !important;
        max-height: 120px !important; font-size: 16px !important;
        border-radius: 0 !important; outline: none;
    }
    .message-form textarea:focus { border-color: transparent !important; }
    .send-btn {
        width: 38px; height: 38px; min-height: 38px !important;
        padding: 0 !important; border-radius: 50% !important;
        font-size: 18px !important; display: flex; align-items: center;
        justify-content: center; flex-shrink: 0;
    }
    .record-btn, .emoji-btn, .image-btn {
        width: 38px !important; height: 38px !important; font-size: 18px !important;
    }
    .emoji-btn {
        border: none !important; background: transparent !important;
        font-size: 20px !important; border-radius: 50% !important;
    }
    .image-btn {
        background: transparent !important; border: none !important;
        font-size: 20px !important; border-radius: 50% !important;
    }
    .record-btn { background: transparent !important; border: none !important; font-size: 20px !important; }
    .record-btn.recording { background: var(--danger) !important; animation: pulse 1.5s infinite; }

    /* === Voice recording overlay === */
    .voice-overlay {
        display: none; position: fixed; inset: 0; z-index: 2000;
        background: rgba(0,0,0,0.85); flex-direction: column;
        align-items: center; justify-content: center; gap: 20px;
    }
    .voice-overlay.show { display: flex; }
    .voice-overlay-icon {
        width: 80px; height: 80px; border-radius: 50%; background: var(--danger);
        display: flex; align-items: center; justify-content: center;
        font-size: 36px; animation: voice-pulse 1.2s ease-in-out infinite;
    }
    @keyframes voice-pulse {
        0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(244,67,54,0.4); }
        50% { transform: scale(1.08); box-shadow: 0 0 0 20px rgba(244,67,54,0); }
    }
    .voice-overlay-timer { color: #fff; font-size: 1.8em; font-weight: 300; font-variant-numeric: tabular-nums; }
    .voice-overlay-hint {
        color: rgba(255,255,255,0.5); font-size: 0.9em;
        position: absolute; bottom: 15vh;
    }
    .voice-overlay-cancel {
        position: absolute; bottom: 8vh; display: flex; align-items: center;
        gap: 8px; color: rgba(255,255,255,0.6); font-size: 0.95em;
        transition: color 0.2s;
    }
    .voice-overlay-cancel.active { color: var(--danger); }
    .voice-overlay-cancel-icon {
        width: 40px; height: 40px; border-radius: 50%;
        background: rgba(255,255,255,0.1); display: flex; align-items: center;
        justify-content: center; font-size: 18px; transition: background 0.2s;
    }
    .voice-overlay-cancel.active .voice-overlay-cancel-icon { background: rgba(244,67,54,0.3); }

    /* === Swipe to reply indicator === */
    .swipe-reply-indicator {
        display: none; position: absolute; left: 8px; top: 50%;
        transform: translateY(-50%); color: var(--accent); font-size: 20px;
        opacity: 0; transition: opacity 0.15s; z-index: 5;
    }

    /* === Bottom sheet context menu === */
    .bottom-sheet-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
        z-index: 3000;
    }
    .bottom-sheet-backdrop.show { display: block; }
    .bottom-sheet {
        display: none; position: fixed; bottom: 0; left: 0; right: 0;
        background: var(--bg-secondary); border-radius: 16px 16px 0 0;
        z-index: 3001; padding: 8px 0; padding-bottom: env(safe-area-inset-bottom, 8px);
        max-height: 70vh; overflow-y: auto;
        animation: sheetSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }
    .bottom-sheet.show { display: block; }
    @keyframes sheetSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .bottom-sheet-handle {
        width: 36px; height: 4px; background: #555; border-radius: 2px;
        margin: 8px auto 12px;
    }
    .bottom-sheet-item {
        display: flex; align-items: center; gap: 14px;
        padding: 13px 20px; cursor: pointer; font-size: 1em;
        color: var(--text-primary); transition: background 0.15s;
    }
    .bottom-sheet-item:active { background: rgba(255,255,255,0.06); }
    .bottom-sheet-item .bs-icon { font-size: 1.2em; width: 24px; text-align: center; }
    .bottom-sheet-item.danger { color: var(--danger); }
    .bottom-sheet-sep { height: 1px; background: var(--border); margin: 4px 16px; }

    /* === Custom voice player === */
    .voice-player {
        display: flex; align-items: center; gap: 8px; padding: 4px 0;
        min-width: 200px;
    }
    .voice-play-btn {
        width: 36px; height: 36px; border-radius: 50%; border: none;
        background: var(--accent); color: #fff; font-size: 14px;
        display: flex; align-items: center; justify-content: center;
        cursor: pointer; flex-shrink: 0;
    }
    .voice-track { flex: 1; height: 32px; position: relative; cursor: pointer; }
    .voice-track-bg {
        position: absolute; top: 50%; left: 0; right: 0; height: 3px;
        background: rgba(255,255,255,0.15); border-radius: 2px; transform: translateY(-50%);
    }
    .voice-track-fill {
        position: absolute; top: 50%; left: 0; height: 3px;
        background: var(--accent); border-radius: 2px; transform: translateY(-50%);
        width: 0%; transition: width 0.1s linear;
    }
    .voice-track-dots {
        position: absolute; top: 0; left: 0; right: 0; bottom: 0;
        display: flex; align-items: center; justify-content: space-between;
    }
    .voice-dot {
        width: 3px; border-radius: 2px; background: rgba(255,255,255,0.2);
        transition: background 0.15s;
    }
    .voice-dot.active { background: var(--accent); }
    .voice-duration {
        font-size: 0.75em; color: var(--msg-time); min-width: 32px;
        text-align: right; font-variant-numeric: tabular-nums;
    }

    /* === Emoji bottom sheet === */
    .emoji-picker {
        position: fixed !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
        width: 100% !important; height: 45vh !important; border-radius: 16px 16px 0 0; z-index: 800;
        border: none; border-top: 1px solid var(--border);
        animation: sheetSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }
    .emoji-grid {
        grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)) !important;
        gap: 4px !important; padding: 8px !important;
    }
    .emoji-item { font-size: 26px !important; }
    .emoji-categories { padding: 6px !important; gap: 4px !important; }
    .emoji-category-btn { font-size: 20px !important; padding: 8px !important; }

    /* === Reply preview on mobile === */
    .reply-preview {
        border-radius: 10px 10px 0 0; margin: 0 6px;
        padding: 8px 12px; border: none;
        background: var(--bg-tertiary); border-bottom: 1px solid var(--border);
    }

    /* === Chat header mobile === */
    .chat-header { padding: 10px 12px !important; font-size: 0.95em; }
    .chat-header .menu-toggle { font-size: 1.3rem; }

    /* === Mobile message bubbles === */
    .message-own .message-bubble {
        border-bottom-left-radius: 12px !important;
        border-bottom-right-radius: 4px !important;
    }
    .message-other .message-bubble {
        border-bottom-left-radius: 4px !important;
        border-bottom-right-radius: 12px !important;
    }

    /* === Mobile reactions === */
    .message-reactions { margin-top: 3px; }
    .reaction-badge { padding: 2px 6px; font-size: 0.75em; }

    /* === Mobile status === */
    .message-status svg { width: 14px; height: 14px; }
}

@media (max-width: 380px) {
    .record-btn, .emoji-btn, .image-btn { width: 32px; height: 32px; font-size: 14px; }
    .chat-tab { padding: 8px; font-size: 0.8em; }
}

/* === DESKTOP SCALING === */
@media (min-width: 1440px) {
    .messages { padding: 10px 22px; }
    .message-bubble { max-width: 72%; }
    .input-area { padding: 10px 14px; gap: 8px; }
    .chat-header { padding: 14px 18px; }
    .modal-content { max-width: 380px; }
}

@media (min-width: 1920px) {
    :root { --sidebar-w: clamp(260px, 15vw, 340px); }
    .messages { padding: 12px 26px; }
    .message-bubble { max-width: 68%; padding: 8px 14px; }
    .input-area { padding: 12px 16px; gap: 10px; }
    .chat-header { padding: 16px 20px; }
    .modal-content { max-width: 400px; }
}

@media (min-width: 2560px) {
    :root { --sidebar-w: 340px; }
    .messages { padding: 14px 30px; }
    .message-bubble { max-width: 65%; padding: 10px 16px; }
    .input-area { padding: 14px 20px; }
}