/* Update CSS overrides for Chat App */
:root {
    --bg-dark: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --accent-color: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --msg-sent: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --msg-received: rgba(51, 65, 85, 0.8);
    --border-radius: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --bg-dark: #f1f5f9;
    --bg-panel: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0, 0, 0, 0.1);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --msg-received: rgba(226, 232, 240, 0.9);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    position: fixed; /* Bulletproof fix for iOS/Android elastic boundary bounces */
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.15) 0%, transparent 50%);
}

.hidden { display: none !important; }
.mb-4 { margin-bottom: 1rem; }
.opacity-50 { opacity: 0.5; }

/* Screens */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 10;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    z-index: 20;
}

/* Glassmorphism Panels */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 420px;
    text-align: center;
    max-height: 95dvh;
    overflow-y: auto;
}

.logo { font-size: 2.5rem; font-weight: 700; margin-bottom: 0.5rem; display: flex; align-items: center; justify-content: center; gap: 10px; }
.glow-text { background: linear-gradient(to right, #60a5fa, #a78bfa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; text-shadow: 0 0 20px rgba(139, 92, 246, 0.3); }
.subtitle { color: var(--success); font-size: 0.9rem; margin-bottom: 2rem; letter-spacing: 1px; }
.desc { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 1.5rem; line-height: 1.5; }

.tabs { display: flex; margin-bottom: 2rem; background: rgba(0,0,0,0.2); border-radius: 8px; padding: 4px; }
.tab-btn { flex: 1; background: transparent; border: none; color: var(--text-secondary); padding: 10px; border-radius: 6px; cursor: pointer; font-weight: 500; transition: var(--transition); }
.tab-btn.active { background: var(--primary-color); color: white; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); }

.input-group { position: relative; margin-bottom: 1.5rem; }
.input-group i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); }
.input-group input { width: 100%; padding: 14px 15px 14px 45px; background: rgba(0,0,0,0.2); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: var(--text-primary); font-size: 1rem; transition: var(--transition); outline: none; }
.input-group input:focus { border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }

.btn { width: 100%; padding: 14px; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; display: flex; justify-content: center; align-items: center; gap: 10px; transition: var(--transition); }
.primary-btn { background: linear-gradient(135deg, var(--primary-color), var(--accent-color)); color: white; box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.3); }
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 20px 25px -5px rgba(59, 130, 246, 0.4); }
.google-btn { background: white; color: #333; }
.google-btn img { width: 20px; }
.google-btn:hover { background: #f8fafc; }

.divider { display: flex; align-items: center; margin: 1.5rem 0; color: var(--text-secondary); font-size: 0.85rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(255,255,255,0.1); }
.divider span { padding: 0 10px; }

.helper-text { font-size: 0.85rem; margin-top: -10px; margin-bottom: 15px; text-align: left; }
.error { color: var(--danger); }
.warning { color: #f59e0b; }
.error-msg { color: var(--danger); font-size: 0.9rem; margin-top: 15px; min-height: 20px; }

/* Spinner */
.spinner { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: white; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Main App Container */
.app-container {
    display: flex;
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Sidebar */
.sidebar { width: 350px; border-right: 1px solid var(--glass-border); display: flex; flex-direction: column; background: rgba(15, 23, 42, 0.1); }
.sidebar-header { padding: 20px; display: flex; flex-direction: row; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--glass-border); }
.sidebar-actions { padding: 15px 20px; display: flex; flex-direction: column; gap: 10px; }

.add-friend-panel { display: flex; gap: 8px; margin-bottom: 5px; }
.add-friend-panel input { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--glass-border); background: rgba(0,0,0,0.1); color: var(--text-primary); outline: none; }


.user-profile { display: flex; align-items: center; gap: 15px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-color), var(--primary-color)); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem; color: white; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.2); flex-shrink: 0; }
.user-info h3 { font-size: 1.1rem; margin-bottom: 4px; }

.status-indicator { font-size: 0.8rem; display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.status-indicator::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--text-secondary); }
.status-indicator.online::before { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-indicator.offline::before { background: var(--danger); }

.icon-btn { background: transparent; border: none; color: var(--text-secondary); font-size: 1.2rem; cursor: pointer; width: 40px; height: 40px; border-radius: 50%; transition: var(--transition); display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }

.search-bar { flex: 1; position: relative; }
.search-bar i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); }
.search-bar input { width: 100%; padding: 12px 15px 12px 40px; background: rgba(0,0,0,0.2); border: 1px solid transparent; border-radius: 20px; color: var(--text-primary); font-size: 0.95rem; transition: var(--transition); outline: none; }
.search-bar input:focus { border-color: rgba(255,255,255,0.1); background: rgba(0,0,0,0.4); }

.contacts-list { flex: 1; overflow-y: auto; }
.contacts-list::-webkit-scrollbar { width: 5px; }
.contacts-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 5px; }

.contact-item { display: flex; align-items: center; padding: 15px 20px; gap: 15px; cursor: pointer; transition: var(--transition); border-bottom: 1px solid rgba(255,255,255,0.02); }
.contact-item:hover, .contact-item.active { background: rgba(255,255,255,0.05); }
.contact-details { flex: 1; min-width: 0; }
.contact-header { display: flex; justify-content: space-between; margin-bottom: 4px; }
.contact-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat Area */
.chat-area { flex: 1; display: flex; flex-direction: column; position: relative; }
.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-secondary); text-align: center; gap: 15px; animation: fadeIn 0.5s ease; padding: 20px; }
.empty-state h2 { color: var(--text-primary); font-weight: 600; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.active-chat { display: flex; flex-direction: column; height: 100%; }
.active-chat.hidden { display: none; }

.chat-header { padding: 15px 25px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--glass-border); background: rgba(15, 23, 42, 0.4); }
.mobile-back-btn { display: none; background: none; border: none; color: white; font-size: 1.5rem; padding: 10px; cursor: pointer; margin-right: 15px; }
.chat-user-info { display: flex; align-items: center; gap: 15px; flex: 1; }
.chat-user-info h3 { font-size: 1.1rem; }
.chat-status { font-size: 0.85rem; color: var(--text-secondary); }
.chat-status.typing { color: var(--success); font-style: italic; }
.secure-icon { color: var(--success); font-size: 1.2rem; opacity: 0.8; }

.messages-container { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 6px; }

.message { max-width: 75%; display: flex; flex-direction: column; animation: msgIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; transform-origin: bottom; opacity: 0; transform: translateY(10px) scale(0.95); }
@keyframes msgIn { to { opacity: 1; transform: translateY(0) scale(1); } }
.message.sent { align-self: flex-end; }
.message.received { align-self: flex-start; }

.msg-bubble { padding: 12px 16px; border-radius: 18px; font-size: 0.95rem; line-height: 1.4; word-wrap: break-word; position: relative; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.message.sent .msg-bubble { background: var(--msg-sent); border-bottom-right-radius: 4px; color: white; }
.message.received .msg-bubble { background: var(--msg-received); border-bottom-left-radius: 4px; border: 1px solid rgba(255,255,255,0.05); }

.msg-info { display: flex; align-items: center; gap: 6px; margin-top: 5px; font-size: 0.75rem; color: var(--text-secondary); }
.message.sent .msg-info { justify-content: flex-end; }
.msg-status i { font-size: 0.8rem; }
.status-sent { color: var(--text-secondary); }
.status-delivered { color: #cbd5e1; }
.status-read { color: #38bdf8; }

.message-delete-btn { color: var(--danger); opacity: 0.6; cursor: pointer; transition: var(--transition); margin-right: 4px; }
.message-delete-btn:hover { opacity: 1; transform: scale(1.1); }

.chat-input-area { padding: 15px 20px; background: rgba(15, 23, 42, 0.6); border-top: 1px solid var(--glass-border); display: flex; align-items: center; gap: 12px; }
.chat-input-area input { flex: 1; background: rgba(0,0,0,0.2); border: 1px solid rgba(255,255,255,0.1); padding: 14px 20px; border-radius: 24px; color: white; font-size: 1rem; transition: var(--transition); outline: none; }
.chat-input-area input:focus { border-color: rgba(255,255,255,0.2); background: rgba(0,0,0,0.3); }

.send-btn { width: 45px; height: 45px; border-radius: 50%; padding: 0; min-width: unset; background: var(--msg-sent); }

.typing-indicator { padding: 5px 20px; display: flex; gap: 4px; align-items: center; }
.typing-indicator span { width: 6px; height: 6px; background: var(--text-secondary); border-radius: 50%; animation: typing 1s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

/* =========================================
   MOBILE RESPONSIVENESS (iOS/Android/Windows)
   ========================================= */
@media (max-width: 800px) {
    .app-container {
        width: 100%;
        height: 100%; /* Stretches exactly to the fixed body */
        max-width: none;
        border-radius: 0;
        border: none;
        background: var(--bg-dark);
    }
    
    .sidebar { width: 100%; display: flex; }
    .chat-area { display: none; width: 100%; }
    
    /* When chat opens on mobile, hide sidebar and show chat strictly */
    body.chat-active .sidebar { display: none !important; }
    body.chat-active .chat-area { display: flex !important; }
    body.chat-active #chat-empty-state { display: none !important; }
    
    body.chat-active .watermark { display: none !important; } /* Stop watermark overlapping chat text */
    
    .mobile-back-btn { display: block; }

    /* Adjust margins for auth screens to fit keyboard view on mobile */
    .glass-panel { padding: 2rem 1.5rem; }
    .logo { font-size: 2rem; }
}

/* Watermark styles */
.watermark {
    position: fixed;
    bottom: 12px;
    width: 100%;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
    opacity: 0.3;
    pointer-events: none;
    z-index: 1000;
    letter-spacing: 0.5px;
}
