:root, [data-theme="light"] {
    --primary: #2AABEE;
    --primary-dark: #2196D8;
    --primary-light: #dff0fd;
    --secondary: #8774E1;
    --success: #3FB950;
    --danger: #EF5350;
    --warning: #FFA726;
    --info: #42A5F5;
    --bg-primary: #ffffff;
    --bg-secondary: #f7f8fa;
    --bg-tertiary: #eef0f4;
    --bg-chat: #e6ebee;
    --bg-input: #f0f2f5;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --text-muted: #8696a0;
    --text-light: #fff;
    --border-color: #e3e6ea;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --msg-self: #d9fdd3;
    --msg-self-text: #111b21;
    --msg-other: #ffffff;
    --msg-other-text: #111b21;
    --hover: #f0f2f5;
    --active: #dff0fd;
    --online: #3FB950;
    --offline: #9e9e9e;
    --away: #FFA726;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, Tahoma, 'Noto Naskh Arabic', sans-serif;
    --transition: all 0.12s ease;
    --sidebar-width: 340px;
    --header-height: 56px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --accent-green: #50b5a0;
}

[data-theme="dark"] {
    --primary: #2AABEE;
    --primary-dark: #2196D8;
    --primary-light: #0a2b3d;
    --secondary: #9B8FFF;
    --success: #3FB950;
    --danger: #EF5350;
    --warning: #FFA726;
    --info: #42A5F5;
    --bg-primary: #111b21;
    --bg-secondary: #182229;
    --bg-tertiary: #1f2c33;
    --bg-chat: #0b141a;
    --bg-input: #1f2c33;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-muted: #667781;
    --text-light: #fff;
    --border-color: #313d45;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
    --msg-self: #005c4b;
    --msg-self-text: #e9edef;
    --msg-other: #1f2c33;
    --msg-other-text: #e9edef;
    --hover: #182229;
    --active: #0a2b3d;
    --online: #3FB950;
    --offline: #667781;
    --away: #FFA726;
}

[data-theme="midnight"] {
    --primary: #BB86FC;
    --primary-dark: #9C64E0;
    --primary-light: #1d1335;
    --secondary: #03DAC6;
    --success: #4CAF50;
    --danger: #CF6679;
    --warning: #FFB74D;
    --info: #64B5F6;
    --bg-primary: #121212;
    --bg-secondary: #1e1e2e;
    --bg-tertiary: #2a2a3e;
    --bg-chat: #0d0d1a;
    --bg-input: #2a2a3e;
    --text-primary: #E0E0E0;
    --text-secondary: #9E9E9E;
    --text-muted: #757575;
    --text-light: #fff;
    --border-color: #333346;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-md: 0 6px 20px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.6);
    --msg-self: #BB86FC;
    --msg-self-text: #000;
    --msg-other: #2a2a3e;
    --msg-other-text: #E0E0E0;
    --hover: #252538;
    --active: #1d1335;
    --online: #03DAC6;
    --offline: #757575;
    --away: #FFB74D;
}

[data-theme="mint"] {
    --primary: #00BFA5;
    --primary-dark: #009688;
    --primary-light: #E0F2F1;
    --secondary: #FF6F00;
    --success: #43A047;
    --danger: #E53935;
    --warning: #FFA000;
    --info: #1E88E5;
    --bg-primary: #ffffff;
    --bg-secondary: #f5faf9;
    --bg-tertiary: #e4f0ee;
    --bg-chat: #d7e8e4;
    --bg-input: #f0f7f6;
    --text-primary: #1a2e2a;
    --text-secondary: #5a7a72;
    --text-muted: #8aa69e;
    --text-light: #fff;
    --border-color: #c8dfda;
    --shadow: 0 2px 8px rgba(0,191,165,0.1);
    --shadow-md: 0 6px 20px rgba(0,191,165,0.15);
    --shadow-lg: 0 8px 30px rgba(0,191,165,0.2);
    --msg-self: #00BFA5;
    --msg-self-text: #ffffff;
    --msg-other: #ffffff;
    --msg-other-text: #1a2e2a;
    --hover: #eef6f4;
    --active: #E0F2F1;
    --online: #00BFA5;
    --offline: #8aa69e;
    --away: #FF6F00;
}

[dir="rtl"] {
    --font-family: Tahoma, 'Segoe UI', 'Noto Naskh Arabic', system-ui, sans-serif;
    text-align: right;
}

[dir="ltr"] {
    --font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    text-align: left;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    transition: var(--transition);
}

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

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }

/* Ripple effect */
.ripple {
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}
.ripple::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at var(--rx, 50%) var(--ry, 50%), rgba(255,255,255,0.3) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.ripple:active::after {
    opacity: 1;
    transition: 0s;
}
input, textarea { font-family: inherit; outline: none; border: none; }
ul { list-style: none; }

/* Login/Register */
.auth-container {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
    top: -200px;
    right: -200px;
    animation: float 20s infinite;
}

.auth-container::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: rgba(255,255,255,0.03);
    border-radius: 50%;
    bottom: -100px;
    left: -100px;
    animation: float 15s infinite reverse;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(30px, -30px) rotate(120deg); }
    66% { transform: translate(-20px, 20px) rotate(240deg); }
}

.auth-box {
    background: var(--bg-primary);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 0 0 1px rgba(255,255,255,0.05);
    position: relative;
    z-index: 1;
    animation: slideUp 0.5s cubic-bezier(0.2, 0, 0, 1);
}
[data-theme="dark"] .auth-box {
    box-shadow: 0 20px 60px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.03);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-logo {
    text-align: center;
    margin-bottom: 30px;
}

.auth-logo .logo-icon {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    font-size: 32px;
    color: white;
    box-shadow: 0 8px 25px rgba(42, 171, 238, 0.3);
}

.auth-logo h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 5px;
}

.auth-logo p {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    transition: var(--transition);
}

.form-group input:focus {
    border-color: var(--primary);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px rgba(42, 171, 238, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(42, 171, 238, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity:0.6;
    cursor:not-allowed;
    transform:none;
    box-shadow:none;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--primary);
    font-weight: 500;
    cursor: pointer;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-primary);
    overscroll-behavior: none;
    touch-action: manipulation;
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    position: relative;
    transition: var(--transition);
}

.sidebar-profile {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-primary);
    height: var(--header-height);
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}

.sidebar-user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 16px;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.sidebar-user-avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(42,171,238,0.25);
}
.profile-header .sidebar-user-avatar {
    width: 100px;
    height: 100px;
    margin: 0 auto;
}

.sidebar-profile-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-profile-info .sidebar-user-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-profile-info .sidebar-user-phone {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-profile-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.sidebar-profile-actions button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.sidebar-profile-actions button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.avatar-placeholder {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-search {
    padding: 8px 12px;
    background: var(--bg-primary);
}

.sidebar-search .search-box {
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    gap: 10px;
    transition: var(--transition);
}

.sidebar-search .search-box:focus-within {
    background: var(--bg-primary);
    border: 2px solid var(--primary);
    padding: 6px 10px;
}

.sidebar-search .search-box svg {
    color: var(--text-muted);
    font-size: 16px;
}

.sidebar-search .search-box input {
    flex: 1;
    background: none;
    font-size: 14px;
    color: var(--text-primary);
}

.sidebar-search .search-box input::placeholder {
    color: var(--text-muted);
}

.sidebar-tabs {
    display: flex;
    padding: 4px 8px;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

/* Feature 13: Chat Folders */
.folder-tabs {
    display: flex; overflow-x: auto; padding: 6px 8px; gap: 6px;
    border-bottom: 1px solid var(--border-color); scrollbar-width: none;
}
.folder-tabs::-webkit-scrollbar { display: none; }
.folder-tab {
    flex-shrink: 0; padding: 4px 14px; font-size: 12px; border-radius: 12px;
    background: var(--bg-secondary); color: var(--text-muted); cursor: pointer;
    white-space: nowrap; transition: var(--transition);
}
.folder-tab:hover { background: var(--hover); }
.folder-tab.active { background: var(--primary); color: white; }
.folder-add-btn { font-size: 16px; font-weight: bold; padding: 4px 10px; }

.sidebar-tab {
    flex: 1;
    padding: 8px 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    line-height: 1.2;
}

.sidebar-tab.active {
    color: var(--primary);
    background: var(--primary-light);
}

.sidebar-tab:hover {
    color: var(--text-primary);
    background: var(--hover);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    border-bottom: 1px solid var(--border-color);
    animation: fadeIn 0.3s ease;
    position: relative;
}

.chat-item:hover {
    background: var(--hover);
}

.chat-item.active {
    background: var(--active);
}

.chat-item:active {
    transform: scale(0.98);
    background: var(--active);
}

.chat-item .chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-item .chat-avatar-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
}

.chat-item .chat-info {
    flex: 1;
    min-width: 0;
}

.chat-item .chat-info .chat-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-item .chat-info .chat-name .time {
    font-weight: 400;
    font-size: 11px;
    color: var(--text-muted);
}

.chat-item .chat-info .chat-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.unread-badge {
    background: var(--primary);
    color: white;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--online);
    border: 2px solid var(--bg-primary);
    position: absolute;
    bottom: 0;
    right: 0;
}

.chat-item .avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 98;
    opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Main Chat Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-chat);
    position: relative;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-primary);
    height: var(--header-height);
    gap: 10px;
    animation: slideDown 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-header .back-btn {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
    flex-shrink: 0;
    background: var(--bg-secondary);
}
.chat-header .back-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
@media (max-width: 768px) {
    .chat-header .back-btn { display: flex; }
}

.chat-header .chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-header .chat-avatar-placeholder {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
}

.chat-header .chat-user-info {
    flex: 1;
    min-width: 0;
    padding: 2px 0;
}

.chat-header .chat-user-info .chat-user-name {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.3;
}

.chat-header .chat-user-info .chat-user-status {
    font-size: 12px;
    color: var(--text-secondary);
    transition: color 0.3s;
    line-height: 1.3;
}
.chat-header .chat-user-info .chat-user-status.typing {
    color: var(--primary);
    font-weight: 500;
}
.chat-header .chat-user-info .chat-user-bio {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
    line-height: 1.2;
    opacity: 0.8;
}
.chat-header .chat-user-info .chat-user-status .typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 4px;
}
.chat-header .chat-user-info .chat-user-status .typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary);
    animation: typingBounce 1.4s ease-in-out infinite;
}
.chat-header .chat-user-info .chat-user-status .typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.chat-header .chat-user-info .chat-user-status .typing-dots span:nth-child(3) { animation-delay: 0.32s; }

.chat-header .header-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    align-items: center;
}

.chat-header .header-actions button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
    flex-shrink: 0;
    background: none;
}

.chat-header .header-actions button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.chat-header .header-more-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.chat-header .header-more-btn:hover {
    background: var(--bg-tertiary);
}

@keyframes menuSlide {
    from { opacity: 0; transform: translateY(-6px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.header-menu {
    display: none;
    position: absolute;
    top: 100%;
    inset-inline-end: 0;
    z-index: 999;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 4px;
    min-width: 190px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    animation: menuSlide 0.12s ease;
    overflow: hidden;
}
.header-menu.show {
    display: block;
}
.header-menu .hm-item {
    padding: 10px 14px; border-radius: 8px; cursor: pointer;
    font-size: 13px; display: flex; align-items: center; gap: 10px;
    transition: background 0.15s; white-space: nowrap;
}
.header-menu .hm-item:hover { background: var(--hover); }
.header-menu .hm-item.hm-danger { color: var(--danger); }
.header-menu .hm-item svg { flex-shrink: 0; }

.chat-header .chat-user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: var(--bg-chat);
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(42,171,238,0.015) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(135,116,225,0.01) 0%, transparent 50%);
    background-attachment: fixed;
}
/* ─── Messages: Premium Telegram Style ─── */
@keyframes msgSlide {
    0% { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}

.message {
    max-width: 78%;
    padding: 6px 12px 5px;
    font-size: 14.5px;
    position: relative;
    animation: msgSlide 0.18s cubic-bezier(0.2, 0, 0, 1);
    line-height: 1.5;
    word-wrap: break-word;
    backdrop-filter: blur(2px);
    transition: box-shadow 0.15s;
}
.message.grouped { margin-top: 1px; }
.message.grouped.self { border-radius: 14px 4px 4px 14px; }
.message.grouped.other { border-radius: 4px 14px 14px 4px; }
[dir="rtl"] .message.grouped.self { border-radius: 4px 14px 14px 4px; }
[dir="rtl"] .message.grouped.other { border-radius: 14px 4px 4px 14px; }
.message.grouped .msg-content { box-shadow: none; }
.message:not(.grouped) { margin-top: 6px; }

.message.self {
    align-self: flex-end;
    background: var(--msg-self);
    color: var(--msg-self-text);
    border-radius: 14px 14px 4px 14px;
    margin-left: 56px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
[dir="rtl"] .message.self {
    margin-left: 0;
    margin-right: 56px;
}

.message.other {
    align-self: flex-start;
    background: var(--msg-other);
    color: var(--msg-other-text);
    border-radius: 4px 14px 14px 14px;
    margin-right: 56px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
[dir="rtl"] .message.other {
    margin-right: 0;
    margin-left: 56px;
}

.message.self::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -7px;
    width: 12px;
    height: 12px;
    background: var(--msg-self);
    border-radius: 0 0 12px 0;
}
.message.other::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -7px;
    width: 12px;
    height: 12px;
    background: var(--msg-other);
    border-radius: 0 0 0 12px;
}

.message .msg-content {
    position: relative;
}

.message .msg-text {
    margin-bottom: 1px;
}

.message .msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 1px;
    line-height: 1;
    direction: ltr;
    padding-right: 2px;
}

.message.self .msg-meta {
    color: rgba(0,0,0,0.45);
}
[data-theme="dark"] .message.self .msg-meta {
    color: rgba(255,255,255,0.4);
}

.message .msg-meta .seen-icon {
    font-size: 13px;
    line-height: 1;
}
.message .msg-meta .seen-icon.delivered {
    color: var(--text-muted);
}
.message .msg-meta .seen-icon.seen {
    color: var(--primary);
}

.message .msg-video {
    cursor: pointer;
    border-radius: 10px;
    overflow: hidden;
    max-width: 280px;
    background: #000;
    margin: -2px -8px 2px;
}
.msg-video .video-thumb {
    position: relative;
    line-height: 0;
}
.msg-video .video-thumb video {
    width: 100%;
    max-height: 220px;
    display: block;
    background: #111;
}
.msg-video .video-play-btn {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .2s;
    pointer-events: none;
}
.msg-video:hover .video-play-btn { opacity: 0.7; }
.msg-video .video-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-secondary);
    font-size: 12px;
    color: var(--text-muted);
    gap: 8px;
}
.msg-video .video-bar .file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.message .msg-image {
    max-width: 280px;
    border-radius: 10px;
    cursor: pointer;
    display: block;
    margin: -2px -8px 2px;
}

.message .msg-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    margin: 2px 0;
}

.message.self .msg-file {
    background: rgba(255,255,255,0.15);
}

.message .msg-file:hover { background: var(--bg-tertiary); }

.message .msg-file .file-icon { font-size: 26px; }
.message .msg-file .file-info { flex: 1; }
.message .msg-file .file-info .file-name { font-size: 13px; font-weight: 500; }
.message .msg-file .file-info .file-size { font-size: 11px; color: var(--text-muted); }
.message.self .msg-file .file-info .file-size { color: rgba(255,255,255,0.6); }

/* Telegram bubble tail effect */
.message.self::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -7px;
    width: 12px;
    height: 12px;
    background: var(--msg-self);
    border-radius: 0 0 12px 0;
}

.message.other::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -7px;
    width: 12px;
    height: 12px;
    background: var(--msg-other);
    border-radius: 0 0 0 12px;
}

.message + .message.self { margin-top: 2px; }
.message + .message.other { margin-top: 2px; }
.message.self + .message.self { margin-top: 1px; }
.message.other + .message.other { margin-top: 1px; }

/* Message 3-dot menu */
.message .msg-menu-wrap {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.15s;
}

.message:hover .msg-menu-wrap { opacity: 1; }

[dir="rtl"] .message .msg-menu-wrap { left: 0; right: auto; }

.message .msg-menu-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
    color: var(--text-secondary);
    -webkit-tap-highlight-color: transparent;
}

.message .msg-menu-btn:hover { background: var(--primary-light); }

.msg-menu-dropdown {
    display: none;
    position: absolute;
    top: 26px;
    right: 0;
    background: var(--bg-primary);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    min-width: 170px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    border: 1px solid var(--border-color);
    animation: menuSlide 0.12s ease;
}

[dir="rtl"] .msg-menu-dropdown { left: 0; right: auto; }
.msg-menu-dropdown.show { display: block; }

.msg-menu-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.12s;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.msg-menu-item:hover { background: var(--bg-secondary); }
.msg-menu-item-danger { color: var(--danger); }

/* Reaction picker - Telegram style */
.reaction-picker {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: var(--bg-primary);
    border-radius: 24px;
    padding: 6px 10px;
    display: flex;
    gap: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 10;
    opacity: 0;
    transform: translateY(8px) scale(0.9);
    transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: none;
    margin-bottom: 6px;
    white-space: nowrap;
}
.reaction-picker.from-longpress {
    transform: translateY(0) scale(0.9);
    bottom: calc(100% + 8px);
}

[dir="rtl"] .reaction-picker {
    right: auto;
    left: 0;
}

.reaction-picker.active {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.reaction-picker span {
    font-size: 24px;
    padding: 4px;
    cursor: pointer;
    border-radius: 50%;
    transition: transform 0.15s, background 0.1s;
    line-height: 1;
}
.reaction-picker span:hover {
    transform: scale(1.3);
    background: var(--bg-secondary);
}

/* Reaction badges on messages */
.msg-reactions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    margin-bottom: -2px;
    flex-wrap: wrap;
}
.reaction-badge {
    font-size: 14px;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1px 6px;
    cursor: pointer;
    transition: transform 0.1s;
    line-height: 1.6;
    border: 1px solid var(--border-color);
}
.reaction-badge:hover {
    transform: scale(1.15);
    background: var(--primary-light);
}

/* For self messages, show picker on the right */
.message.self .reaction-picker {
    right: 0;
    left: auto;
}

[dir="rtl"] .message.self .reaction-picker {
    left: 0;
    right: auto;
}

/* For other messages, show picker on the left */
.message.other .reaction-picker {
    left: 0;
    right: auto;
}

[dir="rtl"] .message.other .reaction-picker {
    right: 0;
    left: auto;
}

.message .msg-edited {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 400;
}
.message.self .msg-edited { color: rgba(255,255,255,0.5); }

.message .msg-sender-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 2px;
}

.message .msg-voice {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
    cursor: pointer;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.message .msg-voice .voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
}

.message .msg-voice .voice-wave {
    flex: 1;
    height: 30px;
    display: flex;
    align-items: center;
    gap: 2px;
}

.message .msg-voice .voice-wave span {
    width: 3px;
    height: 16px;
    background: var(--primary);
    border-radius: 2px;
    animation: voiceWave 0.8s infinite alternate;
}
.message.self .msg-voice .voice-wave span { background: rgba(255,255,255,0.6); }

.message .msg-voice .voice-wave span:nth-child(2) { animation-delay: 0.1s; height: 20px; }
.message .msg-voice .voice-wave span:nth-child(3) { animation-delay: 0.2s; height: 24px; }
.message .msg-voice .voice-wave span:nth-child(4) { animation-delay: 0.3s; height: 12px; }
.message .msg-voice .voice-wave span:nth-child(5) { animation-delay: 0.4s; height: 18px; }

@keyframes voiceWave {
    0% { height: 8px; }
    100% { height: 24px; }
}

.message .msg-voice .voice-duration {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.message.self .msg-voice .voice-duration { color: rgba(255,255,255,0.7); }

.message .msg-reply {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary);
    padding: 5px 8px;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 12px;
}

[dir="rtl"] .message .msg-reply {
    border-left: none;
    border-right: 3px solid var(--primary);
}

.message.self .msg-reply {
    background: rgba(255,255,255,0.12);
    border-left-color: rgba(255,255,255,0.4);
}
[dir="rtl"] .message.self .msg-reply { border-right-color: rgba(255,255,255,0.4); border-left: none; }

.message .msg-reply .reply-sender {
    font-weight: 600;
    color: var(--primary);
}
.message.self .msg-reply .reply-sender { color: rgba(255,255,255,0.9); }

.message .msg-deleted {
    font-style: italic;
    color: var(--text-muted);
    text-align: center;
    padding: 8px;
}

/* Upload progress message */
.message.uploading {
    align-self: flex-end;
    background: var(--msg-self);
    color: var(--msg-self-text);
    border-radius: 16px 16px 4px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 160px;
}

.upload-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Emoji picker */
.emoji-btn {
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.emoji-btn:hover { background: var(--hover); }

.emoji-picker {
    display: none;
    position: absolute;
    bottom: 64px;
    right: 8px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    z-index: 100;
    max-height: 280px;
    overflow-y: auto;
    animation: menuSlide 0.12s ease;
}
[dir="rtl"] .emoji-picker { left: 8px; right: auto; }
.emoji-picker.active { display: block; }
.emoji-picker-content {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
}
.emoji-picker-content span {
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    text-align: center;
    border-radius: 6px;
    transition: background 0.1s;
}
.emoji-picker-content span:hover { background: var(--hover); transform: scale(1.2); }

.upload-progress-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.date-separator {
    text-align: center;
    margin: 16px 0;
    position: relative;
}

.date-separator span {
    background: var(--bg-tertiary);
    padding: 4px 14px;
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Attachment Menu */
.attach-menu {
    position: absolute;
    bottom: 56px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: none;
    z-index: 100;
    min-width: 140px;
    overflow: hidden;
}

.attach-menu.active { display: block; animation: menuSlide 0.15s ease; }

.attach-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 14px;
    font-weight: 500;
}

.attach-item:hover { background: var(--hover); }

/* Voice Recording Panel - Telegram style */
.voice-recording-panel {
    display: none;
    position: absolute;
    bottom: 56px;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
    padding: 14px 16px;
    align-items: center;
    gap: 12px;
    z-index: 10;
    animation: menuSlide 0.15s ease;
}
.voice-recording-panel.active {
    display: flex;
}

/* Animated recording indicator */
.voice-rec-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    animation: voicePulse 1s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes voicePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

.voice-cancel-btn,
.voice-stop-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 24px;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}
.voice-cancel-btn:hover { background: var(--hover); }
.voice-stop-btn {
    background: var(--danger);
    color: white;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.voice-stop-btn:hover { opacity: 0.85; }
.voice-recording-time {
    font-size: 18px;
    font-weight: 600;
    direction: ltr;
    font-variant-numeric: tabular-nums;
    color: var(--danger);
    min-width: 50px;
}
.voice-recording-wave {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 3px;
    height: 32px;
}
.voice-recording-wave span {
    flex: 1;
    background: var(--danger);
    border-radius: 2px;
    animation: waveAnim 0.5s ease-in-out infinite;
    height: 4px;
    transform-origin: bottom;
}
.voice-recording-wave span:nth-child(1) { animation-delay: 0s; }
.voice-recording-wave span:nth-child(2) { animation-delay: 0.1s; }
.voice-recording-wave span:nth-child(3) { animation-delay: 0.2s; }
.voice-recording-wave span:nth-child(4) { animation-delay: 0.3s; }
.voice-recording-wave span:nth-child(5) { animation-delay: 0.4s; }
@keyframes waveAnim {
    0%, 100% { height: 4px; }
    50% { height: 28px; }
}

.ai-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.ai-image { background: #fce4ec; }
.ai-file { background: #e3f2fd; }
.ai-voice { background: #e8f5e9; }

/* Voice recording UI */
.voice-recording-bar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--danger);
    color: white;
    border-radius: 24px;
    flex: 1;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.voice-recording-bar .vr-icon { font-size: 18px; }
.voice-recording-bar .vr-timer { font-size: 14px; font-weight: 600; direction: ltr; }
.voice-recording-bar .vr-cancel {
    margin-right: auto;
    padding: 4px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 12px;
    cursor: pointer;
}

/* ─── Format Bar ─── */
.format-bar {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 2px 0;
    background: transparent;
}
.format-bar span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 26px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    transition: all 0.1s;
}
.format-bar span:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.format-bar span b { font-weight: 700; }
.format-bar span i { font-style: italic; }
.format-bar span code { font-family: monospace; font-size: 11px; }
.format-bar span s { text-decoration: line-through; }

/* Chat Input */
.chat-input-area {
    padding: 4px 10px;
    padding-bottom: max(4px, env(safe-area-inset-bottom, 4px));
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.chat-input-area .reply-preview {
    position: absolute;
    bottom: 100%;
    left: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border-radius: 10px 10px 0 0;
    font-size: 12px;
    border-left: 3px solid var(--primary);
    gap: 8px;
    animation: menuSlide 0.1s ease;
}
[dir="rtl"] .chat-input-area .reply-preview { border-left: none; border-right: 3px solid var(--primary); }

.reply-preview-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.reply-preview-sender {
    font-weight: 600;
    color: var(--primary);
    font-size: 11px;
}

.reply-preview-text {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.reply-preview-close {
    background: none;
    color: var(--text-muted);
    font-size: 16px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.reply-preview-close:hover { background: var(--hover); }

.chat-input-area .input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.chat-input-area .input-actions {
    display: flex;
    gap: 4px;
}

.chat-input-area .input-actions button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    transition: var(--transition);
    font-size: 22px;
    background: none;
}

.chat-input-area .input-actions button:hover {
    background: var(--bg-tertiary);
    transform: scale(1.1);
}

.chat-input-area .input-box {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border-radius: 24px;
    padding: 2px 14px;
    border: 1.5px solid transparent;
    transition: border-color 0.15s;
}

.chat-input-area .input-box:focus-within {
    border-color: var(--primary);
}

.chat-input-area .input-box input {
    flex: 1;
    background: none;
    padding: 6px 0;
    font-size: 14px;
    color: var(--text-primary);
}

.chat-input-area .input-box input::placeholder {
    color: var(--text-muted);
}

.chat-input-area .send-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(42,171,238,0.25);
}

.chat-input-area .send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(42, 171, 238, 0.35);
}

.chat-input-area .send-btn:active {
    transform: scale(0.92);
}

/* Image lightbox */
.lightbox-modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.92);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
}
.lightbox-modal .lb-close {
    position: absolute; top: 12px; right: 16px;
    background: none; border: none;
    color: white; font-size: 36px;
    cursor: pointer; z-index: 1;
    line-height: 1;
}
.lightbox-modal .lb-img-wrap {
    max-width: 94vw; max-height: 92vh;
    display: flex; align-items: center; justify-content: center;
}
.lightbox-modal .lb-img-wrap img {
    max-width: 100%; max-height: 92vh;
    border-radius: 6px;
    box-shadow: 0 8px 40px rgba(0,0,0,.5);
}

/* Video player modal */
.video-player-modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.9);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
}
.video-player-modal .vp-container {
    position: relative;
    width: 90%; max-width: 800px;
}
.video-player-modal .vp-container video {
    width: 100%; max-height: 80vh;
    border-radius: 8px;
}
.video-player-modal .vp-close {
    position: absolute; top: -40px; right: 0;
    background: none; border: none;
    color: white; font-size: 32px;
    cursor: pointer;
    line-height: 1;
}

/* Selection mode (Telegram-style) */
.selection-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    animation: slideDown 0.12s ease;
}
.selection-bar .sel-count {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
}
.selection-bar .sel-btn {
    padding: 6px 12px;
    border-radius: 8px;
    background: var(--bg-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.selection-bar .sel-btn:disabled { opacity: 0.4; cursor: default; }
.selection-bar .sel-btn:hover:not(:disabled) { background: var(--hover); }
.selection-bar .sel-danger { color: var(--danger); }
.selection-bar .sel-close {
    font-size: 18px;
    padding: 4px 8px;
    color: var(--text-muted);
    cursor: pointer;
}
.message.select-mode {
    cursor: pointer;
    transition: padding-left 0.15s;
}
.message .msg-check {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    transition: all 0.15s;
    margin: 0 4px 0 0;
}
[dir="rtl"] .message .msg-check { margin: 0 0 0 4px; }
.message.selected .msg-check {
    background: var(--primary);
    border-color: var(--primary);
}
.message.selected {
    background: var(--primary-light) !important;
}
[data-theme="dark"] .message.selected {
    background: rgba(42,171,238,0.15) !important;
}

/* Encryption notice */
.encryption-notice {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 10px 20px 16px;
    direction: ltr;
}
[dir="rtl"] .encryption-notice { direction: rtl; }
.encryption-notice span { margin: 0 4px; }

/* Forwarded message */
.msg-forwarded {
    font-size: 11px;
    color: var(--primary);
    font-weight: 500;
    margin-bottom: 2px;
    direction: ltr;
}
[dir="rtl"] .msg-forwarded { direction: rtl; }

/* Chat search bar */
.chat-search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    animation: slideDown 0.15s ease;
}
.chat-search-bar input {
    flex: 1;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
}
.chat-search-bar input:focus { border-color: var(--primary); outline: none; }
.btn-sm {
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-sm:hover { background: var(--hover); }

/* Profile modal (Telegram-style) */
.profile-modal { padding: 0 0 16px; }
.profile-modal .pm-header {
    display: flex; flex-direction: column; align-items: center;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-color);
}
.profile-modal .pm-avatar {
    width: 72px; height: 72px; border-radius: 50%; overflow: hidden;
    margin-bottom: 10px;
}
.profile-modal .pm-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-modal .pm-avatar-placeholder {
    width: 100%; height: 100%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 28px; font-weight: 600;
    border-radius: 50%;
}
.profile-modal .pm-name { font-size: 18px; font-weight: 700; }
.profile-modal .pm-status { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.profile-modal .pm-tabs {
    display: flex; padding: 0; border-bottom: 1px solid var(--border-color);
}
.profile-modal .pm-tab {
    flex: 1; padding: 10px; font-size: 13px; font-weight: 500;
    color: var(--text-muted); text-align: center;
    border-bottom: 2px solid transparent; cursor: pointer;
    transition: var(--transition);
}
.profile-modal .pm-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.profile-modal .pm-tab:hover { background: var(--hover); }
.profile-modal .pm-content {
    padding: 12px; max-height: 300px; overflow-y: auto;
    display: flex; flex-wrap: wrap; gap: 4px;
}
.profile-modal .pm-media-item {
    width: 80px; height: 80px; object-fit: cover; border-radius: 6px;
    cursor: pointer; transition: transform 0.15s;
}
.profile-modal .pm-media-item:hover { transform: scale(1.05); }
.profile-modal .pm-file-item {
    width: 100%; padding: 8px 10px; font-size: 13px;
    background: var(--bg-secondary); border-radius: 8px;
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: background 0.15s;
}
.profile-modal .pm-file-item:hover { background: var(--hover); }
.profile-modal .pm-file-size { margin-left: auto; color: var(--text-muted); font-size: 11px; }
.profile-modal .pm-link-item {
    width: 100%; padding: 8px 10px; font-size: 12px;
    background: var(--bg-secondary); border-radius: 8px;
    cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: background 0.15s;
}
.profile-modal .pm-link-item:hover { background: var(--hover); }
.profile-modal .pm-empty { width: 100%; text-align: center; color: var(--text-muted); font-size: 14px; padding: 20px; }
.profile-modal-wrap { max-width: 380px !important; padding: 0 !important; overflow: hidden !important; }

/* Skeleton loading */
@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}
.skeleton {
    background: var(--bg-tertiary);
    background-image: linear-gradient(90deg, var(--bg-tertiary) 0px, var(--hover) 40px, var(--bg-tertiary) 80px);
    background-size: 200px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
}
.skeleton-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
}
.skeleton-line {
    height: 12px;
    width: 100%;
    margin: 4px 0;
}
.skeleton-line:last-child { width: 60%; }
.skeleton-chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}
.skeleton-chat-item .skeleton-text {
    flex: 1;
}
.skeleton-msg {
    padding: 14px 18px;
    margin: 4px 0;
    min-height: 40px;
}
.skeleton-msg.self {
    align-self: flex-end;
    border-radius: 16px 16px 4px 16px;
    margin-left: 48px;
}
.skeleton-msg.other {
    align-self: flex-start;
    border-radius: 4px 16px 16px 16px;
    margin-right: 48px;
}

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 12px;
    padding: 20px;
}

.empty-state .empty-icon {
    font-size: 64px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
    font-weight: 600;
}

.empty-state p {
    font-size: 14px;
    text-align: center;
    color: var(--text-muted);
    max-width: 260px;
    line-height: 1.6;
}

/* New chat floating button (Telegram-style) */
.new-chat-btn {
    position: absolute;
    bottom: 20px;
    right: 16px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #1a8cd8);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    box-shadow: 0 4px 16px rgba(42,171,238,0.4);
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s;
    z-index: 5;
}
.new-chat-btn:hover {
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 8px 28px rgba(42,171,238,0.5);
}
.new-chat-btn:active {
    transform: scale(0.92);
}
    [dir="rtl"] .new-chat-btn {
        right: auto;
        left: 16px;
    }

/* Sidebar toggle for mobile */
.sidebar-toggle-btn {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
    background: var(--bg-secondary);
}
.sidebar-toggle-btn:hover {
    background: var(--bg-tertiary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-primary);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--border-color);
}

@keyframes modalIn {
    0% { opacity: 0; transform: scale(0.9) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-header .close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-header .close-btn:hover {
    background: var(--hover);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #e53935;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: var(--bg-primary);
    box-shadow: var(--shadow-lg);
    z-index: 999;
    transition: right 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow-y: auto;
}

[dir="rtl"] .settings-panel {
    right: auto;
    left: -400px;
}

.settings-panel.active {
    right: 0;
}

[dir="rtl"] .settings-panel.active {
    left: 0;
    right: auto;
}

.settings-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--header-height);
    background: var(--bg-primary);
}

.settings-header button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
    font-size: 18px;
}

.settings-header button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.settings-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.settings-item:hover {
    background: var(--hover);
}

.settings-item .item-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.settings-item .item-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.settings-item .item-text .item-title {
    font-weight: 500;
    font-size: 14px;
}

.settings-item .item-text .item-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.toggle {
    width: 44px;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: var(--transition);
}

.toggle.active {
    background: var(--primary);
}

.toggle::after {
    content: '';
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

[dir="rtl"] .toggle::after {
    left: auto;
    right: 2px;
}

.toggle.active::after {
    left: 22px;
}

[dir="rtl"] .toggle.active::after {
    left: auto;
    right: 22px;
}

/* Profile Page */
.profile-header {
    text-align: center;
    padding: 30px 24px;
    border-bottom: 1px solid var(--border-color);
}

.profile-header .profile-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 16px;
    cursor: pointer;
    border: 3px solid var(--primary);
    padding: 3px;
}

.profile-header .profile-avatar-placeholder {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 36px;
    margin: 0 auto 16px;
    cursor: pointer;
    border: 3px solid var(--primary);
}

.profile-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.profile-header p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* Link preview card */
.link-preview {
    margin-top: 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.link-preview:hover {
    border-color: var(--primary);
}

.link-preview .lp-img-wrap {
    width: 100%;
    max-height: 200px;
    overflow: hidden;
    background: var(--hover);
}

.link-preview .lp-img {
    width: 100%;
    height: auto;
    max-height: 200px;
    object-fit: cover;
    display: block;
}

.link-preview .lp-body {
    padding: 10px 12px;
}

.link-preview .lp-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--primary);
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.link-preview .lp-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.link-preview .lp-domain {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: lowercase;
}

.message.self .link-preview {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.15);
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
        --header-height: 52px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 360px;
        z-index: 100;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: none !important;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    [dir="rtl"] .sidebar {
        left: 0;
        right: auto;
        box-shadow: -2px 0 12px rgba(0,0,0,0.15);
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .sidebar:not(.mobile-open) {
        transform: translateX(-100%);
    }
    [dir="rtl"] .sidebar:not(.mobile-open) {
        transform: translateX(100%);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        width: 100%;
    }

    .main-content.active {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 100;
    }

    .chat-header .back-btn {
        display: flex;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        font-size: 20px;
        -webkit-tap-highlight-color: transparent;
    }

    .message {
        max-width: 90%;
    }

    .message.self {
        max-width: 85%;
    }

    /* Always show 3-dot menu on mobile (touch devices) */
    .message .msg-menu-btn {
        opacity: 0.6;
    }

    .message .msg-menu-wrap {
        top: 4px;
        right: 4px;
    }

    [dir="rtl"] .message .msg-menu-wrap {
        left: 4px;
        right: auto;
    }

    .msg-menu-btn {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .msg-menu-dropdown {
        min-width: 160px;
        font-size: 14px;
    }

    .msg-menu-item {
        padding: 12px 14px;
    }

    /* Larger touch targets */
    .chat-header .header-actions button,
    .sidebar-header .header-actions button {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    .chat-input-area .input-actions button {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }

    .chat-input-area .send-btn {
        width: 48px;
        height: 48px;
    }

    .chat-input-area .input-box {
        padding: 8px 16px;
    }

    .chat-input-area .input-box input {
        font-size: 16px; /* prevents iOS zoom on focus */
        padding: 8px 0;
    }

    .chat-item {
        padding: 14px 16px;
    }

    .chat-item .chat-avatar,
    .chat-item .chat-avatar-placeholder {
        width: 52px;
        height: 52px;
        font-size: 20px;
    }

    .chat-item .chat-info .chat-name {
        font-size: 16px;
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }

    [dir="rtl"] .settings-panel {
        left: -100%;
    }

    .auth-box {
        padding: 24px 20px;
        max-width: 380px;
    }

    .auth-logo .logo-icon {
        width: 56px;
        height: 56px;
        font-size: 26px;
    }

    .auth-logo h1 {
        font-size: 20px;
    }

    .form-group {
        margin-bottom: 14px;
    }

    .form-group input {
        padding: 10px 14px;
        font-size: 16px;
    }

    .btn-primary {
        padding: 12px;
        font-size: 14px;
    }

    .lang-toggle {
        top: 10px;
        left: 10px;
    }

    .lang-toggle button {
        padding: 4px 10px;
        font-size: 11px;
    }

    .messages-container {
        padding: 12px 8px;
    }

    .message .msg-image {
        max-width: 100%;
    }

    .link-preview .lp-img {
        max-height: 150px;
    }

    .modal {
        max-width: 100%;
        max-height: 90vh;
        margin: 10px;
        border-radius: var(--radius);
    }

    .modal-body {
        padding: 16px;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-content {
        max-width: 100% !important;
        margin: 10px;
        max-height: 85vh;
        overflow-y: auto;
    }
}

/* Small phones */
@media (max-width: 400px) {
    :root {
        --header-height: 48px;
    }

    .message {
        max-width: 95%;
        font-size: 13px;
        padding: 6px 10px;
    }

    .message.self {
        max-width: 90%;
    }

    .chat-header {
        padding: 6px 8px;
    }

    .chat-input-area {
        padding: 4px 6px;
    }

    .auth-box {
        padding: 18px 16px;
    }

    .auth-logo .logo-icon {
        width: 48px;
        height: 48px;
        font-size: 22px;
        margin-bottom: 10px;
    }

    .auth-logo h1 {
        font-size: 18px;
    }

    .form-group input {
        padding: 8px 12px;
        font-size: 16px;
    }

    .btn-primary {
        padding: 10px;
        font-size: 13px;
    }
}

/* Group/Channel avatar group */
.avatar-group {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
}

/* Typing indicator */
.typing-indicator {
    display: none;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.typing-indicator.active {
    display: block;
}

/* Loading spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Language toggle in auth */
.lang-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    display: flex;
    gap: 6px;
    z-index: 10;
}

.lang-toggle button {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    background: rgba(255,255,255,0.2);
    color: white;
    transition: var(--transition);
}

.lang-toggle button.active {
    background: rgba(255,255,255,0.4);
}

/* Contact item in modal */
.contact-item {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

/* Saved Messages */
.saved-chat .chat-avatar-placeholder {
    font-size: 20px !important;
    background: linear-gradient(135deg, var(--primary), var(--secondary)) !important;
}
.saved-chat .chat-info .chat-name {
    color: var(--primary);
}
.saved-chat .chat-preview span {
    color: var(--text-muted);
    font-size: 12px;
}

/* Pinned messages bar */
.pinned-bar {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px; margin: 0 8px 4px;
    background: var(--bg-tertiary); border-radius: var(--radius-sm);
    cursor: pointer; font-size: 12px;
    transition: background 0.15s;
    direction: ltr;
}
.pinned-bar:hover { background: var(--hover); }
.pin-icon { font-size: 14px; }
.pin-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.pin-count { color: var(--primary); font-weight: 600; font-size: 11px; }
.pin-close { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 2px 4px; font-size: 12px; }

.contact-item:hover {
    background: var(--hover);
}

.contact-item.selected {
    background: var(--primary-light);
    border-color: var(--primary);
}

/* Secret Chat Badge */
.secret-badge {
    position: absolute;
    bottom: -2px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    border: 2px solid var(--bg-primary);
    z-index: 2;
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(76, 175, 80, 0); }
}

/* Self-destruct badge on header */
.sd-badge {
    background: var(--danger);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-right: 4px;
    vertical-align: middle;
}

/* Encryption typing animation */
.encrypt-anim {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--success);
}
.encrypt-anim.active {
    animation: encrypt-shimmer 1s ease-in-out infinite;
}
@keyframes encrypt-shimmer {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}
.encrypt-dots {
    display: inline-flex;
    gap: 2px;
}
.encrypt-dots span {
    width: 4px;
    height: 4px;
    background: var(--success);
    border-radius: 50%;
    animation: dot-bounce 1.4s infinite ease-in-out both;
}
.encrypt-dots span:nth-child(1) { animation-delay: -0.32s; }
.encrypt-dots span:nth-child(2) { animation-delay: -0.16s; }
.encrypt-dots span:nth-child(3) { animation-delay: 0s; }
@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Auth tabs for OTP/Password toggle */
.auth-tab {
    transition: all 0.2s;
}
.auth-tab:hover {
    opacity: 0.9;
}

/* OTP code inputs */
.otp-digit:focus {
    border-color: var(--primary) !important;
    outline: none;
    box-shadow: 0 0 0 2px rgba(42,171,238,0.2);
}

/* Sessions modal */
#sessionsList > div:last-child {
    border-bottom: none !important;
}

/* Invite search results */
#inviteSearchResults > div:hover {
    background: var(--hover);
}

/* Secret chat message glow */
.chat-input-area.secret-glow {
    box-shadow: 0 0 12px rgba(76, 175, 80, 0.3);
    border-radius: var(--radius);
}
.message .secret-lock {
    font-size: 10px;
    color: var(--success);
    margin-left: 4px;
    opacity: 0.7;
}

/* Edit profile file input */
#editAvatarInput {
    padding: 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    width: 100%;
}

/* Channel delete button */
.channel-delete-btn {
    color: var(--danger);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
}
.channel-delete-btn:hover {
    text-decoration: underline;
}

/* ─── Enhanced Animations ─── */

/* Reaction picker spring effect - staggered emoji pop */
.reaction-picker.active {
    animation: reactionSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.reaction-picker.active span {
    animation: emojiSpring 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.reaction-picker.active span:nth-child(1) { animation-delay: 0.02s; }
.reaction-picker.active span:nth-child(2) { animation-delay: 0.04s; }
.reaction-picker.active span:nth-child(3) { animation-delay: 0.06s; }
.reaction-picker.active span:nth-child(4) { animation-delay: 0.08s; }
.reaction-picker.active span:nth-child(5) { animation-delay: 0.10s; }
.reaction-picker.active span:nth-child(6) { animation-delay: 0.12s; }
.reaction-picker.active span:nth-child(7) { animation-delay: 0.14s; }

@keyframes reactionSlideIn {
    0% { opacity: 0; transform: translateY(10px) scale(0.7); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes emojiSpring {
    0% { opacity: 0; transform: scale(0) rotate(-15deg); }
    60% { transform: scale(1.25) rotate(4deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

/* Message send slide-in animation (for newly sent messages) */
.message.new-message .msg-content {
    animation: slideInUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes slideInUp {
    0% { opacity: 0; transform: translateY(24px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Profile modal enhanced scale + fade transition */
.profile-modal-wrap {
    animation: profileModalIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes profileModalIn {
    0% { opacity: 0; transform: scale(0.85) translateY(15px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Enhanced typing dots animation with bounce */
.chat-header .chat-user-info .chat-user-status .typing-dots span {
    animation: typingBounce 1.4s ease-in-out infinite;
}
.chat-header .chat-user-info .chat-user-status .typing-dots span:nth-child(1) { animation-delay: 0s; }
.chat-header .chat-user-info .chat-user-status .typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.chat-header .chat-user-info .chat-user-status .typing-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Pinned bar slide-in animation */
.pinned-bar {
    animation: pinnedSlideDown 0.3s ease;
}
@keyframes pinnedSlideDown {
    0% { opacity: 0; transform: translateY(-100%) scaleY(0.8); max-height: 0; padding: 0 12px; }
    100% { opacity: 1; transform: translateY(0) scaleY(1); max-height: 40px; padding: 6px 12px; }
}

/* Channel delete button confirmation shake */
.channel-delete-btn.confirming {
    animation: shake 0.5s ease;
    color: var(--danger);
    font-weight: 700;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-5px) rotate(-2deg); }
    30% { transform: translateX(5px) rotate(2deg); }
    45% { transform: translateX(-4px) rotate(-1deg); }
    60% { transform: translateX(4px) rotate(1deg); }
    75% { transform: translateX(-2px); }
    90% { transform: translateX(2px); }
}

/* Location message */
.msg-location { display:flex; align-items:center; gap:10px; cursor:pointer; padding:4px 0 }
.msg-location .loc-icon { font-size:28px }
.msg-location .loc-info .loc-title { font-weight:600; font-size:13px }
.msg-location .loc-info .loc-coords { font-size:11px; color:var(--text-muted) }

/* Telegram-style bubble shadows */
.message { box-shadow: 0 1px 2px rgba(0,0,0,0.06) }
.message.self { box-shadow: 0 1px 2px rgba(42,171,238,0.15) }

/* Smooth scrollbar */
.messages-container::-webkit-scrollbar { width: 4px }
.messages-container::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px }
.messages-container::-webkit-scrollbar-track { background: transparent }

/* Better hover transitions */
.chat-item { transition: background 0.15s ease, transform 0.1s ease }
.chat-item:active { transform: scale(0.98) }

/* System messages */
.msg-system { text-align:center; font-size:12px; color:var(--text-muted); padding:8px 20px; margin:4px 0 }
.msg-system .time-sep { display:inline-block; padding:4px 12px; background:var(--bg-secondary); border-radius:8px }

/* Text formatting */
.msg-text b { font-weight:700 }
.msg-text i { font-style:italic }
.msg-text s { text-decoration:line-through }
.msg-text code { background:var(--bg-secondary); padding:1px 5px; border-radius:3px; font-family:monospace; font-size:0.9em }

/* Spoiler */
.spoiler { background:currentColor; color:transparent; border-radius:3px; cursor:pointer; transition:background 0.2s; user-select:none }
.spoiler.revealed { background:transparent; color:inherit; user-select:text }

/* Sticker picker */
.sticker-picker { display:none; position:absolute; bottom:64px; left:8px; right:8px; max-height:280px; background:var(--bg-primary); border:1px solid var(--border-color); border-radius:12px; box-shadow:var(--shadow-lg); z-index:200; overflow:hidden; animation:menuSlide 0.12s ease }
.sticker-picker.active { display:flex; flex-direction:column }
.sticker-picker-header { display:flex; align-items:center; justify-content:space-between; padding:8px 8px; border-bottom:1px solid var(--border-color); font-size:13px; font-weight:600 }
.sticker-picker-header button { background:none; border:none; font-size:16px; cursor:pointer; color:var(--text-muted); padding:2px 6px; border-radius:4px; flex-shrink:0 }
.sticker-picker-header button:hover { background:var(--bg-secondary) }
.sticker-tabs { display:flex; gap:4px }
.sticker-tab { padding:4px 12px; border-radius:6px; cursor:pointer; font-size:12px; color:var(--text-muted); transition:all 0.15s; user-select:none }
.sticker-tab:hover { background:var(--bg-secondary) }
.sticker-tab.active { background:var(--accent); color:#fff }
.sticker-picker-content { overflow-y:auto; flex:1; padding:8px }
.sticker-pack { margin-bottom:12px }
.sticker-pack-name { font-size:11px; color:var(--text-muted); padding:4px 4px 6px }
.sticker-grid { display:grid; grid-template-columns:repeat(5,1fr); gap:6px }
.sticker-item { display:flex; align-items:center; justify-content:center; padding:4px; border-radius:8px; cursor:pointer; transition:background 0.15s }
.sticker-item:hover { background:var(--bg-secondary) }
.sticker-item img { width:52px; height:52px; object-fit:contain }
.sticker-picker-content .btn-primary { width:auto; padding:8px 20px; font-size:13px; display:inline-block }

/* Mention dropdown */
.mention-dropdown { display:none; position:absolute; bottom:64px; left:60px; max-width:250px; max-height:180px; background:var(--bg-primary); border:1px solid var(--border-color); border-radius:10px; box-shadow:var(--shadow-lg); z-index:200; overflow-y:auto; animation:menuSlide 0.1s ease }
.mention-dropdown.active { display:block }
.mention-item { padding:8px 12px; cursor:pointer; display:flex; align-items:center; gap:8px; font-size:13px; transition:background 0.1s }
.mention-item:hover, .mention-item.active { background:var(--bg-secondary) }
.mention-name { font-size:11px; color:var(--text-muted) }

/* Right-click context menu for chat items */
.chat-menu-dropdown { position:fixed; z-index:5000; min-width:180px }
.chat-menu-dropdown .msg-menu-item { padding:10px 14px; font-size:13px }

/* FEATURE 4: Animated emoji reactions */
.reaction-animate {
    animation: bounceIn 0.3s ease;
}
@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); opacity: 1; }
}

/* FEATURE 5: Confetti */
.confetti-piece {
    position: fixed;
    width: 10px;
    height: 10px;
    z-index: 9999;
    pointer-events: none;
    animation: confettiFall 3s ease-out forwards;
}
@keyframes confettiFall {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* FEATURE 6: PIN Overlay */
.pin-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.pin-box {
    text-align: center;
    max-width: 320px;
    width: 100%;
    padding: 20px;
}
.pin-box h3 { margin-bottom: 20px; font-size: 18px; }
.pin-dots {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 24px;
}
.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    transition: all 0.15s;
}
.pin-dot.filled { background: var(--primary); }
.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 260px;
    margin: 0 auto;
}
.pin-pad button {
    height: 56px;
    border-radius: 50%;
    font-size: 22px;
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: none;
    cursor: pointer;
    transition: background 0.1s;
}
.pin-pad button:hover { background: var(--bg-tertiary); }
.pin-pad button:active { transform: scale(0.95); }
.pin-pad .pin-empty { background: transparent; pointer-events: none; }

/* FEATURE 10: Custom Wallpaper */
.chat-wallpaper-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 12px;
}
.chat-wallpaper-item {
    width: 100%;
    height: 60px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border 0.15s;
}
.chat-wallpaper-item:hover, .chat-wallpaper-item.active { border-color: var(--primary); }

/* FEATURE 12: Call UI */
/* ─── Call Overlay ─── */
.call-overlay {
    position: fixed; inset: 0;
    background: linear-gradient(160deg, #0f1a24 0%, #1a2a3a 40%, #0d1520 100%);
    z-index: 10001; display: flex; flex-direction: column;
    align-items: center; justify-content: center; color: white;
}
[data-theme="light"] .call-overlay {
    background: linear-gradient(160deg, #1a3448 0%, #2a4a6a 40%, #14202e 100%);
}
.call-overlay::before {
    content: '';
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(42,171,238,0.08) 0%, transparent 60%),
                radial-gradient(ellipse at 70% 80%, rgba(135,116,225,0.06) 0%, transparent 60%);
    pointer-events: none;
}
.call-overlay .call-video-container {
    position: absolute; inset: 0; background: #000;
    display: flex; align-items: center; justify-content: center;
}
.call-overlay .call-video-container video { max-width: 100%; max-height: 100%; }
.call-overlay #remoteVideo { width: 100%; height: 100%; object-fit: contain; }
.call-overlay #localVideo {
    position: absolute; bottom: 100px; right: 16px; z-index: 10;
    width: 120px; height: 160px; border-radius: 12px;
    object-fit: cover; border: 2px solid rgba(255,255,255,0.3);
    background: #222; box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.call-overlay .call-avatar {
    width: 120px; height: 120px; border-radius: 50%;
    background: var(--primary); display: flex; align-items: center;
    justify-content: center; font-size: 48px; margin-bottom: 16px;
    z-index: 5; box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.call-overlay .call-name { font-size: 26px; font-weight: 600; margin-bottom: 4px; z-index: 5; text-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.call-overlay .call-status { font-size: 14px; color: rgba(255,255,255,0.5); margin-bottom: 40px; z-index: 5; }
.call-overlay .call-timer { font-size: 18px; font-variant-numeric: tabular-nums; margin-bottom: 32px; z-index: 5; letter-spacing: 1px; }
.call-overlay .call-actions { display: flex; gap: 24px; z-index: 5; }
.call-overlay .call-actions button {
    width: 56px; height: 56px; border-radius: 50%;
    border: none; font-size: 22px; cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex; align-items: center; justify-content: center;
}
.call-overlay .call-actions button:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.call-overlay .call-actions button:active { transform: scale(0.95); }
.call-overlay .call-actions .call-end { background: #EF5350; color: white; }
.call-overlay .call-actions .call-accept { background: #4CAF50; color: white; }
.call-overlay .call-actions .call-action-btn { background: rgba(255,255,255,0.12); color: white; backdrop-filter: blur(4px); }
.call-overlay .call-actions .call-action-btn:hover { background: rgba(255,255,255,0.2); }
.call-overlay .call-actions .call-end-btn { background: #EF5350; color: white; width: 64px; height: 64px; }

/* Forward modal tab buttons */
.forward-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}
.forward-tab {
    flex: 1;
    padding: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    background: none;
}
.forward-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Poll UI */
.poll-container {
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 10px;
    margin: 4px 0;
}
.poll-question { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.poll-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    margin: 4px 0;
    background: var(--bg-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.1s;
}
.poll-option:hover { background: var(--hover); }
.poll-option .poll-bar {
    height: 6px;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
}
.poll-option .poll-pct { font-size: 12px; color: var(--text-muted); min-width: 30px; text-align: right; }
.poll-voted { border-color: var(--primary); background: var(--primary-light); }

/* ─── Compact Mode & Font Size ─── */
.compact-mode .message {
    padding: 3px 8px 2px;
    margin-bottom: -1px;
}
.compact-mode .message .msg-text {
    line-height: 1.3;
}
.compact-mode .message .msg-meta {
    margin-top: 0;
    font-size: 9px;
}
.compact-mode .message .msg-content {
    margin: 0;
}
.compact-mode .date-separator {
    padding: 4px 0;
    margin: 2px 0;
}
.compact-mode .date-separator span {
    font-size: 11px;
    padding: 2px 10px;
}

/* ─── Font Size Variable ─── */
.messages-container {
    --msg-font-size: 14px;
}

/* ─── Custom Scrollbar ─── */
.messages-container::-webkit-scrollbar {
    width: 4px;
}
.messages-container::-webkit-scrollbar-track {
    background: transparent;
}
.messages-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 2px;
}
[data-theme="dark"] .messages-container::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
}

/* ─── Telegram-style Click Animation ─── */
@keyframes msgTap {
    0% { transform: scale(1); }
    50% { transform: scale(0.96); }
    100% { transform: scale(1); }
}
.message:active {
    animation: msgTap 0.12s ease;
}

/* ─── Improved Voice Wave Animation ─── */
.message .msg-voice .voice-wave.playing span {
    animation: voiceWave 0.6s infinite alternate ease-in-out;
}
.message .msg-voice .voice-wave:not(.playing) span {
    animation: none;
    height: 14px;
}

/* ─── Typing Indicator Animation ─── */
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 8px 12px;
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* ─── Send Fly Animation ─── */
@keyframes sendFly {
    0% { transform: translateX(0) scale(1); opacity: 1; }
    100% { transform: translateX(30px) scale(0.5); opacity: 0; }
}
.send-btn:active svg {
    animation: sendFly 0.3s ease-out;
}

/* ─── Quick Reaction Animation ─── */
@keyframes popReaction {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}
.reaction-badge .reaction-emoji {
    animation: popReaction 0.2s ease-out;
}

/* ─── Message Menu ─── */
.message-menu {
    position: fixed; z-index: 10002;
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 4px;
    min-width: 180px;
    animation: menuSlide 0.1s ease;
}
.message-menu .mm-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; cursor: pointer; border-radius: 8px;
    font-size: 13px; color: var(--text-primary);
    transition: background 0.1s;
}
.message-menu .mm-item:hover { background: var(--hover); }
.message-menu .mm-item.mm-danger { color: var(--danger); }
.message-menu .mm-item svg { flex-shrink: 0; }

/* ─── Reply Preview Telegram Style ─── */
.reply-preview {
    border-left: 3px solid var(--primary);
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
[dir="rtl"] .reply-preview { border-left: none; border-right: 3px solid var(--primary); }
.reply-preview-content { flex: 1; overflow: hidden; }
.reply-preview-sender { font-weight: 600; font-size: 12px; color: var(--primary); }
.reply-preview-text { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast.warning { background: #FFA726; color: white; }

/* ─── PWA install banner ─── */
.pwa-banner {
    display: flex; align-items: center; gap: 12px;
    position: fixed; bottom: 64px; left: 8px; right: 8px;
    padding: 12px 16px;
    background: var(--bg-primary); color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    z-index: 99998;
    cursor: pointer;
    backdrop-filter: blur(8px);
    animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.pwa-banner-icon { font-size: 28px; flex-shrink: 0 }
.pwa-banner-text { flex: 1; min-width: 0 }
.pwa-banner-title { font-size: 14px; font-weight: 600 }
.pwa-banner-desc { font-size: 11px; color: var(--text-muted) }
.pwa-banner-close {
    background: none; border: none; font-size: 16px; color: var(--text-muted);
    cursor: pointer; padding: 4px 8px; border-radius: 4px; flex-shrink: 0;
}
.pwa-banner-close:hover { background: var(--bg-secondary) }
