/* ==========================================
   TEMA PREMIUM: OCEANIC NEON & GLASSMORPHISM
   ========================================== */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
    --neon-blue: #00f3ff;
    --neon-glow: 0 0 5px rgba(0, 243, 255, 0.3), 0 0 10px rgba(0, 243, 255, 0.5);
    --glass-bg: rgba(10, 20, 35, 0.65);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-panel: rgba(255, 255, 255, 0.05);
    --text-light: #f0f8ff;
    --text-muted: #94a3b8;
    --danger: #ff4757;
    --success: #2ed573;
    --star: #f1c40f;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: url('https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-1.2.1&auto=format&fit=crop&w=1920&q=80') no-repeat center center fixed;
    background-size: cover;
    /* Menggunakan dvh (Dynamic Viewport Height) agar pas di layar HP tanpa terpotong */
    height: 100dvh; 
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-light);
    overflow: hidden;
}

.overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(2, 6, 23, 0.85) 0%, rgba(15, 23, 42, 0.7) 100%);
    z-index: -1;
}

/* --- Container Utama --- */
.container {
    width: 95%;
    max-width: 1100px;
    height: 90dvh; /* Lebih proporsional di Desktop */
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    overflow: hidden;
    position: relative;
}

/* --- Utilities & Typography --- */
.panel { display: none; height: 100%; width: 100%; }
.panel.active { display: flex; }
.hidden { display: none !important; }

.glow-text { color: #fff; text-shadow: var(--neon-glow); font-weight: 600; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 25px; }

/* --- Auth Panel (Login/Register) --- */
#auth-panel { justify-content: center; align-items: center; padding: 20px; }
.auth-box { width: 100%; max-width: 380px; padding: 40px 30px; text-align: center; border-radius: 15px; border-top: 3px solid var(--neon-blue); }
.glass-card { background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(10px); border: 1px solid var(--glass-border); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); }
.logo-icon { font-size: 2.5rem; margin-bottom: 10px; }

.tabs { display: flex; gap: 10px; margin-bottom: 25px; background: var(--glass-panel); padding: 5px; border-radius: 10px; }
.tab-btn { flex: 1; padding: 10px; border: none; background: transparent; color: var(--text-muted); border-radius: 8px; cursor: pointer; transition: 0.3s; font-weight: 500; font-size: 0.95rem; }
.tab-btn.active, .tab-btn:hover { background: var(--neon-blue); color: #000; box-shadow: var(--neon-glow); }

.auth-form { display: none; flex-direction: column; gap: 15px; }
.auth-form.active { display: flex; animation: fadeIn 0.4s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

input { width: 100%; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--glass-border); color: var(--text-light); padding: 14px 16px; border-radius: 10px; outline: none; transition: 0.3s; }
input:focus { border-color: var(--neon-blue); background: rgba(0, 0, 0, 0.5); }

.glow-btn { background: var(--neon-blue); color: #000; border: none; padding: 14px; border-radius: 10px; font-weight: 600; font-size: 1rem; cursor: pointer; box-shadow: var(--neon-glow); transition: 0.3s; margin-top: 10px; }
.glow-btn:hover { background: #fff; box-shadow: 0 0 20px rgba(255,255,255,0.6); transform: translateY(-2px); }
.glow-btn-small { background: var(--neon-blue); color: #000; border: none; padding: 8px 15px; border-radius: 6px; font-weight: 600; cursor: pointer; transition: 0.3s; }

#auth-message { margin-top: 15px; font-size: 0.9rem; }
.error { color: var(--danger); }
.success { color: var(--success); }

/* ==========================================
   LAYOUT CHAT (SIDEBAR & MAIN AREA)
   ========================================== */
#chat-panel { flex-direction: row; }

/* --- Sidebar --- */
.sidebar { width: 320px; background: rgba(0, 0, 0, 0.3); border-right: 1px solid var(--glass-border); display: flex; flex-direction: column; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid var(--glass-border); background: rgba(255,255,255,0.02); }
.app-brand { display: flex; align-items: center; gap: 10px; }
.logo-small { font-size: 1.5rem; }

.user-avatar { width: 42px; height: 42px; border-radius: 50%; background: linear-gradient(135deg, var(--neon-blue), #0055ff); display: flex; justify-content: center; align-items: center; font-weight: 600; font-size: 1.2rem; color: #fff; cursor: pointer; box-shadow: var(--neon-glow); transition: 0.3s; object-fit: cover; }
.user-avatar:hover { transform: scale(1.05); }
img.user-avatar { padding: 0; border: 2px solid var(--neon-blue); }

.search-box { display: flex; gap: 10px; padding: 15px 20px; }
.search-box input { padding: 10px 15px; border-radius: 20px; font-size: 0.9rem; }
.icon-btn { background: transparent; border: none; color: var(--text-light); font-size: 1.2rem; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover:not(:disabled) { color: var(--neon-blue); transform: scale(1.1); }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.contact-header { padding: 10px 20px; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

#contact-list, #search-results { list-style: none; overflow-y: auto; flex: 1; padding: 0 10px 10px; }
.contact-item { display: flex; align-items: center; gap: 15px; padding: 12px 15px; border-radius: 12px; cursor: pointer; transition: 0.3s; margin-bottom: 5px; }
.contact-item:hover, .contact-item.active { background: var(--glass-panel); }
.contact-avatar { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.1); display: flex; justify-content: center; align-items: center; font-weight: 600; object-fit: cover; }
.contact-item.active .contact-avatar { background: var(--neon-blue); color: #000; }
img.contact-avatar { border: 1px solid var(--glass-border); }
.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-weight: 500; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Main Chat Area --- */
.chat-area { flex: 1; display: flex; flex-direction: column; background: rgba(0, 0, 0, 0.15); position: relative; }

.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 25px; border-bottom: 1px solid var(--glass-border); background: rgba(255,255,255,0.02); backdrop-filter: blur(5px); min-height: 70px; }
.chat-header-info { display: flex; align-items: center; gap: 15px; flex: 1; transition: 0.2s; padding: 5px; border-radius: 10px; }
.chat-header-info:hover { background: rgba(255,255,255,0.05); }
.back-btn { display: none; }
.chat-avatar { width: 45px; height: 45px; border-radius: 50%; background: #334155; display: flex; justify-content: center; align-items: center; font-weight: 600; font-size: 1.2rem; object-fit: cover; }
.chat-header-actions { display: flex; gap: 15px; }
.danger-text { color: var(--danger); font-size: 1.2rem; }
.danger-text:hover:not(:disabled) { color: #ff6b81; text-shadow: 0 0 10px rgba(255,71,87,0.5); }

.status-indicator { font-size: 0.8rem; color: var(--success); display: flex; align-items: center; gap: 5px; }
.status-indicator::before { content: ''; width: 8px; height: 8px; background: var(--success); border-radius: 50%; box-shadow: 0 0 5px var(--success); }

/* Balon Pesan & Kedip Fix */
.chat-messages { flex: 1; padding: 25px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.welcome-chat { margin: auto; text-align: center; color: var(--text-muted); }

/* Kita hapus animasi fadeIn di .msg agar tidak berkedip saat setInterval (polling) */
.msg { padding: 10px 15px; border-radius: 18px; max-width: 75%; line-height: 1.4; font-size: 0.95rem; position: relative; word-wrap: break-word; display: flex; flex-direction: column; }
.msg.sent { align-self: flex-end; background: linear-gradient(135deg, rgba(0, 243, 255, 0.15), rgba(0, 163, 255, 0.05)); border: 1px solid rgba(0, 243, 255, 0.2); border-bottom-right-radius: 4px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.msg.received { align-self: flex-start; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--glass-border); border-bottom-left-radius: 4px; }

.msg-footer { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 5px; }
.msg-time { font-size: 0.7rem; opacity: 0.6; }
.star-btn { font-size: 1rem; cursor: pointer; opacity: 0.3; transition: 0.2s; background: none; border: none; padding: 0; }
.star-btn:hover { opacity: 0.8; transform: scale(1.2); }
.star-btn.starred { opacity: 1; color: var(--star); text-shadow: 0 0 8px rgba(241, 196, 15, 0.6); }

/* Media Upload UI dalam Chat */
.chat-media-img { max-width: 100%; max-height: 250px; border-radius: 10px; margin-bottom: 8px; cursor: pointer; object-fit: contain; background: rgba(0,0,0,0.2); }
.chat-media-vid { max-width: 100%; max-height: 250px; border-radius: 10px; margin-bottom: 8px; background: rgba(0,0,0,0.5); }

/* Preview Sebelum Kirim */
#media-preview-container { padding: 10px 20px; background: rgba(0,0,0,0.5); border-top: 1px solid var(--glass-border); display: flex; align-items: center; gap: 15px; position: relative; }
#media-preview-img, #media-preview-video { max-height: 60px; border-radius: 8px; border: 1px solid var(--glass-border); }
#cancel-media-btn { position: absolute; top: 5px; right: 15px; font-size: 1.5rem; color: var(--danger); cursor: pointer; }
#media-preview-name { font-size: 0.8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }

/* Input Area */
.message-input-area { display: flex; gap: 10px; padding: 15px 25px; border-top: 1px solid var(--glass-border); background: rgba(255,255,255,0.02); align-items: center; }
.message-input-area input[type="text"] { flex: 1; border-radius: 25px; padding: 12px 20px; background: rgba(0,0,0,0.4); margin: 0; }
#attach-btn { font-size: 1.5rem; }
.send-btn { width: 45px; height: 45px; border-radius: 50%; background: var(--neon-blue); color: #000; border: none; display: flex; justify-content: center; align-items: center; cursor: pointer; box-shadow: var(--neon-glow); transition: 0.3s; flex-shrink: 0; }
.send-btn:hover:not(:disabled) { transform: scale(1.1); background: #fff; }
.send-btn:disabled { background: #334155; color: #94a3b8; box-shadow: none; cursor: not-allowed; }

/* --- Modal Profil Premium --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px); z-index: 1000; display: flex; justify-content: center; align-items: center; }
.modal-content { width: 90%; max-width: 350px; padding: 30px; border-radius: 20px; position: relative; text-align: center; }
.close-btn { position: absolute; top: 15px; right: 20px; background: transparent; border: none; font-size: 1.8rem; color: var(--text-muted); cursor: pointer; }
.close-btn:hover { color: var(--danger); }

.avatar-wrapper { position: relative; display: inline-block; margin-bottom: 15px; }
.large-avatar { width: 100px; height: 100px; border-radius: 50%; background: linear-gradient(135deg, var(--neon-blue), #0055ff); display: flex; justify-content: center; align-items: center; font-size: 3rem; font-weight: bold; color: #fff; box-shadow: var(--neon-glow); margin: 0 auto; border: 3px solid var(--glass-panel); }
.edit-pic-btn { position: absolute; bottom: 0; right: 0; background: var(--neon-blue); color: #000; width: 35px; height: 35px; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 1rem; box-shadow: 0 2px 10px rgba(0,0,0,0.5); border: 2px solid #1e272e; }
.edit-pic-btn:hover { background: #fff; }

.bio-section { margin-bottom: 25px; }
.bio-input { text-align: center; font-size: 0.9rem; margin-bottom: 5px; background: rgba(0,0,0,0.2); padding: 8px; border-radius: 8px; }

.profile-actions { display: flex; flex-direction: column; gap: 10px; }
.action-btn { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--glass-border); background: rgba(255,255,255,0.05); color: var(--text-light); font-size: 1rem; cursor: pointer; transition: 0.3s; text-align: left; padding-left: 20px; font-weight: 500; }
.action-btn:hover { background: rgba(255,255,255,0.1); }
.danger-btn { color: var(--danger); }
.danger-btn:hover { background: rgba(255, 71, 87, 0.1); border-color: rgba(255, 71, 87, 0.3); }

.change-pass-box { background: rgba(0,0,0,0.3); padding: 15px; border-radius: 10px; border: 1px solid var(--glass-border); margin-top: -5px; margin-bottom: 5px; }
.change-pass-box input { margin-bottom: 10px; padding: 10px 15px; border-radius: 8px; font-size: 0.9rem; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--neon-blue); }

/* ==========================================
   RESPONSIVITAS HP (MOBILE FULLSCREEN)
   ========================================== */
@media (max-width: 768px) {
    .container {
        width: 100%; 
        height: 100dvh; /* Sangat penting: 100dvh agar tidak terpotong address bar Safari/Chrome */
        max-width: none; 
        border-radius: 0; 
        border: none;
    }
    
    .sidebar { width: 100%; border-right: none; }
    .chat-area.hidden-mobile { display: none !important; }
    .sidebar.hidden-mobile { display: none !important; }
    
    .back-btn { display: flex; margin-right: 10px; font-size: 1.5rem; }
    .chat-header { padding: 10px 15px; }
    .message-input-area { padding: 12px 15px; }
    
    /* Perbaikan padding bawah chat agar tidak tertutup keyboard/input area */
    .chat-messages { padding: 15px 15px 30px 15px; }
}