:root {
    --bg-dark: #000000;
    --bg-card: #121212;
    --bg-header: #1f1f1f;
    --bg-input: #1f1f1f;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-red: #ff0000;
    --accent-blue: #00a884; /* WA Accent */
    --bubble-me: #005c4b;
    --bubble-you: #1f1f1f;
    --nav-height: 60px; /* Tinggi Nav Bawah */
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent body scroll, handle inside containers */
    height: 100vh;
    height: 100dvh; /* Dynamic Viewport Height for Mobile */
}

/* --- LAYOUT UTAMA --- */
.chat-container {
    width: 100%;
    height: 100%;
    display: flex;
    background: var(--bg-dark);
    position: relative;
    overflow: hidden;
}

/* --- HEADER STYLES --- */
.villain-header {
    background: var(--bg-header);
    padding: 0 15px;
    height: 65px; /* Sedikit lebih tinggi biar lega */
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    z-index: 10;
}

/* New Mobile Main Header Styles */
.mobile-main-header {
    background: #000; /* Header hitam pekat */
    border-bottom: 1px solid #222;
}

.brand-title {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 800; /* Extra Bold */
    color: #fff;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    font-family: 'Poppins', sans-serif;
}

.brand-red { 
    color: var(--accent-red); 
    text-shadow: 0 0 15px rgba(255, 0, 0, 0.4); /* Glow effect */
    margin-right: 2px;
}

/* Compact Identity Box */
.compact-identity {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #111;
    padding: 4px 8px 4px 12px;
    border-radius: 20px;
    border: 1px solid #333;
}

.user-identity {
    font-size: 0.8rem;
    color: #aaa;
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

/* --- VIEW: USER LIST (INBOX) --- */
#user-list-view {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #000;
}

.users-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 80px; /* Space untuk Bottom Nav */
    scrollbar-width: thin;
    scrollbar-color: #333 #000;
}

.group-title {
    font-size: 0.75rem;
    color: var(--accent-red);
    padding: 15px 20px 5px;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    background: #000;
    position: sticky;
    top: 0;
    z-index: 5; /* Biar gak ketutup item saat scroll */
}

/* User Card Items */
.user-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
}

.user-item:active {
    background: #1a1a1a;
}

/* Garis Separator */
.user-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 75px; 
    right: 0;
    height: 1px;
    background: #222;
}

.user-item:last-child::after { display: none; }

.avatar-wrapper {
    position: relative;
    margin-right: 15px;
    flex-shrink: 0;
}

.user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    background: #333;
    border: 1px solid #222;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    position: absolute;
    bottom: 2px;
    right: 2px;
    border: 2px solid #000;
}
.status-dot.online { background: #00ff00; box-shadow: 0 0 5px #00ff00; }
.status-dot.offline { background: #666; display: none; }

.user-info {
    flex: 1;
    min-width: 0; /* Fix flex child truncate */
}

.user-info h4 {
    margin: 0;
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 5px;
}

.admin-badge {
    background: rgba(255, 215, 0, 0.15);
    color: gold;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid gold;
    font-weight: bold;
}

.user-info p {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* --- SKELETON LOADING ANIMATION --- */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: #1a1a1a;
    background: linear-gradient(90deg, #1f1f1f 25%, #2a2a2a 50%, #1f1f1f 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 4px;
}

/* User List Skeleton */
.skeleton-user-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #111;
}

.skeleton-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-right: 15px;
    flex-shrink: 0;
}

.skeleton-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skeleton-text {
    height: 14px;
    width: 60%;
}
.skeleton-text.short {
    width: 40%;
}

/* Chat Bubble Skeleton */
.skeleton-bubble {
    max-width: 65%;
    height: 40px;
    margin-bottom: 10px;
    border-radius: 12px;
}

.skeleton-bubble.sent {
    align-self: flex-end;
    border-top-right-radius: 0;
    margin-left: auto;
}

.skeleton-bubble.received {
    align-self: flex-start;
    border-top-left-radius: 0;
}


/* --- VIEW: CHAT ROOM --- */
#chat-room-view {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: #0b141a; /* WA Dark */
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-blend-mode: overlay;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1); /* Slide Animation */
}

#chat-room-view.active {
    transform: translateX(0);
}

/* Chat Header */
.chat-header {
    background: #202c33;
    padding: 0 10px;
    height: 60px;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.back-btn {
    background: none;
    border: none;
    color: #aebac1;
    font-size: 1.2rem;
    padding: 10px;
    margin-right: 5px;
    cursor: pointer;
    border-radius: 50%;
}
.back-btn:active { background: rgba(255,255,255,0.1); }

.chat-partner-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    cursor: pointer; /* Klik header untuk lihat info (future) */
}

.chat-partner-info img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
}

.partner-text {
    display: flex;
    flex-direction: column;
}

.partner-text h3 {
    margin: 0;
    font-size: 1rem;
    color: #e9edef;
    font-weight: 500;
}

.partner-text span {
    font-size: 0.75rem;
    color: #8696a0;
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 15px 15px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

/* Security Banner (E2E) */
.security-banner {
    background: rgba(255, 215, 0, 0.1);
    color: #ffd700;
    font-size: 0.75rem;
    padding: 8px 15px;
    text-align: center;
    border-radius: 8px;
    margin: 10px auto 20px;
    max-width: 90%;
    line-height: 1.4;
    border: 1px solid rgba(255, 215, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* Bubbles */
.message-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    animation: fadeIn 0.2s ease;
}

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

/* Sent Message (Me) */
.message-bubble.sent {
    background: var(--bubble-me);
    color: #e9edef;
    align-self: flex-end;
    border-top-right-radius: 0;
}
.message-bubble.sent::before {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-top-color: var(--bubble-me);
    border-left-color: var(--bubble-me);
    border-radius: 2px;
}

/* Received Message (You) */
.message-bubble.received {
    background: var(--bubble-you);
    color: #e9edef;
    align-self: flex-start;
    border-top-left-radius: 0;
}
.message-bubble.received::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-top-color: var(--bubble-you);
    border-right-color: var(--bubble-you);
    border-radius: 2px;
}

.message-time {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.5);
    text-align: right;
    margin-top: 4px;
    display: block;
    margin-right: -4px;
    margin-bottom: -4px;
}

/* Input Area */
.message-input-area {
    background: #202c33;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 60px;
    /* Safe area for iPhone X+ handled by padding-bottom on body/container if needed */
}

.message-input-area input {
    flex: 1;
    background: #2a3942;
    border: none;
    color: #d1d7db;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 1rem;
    outline: none;
}

.message-input-area input::placeholder { color: #8696a0; }

.send-btn {
    background: var(--accent-blue);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: transform 0.1s;
    flex-shrink: 0;
}
.send-btn:active { transform: scale(0.95); }

/* --- UTILITY CLASSES --- */
.hidden { display: none !important; }

/* Desktop Tweaks (Optional if user opens on PC) */
@media (min-width: 768px) {
    .chat-container {
        border: 1px solid #333;
        max-width: 1200px;
        margin: 0 auto;
        /* Navigasi top udah dihapus, jadi full height parent */
        height: 100vh; 
    }
    
    #user-list-view { width: 350px; border-right: 1px solid #333; }
    
    /* On desktop, show both side-by-side */
    #chat-room-view {
        position: static;
        transform: none;
        flex: 1;
        display: flex !important; /* Always show chat on right */
        background-color: #0b141a;
    }

    #chat-room-view.hidden { 
        /* If no chat selected, show placeholder */
        background-image: none;
        align-items: center;
        justify-content: center;
    }
    
    .back-btn { display: none; } /* No back button on desktop */
}

/* Mobile Tweaks */
@media (max-width: 768px) {
    /* Hide Bottom Nav when chat is active */
    body.chat-active #main-bottom-nav {
        display: none !important;
    }
    
    body.chat-active .users-scroll-area {
        padding-bottom: 0;
    }
}
