body {
    font-family: sans-serif;
    margin: 10px; /* Reduced margin for smaller screens */
    background-color: #f4f4f4;
}

h1, h2, h3 {
    color: #333;
    margin-top: 0;
}

.container {
    display: flex;
    flex-direction: row; /* Default layout */
    gap: 15px; /* Reduced gap */
    background-color: #fff;
    padding: 15px; /* Reduced padding */
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    /* Let height be determined by content, remove fixed max-height */
}

#conversation-list-section {
    flex: 0 0 250px; /* Fixed width for conversation list */
    border-right: 1px solid #ccc;
    padding-right: 15px;
    height: calc(100vh - 100px); /* Adjust height based on viewport, leave space for header/padding */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#message-view-section {
    flex: 1; /* Take remaining space */
    display: flex;
    flex-direction: column;
    height: calc(100vh - 100px); /* Match height */
    min-width: 0; /* Prevent flex item from overflowing */
}

#conversation-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
}

#conversation-list li {
    padding: 8px 10px; /* Adjusted padding */
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9em; /* Slightly smaller font */
}

#conversation-list li:hover {
    background-color: #e9e9e9;
}

#conversation-list li.selected {
    background-color: #d0e0f0;
    font-weight: bold;
}

#message-list {
    flex-grow: 1;
    border: 1px solid #ccc;
    padding: 10px; /* Reduced padding */
    margin-bottom: 10px; /* Reduced margin */
    overflow-y: auto;
    background-color: #f9f9f9;
    border-radius: 5px;
}

.message {
    margin-bottom: 8px; /* Reduced margin */
    padding: 8px 12px;
    border-radius: 15px;
    max-width: 80%; /* Allow slightly wider messages */
    word-wrap: break-word;
    clear: both;
    display: table; /* Use table display for better float containment */
}

/* --- Swapped Alignment --- */
.message.user {
    background-color: #e1fec6; /* Lighter WhatsApp green */
    margin-right: auto; /* Align user messages to the LEFT */
    float: left; /* Float LEFT */
    /* text-align: left; /* Default */
}

.message.bot, .message.agent {
    background-color: #fff;
    margin-left: auto; /* Align bot/agent messages to the RIGHT */
    border: 1px solid #eee;
    float: right; /* Float RIGHT */
    /* text-align: right; /* Align text right */
}
/* --- End Swapped Alignment --- */


.message .sender {
    font-size: 0.8em;
    color: #888;
    display: block;
    margin-bottom: 3px;
    font-weight: bold;
}

.message .timestamp {
    font-size: 0.75em;
    color: #aaa;
    display: block;
    margin-top: 4px;
    /* Align based on parent's float */
}

/* --- Swapped Timestamp Alignment --- */
.message.user .timestamp {
     text-align: left;
}
.message.bot .timestamp, .message.agent .timestamp {
     text-align: right;
}
/* --- End Swapped Timestamp Alignment --- */


#reply-section {
    margin-top: auto;
    padding-top: 10px; /* Reduced padding */
    border-top: 1px solid #ccc;
}

#reply-section textarea {
    width: calc(100% - 22px);
    padding: 8px 10px; /* Adjusted padding */
    margin-bottom: 8px; /* Reduced margin */
    border: 1px solid #ccc;
    border-radius: 5px;
    resize: vertical;
    min-height: 40px; /* Reduced min-height */
    font-size: 0.95em;
}

#reply-section button {
    padding: 8px 12px; /* Adjusted padding */
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    float: right; /* Align button right */
}

#reply-section button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

#reply-section button:hover:not(:disabled) {
    background-color: #0056b3;
}

#reply-status {
    margin-top: 5px;
    font-size: 0.9em;
    color: #666;
    min-height: 1.2em;
    clear: both; /* Clear float from button */
}

/* --- Media Styles --- */
.media-content {
    display: block;
    max-width: 100%;
    height: auto;
    margin-top: 5px;
    margin-bottom: 5px;
    border-radius: 8px;
}

.caption {
    margin-top: 5px;
    font-size: 0.95em;
}

.message a {
    color: #0056b3;
    text-decoration: underline;
}

.message a:hover {
    color: #003d80;
}
/* --- End Media Styles --- */

/* --- Responsive Design --- */
@media (max-width: 768px) {
    body {
        margin: 5px; /* Further reduce margin */
    }
    .container {
        flex-direction: column; /* Stack vertically */
        padding: 10px;
        max-height: none; /* Remove max height */
        height: calc(100vh - 20px); /* Fill viewport height */
    }

    #conversation-list-section {
        flex: 0 0 auto; /* Don't grow/shrink, size based on content */
        max-width: none; /* Remove max width */
        height: 35vh; /* Set a percentage height */
        border-right: none; /* Remove border */
        border-bottom: 1px solid #ccc; /* Add bottom border */
        padding-right: 0;
        margin-bottom: 10px; /* Add margin below */
    }

    #message-view-section {
        flex: 1; /* Take remaining space */
        height: auto; /* Let height be flexible */
        min-height: 0; /* Allow shrinking */
    }

     #message-list {
        height: auto; /* Adjust height */
    }

    .message {
        max-width: 85%; /* Allow slightly wider messages on mobile */
    }

    #reply-section textarea {
        min-height: 35px;
    }
}