:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-hover: rgba(255,255,255,0.06);
    --bg-glass: rgba(255,255,255,0.05);
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --accent: #7c5cfc;
    --accent-hover: #6a4ae0;
    --accent-glow: rgba(124,92,252,0.3);
    --danger: #ff4757;
    --success: #2ed573;
    --border: rgba(255,255,255,0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

[data-theme="light"] {
    --bg-primary: #f5f5fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef0f6;
    --bg-hover: rgba(0,0,0,0.04);
    --bg-glass: rgba(255,255,255,0.7);
    --text-primary: #1a1a2e;
    --text-secondary: #6b6b8a;
    --accent: #7c5cfc;
    --accent-hover: #6a4ae0;
    --accent-glow: rgba(124,92,252,0.15);
    --danger: #e53935;
    --success: #2ed573;
    --border: rgba(0,0,0,0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

[data-accent="blue"] {
    --accent: #4a7cff;
    --accent-hover: #3a68e0;
    --accent-glow: rgba(74,124,255,0.3);
}
[data-theme="light"][data-accent="blue"] {
    --accent-glow: rgba(74,124,255,0.15);
}

[data-accent="green"] {
    --accent: #2ed573;
    --accent-hover: #26b863;
    --accent-glow: rgba(46,213,115,0.3);
}
[data-theme="light"][data-accent="green"] {
    --accent-glow: rgba(46,213,115,0.15);
}

[data-accent="orange"] {
    --accent: #ff7f50;
    --accent-hover: #e06a3e;
    --accent-glow: rgba(255,127,80,0.3);
}
[data-theme="light"][data-accent="orange"] {
    --accent-glow: rgba(255,127,80,0.15);
}

[data-accent="pink"] {
    --accent: #ff6b9d;
    --accent-hover: #e05585;
    --accent-glow: rgba(255,107,157,0.3);
}
[data-theme="light"][data-accent="pink"] {
    --accent-glow: rgba(255,107,157,0.15);
}

[data-accent="teal"] {
    --accent: #00bcd4;
    --accent-hover: #00a0b5;
    --accent-glow: rgba(0,188,212,0.3);
}
[data-theme="light"][data-accent="teal"] {
    --accent-glow: rgba(0,188,212,0.15);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    height: 100dvh;
    overflow: hidden;
}

#app {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    height: 100dvh;
}

/* Auth */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: radial-gradient(ellipse at top, rgba(124,92,252,0.15), transparent 60%),
                radial-gradient(ellipse at bottom, rgba(45,52,227,0.1), transparent 60%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    width: 56px;
    height: 56px;
    color: var(--accent);
    margin-bottom: 16px;
}

.auth-header h1 {
    font-size: 28px;
    font-weight: 700;
}

.auth-header p {
    color: var(--text-secondary);
    margin-top: 4px;
}

.auth-form { display:flex; flex-direction:column; gap:16px; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.glass-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.glass-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.glass-input::placeholder { color: var(--text-secondary); opacity:0.6; }

textarea.glass-input { resize: vertical; min-height:80px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:hover { background: var(--accent-hover); transform:translateY(-1px); }

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

.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    width: 100%;
}

.btn-danger-outline:hover {
    background: rgba(255,71,87,0.1);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.btn-icon svg { width: 22px; height: 22px; }
.msg-checkbox svg, .reaction-btn svg, .msg-action svg { display:block; }
.context-menu-item svg { margin-right:8px; vertical-align:middle; }
.reaction-btn svg { display:block; margin:auto; }
.msg-action svg { display:block; margin:auto; }
.msg-checkbox svg { display:block; margin:auto; }
.forward-banner .forward-icon svg { vertical-align:middle; margin-right:4px; }
.message-meta .status svg { vertical-align:middle; }

.auth-links {
    text-align: center;
    margin-top: 20px;
}

.auth-links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
}

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

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.alert-error {
    background: rgba(255,71,87,0.15);
    border: 1px solid rgba(255,71,87,0.3);
    color: var(--danger);
}

.alert-success {
    background: rgba(76,175,80,0.15);
    border: 1px solid rgba(76,175,80,0.3);
    color: #4caf50;
}

.alert button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 18px;
}

/* Messenger Layout */
.messenger-layout {
    display: flex;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    height: 100dvh;
}

.sidebar {
    width: 360px;
    min-width: 360px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(124,92,252,0.08) 0%, transparent 100%);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #45aaf2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-actions { display:flex; gap: 2px; }

.spinner-sm {
    position: absolute;
    right: 28px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.htmx-indicator { opacity:0; transition:opacity 0.3s; }
.htmx-request .htmx-indicator { opacity:1; }

.stories-bar {
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    overflow-x: auto;
}

.stories-list {
    display: flex;
    gap: 16px;
    padding: 4px 0;
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    min-width: 60px;
}

.story-item .story-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(45deg, var(--accent), #45aaf2);
}

.story-item .story-avatar.unseen {
    background: linear-gradient(45deg, var(--accent), #ff6b6b);
}

.story-item .story-avatar .avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    font-weight: 700;
    font-size: 18px;
    color: var(--accent);
}

.story-item .story-avatar .avatar.add-avatar {
    background: var(--accent);
    color: white;
    font-size: 22px;
    font-weight: 400;
}

.story-username {
    font-size: 11px;
    color: var(--text-secondary);
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.conversations { flex:1; overflow-y:auto; min-height:0; }

/* Story Viewer */
.story-viewer-container {
    width: 100%;
    max-width: 420px;
    height: 90vh;
    max-height: 700px;
    background: #000;
    border-radius: var(--radius);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.story-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: linear-gradient(180deg, rgba(0,0,0,0.6), transparent);
}

.story-viewer-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
}

.story-viewer-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.viewer-time {
    font-size: 12px;
    opacity: 0.7;
}

.story-viewer-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 16px 16px;
    color: white;
    font-size: 18px;
    text-align: center;
    overflow: hidden;
}

.story-viewer-body img,
.story-viewer-body video {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}

.story-viewer-nav {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 8px;
    transform: translateY(-50%);
    pointer-events: none;
}

.story-viewer-nav .btn-icon {
    pointer-events: all;
    color: white;
    font-size: 28px;
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

/* Story Creation */
.story-preview {
    width: 100%;
    height: 180px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px dashed var(--border);
}

.story-preview img,
.story-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-preview-placeholder {
    color: var(--text-secondary);
    font-size: 14px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.15s, transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.conversation-item:hover { background: rgba(124,92,252,0.06); transform:translateX(2px); }
.conversation-item:active { background: rgba(124,92,252,0.1); transform:translateX(1px); }

.conversation-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 72px;
    right: 20px;
    height: 1px;
    background: var(--border);
}

.conversation-item:last-child::after {
    display: none;
}

.conversation-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--bg-glass);
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.conversation-item .avatar img { width:100%;height:100%;object-fit:cover; }
.conversation-item .avatar span { font-weight:600;font-size:18px;color:var(--accent); }

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

.conversation-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.badge {
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    display: inline-block;
}

.status-dot.online { background: var(--success); }

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-height: 0;
    position: relative;
}

.chat-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-glow), transparent);
    opacity: 0.5;
}

.chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-secondary);
}

.chat-placeholder svg { width: 80px;height:80px; }
.chat-placeholder h3 { font-size:20px;color:var(--text-primary); }

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    background: linear-gradient(180deg, rgba(124,92,252,0.06) 0%, transparent 100%);
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-user-info .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-glass);
}

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

.messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    overflow: hidden;
}

.messages-container .messages {
    flex: 1;
    padding: 16px 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
    scroll-behavior: smooth;
}

/* Group consecutive messages from same sender — bubble chat style */
.message {
    margin-top: 2px;
}
/* First message in a group gets rounder top corners */
.message.outgoing .message-content {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}
.message.incoming .message-content {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}
/* Singleton or first in group */
.message.outgoing:first-child .message-content,
.message.incoming + .message.outgoing .message-content {
    border-top-right-radius: 18px;
}
.message.incoming:first-child .message-content,
.message.outgoing + .message.incoming .message-content {
    border-top-left-radius: 18px;
}
.message.outgoing + .message.outgoing {
    margin-top: 1px;
}
.message.outgoing + .message.outgoing .message-content {
    border-top-right-radius: 14px;
}
.message.incoming + .message.incoming {
    margin-top: 1px;
}
.message.incoming + .message.incoming .message-content {
    border-top-left-radius: 14px;
}

/* New message slide-in */
@keyframes msgIn {
    from { opacity:0; transform:translateY(8px); }
    to   { opacity:1; transform:translateY(0); }
}
@keyframes msgIncoming {
    from { opacity:0; transform:translateX(-12px) translateY(4px); }
    to   { opacity:1; transform:translateX(0) translateY(0); }
}
@keyframes msgOutgoing {
    from { opacity:0; transform:translateX(12px) translateY(4px); }
    to   { opacity:1; transform:translateX(0) translateY(0); }
}
.message.incoming:last-of-type {
    animation: msgIncoming 0.2s ease;
}
.message.outgoing:last-of-type {
    animation: msgOutgoing 0.2s ease;
}
.message:last-of-type:not(.incoming):not(.outgoing) {
    animation: msgIn 0.2s ease;
}

/* Scroll-to-bottom button */
.scroll-down-btn {
    position: absolute;
    bottom: 16px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px var(--accent-glow);
    z-index: 5;
    transition: all 0.2s;
}
.scroll-down-btn:hover {
    transform: scale(1.08);
}
.scroll-down-btn.visible {
    display: flex;
    animation: fadeIn 0.2s ease;
}
.scroll-down-btn svg {
    width: 20px;
    height: 20px;
}

.messages-container .message-form {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    background: linear-gradient(0deg, rgba(124,92,252,0.04) 0%, transparent 100%);
}
.messages-container .message-form .reply-input-bar {
    flex: 1 1 100%;
    order: -1;
}
.messages-container .message-form #message-input {
    flex: 1;
    min-width: 60px;
}

.message {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 4px;
    max-width: 70%;
    margin-bottom: 4px;
}

.message.outgoing {
    align-self: flex-end;
}
.message.incoming {
    align-self: flex-start;
}

.message.outgoing {
    align-self: flex-end;
    align-items: flex-end;
}

.message.incoming {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.outgoing .message-content {
    background: var(--accent);
    color: white;
}

.message.incoming .message-content {
    background: var(--bg-secondary);
}

.message-media {
    max-width: 100%;
    border-radius: 12px;
    overflow: hidden;
}

.message-media img,
.message-media video {
    max-width: 300px;
    max-height: 400px;
}

.message-media img,
.message-media video {
    width: 100%;
    display: block;
}

.message-media audio { width:100%; }

.voice-message {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
    cursor: pointer;
    user-select: none;
}

.voice-circle {
    position: relative;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.voice-circle svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.voice-track {
    fill: none;
    stroke: rgba(255,255,255,0.15);
    stroke-width: 3;
}

.voice-progress {
    fill: none;
    stroke: currentColor;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 119.38;
    stroke-dashoffset: 119.38;
    transition: stroke-dashoffset 0.3s linear;
}

.message.outgoing .voice-track { stroke: rgba(255,255,255,0.25); }
.message.incoming .voice-track { stroke: rgba(255,255,255,0.15); }

.voice-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    pointer-events: none;
    line-height: 1;
}

.voice-time, .voice-dur {
    font-size: 13px;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
}

.voice-dur::before {
    content: '/';
    margin: 0 4px;
    opacity: 0.4;
}

.message.outgoing .voice-time,
.message.outgoing .voice-dur { color: rgba(255,255,255,0.8); }
.message.incoming .voice-time,
.message.incoming .voice-dur { color: var(--text-secondary); }

/* Avatar Upload */
.avatar-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--bg-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    overflow: hidden;
    position: relative;
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* User Profile Panel */
.profile-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    justify-content: flex-end;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(2px);
    animation: profileOverlayIn 0.2s ease;
}

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

.profile-panel {
    width: 380px;
    max-width: 90vw;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    animation: profilePanelIn 0.3s ease;
    box-shadow: -8px 0 40px rgba(0,0,0,0.3);
}

@keyframes profilePanelIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.profile-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.profile-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.profile-panel-footer {
    padding: 16px 24px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.profile-panel-avatar {
    margin-bottom: 16px;
}

#profile-avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    font-size: 40px;
    font-weight: 700;
    color: var(--accent);
    overflow: hidden;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.06);
}

#profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-status .status-dot {
    width: 10px;
    height: 10px;
}

@media (max-width: 768px) {
    .profile-panel {
        width: 100%;
        max-width: 100%;
    }
    .profile-overlay {
        background: var(--bg-secondary);
    }
    @keyframes profilePanelIn {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
}

/* ─── Reactions ─── */
.message-reaction-bar {
    display: none;
    gap: 2px;
    padding: 2px 0;
    margin-top: 2px;
}
.message:hover .message-reaction-bar {
    display: flex;
}
.message-reaction-bar.visible {
    display: flex !important;
}
.reaction-btn {
    font-size: 16px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s, transform 0.15s;
    padding: 2px;
    line-height: 1;
}
.reaction-btn:hover {
    opacity: 1;
    transform: scale(1.2);
}
/* ─── Pinned Banner ─── */
.pinned-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(124,92,252,0.1);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    position: sticky;
    top: 60px;
    z-index: 100;
}
.pinned-banner .pinned-content {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.7;
}
.pin-icon {
    margin-right: 4px;
    font-size: 12px;
}
.message.pinned {
    border-left: 3px solid var(--accent);
}

/* ─── Message Action Bar (Telegram-style) ─── */
.message-action-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: none;
    background: transparent;
}
.message-action-overlay.active {
    display: block;
}
.message-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-secondary);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.3);
    animation: actionBarIn 0.2s ease;
}
@keyframes actionBarIn {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.message-action-bar.active {
    display: flex;
}
.message-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 10px;
    transition: all 0.15s;
    min-width: 56px;
    font-family: inherit;
}
.message-action-btn svg {
    width: 22px;
    height: 22px;
    transition: transform 0.15s;
}
.message-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.message-action-btn:hover svg {
    transform: scale(1.15);
}
.message-action-btn.danger:hover {
    color: var(--danger);
    background: rgba(255,71,87,0.1);
}
.message-action-btn.primary:hover {
    color: var(--accent);
    background: rgba(124,92,252,0.1);
}

/* ─── Context Menu ─── */
.context-menu {
    position: fixed;
    z-index: 9999;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    flex-direction: column;
    padding: 6px;
    min-width: 180px;
    animation: contextMenuIn 0.12s ease;
    transform-origin: top left;
}
@keyframes contextMenuIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    color: var(--text-primary);
}
.context-menu-item:hover {
    background: var(--accent);
    color: white;
}
.context-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 8px;
}

/* ─── Selection Bar ─── */
.selection-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    animation: slideDown 0.15s ease;
}
@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}
.selection-count {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0 8px;
}
.message.selected {
    background: rgba(124,92,252,0.12);
    border-radius: var(--radius);
}
.message-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}
.msg-checkbox {
    display: none;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--text-secondary);
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--bg-primary);
    margin-top: 8px;
}
.messages.selecting .message { cursor: pointer; }
.messages.selecting .message:hover { background: rgba(124,92,252,0.05); }
.messages.selecting .msg-checkbox { display: flex; }
.msg-checkbox.checked {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ─── Search ─── */
.search-match {
    background: #ffd54f;
    color: #333;
    border-radius: 2px;
    padding: 0 1px;
}
.message.search-highlight {
    background: rgba(255,213,79,0.15) !important;
    border-radius: var(--radius);
    transition: background 0.5s;
}
.search-results-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}
.search-results-info .btn-icon {
    font-size: 14px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-primary);
}
.search-results-info .btn-icon:hover {
    background: rgba(255,255,255,0.1);
}

/* ─── Emoji Picker ─── */
.emoji-picker {
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    max-height: 300px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.15s ease;
}
.emoji-picker-header {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.emoji-categories {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    flex-shrink: 0;
}
.emoji-cat-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
    border: none;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}
.emoji-cat-btn:hover, .emoji-cat-btn.active {
    background: rgba(124,92,252,0.15);
}
.emoji-search {
    font-size: 12px;
    padding: 4px 8px;
    width: 100%;
}
.emoji-picker-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 2px;
    padding: 6px;
    overflow-y: auto;
    flex: 1;
    align-content: start;
}
.emoji-picker-body .emoji-item {
    width: 100%;
    aspect-ratio: 1;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}
.emoji-picker-body .emoji-item:hover {
    background: rgba(124,92,252,0.1);
}

/* ─── Sticker Picker ─── */
.sticker-picker {
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    max-height: 250px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.15s ease;
}
@keyframes slideUp {
    from { max-height: 0; }
    to { max-height: 250px; }
}
.sticker-picker-header {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.sticker-picker-tabs {
    display: flex;
    gap: 4px;
}
.sticker-pack-tab {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
    border: none;
    padding: 0;
    overflow: hidden;
    transition: background 0.15s;
    flex-shrink: 0;
}
.sticker-pack-tab:hover, .sticker-pack-tab.active {
    background: rgba(124,92,252,0.15);
}
.sticker-pack-tab img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.sticker-picker-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 4px;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}
.sticker-picker-body .sticker-item {
    width: 100%;
    aspect-ratio: 1;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sticker-picker-body .sticker-item:hover {
    background: rgba(124,92,252,0.1);
}
.sticker-picker-body .sticker-item img,
.sticker-picker-body .sticker-item video {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 4px;
    width: 100%;
}

.sticker-picker-actions {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    align-items: center;
    border-top: 1px solid var(--border);
}
.sticker-search {
    flex: 1;
    font-size: 12px;
    padding: 4px 8px;
    height: 28px;
}

/* ─── Sticker Store ─── */
.store-pack-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    transition: background 0.15s;
    cursor: default;
}
.store-pack-card:hover {
    background: var(--bg-hover);
}
.store-pack-card .store-pack-thumb {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
}
.store-pack-card .store-pack-thumb img,
.store-pack-card .store-pack-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.store-pack-info {
    flex: 1;
    min-width: 0;
}
.store-pack-info .store-pack-name {
    font-weight: 600;
    font-size: 14px;
}
.store-pack-info .store-pack-count {
    font-size: 12px;
    color: var(--text-secondary);
}
.store-pack-info .store-pack-desc {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.store-pack-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.store-pack-btn.install {
    background: var(--accent);
    color: #fff;
    border: none;
}
.store-pack-btn.install:hover {
    opacity: 0.85;
}
.store-pack-btn.uninstall {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.store-pack-btn.uninstall:hover {
    border-color: var(--danger);
    color: var(--danger);
}
.store-pack-stickers {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 4px;
    padding: 8px 12px 4px 68px;
}
.store-pack-card.expanded + .store-pack-stickers {
    display: grid;
}
.store-pack-stickers img,
.store-pack-stickers video {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.15s;
}
.store-pack-stickers img:hover,
.store-pack-stickers video:hover {
    transform: scale(1.15);
}

/* ─── Sticker message in chat ─── */
.message.sticker {
    max-width: 180px;
}
.message.sticker .message-content {
    background: transparent !important;
    border: none;
    box-shadow: none;
    padding: 2px;
}
.message.sticker .message-content img,
.message.sticker .message-content video {
    max-width: 180px;
    max-height: 180px;
    border-radius: 12px;
    display: block;
}
.message.sticker.sent .message-body {
    animation: stickerSent 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes stickerSent {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
.message.sticker .reply-preview {
    display: none;
}
.message.sticker .forward-banner {
    font-size: 12px;
}

@keyframes reactionIn {
    0% { transform:scale(0.5); opacity:0; }
    60% { transform:scale(1.15); }
    100% { transform:scale(1); opacity:1; }
}

/* ─── Global Search ─── */
.global-search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border);
}
.global-search-item:hover {
    background: rgba(124,92,252,0.08);
}
.global-search-item:last-child {
    border-bottom: none;
}

/* ─── Edited badge ─── */
.edited-badge {
    font-size: 11px;
    opacity: 0.5;
    font-style: italic;
    font-weight: 400;
}
.message.outgoing .edited-badge { display: inline; }

/* ─── Forward ─── */
.forward-banner {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 2px;
    padding: 2px 0;
    color: var(--accent);
    border-bottom: 1px solid rgba(124,92,252,0.15);
    margin-bottom: 4px;
    padding-bottom: 4px;
}
.forward-icon {
    font-size: 13px;
}
.message.outgoing .forward-banner {
    color: rgba(255,255,255,0.7);
    border-bottom-color: rgba(255,255,255,0.15);
}

/* ─── Reply ─── */
.reply-preview {
    display: flex;
    gap: 8px;
    align-items: stretch;
    margin-bottom: 4px;
    padding: 4px 0;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
}
.reply-preview:hover {
    background: rgba(255,255,255,0.05);
}
.reply-line {
    width: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}
.message.outgoing .reply-line {
    background: rgba(255,255,255,0.5);
}
.message.incoming .reply-line {
    background: var(--accent);
}
.reply-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}
.reply-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}
.reply-text {
    font-size: 13px;
    opacity: 0.7;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Reply input bar */
.reply-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 12px;
    background: var(--bg-glass);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    margin-bottom: 2px;
}
.reply-input-line {
    width: 3px;
    height: 32px;
    border-radius: 2px;
    background: var(--accent);
    flex-shrink: 0;
}
.reply-input-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
    min-width: 0;
}
.reply-input-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}
.reply-input-text {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 2px 4px;
    align-items: center;
}
.reaction-item {
    font-size: 14px;
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 12px;
    background: var(--bg-glass);
    border: 1px solid transparent;
    transition: all 0.15s;
    line-height: 1.4;
    user-select: none;
    animation: reactionIn 0.2s ease;
}
.reaction-item:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
}
.reaction-item.mine {
    background: rgba(124,92,252,0.15);
    border-color: var(--accent);
}
.reaction-count {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 1px;
    font-weight: 600;
}
.reaction-item.mine .reaction-count {
    color: var(--accent);
}
.reaction-add {
    font-size: 12px;
    cursor: pointer;
    opacity: 0.4;
    padding: 1px 4px;
    border-radius: 12px;
    transition: opacity 0.15s;
    line-height: 1.4;
}
.reaction-add:hover {
    opacity: 1;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    padding: 0 4px;
}

.message.outgoing .message-meta { justify-content: flex-end; }

.message-actions,
.message-hover-actions {
    display: none;
    gap: 4px;
    margin-top: 2px;
}

.message.show-actions .message-actions,
.message.show-actions .message-hover-actions {
    display: flex;
}

.msg-action {
    font-size: 12px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.msg-action:hover { opacity: 1; }

/* Telegram-style message highlight on click */
.message.highlighted {
    background: rgba(124,92,252,0.08);
    border-radius: var(--radius);
    transition: background 0.2s;
}

.message.sticker:not(.show-actions) .message-body::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--surface);
    border-radius: inherit;
    z-index: 1;
}
.message.sticker:not(.show-actions) img,
.message.sticker:not(.show-actions) video {
    filter: blur(40px);
    opacity: 0.4;
}
.message.sticker.show-actions img,
.message.sticker.show-actions video {
    filter: none;
    opacity: 1;
}

/* Sidebar search bar — tabs stacked above search input */
.sidebar > .search-bar {
    padding: 12px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(124,92,252,0.04) 0%, transparent 100%);
}

/* Chat search bar — input + button in a row */
#search-bar.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-glass);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-bar .glass-input {
    flex: 1;
}

.search-results-info {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-glass);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}    

.message.encrypted .message-content::before {
    content: '🔒 ';
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 20px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 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; }

@keyframes typing {
    0%,60%,100% { opacity:0.3;transform:translateY(0); }
    30% { opacity:1;transform:translateY(-4px); }
}

.message-input {
    flex: 1;
    padding: 10px 16px;
    border-radius: 24px;
}

.btn-send {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
}
@keyframes btnPulse {
    0% { transform:scale(1); }
    50% { transform:scale(0.9); }
    100% { transform:scale(1); }
}
.btn-send.sending {
    animation: btnPulse 0.25s ease;
}

/* Voice Recording */
#mic-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    flex-shrink: 0;
}

#mic-btn.recording {
    background: var(--danger);
    color: white;
    animation: micPulse 1s infinite;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,71,87,0.6); }
    50% { box-shadow: 0 0 0 8px rgba(255,71,87,0); }
}

#mic-btn svg {
    width: 20px;
    height: 20px;
}

.recording-timer {
    font-family: monospace;
    font-size: 14px;
    color: var(--danger);
    flex-shrink: 0;
    min-width: 36px;
    text-align: center;
}

.btn-send svg { width: 20px;height:20px; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(8px);
    animation: modalFadeIn 0.2s ease;
}

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

.modal {
    width: 100%;
    max-width: 480px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    animation: modalSlideIn 0.25s ease;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h3 {
    font-size: 17px;
    font-weight: 700;
}

.modal-body {
    padding: 20px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-body hr { border:none;border-top:1px solid var(--border);margin:4px 0; }

/* Loading & Empty */
.loading, .empty-state, .empty-messages {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
    position: relative;
}

.tab.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.tab:hover:not(.active) {
    background: var(--bg-glass);
    color: var(--text-primary);
}

/* ============================
   Call Overlay — fullscreen UI
   ============================ */
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f0f1a 0%, #1a1a2e 40%, #16213e 100%);
    animation: callFadeIn 0.3s ease;
}
@keyframes callFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes callPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.5); }
    50%      { box-shadow: 0 0 0 20px rgba(99,102,241,0); }
}

/* Remote video — fills the screen behind */
.call-remote-wrap {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #000;
}
.call-remote-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Glass content layer */
.call-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
}

/* Avatar ring */
.call-avatar-ring {
    width: 128px;
    height: 128px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: callPulse 2s infinite;
    margin-bottom: 8px;
}
.call-avatar-ring .avatar {
    width: 118px;
    height: 118px;
    font-size: 48px;
    font-weight: 700;
    border: 3px solid var(--bg);
}

/* Caller info */
.call-name {
    font-size: 26px;
    font-weight: 700;
    color: #fff;
    margin: 0;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.call-status {
    font-size: 14px;
    color: rgba(255,255,255,0.6);
    margin: 0;
    letter-spacing: 0.3px;
}

/* Call timer */
.call-timer {
    font-size: 16px;
    color: rgba(255,255,255,0.8);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
    display: none;
}

/* Controls row */
.call-controls {
    display: flex;
    gap: 20px;
    margin-top: 32px;
    align-items: center;
}

.call-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(8px);
    color: #fff;
    position: relative;
}
.call-btn:hover {
    background: rgba(255,255,255,0.18);
    transform: scale(1.05);
}
.call-btn:active {
    transform: scale(0.95);
}
.call-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}
.call-btn.active {
    background: rgba(99,102,241,0.35);
}

.call-btn-end {
    width: 64px;
    height: 64px;
    background: #ef4444;
}
.call-btn-end:hover {
    background: #dc2626 !important;
}

/* Muted indicator */
.call-btn.muted {
    background: rgba(239,68,68,0.25);
}

/* Local video PiP */
.call-pip {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 140px;
    height: 200px;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.15);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 3;
    background: #1a1a2e;
    cursor: pointer;
    transition: all 0.3s ease;
}
.call-pip:hover {
    transform: scale(1.03);
}
.call-pip video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.call-pip .pip-label {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: rgba(255,255,255,0.4);
    background: rgba(0,0,0,0.5);
    padding: 2px 8px;
    border-radius: 6px;
}

/* Remote muted badge */
.call-muted-badge {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--bg);
    z-index: 5;
}
.call-muted-badge svg {
    width: 16px;
    height: 16px;
}

/* Incoming call modal */
.call-incoming-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
    animation: callSlideUp 0.4s ease;
}
@keyframes callSlideUp {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.call-incoming-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px;
}

.call-incoming-label {
    font-size: 15px;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
}

.call-incoming-actions {
    display: flex;
    gap: 40px;
    margin-top: 24px;
}

.call-btn-answer {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #22c55e;
    color: #fff;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(34,197,94,0.4);
}
.call-btn-answer:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(34,197,94,0.5);
}
.call-btn-answer:active {
    transform: scale(0.95);
}
.call-btn-answer svg {
    width: 32px;
    height: 32px;
}

.call-btn-reject {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    color: #fff;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(239,68,68,0.3);
}
.call-btn-reject:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(239,68,68,0.4);
}
.call-btn-reject:active {
    transform: scale(0.95);
}
.call-btn-reject svg {
    width: 32px;
    height: 32px;
}

/* Unread conversation */
.conversation-item.unread {
    background: rgba(124,92,252,0.05);
}

/* Animations */
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

@keyframes fadeIn { from { opacity:0;transform:translateX(-50%) translateY(20px); } to { opacity:1;transform:translateX(-50%) translateY(0); } }

.htmx-request .btn-primary {
    opacity: 0.7;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
    }
    .sidebar.hidden-mobile {
        display: none;
    }
    .chat-area {
        width: 100%;
    }
    .chat-area.hidden-mobile {
        display: none;
    }
    .back-btn {
        display: flex !important;
    }
}

.back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 0 8px 0 0;
}

/* Error Toast */
.error-toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius);
    z-index: 9999;
    font-size: 14px;
    animation: toastIn 0.3s ease;
    max-width: 90vw;
    text-align: center;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Date separator */
.date-separator {
    text-align: center;
    padding: 12px 0 8px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.date-separator span {
    background: var(--bg-secondary);
    padding: 4px 12px;
    border-radius: 12px;
}

/* Floating new chat button — moved OUT of scrollable area via fixed */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px var(--accent-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: transform 0.2s;
}

.fab:hover {
    transform: scale(1.1);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
}

/* Conversations container — needs room for FAB at bottom */
.conversations {
    padding-bottom: 72px;
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    gap: 0;
}

.settings-tab {
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.2s, border-color 0.2s;
}

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

.settings-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.settings-tab-content {
    padding-top: 8px;
    animation: tabFadeIn 0.2s ease;
}
@keyframes tabFadeIn {
    from { opacity:0; transform:translateY(6px); }
    to   { opacity:1; transform:translateY(0); }
}

/* Settings Action Buttons */
.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.settings-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.settings-action-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.settings-action-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.12);
}

.settings-action-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.settings-action-btn.danger {
    color: var(--danger);
    border-color: rgba(255,71,87,0.2);
    background: rgba(255,71,87,0.06);
}

.settings-action-btn.danger:hover {
    background: rgba(255,71,87,0.12);
    border-color: rgba(255,71,87,0.3);
}

.settings-action-btn.danger svg {
    color: var(--danger);
}

/* About section */
.about-logo {
    font-size: 36px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #45aaf2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.about-version {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 4px;
}

.about-desc {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

.about-divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.about-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.about-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
}

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

.about-value {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.about-copy {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 16px;
    opacity: 0.6;
}

/* ─── Profile Tabs ─── */
.profile-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 12px;
    gap: 0;
    flex-shrink: 0;
}
.profile-tab {
    flex: 1;
    padding: 10px 4px;
    font-size: 13px;
    font-weight: 600;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    text-align: center;
}
.profile-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.profile-tab:hover {
    color: var(--text-primary);
}
.profile-info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

/* ─── Profile Media Grid ─── */
.profile-media-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    overflow-y: auto;
}
.profile-media-grid .media-thumb {
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    border-radius: 4px;
}
.profile-media-grid .media-thumb img,
.profile-media-grid .media-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}
.profile-media-grid .media-thumb:hover img,
.profile-media-grid .media-thumb:hover video {
    transform: scale(1.05);
}
.profile-media-grid .media-thumb .media-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    font-size: 28px;
    opacity: 0.8;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

/* ─── Profile Files List ─── */
.profile-files-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}
.file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    cursor: pointer;
}
.file-item:hover {
    background: var(--bg-hover);
}
.file-item .file-icon {
    font-size: 24px;
    flex-shrink: 0;
}
.file-item .file-info {
    flex: 1;
    min-width: 0;
}
.file-item .file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-item .file-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

/* ─── Media Viewer ─── */
.media-viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.92);
}
.media-viewer-content {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.media-viewer-content img,
.media-viewer-content video {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
}
.media-viewer-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0,0,0,0.4);
    color: #fff;
    font-size: 22px;
    border: none;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}
.media-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0,0,0,0.4);
    color: #fff;
    font-size: 24px;
    border: none;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.media-viewer-nav:hover {
    background: rgba(0,0,0,0.6);
}
.media-viewer-prev { left: 12px; }
.media-viewer-next { right: 12px; }
.media-viewer-download {
    position: absolute;
    bottom: 16px;
    right: 16px;
    font-size: 24px;
    background: rgba(0,0,0,0.4);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    z-index: 10;
}
.media-viewer-counter {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 13px;
    background: rgba(0,0,0,0.4);
    padding: 4px 12px;
    border-radius: 12px;
    z-index: 10;
}

/* ─── Contacts in Sidebar ─── */
.contact-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: var(--radius-sm);
    margin: 0 8px;
}
.contact-item:hover {
    background: var(--bg-hover);
}
.contact-item .contact-info {
    flex: 1;
    min-width: 0;
}
.contact-item .contact-name {
    font-size: 14px;
    font-weight: 500;
}
.contact-item .contact-username {
    font-size: 12px;
    color: var(--text-secondary);
}
.contact-item .contact-remove {
    font-size: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: color 0.15s;
}
.contact-item .contact-remove:hover {
    color: var(--danger);
}

/* Drag-and-drop overlay */
.drop-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15,15,26,0.85);
    backdrop-filter: blur(4px);
    z-index: 100;
    border: 2px dashed var(--accent);
    margin: 4px;
    border-radius: var(--radius);
}
[data-theme="light"] .drop-overlay {
    background: rgba(245,245,250,0.85);
}
.drop-overlay.active {
    display: flex;
    animation: dropOverlayIn 0.2s ease;
}
.drop-overlay.drag-hover {
    border-color: var(--accent-hover);
    background: rgba(124,92,252,0.08);
}
[data-theme="light"] .drop-overlay.drag-hover {
    background: rgba(124,92,252,0.06);
}
.drop-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--accent);
    font-size: 16px;
    font-weight: 500;
    pointer-events: none;
}
.drop-overlay-content svg {
    opacity: 0.6;
}
@keyframes dropOverlayIn {
    from { opacity:0; }
    to { opacity:1; }
}


/* === UI IMPROVEMENTS === */

/* Smooth scrollbar */
.sidebar-content::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 4px;
}
.sidebar-content::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-content::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
.sidebar-content::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Smooth sidebar */
.sidebar {
    transition: all 0.3s ease;
}

/* Better conversation items */
.conversation-item {
    transition: all 0.2s ease;
    border-radius: var(--radius-sm);
    margin: 2px 8px;
}
.conversation-item:hover {
    background: var(--bg-hover);
    transform: translateX(2px);
}
.conversation-item.active {
    background: var(--accent-glow);
    border-left: 3px solid var(--accent);
}

/* Message bubble improvements */
.message-content {
    transition: all 0.15s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.message.outgoing .message-content {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    box-shadow: 0 2px 8px var(--accent-glow);
}
.message.incoming .message-content {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}
.message-content:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Media viewer fullscreen */
.media-viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(20px);
}
.media-viewer-content {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.media-viewer-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    object-fit: contain;
    transition: transform 0.3s ease;
}
.media-viewer-content video {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.media-viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.media-viewer-close:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}
.media-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}
.media-viewer-nav:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-50%) scale(1.1);
}
.media-viewer-prev { left: 20px; }
.media-viewer-next { right: 20px; }
.media-viewer-download {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 10;
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s;
}
.media-viewer-download:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}
.media-viewer-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.6);
    font-size: 14px;
    z-index: 10;
    background: rgba(0,0,0,0.5);
    padding: 4px 12px;
    border-radius: 20px;
}

/* Image in message with smooth load */
.message-media img,
.message.sticker img,
.message.sticker video {
    opacity: 0;
    transition: opacity 0.3s ease;
}
.message-media img.loaded,
.message.sticker img.loaded,
.message.sticker video.loaded {
    opacity: 1;
}

/* Image loading skeleton/placeholder */
.message-media {
    position: relative;
    background: var(--bg-glass);
    min-height: 40px;
}
.message-media::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    opacity: 1;
    transition: opacity 0.3s;
    border-radius: 12px;
}
.message-media.loaded::before {
    opacity: 0;
}
.message.sticker img,
.message.sticker video {
    position: relative;
    z-index: 1;
}

/* Image in message with hover zoom */
.message-content img[src*="/uploads/"] {
    max-width: 100%;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.message-content img[src*="/uploads/"]:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

/* Video in message */
.message-content video {
    max-width: 100%;
    border-radius: 8px;
    cursor: pointer;
}

/* Loading shimmer */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Smooth media viewer transitions */
.media-viewer-container {
    animation: mediaViewerIn 0.2s ease;
}
@keyframes mediaViewerIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.media-viewer-content img,
.media-viewer-content video {
    animation: mediaContentIn 0.3s ease;
}
@keyframes mediaContentIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.media-viewer-close,
.media-viewer-nav,
.media-viewer-download,
.media-viewer-counter {
    animation: mediaFadeIn 0.3s ease 0.1s both;
}
@keyframes mediaFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes mediaViewerOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Zoom button in media viewer */
.media-zoom-btn {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 10;
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}
.media-zoom-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.1);
}
.loading {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    color: transparent;
}

/* Better modal */
.modal-overlay {
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}
.modal {
    animation: slideUp 0.25s ease;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
@keyframes slideUp {
    from { opacity:0; transform:translateY(20px); }
    to { opacity:1; transform:translateY(0); }
}
@keyframes fadeIn {
    from { opacity:0; }
    to { opacity:1; }
}

/* Message input */
.message-input {
    flex: 1;
    min-width: 60px;
    padding: 10px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
}
.message-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

/* Better emoji picker */
.emoji-picker {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* Profile panel slide-in */
.profile-panel {
    animation: slideInRight 0.3s ease;
}
@keyframes slideInRight {
    from { transform:translateX(100%); }
    to { transform:translateX(0); }
}

/* Smooth tab switching */
.settings-tab-content {
    animation: fadeIn 0.2s ease;
}

/* Header gradient */
.chat-header {
    background: linear-gradient(180deg, rgba(124,92,252,0.06) 0%, transparent 100%);
    border-bottom: 1px solid var(--border);
}

/* Message actions on hover */
.message-actions {
    opacity: 0;
    transition: opacity 0.2s;
}
.message:hover .message-actions {
    opacity: 1;
}

/* Selected messages */
.message.selected .message-content {
    border: 2px solid var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

/* Status dot pulse */
.status-dot {
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity:1; }
    50% { opacity:0.5; }
}

/* Smooth scroll for messages */
.messages {
    scroll-behavior: smooth;
}

/* Better pinned banner */
.pinned-banner {
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    animation: slideDown 0.2s ease;
}
@keyframes slideDown {
    from { opacity:0; transform:translateY(-100%); }
    to { opacity:1; transform:translateY(0); }
}

/* Send button pulse */
.btn-send {
    transition: all 0.2s;
}
.btn-send:hover {
    transform: scale(1.08);
}

/* Better date separator */
.date-separator {
    text-align: center;
    margin: 16px 0;
    position: relative;
}
.date-separator::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background: var(--border);
    z-index: 0;
}
.date-separator span {
    background: var(--bg-primary);
    padding: 0 12px;
    position: relative;
    z-index: 1;
    color: var(--text-secondary);
    font-size: 12px;
    border-radius: 12px;
}

/* Message time on hover */
.message-time {
    opacity: 0;
    transition: opacity 0.2s;
}
.message:hover .message-time {
    opacity: 1;
}

/* FAB button */
.fab {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px var(--accent-glow);
    transition: all 0.2s;
    z-index: 5;
}
.fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px var(--accent-glow);
}

/* Drag-and-drop overlay */
.drop-overlay {
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.2s ease;
}

/* Better context menu */
.context-menu {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: fadeIn 0.15s ease;
    z-index: 100;
}
.context-menu-item {
    transition: background 0.15s;
}
.context-menu-item:hover {
    background: var(--bg-hover);
}

/* Story progress bar */
.story-progress {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
}
.story-progress-bar {
    flex: 1;
    height: 3px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    overflow: hidden;
}
.story-progress-fill {
    height: 100%;
    background: #fff;
    border-radius: 2px;
    transition: width 0.1s linear;
}

/* Search highlight */
.search-highlight {
    background: var(--accent);
    color: #fff;
    border-radius: 2px;
    padding: 0 2px;
}

/* Group avatar */
.group-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* System message */
.message.system {
    text-align: center;
    margin: 8px 0;
}
.message.system .message-content {
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    box-shadow: none;
    border: none;
}

/* ===== Toast notifications ===== */
@keyframes messageIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.message {
  animation: messageIn 0.25s ease-out both;
}

.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    animation: toastSlideIn .3s ease;
    max-width: 380px;
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
}
.toast.error { border-left: 3px solid var(--danger); }
.toast.success { border-left: 3px solid var(--success); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastSlideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toastSlideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ===== Connection status bar ===== */
.connection-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    text-align: center;
    padding: 4px 0;
    font-size: 12px;
    font-weight: 600;
    transition: transform .3s ease, opacity .3s ease;
    transform: translateY(-100%);
    opacity: 0;
}
.connection-bar.visible {
    transform: translateY(0);
    opacity: 1;
}
.connection-bar.offline {
    background: var(--danger);
    color: #fff;
}
.connection-bar.reconnecting {
    background: #f59e0b;
    color: #fff;
}

/* ===== Skeleton loading ===== */
@keyframes skeletonPulse {
    0% { opacity: .6; }
    50% { opacity: 1; }
    100% { opacity: .6; }
}
.skeleton {
    background: var(--bg-tertiary);
    border-radius: 8px;
    animation: skeletonPulse 1.5s ease-in-out infinite;
}
.skeleton-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    flex-shrink: 0;
}
.skeleton-line {
    height: 14px;
    border-radius: 4px;
    margin-bottom: 6px;
}
.skeleton-line-sm { width: 60%; }
.skeleton-line-md { width: 80%; }
.skeleton-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}
.skeleton-item .skeleton-content {
    flex: 1;
}
