.chat-container {
    display: flex;
    height: 600px;
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.chat-sidebar {
    width: 30%;
    background: #ab9b86; /* The brown color in your image */
    padding: 30px 20px;
    color: #fff;
}

.chat-sidebar h3 {
    font-size: 16px;
    margin-bottom: 30px;
    letter-spacing: 1px;
    color: white;
}

.conv-item {
    padding: 10px 0;
    cursor: pointer;
    font-weight: bold;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    transition: 0.3s;
}

.conv-item:hover, .conv-item.active {
    color: #d1d1d1;
    padding-left: 5px;
}

.chat-main {
    width: 70%;
    display: flex;
    flex-direction: column;
    height: 100%;
}

#chat-messages {
    flex: 1; /* This pushes header up and footer down */
    padding: 20px;
    overflow-y: auto;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
}

.msg-bubble {
    max-width: 70%;
    padding: 12px 18px;
    margin-bottom: 15px;
    border-radius: 15px;
    line-height: 1.4;
}

.msg-bubble.them {
    background: #eef1f6;
    align-self: flex-start;
    margin-right: auto;
}

.msg-bubble.me {
    background: #8e625a;
    color: #fff;
    align-self: flex-end;
    margin-left: auto;
}

.chat-footer {
    padding: 15px 25px;
    border-top: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
}

.footer-input-wrapper {
    display: flex;
    align-items: center;
    background: #f5f5f5; /* Light grey bar like your image */
    padding: 10px 20px;
    border-radius: 30px;
}

#chat-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    padding: 5px 0;
    font-size: 15px;
}

#send-msg-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #8e625a;
    font-size: 20px;
    padding-left: 10px;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px; /* Slightly more padding for a premium feel */
    border-bottom: 1px solid #f0f0f0;
    background: #fff;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

#active-chat-name {
    font-weight: 700;
    font-size: 20px;
    color: #1a1a1a;
    letter-spacing: -0.5px;
}

.chat-avatar {
    width: 45px;
    height: 45px;
    background-color: #5d538a; /* Purple color from your image */
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    text-transform: uppercase;
}

.header-right .header-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #b0b0b0; /* Light grey icons like in your image */
    font-size: 18px;
    transition: transform 0.2s ease, color 0.2s ease;
}

.header-right .header-icon-btn:hover {
    color: #e74c3c; /* Turns red on hover for delete */
    transform: scale(1.1);
}

#chat-window {
    display: none; /* Toggled to 'flex' by JS */
    flex-direction: column;
    height: 100%; 
    width: 100%;
}

#chat-welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    font-weight: 700;
    font-size: 20px;
    color: #ccc; /* Lighter color for placeholder text */
}

/* 1. Force the container to a fixed viewport height on mobile */
@media (max-width: 768px) {
    .chat-container {
        display: flex;
        flex-direction: column;
        height: 85vh !important; /* Forces the box to stay on screen */
        max-height: 85vh;
        overflow: hidden; /* Prevents the whole page from stretching */
    }

    /* 2. Stack sidebar and main */
    .chat-sidebar {
        width: 100% !important;
        height: 150px; /* Small scrollable area for names at top */
        flex-shrink: 0;
        border-radius: 20px 20px 0 0;
    }

    .chat-main {
        width: 100% !important;
        flex: 1; /* Takes exactly the remaining space */
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Locks the footer inside this area */
    }

    /* 3. The Chat Window inside Main */
    #chat-window {
        display: flex; /* Ensure it stays flex */
        flex-direction: column;
        height: 100%;
        width: 100%;
    }

    /* 4. The Message Area - THIS MUST SCROLL */
    #chat-messages {
        flex: 1 !important;
        overflow-y: auto !important;
        background: #f9f9f9;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
        padding-bottom: 20px;
    }

    /* 5. The Footer - Pin it to the bottom */
    .chat-footer {
        flex-shrink: 0; /* Prevents footer from disappearing */
        background: #fff;
        padding: 10px 15px;
        border-top: 1px solid #eee;
    }

    .footer-input-wrapper {
        padding: 5px 15px;
    }
}