/* ============== CSS VARIABLES - LIQUID GLASS EDITION ============== */
:root {
    /* Toast-themed colors */
    --toast-light: #F5E6D3;
    --toast-medium: #D4A574;
    --toast-dark: #8B6914;
    --toast-crust: #5C4033;
    --toast-butter: #FFE135;

    /* Primary colors */
    --primary: #D4A574;
    --primary-dark: #B8956A;
    --secondary: #128C7E;

    /* Liquid Glass Background - Dynamic gradient */
    --bg-dark: #0a0a0f;
    --bg-medium: #12121a;
    --bg-light: #1a1a25;
    --bg-chat: #080810;

    /* Text colors - High contrast for readability */
    --text-primary: #ffffff;
    --text-secondary: #b8c0c8;
    --text-muted: #7a8490;
    --border-color: rgba(255, 255, 255, 0.15);

    /* Message colors - Glass variants */
    --message-out: rgba(0, 92, 75, 0.7);
    --message-in: rgba(32, 44, 51, 0.7);
    --online: #25D366;
    --danger: #F15C6D;
    --success: #25D366;

    /* Spacing */
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 50%;

    /* Liquid Glass Effects */
    --glass-blur: 30px;
    --glass-blur-heavy: 40px;
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-bg-light: rgba(255, 255, 255, 0.12);
    --glass-bg-dark: rgba(0, 0, 0, 0.4);
    --glass-border: 1.5px solid rgba(255, 255, 255, 0.25);
    --glass-border-strong: 2px solid rgba(255, 255, 255, 0.35);
    --glass-highlight: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.05) 50%, rgba(255, 255, 255, 0.1) 100%);
    --glass-inner-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.15), inset 0 -1px 1px rgba(0, 0, 0, 0.1);

    /* Specular Highlights */
    --specular-top: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, transparent 50%);
    --specular-edge: 0 0 0 1px rgba(255, 255, 255, 0.2);

    /* Text Glow for Glass Readability */
    --text-glow: 0 0 10px rgba(0, 0, 0, 0.8), 0 0 20px rgba(0, 0, 0, 0.5), 0 0 30px rgba(0, 0, 0, 0.3);
    --text-glow-light: 0 0 8px rgba(255, 255, 255, 0.3), 0 1px 2px rgba(0, 0, 0, 0.5);

    /* Shadows - Glass Style */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.15);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.2);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* ============== RESET & BASE ============== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ============== AUTH PAGES ============== */
.auth-page {
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--toast-crust) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: linear-gradient(180deg, var(--bg-medium) 0%, var(--bg-dark) 100%);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--toast-medium), var(--toast-butter), var(--toast-medium));
}

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

.logo-container {
    position: relative;
    display: inline-block;
    margin-bottom: 16px;
}

.logo-emoji {
    font-size: 64px;
    display: block;
    animation: bounce 2s ease-in-out infinite;
}

.toast-steam {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
}

.toast-steam::before,
.toast-steam::after {
    content: '~';
    position: absolute;
    color: var(--text-muted);
    font-size: 16px;
    animation: steam 1.5s ease-in-out infinite;
}

.toast-steam::after {
    left: 15px;
    animation-delay: 0.3s;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes steam {
    0% {
        opacity: 0;
        transform: translateY(0);
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translateY(-15px);
    }
}

.auth-header h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--toast-light), var(--toast-butter));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

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

/* Form Styles */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 16px;
    font-size: 18px;
    z-index: 1;
}

.input-group input {
    width: 100%;
    padding: 16px 16px 16px 52px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    transition: all 0.3s ease;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.2);
}

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

/* Buttons - LIQUID GLASS */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 28px;
    background: linear-gradient(135deg, rgba(212, 165, 116, 0.85), rgba(139, 105, 20, 0.9));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: var(--glass-border-strong);
    border-radius: var(--radius-md);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 8px;
    box-shadow: var(--shadow-glass), var(--specular-edge);
    text-shadow: var(--text-glow);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, transparent 100%);
    border-radius: inherit;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    pointer-events: none;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(212, 165, 116, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-emoji {
    font-size: 18px;
    animation: wiggle 0.5s ease-in-out infinite;
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-5deg);
    }

    75% {
        transform: rotate(5deg);
    }
}

.btn-secondary {
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
    box-shadow: var(--shadow-md), 0 0 15px rgba(212, 165, 116, 0.2);
}

/* Flash Messages */
.flash-message {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.flash-message.error {
    background: rgba(241, 92, 109, 0.15);
    border: 1px solid var(--danger);
    color: var(--danger);
}

.flash-message.success {
    background: rgba(37, 211, 102, 0.15);
    border: 1px solid var(--success);
    color: var(--success);
}

/* Auth Footer */
.auth-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

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

.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

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

/* Bread Decoration */
.bread-decoration {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
    opacity: 0.6;
}

.bread-decoration span {
    font-size: 24px;
    animation: float 3s ease-in-out infinite;
}

.bread-decoration span:nth-child(2) {
    animation-delay: 0.2s;
}

.bread-decoration span:nth-child(3) {
    animation-delay: 0.4s;
}

.bread-decoration span:nth-child(4) {
    animation-delay: 0.6s;
}

.bread-decoration span:nth-child(5) {
    animation-delay: 0.8s;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

/* ============== CHAT PAGE ============== */
.chat-page {
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-dark);
}

/* Sidebar - LIQUID GLASS with Plus Grid Pattern */
.sidebar {
    width: 100%;
    max-width: 420px;
    background:
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.08'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
        linear-gradient(180deg, rgba(12, 12, 18, 0.92), rgba(8, 8, 12, 0.98));
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border-right: var(--glass-border-strong);
    display: flex;
    flex-direction: column;
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.1);
}

.sidebar-header {
    padding: 16px;
    background: linear-gradient(180deg, rgba(26, 26, 37, 0.9), rgba(18, 18, 26, 0.85));
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: var(--glass-border);
    box-shadow: var(--glass-inner-shadow);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.user-profile:hover {
    background: var(--bg-medium);
}

.user-avatar {
    font-size: 36px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--toast-medium), var(--toast-dark));
    border-radius: var(--radius-full);
}

.user-info {
    display: flex;
    flex-direction: column;
}

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

.user-status-text {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background 0.2s;
    font-size: 20px;
}

.icon-btn:hover {
    background: var(--bg-medium);
}

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

.search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
}

.search-box input {
    width: 100%;
    padding: 12px 12px 12px 44px;
    background: var(--bg-light);
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
}

.search-box input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(212, 165, 116, 0.3);
}

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

/* Contacts List */
.contacts-list {
    flex: 1;
    overflow-y: auto;
}

.contacts-list::-webkit-scrollbar {
    width: 6px;
}

.contacts-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

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

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    animation: bounce 2s ease-in-out infinite;
}

.empty-contacts p {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

/* Contact Item - LIQUID GLASS */
.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: transparent;
    position: relative;
}

.contact-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--glass-highlight);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.contact-item:hover {
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.contact-item:hover::before {
    opacity: 0.5;
}

.contact-item.active {
    background: linear-gradient(90deg, rgba(212, 165, 116, 0.15), rgba(255, 255, 255, 0.05));
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-left: 3px solid var(--primary);
    box-shadow: inset 0 0 20px rgba(212, 165, 116, 0.1);
}

.contact-item .contact-avatar {
    font-size: 32px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-light), var(--bg-medium));
    border-radius: var(--radius-full);
    position: relative;
}

.contact-item .online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--online);
    border: 2px solid var(--bg-medium);
    border-radius: var(--radius-full);
}

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

.contact-item .contact-name {
    font-weight: 500;
    font-size: 15px;
    margin-bottom: 2px;
}

.contact-item .contact-last-message {
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.contact-item .unread-badge {
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
}

/* Message Ticks */
.tick {
    font-size: 10px;
    margin-left: 4px;
    color: rgba(255, 255, 255, 0.5);
    /* Grey for sent */
    display: inline-block;
}

.tick.read {
    color: #4FB6EC;
    /* WhatsApp-like Blue for read */
}

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

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, var(--bg-medium) 0%, var(--bg-dark) 100%);
}

.welcome-content {
    text-align: center;
    padding: 24px;
}

.welcome-logo {
    position: relative;
    display: inline-block;
    margin-bottom: 24px;
}

.big-emoji {
    font-size: 96px;
    display: block;
    animation: bounce 2s ease-in-out infinite;
}

.toast-steam-large {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
}

.toast-steam-large::before,
.toast-steam-large::after,
.toast-steam-large span {
    content: '~';
    position: absolute;
    color: var(--text-muted);
    font-size: 24px;
    animation: steam 1.5s ease-in-out infinite;
}

.toast-steam-large::after {
    left: 25px;
    animation-delay: 0.5s;
}

.welcome-content h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--toast-light), var(--toast-butter));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.bread-row {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.bread-row span {
    font-size: 32px;
    animation: float 3s ease-in-out infinite;
}

.bread-row span:nth-child(2) {
    animation-delay: 0.15s;
}

.bread-row span:nth-child(3) {
    animation-delay: 0.3s;
}

.bread-row span:nth-child(4) {
    animation-delay: 0.45s;
}

.bread-row span:nth-child(5) {
    animation-delay: 0.6s;
}

/* Chat Area - with Bread Emoji Outline Background (Reference PS Design) */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #121212;
    /* Darker background like in screenshot */
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    max-height: 100%;
}

/* Animated bread emoji pattern overlay - Seamless SVG Pattern */
.chat-area::before {
    content: '';
    position: absolute;
    inset: 0;
    /* Mathematically seamless SVG pattern */
    background-image: url('/static/img/bread_pattern_seamless.svg');
    background-size: 280px 280px;
    background-repeat: repeat;
    opacity: 0.25;
    /* Subtle and crisp */
    pointer-events: none;
    z-index: 0;
    animation: breadDrift 180s linear infinite;
}

@keyframes breadDrift {
    0% {
        background-position: 0 0;
    }

    100% {
        background-position: 480px 240px;
    }
}

.chat-header {
    padding: 12px 16px;
    background: var(--bg-light);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
    /* Ensure header is above background overlay */
}

.back-btn {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 20px;
    color: var(--text-primary);
}

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

.chat-header .contact-avatar {
    font-size: 28px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-dark), var(--bg-medium));
    border-radius: var(--radius-full);
}

.contact-details {
    display: flex;
    flex-direction: column;
}

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

.chat-header .contact-status {
    font-size: 12px;
    color: var(--online);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Message Bubbles - LIQUID GLASS */
.message {
    max-width: 65%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    position: relative;
    animation: messageIn 0.3s ease-out;
    /* Prevent text selection and default context menu on mobile */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;

    /* Ultra Crystal Clear: No Blur on the pane itself */
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    box-shadow: var(--shadow-glass), var(--specular-edge);
}

.message::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--glass-highlight);
    pointer-events: none;
    z-index: 1;
}

.message::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    border-radius: inherit;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    background: var(--specular-top);
    pointer-events: none;
    opacity: 0.6;
    /* Increased for better glass reflection */
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.sent {
    align-self: flex-end;
    /* Crystal Clear: Updated Green Tint */
    background: linear-gradient(135deg, rgba(80, 255, 150, 0.25), rgba(50, 200, 120, 0.15));
    border: 1.5px solid rgba(150, 255, 180, 0.65);
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15), inset 0 0 20px rgba(100, 255, 150, 0.1);
}

.message.received {
    align-self: flex-start;
    /* Crystal Clear: Pure white glass, fully transparent */
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    border-bottom-left-radius: 6px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), inset 0 0 20px rgba(255, 255, 255, 0.05);
}

.message-content {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    z-index: 2;
    color: #ffffff;
    /* Engraved effect: Darker core shadow with a tiny white blur/glow around characters */
    text-shadow:
        0 px 1px rgba(0, 0, 0, 0.8),
        0 1px 2px rgba(0, 0, 0, 1),
        0 0 1px rgba(255, 255, 255, 0.4);
    font-weight: 500;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    position: relative;
    z-index: 2;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.message-status {
    font-size: 14px;
}

/* Date Separator */
.date-separator {
    text-align: center;
    margin: 16px 0;
}

.date-separator span {
    background: var(--bg-light);
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: 8px;
    font-size: 12px;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0 16px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 13px;
}

.typing-dots span {
    animation: typingDot 1.4s infinite;
}

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

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

@keyframes typingDot {

    0%,
    60%,
    100% {
        opacity: 0.3;
    }

    30% {
        opacity: 1;
    }
}

/* Chat Footer */
.chat-footer {
    padding: 12px 16px;
    background: var(--bg-light);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 10;
    /* Ensure footer/input bar is above background overlay */
}

.emoji-btn,
.send-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 24px;
    transition: all 0.2s;
}

.emoji-btn:hover {
    background: var(--bg-medium);
}

.send-btn {
    background: linear-gradient(135deg, var(--toast-medium), var(--toast-dark));
}

.send-btn:hover {
    transform: scale(1.05);
}

.message-input-container {
    flex: 1;
}

.message-input-container input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-medium);
    border: none;
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 15px;
}

.message-input-container input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(212, 165, 116, 0.3);
}

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

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 80px;
    left: 16px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-width: 320px;
    animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.emoji-category h4 {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.emoji-category+.emoji-category {
    margin-top: 16px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.emoji-grid span {
    font-size: 24px;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.emoji-grid span:hover {
    background: var(--bg-medium);
}

/* ============== MODALS ============== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-medium);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    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: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

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

.close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 24px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

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

.modal-body {
    padding: 24px;
}

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

/* Profile Avatar Selector */
.profile-avatar-selector {
    text-align: center;
    margin-bottom: 24px;
}

.current-avatar {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
}

.avatar-options {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.avatar-options span {
    font-size: 28px;
    padding: 8px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.avatar-options span:hover {
    background: var(--bg-light);
    transform: scale(1.1);
}

/* Search Results */
.search-results {
    margin-top: 16px;
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

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

.search-result-item .avatar {
    font-size: 24px;
}

/* ============== RESPONSIVE ============== */
@media (max-width: 768px) {
    .sidebar {
        max-width: 100%;
        position: absolute;
        z-index: 10;
        transition: transform 0.3s ease;
    }

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

    .chat-main {
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
    }

    .back-btn {
        display: flex;
    }

    .mobile-only {
        display: flex;
    }

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

@media (min-width: 769px) {
    .mobile-only {
        display: none;
    }
}

/* ============== FILE MANAGER ============== */
.file-manager-modal .modal-content {
    width: 95% !important;
    min-width: 320px !important;
    max-width: 800px !important;
    max-height: 90vh;
    background: linear-gradient(180deg, var(--bg-medium) 0%, var(--bg-dark) 100%);
    padding: 24px;
}

.file-manager-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.file-manager-header h3 {
    background: linear-gradient(135deg, var(--toast-medium), var(--toast-butter));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.4rem;
}

/* Storage Bar */
.storage-bar-container {
    background: linear-gradient(135deg, var(--bg-light), var(--bg-dark));
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    overflow: visible;
}

.storage-info {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    min-height: 28px;
    line-height: 1.4;
}

.storage-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    line-height: 1.4;
}

.storage-value {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    white-space: nowrap;
}

.storage-bar {
    background: var(--bg-dark);
    border-radius: 8px;
    height: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.storage-fill {
    height: 100%;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--secondary), var(--online), var(--toast-butter));
    background-size: 200% 100%;
    animation: storageGradient 3s ease infinite;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.storage-fill.warning {
    background: linear-gradient(90deg, #f4b400, #ff8c00);
}

.storage-fill.danger {
    background: linear-gradient(90deg, var(--danger), #ff4500);
}

@keyframes storageGradient {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    text-align: center;
    margin-bottom: 20px;
    transition: all 0.3s ease;
    cursor: pointer;
    background: rgba(212, 165, 116, 0.02);
}

.upload-zone:hover {
    border-color: var(--primary);
    background: rgba(212, 165, 116, 0.08);
    transform: translateY(-2px);
}

.upload-zone.dragover {
    border-color: var(--online);
    background: rgba(37, 211, 102, 0.1);
    transform: scale(1.01);
}

.upload-zone-icon {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.upload-zone-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.upload-zone-text strong {
    color: var(--primary);
}

/* File List */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

.file-list::-webkit-scrollbar {
    width: 6px;
}

.file-list::-webkit-scrollbar-track {
    background: var(--bg-dark);
    border-radius: 3px;
}

.file-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.file-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* File Item */
.file-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--bg-light), var(--bg-medium));
    border-radius: var(--radius-sm);
    gap: 12px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.file-item:hover {
    background: linear-gradient(135deg, var(--bg-medium), var(--bg-light));
    border-color: var(--border-color);
    transform: translateX(4px);
}

.file-thumbnail {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.file-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--toast-medium));
    border-radius: 6px;
    font-size: 22px;
}

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

.file-name {
    color: var(--text-primary);
    text-decoration: none;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    margin-bottom: 4px;
    transition: color 0.2s;
}

.file-name:hover {
    color: var(--primary);
}

.file-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-meta .sent-badge {
    color: var(--online);
    font-weight: 500;
}

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

.file-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-dark);
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-action-btn:hover {
    background: var(--primary);
    transform: scale(1.1);
}

.file-action-btn.delete:hover {
    background: var(--danger);
}

/* Upload Progress */
.upload-progress-item {
    display: flex;
    align-items: center;
    padding: 14px;
    background: linear-gradient(135deg, rgba(212, 165, 116, 0.1), var(--bg-light));
    border-radius: var(--radius-sm);
    gap: 12px;
    border: 1px solid var(--primary);
    animation: uploadPulse 2s ease-in-out infinite;
}

@keyframes uploadPulse {

    0%,
    100% {
        border-color: var(--primary);
    }

    50% {
        border-color: var(--toast-butter);
    }
}

.upload-icon {
    font-size: 24px;
    animation: uploadBounce 1s ease-in-out infinite;
}

@keyframes uploadBounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

.upload-progress-bar {
    background: var(--bg-dark);
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
    margin: 6px 0 4px;
}

.upload-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--toast-butter));
    border-radius: 4px;
    transition: width 0.2s ease;
    position: relative;
}

.upload-progress-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3));
    animation: uploadShine 1s ease-in-out infinite;
}

@keyframes uploadShine {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

.upload-cancel-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    color: var(--danger);
    transition: all 0.2s;
    border-radius: 4px;
}

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

/* Empty State */
.file-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.file-empty-state .empty-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 12px;
    opacity: 0.5;
}

.file-empty-state p {
    margin-top: 8px;
    font-size: 0.9rem;
}

/* Profile Dropdown */
.profile-dropdown {
    background: linear-gradient(180deg, var(--bg-medium), var(--bg-dark));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    min-width: 160px;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.profile-dropdown .dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    transition: all 0.2s;
}

.profile-dropdown .dropdown-item:hover {
    background: var(--bg-light);
}

.profile-dropdown .dropdown-item.logout {
    border-top: 1px solid var(--border-color);
    color: var(--danger);
}

.profile-dropdown .dropdown-item.logout:hover {
    background: rgba(241, 92, 109, 0.1);
}

/* Swipe to Reply */
.swipe-reply-icon {
    position: absolute;
    left: -40px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    font-size: 20px;
    opacity: 0;
    transition: transform 0.2s, opacity 0.2s;
    pointer-events: none;
    z-index: 10;
}

.message {
    /* Essential for swipe positioning */
    transform: translateX(0);
    touch-action: pan-y;
    /* Allow vertical scroll, handle horizontal manual */
    will-change: transform;
    /* Performance hint */
}

.message-reply-context:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* ============== MESSAGE CONTEXT MENU ============== */
.context-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.context-menu {
    background: rgba(30, 30, 30, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 24px;
    width: 90%;
    max-width: 400px;
    margin-bottom: 24px;
    padding: 8px;
    animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes slideUp {
    from {
        transform: translateY(120%) scale(0.9);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.context-menu-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 4px;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    font-size: 1rem;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    border-radius: 12px;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.02);
}

.context-menu-item:active {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(0.98);
}

.context-menu-icon {
    font-size: 1.2rem;
}

.context-menu-cancel {
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #ff5252;
    justify-content: center;
    font-weight: 500;
}

.context-menu-cancel:hover {
    background: rgba(255, 82, 82, 0.1);
}

/* Deleted message styling */
.message.deleted .message-content {
    font-style: italic;
    color: var(--text-muted);
    opacity: 0.7;
}