/* ==========================================================================
   Premium Responsive Chat Interface (Dark Discord / WhatsApp Web Style)
   ========================================================================== */

:root {
    --bg-app: #0f172a;              /* Slate super gelap */
    --bg-sidebar: #1e293b;          /* Panel kiri */
    --bg-chat: #0b1329;             /* Ruang chat gelap eksklusif */
    --surface-card: #334155;        /* Komponen aktif / terpilih */
    
    --accent: #10b981;              /* Emerald Green */
    --accent-hover: #059669;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: rgba(148, 163, 184, 0.12);
    
    --bubble-out: #065f46;          /* Balon chat pengirim */
    --bubble-in: #1e293b;           /* Balon chat penerima */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body, html {
    height: 100vh;
    background-color: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
}

/* --- HALAMAN AUTENTIKASI (Login & Register Modern Glassmorphism) --- */
.auth-body {
    background: radial-gradient(circle at top right, #065f46 0%, #0f172a 100%);
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
}

.auth-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
}

.auth-card h2 {
    margin-bottom: 28px;
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.form-group {
    margin-bottom: 22px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.form-group input {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-size: 15px;
    background-color: #0f172a;
    color: var(--text-primary);
    transition: all 0.25s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--accent);
    color: #0f172a;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.alert {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
}
.alert-danger { background-color: rgba(239, 68, 68, 0.1); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }
.alert-success { background-color: rgba(16, 185, 129, 0.1); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.2); }

.auth-link { margin-top: 24px; font-size: 14px; color: var(--text-secondary); }
.auth-link a { color: var(--accent); text-decoration: none; font-weight: 600; }


/* --- MASTER INTERFACE LAYOUT (Dua Kolom) --- */
.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-chat);
}

/* --- KIRI: PANEL SIDEBAR DAFTAR KONTAK --- */
.sidebar {
    width: 350px;
    min-width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(15, 23, 42, 0.2);
    border-bottom: 1px solid var(--border);
}

.user-profile { display: flex; align-items: center; gap: 12px; }
.user-meta h4 { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.user-meta .status-online { font-size: 11px; color: var(--accent); font-weight: 500; }

.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, #3b82f6 100%);
    color: #0f172a; display: flex; justify-content: center; align-items: center; font-weight: 700;
}

.logout-link {
    font-size: 13px; color: #f87171; text-decoration: none; font-weight: 500;
    padding: 6px 12px; border-radius: 6px; background: rgba(248, 113, 113, 0.1);
}
.logout-link:hover { background: #ef4444; color: white; }

.search-container { padding: 12px 16px; }
.search-container input {
    width: 100%; padding: 10px 16px; border: none; border-radius: 8px;
    background-color: #0f172a; color: var(--text-primary); font-size: 14px; outline: none;
}

.contact-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.contact-item {
    display: flex; align-items: center; gap: 12px; padding: 12px;
    border-radius: 10px; text-decoration: none; color: var(--text-primary);
    margin-bottom: 4px; transition: background 0.2s;
}
.contact-item:hover { background-color: rgba(255, 255, 255, 0.03); }
.contact-item.active { background-color: var(--surface-card); }

.avatar-sm {
    width: 38px; height: 38px; border-radius: 50%; background-color: #475569;
    color: var(--text-primary); display: flex; justify-content: center; align-items: center; font-weight: 600;
}
.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-size: 14.5px; font-weight: 600; }
.contact-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }


/* --- KANAN: RUANG UTAMA OBROLAN --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-chat);
}

/* Welcome Area Saat Belum Pilih Kontak */
.chat-welcome { flex: 1; display: flex; justify-content: center; align-items: center; text-align: center; padding: 24px; }
.welcome-icon { font-size: 64px; margin-bottom: 16px; }
.chat-welcome h2 { font-size: 24px; margin-bottom: 8px; }
.chat-welcome p { color: var(--text-secondary); max-width: 400px; font-size: 14px; line-height: 1.5; }

/* Header Obrolan Aktif */
.chat-header {
    padding: 14px 20px; background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 16px;
}
.back-button {
    display: none; font-size: 22px; color: var(--text-primary); text-decoration: none; font-weight: bold;
}
.chat-target { display: flex; align-items: center; gap: 12px; }
.target-avatar { background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%); }
.target-meta h3 { font-size: 15px; font-weight: 600; }
.target-meta .status-indicator { font-size: 12px; color: var(--accent); }

/* Kontainer Riwayat Obrolan */
.chat-box {
    flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 8px;
    background-image: radial-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 0px); background-size: 24px 24px;
}

/* Komponen Balon Gelembung Chat */
.message-wrapper { display: flex; flex-direction: column; max-width: 70%; animation: popUp 0.15s ease-out; }
@keyframes popUp { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

.message-wrapper.outgoing { align-self: flex-end; align-items: flex-end; }
.message-wrapper.incoming { align-self: flex-start; align-items: flex-start; }

.bubble { padding: 10px 16px; border-radius: 14px; font-size: 14.5px; line-height: 1.5; word-break: break-word; }
.outgoing .bubble { background-color: var(--bubble-out); color: #f8fafc; border-top-right-radius: 0; }
.incoming .bubble { background-color: var(--bubble-in); color: #f8fafc; border-top-left-radius: 0; }
.timestamp { font-size: 10px; color: var(--text-secondary); margin-top: 4px; padding: 0 4px; }

/* Bar Input Bagian Bawah */
.chat-input-area {
    padding: 16px 24px; background-color: var(--bg-sidebar);
    border-top: 1px solid var(--border); display: flex; gap: 16px; align-items: center;
}
.chat-input-area input {
    flex: 1; padding: 14px 20px; border: none; border-radius: 12px;
    background-color: var(--bg-app); color: var(--text-primary); font-size: 14.5px; outline: none;
}
.chat-input-area button {
    background-color: var(--accent); color: #0f172a; border: none; width: 46px; height: 46px;
    border-radius: 12px; cursor: pointer; display: flex; justify-content: center; align-items: center;
    transition: background 0.2s;
}
.chat-input-area button:hover { background-color: var(--accent-hover); }

.loading-text, .chat-empty { text-align: center; color: var(--text-secondary); font-size: 13.5px; margin-top: 20px; font-style: italic; }


/* ==========================================================================
   RESPONSIVE LAYOUT ENGINE: KHUSUS LAYAR HP (MOBILE BREAKPOINT)
   ========================================================================== */
@media (max-width: 768px) {
    .sidebar { width: 100vw; }
    .chat-area { width: 100vw; }
    
    /* Otomatis sembunyikan salah satu panel di layar HP kecil */
    .mobile-hide { display: none !important; }
    
    /* Tampilkan tombol kembali panah kirim hanya di HP */
    .back-button { display: block !important; margin-right: 8px; }
    .chat-welcome { display: none !important; }
}