body {
    font-family: Arial, sans-serif;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
}

.main-container {
    display: flex;
    width: 90%;
    max-width: 1400px; /* Increased max-width to accommodate new sidebar */
    height: 80vh;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    background-color: #fff; /* Ensure main container has a background */
}

.sidebar {
    width: 250px; /* Fixed width for the sidebar */
    background-color: #f8f9fa;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    padding: 15px;
    box-sizing: border-box; /* Include padding in width */
}

.sidebar-header {
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    margin-bottom: 10px;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.3em;
    color: #333;
}

#chatSearchInput {
    width: calc(100% - 22px); /* Adjust for padding and border */
    padding: 8px 10px;
    margin-top: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 0.9em;
    box-sizing: border-box;
}

#newChatButton {
    background-color: #007bff;
    color: #fff;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin-bottom: 20px;
    transition: background-color 0.2s;
}

#newChatButton:hover {
    background-color: #0056b3;
}

.chat-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0;
    flex-shrink: 0; /* Add this to prevent shrinking */
}

.chat-item {
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 5px;
    margin-bottom: 5px;
    transition: background-color 0.2s;
    color: #333;
    word-wrap: break-word; /* Ensure long chat names wrap */
    position: relative; /* Needed for absolute positioning of trash icon */
    display: flex; /* Use flexbox to align content and trash icon */
    justify-content: space-between; /* Space out text and icon */
    align-items: center; /* Vertically center items */
}

.chat-item:hover {
    background-color: #e2e6ea;
}

.chat-item.active {
    background-color: #007bff;
    color: #fff;
    font-weight: bold;
}

.chat-item-text {
    flex-grow: 1; /* Allow text to take up available space */
    margin-right: 5px; /* Add some space between text and icon */
}

.delete-chat-button, .rename-chat-button {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1em;
    padding: 5px;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s;
    margin-left: 5px; /* Space between buttons */
}

.chat-item:hover .delete-chat-button,
.chat-item:hover .rename-chat-button {
    opacity: 1; /* Show on hover */
}

.chat-item.active .delete-chat-button,
.chat-item.active .rename-chat-button {
    color: #fff; /* White icon for active item */
}

.chat-container {
    flex-grow: 1; /* Allows chat container to take remaining space */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background-color: #fff;
    color: #333;
    padding: 15px;
    text-align: center;
    font-size: 1.2em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    height: 40px;
    width: auto;
}

.header-text h1 {
    margin: 0;
    font-size: 1.5em;
    color: #333;
}

.header-text .subtitle {
    margin: 0;
    font-size: 0.8em;
    color: #666;
}

.chat-header button {
    background-color: #fff;
    color: #007bff;
    border: none; /* No outline */
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
}

.chat-header button:hover {
    background-color: #f0f2f5; /* Changed from orange to light grey */
}

.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    word-wrap: break-word; /* Add this to break long words */
    white-space: pre-wrap; /* Preserve whitespace and wrap text */
}

.message-wrapper {
    display: flex;
    align-items: flex-start; /* Align icon and message at the top */
    margin-bottom: 10px;
    position: relative; /* For positioning controls */
}

.message-wrapper.user {
    justify-content: flex-end;
}

.message-wrapper.ai {
    justify-content: flex-start;
}

.message-avatar {
    width: 30px; /* Adjust as needed */
    height: 30px; /* Adjust as needed */
    border-radius: 50%;
    margin: 0 10px;
    flex-shrink: 0; /* Prevent avatar from shrinking */
    object-fit: cover; /* Ensure image covers the area */
}

.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    line-height: 1.4;
    word-break: break-all; /* Break words if they are too long to fit */
    white-space: pre-wrap; /* Ensure wrapping and preserve white space */
    position: relative; /* For positioning controls */
}

.message-text {
    /* Style for the actual text content inside the message bubble */
}

.message-controls {
    position: absolute;
    top: -10px; /* Adjust as needed */
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    display: flex;
    gap: 5px;
}

.message-wrapper.user .message-controls {
    right: 100%; /* Position to the left of user message */
}

.message-wrapper.ai .message-controls {
    left: 100%; /* Position to the right of AI message */
}

.message-wrapper:hover .message-controls {
    opacity: 1;
}

.message-controls button {
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 5px 8px;
    cursor: pointer;
    font-size: 0.8em;
    line-height: 1;
}

.message-controls button:hover {
    background: rgba(0, 0, 0, 0.8);
}

.user-message {
    background-color: #007bff;
    color: #fff;
    border-bottom-right-radius: 2px;
}

.ai-message {
    background-color: #e2e6ea;
    color: #333;
    border-bottom-left-radius: 2px;
}

.chat-input {
    display: flex;
    padding: 15px;
    border-top: 1px solid #eee;
    flex-shrink: 0; /* Prevent input from shrinking */
}

.chat-input input {
    flex-grow: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 1em;
    outline: none;
}

.upload-button {
    background-color: #6c757d; /* Grey color for upload button */
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 10px 15px;
    margin-left: 10px;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.upload-button:hover {
    background-color: #5a6268;
}

.chat-input button {
    background-color: #28a745;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    margin-left: 10px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s;
}

.chat-input button:hover {
    background-color: #218838;
}

/* Modal styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    border-radius: 8px;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
    text-align: center;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal-content h2 {
    margin-top: 0;
    color: #333;
}

.modal-content input[type="text"], .modal-content textarea {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
    width: calc(100% - 22px); /* Adjust for padding and border */
    box-sizing: border-box;
    resize: vertical; /* Allow vertical resizing for textarea */
    min-height: 80px; /* Minimum height for textarea */
}

.modal-content button {
    background-color: #007bff;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s;
}

.modal-content button:hover {
    background-color: #0056b3;
}

/* Multiplayer Sidebar Styles */
.multiplayer-sidebar {
    width: 320px; /* Fixed width for the multiplayer sidebar */
    background-color: #f8f9fa;
    border-left: 1px solid #eee;
    display: flex;
    flex-direction: column;
    padding: 15px;
    box-sizing: border-box;
}

.multiplayer-header {
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    margin-bottom: 10px;
    text-align: center;
}

.multiplayer-header h2 {
    margin: 0;
    font-size: 1.3em;
    color: #333;
}

.multiplayer-messages {
    flex-grow: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    word-wrap: break-word;
    white-space: pre-wrap;
    min-height: 0; /* Important for flex-grow to work */
}

.multiplayer-message-wrapper {
    display: flex;
    align-items: flex-start;
    margin-bottom: 10px;
    gap: 10px;
}

.multiplayer-message-wrapper.user {
    justify-content: flex-end;
}

.multiplayer-message-wrapper.other {
    justify-content: flex-start;
}

.multiplayer-message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.multiplayer-message-content {
    max-width: 75%; /* Adjust as needed */
    display: flex;
    flex-direction: column;
}

.multiplayer-username {
    font-weight: bold;
    font-size: 0.9em;
    color: #555;
    margin-bottom: 2px;
}

.multiplayer-message-text {
    padding: 8px 12px;
    border-radius: 15px;
    line-height: 1.4;
    word-break: break-word;
    background-color: #e0f7fa; /* Light blue for multiplayer messages */
    color: #333;
}

.multiplayer-message-wrapper.user .multiplayer-message-text {
    background-color: #cfe2ff; /* Lighter blue for user's own messages in multiplayer */
}

.multiplayer-message-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 5px;
}

.multiplayer-input {
    display: flex;
    padding: 15px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    align-items: center; /* Align items vertically */
    flex-direction: column; /* Stack input and tip vertically */
}

.multiplayer-input-row {
    display: flex;
    width: 100%;
    align-items: center;
    margin-bottom: 5px; /* Space between input row and tip */
}

.multiplayer-input input {
    flex-grow: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 1em;
    outline: none;
}

/* Adjustments for multiplayer upload button */
.multiplayer-input .upload-button {
    padding: 7px 10px; /* Smaller padding */
    font-size: 1em; /* Smaller font size */
    border-radius: 15px; /* Adjust border-radius to match new size */
    margin-right: 10px; /* Space to the right of the button */
    margin-left: 0; /* Remove left margin */
    order: -1; /* Move to the left of the input field */
}

.multiplayer-input button {
    background-color: #28a745;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    margin-left: 10px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s;
}

.multiplayer-input button:hover {
    background-color: #218838;
}

.multiplayer-tip {
    font-size: 0.8em;
    color: #666;
    text-align: center;
    width: 100%;
    margin-top: 5px; /* Space above the tip */
}

/* New NOAL Answers Sidebar Styles */
.noal-answers-sidebar {
    width: 320px; /* Fixed width for the NOAL Answers sidebar */
    background-color: #f0f8ff; /* Light blue background for distinction */
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    padding: 15px;
    box-sizing: border-box;
    flex-shrink: 0; /* Prevent shrinking */
}

.noal-answers-header {
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 10px;
    text-align: center;
}

.noal-answers-header h2 {
    margin: 0;
    font-size: 1.3em;
    color: #333;
}

.noal-answers-messages {
    flex-grow: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    word-wrap: break-word;
    white-space: pre-wrap;
    min-height: 0;
}

/* Ensure only one message is visible at a time in NOAL's answer section */
.noal-answers-messages .multiplayer-message-wrapper {
    background-color: #e2f5ff; /* Slightly different shade for answers */
    border-radius: 10px;
    padding: 8px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.noal-answers-messages .multiplayer-message-avatar {
    /* NOAL's avatar is already styled, just ensure it's on the left */
}

.noal-answers-messages .multiplayer-username {
    color: #007bff; /* Highlight NOAL's username */
}

.noal-answers-messages .multiplayer-message-text {
    background-color: transparent; /* No background for the text bubble itself */
    padding: 0;
    border-radius: 0;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
        height: auto;
        width: 100%;
    }

    .sidebar, .multiplayer-sidebar, .noal-answers-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #eee;
        height: auto;
    }

    .chat-container {
        width: 100%;
        height: 60vh; /* Adjust as needed for smaller screens */
    }
}