/* =============================================
   ChatApp — Premium Dark Theme Stylesheet
   ============================================= */

/* ==================== CSS VARIABLES ==================== */
:root {
    /* Colors */
    --bg-primary: #0a0a14;
    --bg-secondary: #111122;
    --bg-tertiary: #181830;
    --bg-elevated: rgba(255, 255, 255, 0.04);
    --bg-hover: rgba(255, 255, 255, 0.06);
    --bg-active: rgba(124, 58, 237, 0.12);

    --text-primary: #f0f0f5;
    --text-secondary: #9090b0;
    --text-muted: #606080;
    --text-accent: #a78bfa;

    --accent-primary: #7c3aed;
    --accent-secondary: #3b82f6;
    --accent-gradient: linear-gradient(135deg, #7c3aed, #3b82f6);
    --accent-gradient-hover: linear-gradient(135deg, #6d28d9, #2563eb);
    --accent-glow: rgba(124, 58, 237, 0.4);

    --border-color: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);

    --success: #22c55e;
    --danger: #ef4444;
    --warning: #eab308;

    --msg-sent: linear-gradient(135deg, #7c3aed, #6d28d9);
    --msg-received: rgba(255, 255, 255, 0.06);

    /* Sizing */
    --sidebar-width: 360px;
    --header-height: 64px;
    --input-height: 64px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(124, 58, 237, 0.15);
}

/* ==================== RESET ==================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

a { color: var(--text-accent); text-decoration: none; }
img { display: block; max-width: 100%; }
input, textarea, button { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ==================== VIEW SYSTEM ==================== */
.view {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1;
}
.view.active { display: flex; }

/* ==================== LOGIN VIEW ==================== */
.login-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

.login-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(124, 58, 237, 0.15) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: glowPulse 4s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

.login-card {
    position: relative;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    max-width: 420px;
    width: 90%;
    backdrop-filter: blur(40px);
    text-align: center;
    animation: fadeInUp 0.6s ease;
    box-shadow: var(--shadow-glow);
}

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

.login-logo { margin-bottom: 24px; display: inline-block; }
.login-logo svg { filter: drop-shadow(0 4px 12px rgba(124, 58, 237, 0.3)); }

.login-title {
    font-size: 28px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
    line-height: 1.6;
}

.btn-github {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 14px 24px;
    background: #ffffff;
    color: #0a0a14;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 15px;
    transition: all var(--transition-normal);
    text-decoration: none;
    box-shadow: var(--shadow-sm);
}

.btn-github:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.15);
    background: #f0f0f0;
}

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

.login-features {
    margin-top: 36px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feature {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.feature:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.feature-icon { font-size: 16px; }

/* ==================== USERNAME SETUP ==================== */
.setup-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin: 0 auto 20px;
    overflow: hidden;
    border: 3px solid transparent;
    background: var(--accent-gradient) border-box;
    padding: 3px;
}

.setup-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.username-form {
    margin-top: 24px;
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition-fast);
}

.input-group:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.input-prefix {
    padding: 14px 0 14px 16px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 16px;
}

.input-group input {
    flex: 1;
    padding: 14px 16px 14px 4px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
}

.input-group input::placeholder { color: var(--text-muted); }

.input-hint {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.input-error {
    margin-top: 6px;
    font-size: 13px;
    color: var(--danger);
    min-height: 20px;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 24px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 15px;
    margin-top: 16px;
    transition: all var(--transition-normal);
    cursor: pointer;
}

.btn-primary:hover {
    background: var(--accent-gradient-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ==================== CHAT LAYOUT ==================== */
.chat-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: var(--bg-primary);
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    z-index: 10;
}

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

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

.sidebar-brand svg { width: 32px; height: 32px; }

.brand-text {
    font-size: 18px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

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

/* Search */
.sidebar-search {
    padding: 12px 16px;
    position: relative;
}

.search-input-wrap {
    display: flex;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 0 14px;
    transition: all var(--transition-fast);
}

.search-input-wrap:focus-within {
    border-color: var(--accent-primary);
    background: rgba(124, 58, 237, 0.06);
}

.search-icon { color: var(--text-muted); flex-shrink: 0; }

.search-input-wrap input {
    flex: 1;
    padding: 10px 10px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

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

.search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    color: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.search-clear:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Search Results */
.search-results {
    position: absolute;
    top: 100%;
    left: 16px;
    right: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 300px;
    overflow-y: auto;
    z-index: 20;
    animation: slideDown 0.2s ease;
}

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

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.search-result-item:hover { background: var(--bg-hover); }

.search-result-item .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.search-result-info { flex: 1; }
.search-result-info .name { font-weight: 500; font-size: 14px; }
.search-result-info .handle { font-size: 12px; color: var(--text-muted); }

.search-result-online {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

/* Conversation List */
.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active { background: var(--bg-active); }

.conversation-item .avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.conversation-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.conversation-item .status-indicator {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    background: var(--text-muted);
}

.conversation-item .status-indicator.online {
    background: var(--success);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

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

.conversation-info .top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

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

.conversation-info .time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.conversation-info .preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.conversation-info .preview.unread {
    color: var(--text-primary);
    font-weight: 500;
}

.unread-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.empty-state p {
    margin-top: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

.empty-state span {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Sidebar Footer */
.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

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

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

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

.user-handle {
    font-size: 11px;
    color: var(--text-muted);
}

.btn-logout { color: var(--text-muted); }
.btn-logout:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }

/* ==================== CHAT MAIN ==================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    background: var(--bg-primary);
}

/* Chat Empty State */
.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-empty-content {
    text-align: center;
    animation: fadeInUp 0.6s ease;
}

.chat-empty-content h2 {
    margin-top: 20px;
    font-size: 24px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chat-empty-content p {
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: var(--header-height);
    border-bottom: 1px solid var(--border-color);
    background: rgba(17, 17, 34, 0.8);
    backdrop-filter: blur(20px);
    z-index: 5;
}

.btn-back { display: none; }

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

.avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    background: var(--text-muted);
    transition: background var(--transition-fast);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.chat-header-info {
    display: flex;
    flex-direction: column;
}

.chat-header-name {
    font-weight: 600;
    font-size: 15px;
}

.chat-header-status {
    font-size: 12px;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}

.chat-header-status.typing {
    color: var(--success);
}

/* ==================== MESSAGES ==================== */
.messages-area {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.messages-scroll {
    height: 100%;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
}

#messages-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: auto;
}

.load-more {
    text-align: center;
    padding: 12px;
}

.btn-load-more {
    padding: 8px 20px;
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

/* Message Bubble */
.message {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    animation: msgIn 0.3s ease;
}

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

.message.sent { align-self: flex-end; align-items: flex-end; }
.message.received { align-self: flex-start; align-items: flex-start; }

.message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}

.message.sent .message-bubble {
    background: var(--msg-sent);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.received .message-bubble {
    background: var(--msg-received);
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
    border: 1px solid var(--border-color);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding: 0 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
}

.message-seen {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}

.message-seen.seen { color: var(--accent-secondary); }

.message-seen svg { width: 14px; height: 14px; }

/* Date Separator */
.date-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.date-separator span {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

/* Image Message */
.message-image {
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    max-width: 300px;
    transition: transform var(--transition-fast);
}

.message-image:hover { transform: scale(1.02); }

.message-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* Document Message */
.message-document {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    min-width: 240px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.message.received .message-document { background: rgba(255, 255, 255, 0.04); }
.message-document:hover { background: rgba(255, 255, 255, 0.08); }

.doc-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

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

.doc-size {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.doc-download {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.doc-download:hover {
    background: var(--accent-primary);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    animation: fadeIn 0.3s ease;
}

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

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: var(--msg-received);
    border-radius: 18px;
    border: 1px solid var(--border-color);
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.typing-text {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* ==================== MESSAGE INPUT ==================== */
.message-input-area {
    border-top: 1px solid var(--border-color);
    background: rgba(17, 17, 34, 0.8);
    backdrop-filter: blur(20px);
}

.input-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
}

.btn-attach {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.text-input-wrap {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 22px;
    overflow: hidden;
    transition: border-color var(--transition-fast);
}

.text-input-wrap:focus-within {
    border-color: var(--accent-primary);
}

.text-input-wrap textarea {
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
}

.text-input-wrap textarea::placeholder { color: var(--text-muted); }

.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    color: white;
}

.btn-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* File Preview */
.file-preview {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    animation: slideDown 0.2s ease;
}

.file-preview-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.file-preview-content img {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.file-preview-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-size {
    font-size: 11px;
    color: var(--text-muted);
}

.file-preview-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.file-preview-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* Upload Progress */
.upload-progress {
    padding: 8px 16px;
    position: relative;
}

.upload-progress-bar {
    height: 3px;
    background: var(--accent-gradient);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-progress-text {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

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

.modal {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 440px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-body .search-input-wrap { margin-bottom: 16px; }

.modal-search-results {
    max-height: 360px;
    overflow-y: auto;
}

/* ==================== LIGHTBOX ==================== */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.3s ease;
}

.lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }

/* ==================== TOAST ==================== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 300;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    pointer-events: auto;
    font-size: 14px;
    max-width: 360px;
}

.toast.error { border-left: 3px solid var(--danger); }
.toast.success { border-left: 3px solid var(--success); }
.toast.info { border-left: 3px solid var(--accent-secondary); }

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

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

/* ==================== MOBILE OVERLAY ==================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
}

/* ==================== RESPONSIVE & MOBILE OPTIMIZATIONS ==================== */
html, body {
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.chat-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    background: var(--bg-primary);
    overflow: hidden;
}

@media (max-width: 768px) {
    :root { 
        --sidebar-width: 100vw; 
        --header-height: 58px;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        transform: translateX(0);
        transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 20;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .sidebar.hidden {
        transform: translateX(-100%);
    }

    .sidebar-overlay.active {
        display: block;
        backdrop-filter: blur(4px);
    }

    .btn-back { 
        display: flex !important;
        width: 40px;
        height: 40px;
    }

    .chat-main { 
        width: 100vw; 
        height: 100vh;
        height: 100dvh;
    }

    .chat-header {
        padding: 0 12px;
    }

    .chat-header-name {
        font-size: 14px;
    }

    .message { 
        max-width: 88%; 
    }

    .message-image { 
        max-width: 240px; 
    }

    .message-document {
        min-width: 200px;
        padding: 10px;
    }

    input[type="text"], textarea {
        font-size: 16px !important;
    }

    .input-bar {
        padding: 8px 10px;
        gap: 6px;
    }

    .btn-attach, .btn-send {
        width: 42px;
        height: 42px;
    }

    .messages-scroll {
        padding: 12px 14px;
    }

    .toast-container {
        bottom: 16px;
        right: 16px;
        left: 16px;
    }

    .toast { 
        max-width: 100%; 
    }

    .friend-item {
        padding: 8px 10px;
    }

    .friend-actions .btn-xs {
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    .login-card { 
        padding: 28px 20px; 
        width: 95%;
    }
    .login-title { 
        font-size: 22px; 
    }
    .login-subtitle {
        font-size: 13px;
        margin-bottom: 24px;
    }
    .message { 
        max-width: 92%; 
    }
    .message-bubble {
        padding: 8px 12px;
        font-size: 13.5px;
    }
    .msg-delete-btn {
        opacity: 0.8;
        pointer-events: auto;
    }
}

/* ==================== LOADING SPINNER ==================== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

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

.btn-loading {
    pointer-events: none;
    opacity: 0.7;
}

.btn-loading .spinner { margin-right: 8px; }

.drag-overlay {
    position: absolute;
    inset: 0;
    background: rgba(124, 58, 237, 0.1);
    border: 2px dashed var(--accent-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    pointer-events: none;
    animation: fadeIn 0.2s ease;
}

.drag-overlay-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-primary);
}

.message-caption {
    margin-top: 6px;
    font-size: 13px;
    opacity: 0.9;
}

/* ==================== SIDEBAR TABS ==================== */
.sidebar-tabs {
    display: flex;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid var(--border-color);
    gap: 8px;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
}

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

.tab-btn.active {
    color: white;
    background: var(--accent-gradient);
    border-color: transparent;
}

.badge-count {
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    min-width: 16px;
    text-align: center;
}

.tab-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ==================== FRIENDS SECTION ==================== */
.friends-container {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.friends-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding: 0 4px;
}

.friend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

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

.friend-item-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.friend-item-info img, .friend-avatar {
    width: 38px !important;
    height: 38px !important;
    max-width: 38px !important;
    max-height: 38px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    flex-shrink: 0 !important;
}

.friend-item-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.friend-item-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friend-item-handle {
    font-size: 11px;
    color: var(--text-muted);
}

.friend-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.btn-xs {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    outline: none;
}

.btn-accept {
    background: var(--success);
    color: white;
}
.btn-accept:hover { opacity: 0.9; }

.btn-reject, .btn-cancel {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}
.btn-reject:hover, .btn-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.btn-add-friend {
    background: var(--accent-gradient);
    color: white;
}
.btn-add-friend:hover { opacity: 0.9; }

/* ==================== CHAT MAIN & ACTIVE LAYOUT FIX ==================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    min-width: 0;
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
}

.chat-empty {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-active {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.chat-header {
    width: 100%;
    height: var(--header-height);
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(17, 17, 34, 0.85);
    backdrop-filter: blur(20px);
    z-index: 5;
    flex-shrink: 0;
}

.messages-area {
    flex: 1;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.messages-scroll {
    flex: 1;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

#messages-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: auto;
    width: 100%;
}

.message-input-area {
    width: 100%;
    flex-shrink: 0;
    background: rgba(17, 17, 34, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    z-index: 10;
}

/* ==================== MESSAGE HOVER DELETE ==================== */
.message {
    position: relative;
}

.message-bubble-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
}

.message.sent .message-bubble-wrap { flex-direction: row-reverse; }

.msg-delete-btn {
    opacity: 0;
    pointer-events: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    border: none;
}

.message-bubble-wrap:hover .msg-delete-btn {
    opacity: 1;
    pointer-events: auto;
}

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

.chat-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-delete-chat:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.15);
}

/* ==================== MODAL BUTTONS ==================== */
.modal-sm { max-width: 380px; }

.btn-secondary {
    padding: 10px 18px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.15); }

.btn-danger {
    padding: 10px 18px;
    background: var(--danger);
    color: white;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
}
.btn-danger:hover { opacity: 0.9; box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3); }

/* ==================== USER AVATAR CONTAINER & EDIT BADGE ==================== */
.user-avatar-container {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.user-avatar-wrap {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.user-avatar-wrap:hover {
    transform: scale(1.05);
    box-shadow: 0 0 12px var(--accent-glow);
}

.user-avatar-wrap img {
    width: 40px !important;
    height: 40px !important;
    max-width: 40px !important;
    max-height: 40px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
}

.avatar-edit-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: 2px solid var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--transition-fast);
    z-index: 5;
}

.avatar-edit-badge:hover {
    transform: scale(1.2);
    box-shadow: 0 0 8px var(--accent-glow);
}
