:root {
    --primary: #4CAF50; /* ICQ Green */
    --secondary: #FFC107; /* Status Yellow */
    --danger: #F44336; /* Offline Red */
    --bg-light: #f5f5f5;
    --text-dark: #333;
    --bubble-sent: #DCF8C6;
    --bubble-received: #ffffff;
    --chat-bg: #e5ddd5;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* Darker body background to frame the app */
    background: #dcdcdc;
    height: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center; /* Center app horizontally */
}

/* --- Login --- */
#login-screen {
    position: fixed; /* Force full screen overlay */
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #4CAF50, #8BC34A);
    z-index: 2000; /* Above everything */
}

.login-box {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    text-align: center;
    width: 300px;
}

.flower-logo {
    width: 60px;
    height: 60px;
    margin: 0 auto 1rem;
    position: relative;
}

.flower-logo .petal {
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    position: absolute;
}
/* Simplified pseudo flower */
.flower-logo .petal:nth-child(1) { top: 0; left: 20px; background: #E91E63; }
.flower-logo .petal:nth-child(2) { top: 10px; left: 38px; background: #FFC107; }
.flower-logo .petal:nth-child(3) { top: 30px; left: 38px; background: #8BC34A; }
.flower-logo .petal:nth-child(4) { top: 40px; left: 20px; background: #00BCD4; }
.flower-logo .petal:nth-child(5) { top: 30px; left: 2px; background: #3F51B5; }
.flower-logo .petal:nth-child(6) { top: 10px; left: 2px; background: #9C27B0; }
.flower-logo .center { 
    width: 16px; height: 16px; 
    background: white; 
    border-radius: 50%; 
    position: absolute; 
    top: 22px; left: 22px; 
}

.login-box input {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-sizing: border-box;
}

.login-box button {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

.login-box button:hover {
    background: #388E3C;
}

/* --- Main App (DESKTOP FIRST) --- */
#main-app {
    display: none;
    height: 100vh;
    width: 100vw;
    background: #e5ddd5; /* Default fallback */
    overflow: hidden;
    /* Force side-by-side layout on desktop */
    flex-direction: row !important; 
    
    /* Limit max width on very large screens */
    max-width: 1400px; /* Max width for the whole app */
    box-shadow: 0 0 20px rgba(0,0,0,0.2); /* Shadow around app */
}

#main-app.active {
    display: flex; /* This makes it visible */
}

/* Sidebar is fixed width on desktop */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: rgba(255, 255, 255, 0.4); /* Much more transparent */
    backdrop-filter: blur(20px); /* Stronger blur for readability */
    border-right: 1px solid rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    position: static; 
    transform: none !important;
}

/* Chat area takes remaining space */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: transparent; /* Totally clear */
    position: relative;
    transform: none !important;
}

/* --- Sidebar Content --- */
#admin-btn {
    cursor: pointer;
    background: none;
    border: none;
    font-size: 1.4rem;
    padding: 5px;
    margin-right: 5px;
}
#admin-btn:hover { transform: scale(1.1); }

.user-profile {
    padding: 15px;
    background: rgba(255, 255, 255, 0.2); /* Very subtle */
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.avatar {
    width: 40px;
    height: 40px;
    background: #ccc;
    border-radius: 50%;
    margin-right: 10px;
    background-size: cover;
    cursor: pointer; /* Click to edit profile */
}
.avatar:hover { opacity: 0.8; }

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
}

.logout-btn { margin-left: auto; }

.contact-list { flex: 1; overflow-y: auto; }

.contact-item {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    transition: background 0.2s;
}

.contact-item:hover { background: rgba(0,0,0,0.05); }
.contact-item.active { background: rgba(0,0,0,0.1); }

.contact-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 10px;
    background: #ccc; 
}
.contact-status.online { background: var(--primary); }
.contact-status.away { background: var(--secondary); }

/* --- Unread Badge --- */
.contact-info {
    flex: 1;
}
.contact-uin {
    font-size: 0.7rem;
    color: #666;
}

.unread-badge {
    background: #FF5722;
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 0.75rem;
    font-weight: bold;
    min-width: 14px;
    text-align: center;
    margin-left: 5px;
    display: none; /* Hidden by default */
}
.unread-badge.active {
    display: inline-block;
}

/* --- Chat Area --- */
.chat-header {
    padding: 10px 15px;
    background: rgba(237, 237, 237, 0.9); /* Glass effect header */
    backdrop-filter: blur(5px);
    border-bottom: 1px solid rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    height: 60px;
}

.back-btn {
    display: none; /* Hidden on Desktop */
    background: none;
    border: none;
    font-size: 2rem;
    margin-right: 15px;
    cursor: pointer;
    color: var(--primary);
    padding: 5px 10px;
}

.messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    
    /* Limit width for better readability on large screens */
    max-width: 700px; /* Compact chat width */
    width: 100%;
    margin: 0 auto; /* Center it */
    
    /* Subtle frame/shadow to distinguish from background */
    background: rgba(255, 255, 255, 0.15); /* Very faint white tint */
    box-shadow: 0 0 15px rgba(0,0,0,0.05); /* Soft shadow */
    border-radius: 8px; /* Rounded corners */
    margin-top: 10px; /* Spacing from header */
    margin-bottom: 10px; /* Spacing from input */
}

.message {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 7px;
    position: relative;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.4;
}

.message.sent {
    align-self: flex-end;
    background: var(--bubble-sent);
    border-bottom-right-radius: 0;
}

.message.received {
    align-self: flex-start;
    background: var(--bubble-received);
    border-bottom-left-radius: 0;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

.message img {
    max-width: 100%;
    border-radius: 5px;
    margin-top: 5px;
}

.timestamp {
    font-size: 0.7rem;
    color: #999;
    text-align: right;
    display: block;
    margin-top: 4px;
}

/* --- Input Area --- */
.input-area {
    padding: 10px;
    background: rgba(255, 255, 255, 0.3); /* Transparent */
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0,0,0,0.1);
    display: flex;
    justify-content: center; /* Center content */
}

/* Inner wrapper for input to limit width */
.input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 700px; /* Match messages width */
    width: 100%;
}

.input-area textarea {
    flex: 1;
    padding: 10px;
    background: rgba(255, 255, 255, 0.7); /* Slightly more opaque for typing */
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 20px;
    resize: none;
    height: 40px;
    font-family: inherit;
    outline: none;
}
.input-area textarea:focus {
    background: white; /* Full white when typing */
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
}

.send-btn, .attach-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary);
    padding: 0 10px;
}

.attach-btn { color: #666; }

/* --- Modals (Admin & Profile) --- */
.modal {
    display: none; 
    position: fixed; 
    z-index: 100; 
    left: 0; top: 0; width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.5); 
    overflow-y: auto; /* Allow scrolling the backdrop if needed */
}

.modal-content {
    background-color: #fefefe;
    margin: 20px auto; /* Reduced from 5% or 10% to fit on smaller screens */
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    position: relative;
    max-height: 85vh; /* Ensure it fits in viewport */
    overflow-y: auto; /* Scroll inside the modal content */
    display: flex;
    flex-direction: column;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.close:hover { color: black; }

.admin-controls, .profile-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.admin-controls input, .profile-controls input, .profile-controls select {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

.admin-controls button, .profile-controls button {
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#user-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#user-list li {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

/* Background Selector Grid */
.bg-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin: 10px 0;
    max-height: 300px; /* Double height */
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 5px;
}
.bg-option {
    width: 100%;
    padding-bottom: 100%; /* square */
    border-radius: 5px;
    cursor: pointer;
    border: 2px solid transparent;
}
.bg-option.selected { border-color: black; }

/* --- Toast Notification --- */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    animation: slideIn 0.3s ease-out;
    max-width: 300px;
}
.toast.hide {
    animation: slideOut 0.3s ease-in forwards;
}
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
    to { transform: translateX(100%); opacity: 0; }
}
.toast-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: #ccc;
}

/* --- MOBILE ONLY (Override Desktop) --- */
@media (max-width: 768px) {
    #main-app {
        max-width: 100%;
        height: 100vh;
        margin: 0;
        box-shadow: none;
    }

    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 10;
        height: 100%;
        left: 0; top: 0;
        transform: translateX(0);
        transition: transform 0.3s ease;
    }

    .chat-area {
        width: 100%;
        position: absolute;
        height: 100%;
        left: 0; top: 0;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .messages {
        max-width: 100%;
    }

    .input-wrapper {
        max-width: 100%;
    }

    /* When chat is open, slide sidebar OUT and chat IN */
    .chat-open .sidebar {
        transform: translateX(-100%) !important;
    }

    .chat-open .chat-area {
        transform: translateX(0) !important;
    }

    /* Show back button only on mobile */
    .back-btn {
        display: block !important;
    }
}
