/* General Body and Container Styles - No Change */
body {
    margin: 0;
    font-family: 'Roboto', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-image: url('bg.png'); /* Make sure this image exists in your directory */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: #fff; /* White text for better contrast on background */
    text-align: center;
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
    padding: 20px; /* Add some padding for smaller screens if chat-wrapper takes full width */
}

/* Styles for index.php, login.php, register.php content containers - No Change */
.container {
    background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent background for content */
    padding: 40px 30px;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    width: 90%; /* Responsive width */
    -webkit-backdrop-filter: blur(5px); /* For Safari */
}

.header h1 {
    font-family: 'Pacifico', cursive; /* A fun, cursive font for the main title */
    font-size: 2.8em;
    margin-bottom: 15px;
    color: #FFD700; /* A golden yellow for emphasis */
}

.header p {
    font-size: 1.1em;
    line-height: 1.6;
    margin-bottom: 30px;
}

/* --- Buttons for index.php - No Change --- */
.buttons {
    display: flex;
    flex-direction: column; /* Stack buttons on small screens */
    gap: 20px; /* Space between buttons */
    margin-top: 20px;
}

.btn {
    display: block; /* Make links behave like block elements */
    padding: 15px 25px;
    font-size: 1.2em;
    font-weight: bold;
    text-decoration: none;
    border-radius: 8px;
    transition: background-color 0.3s ease, transform 0.2s ease;
    width: 100%; /* Full width for buttons on small screens */
    box-sizing: border-box; /* Include padding in width */
    cursor: pointer; /* Indicate it's clickable for button type */
    border: none; /* Remove default button border */
}

.login-btn {
    background-color: #4CAF50; /* Green */
    color: white;
}

.login-btn:hover {
    background-color: #45a049;
    transform: translateY(-2px);
}

.register-btn {
    background-color: #008CBA; /* Blue */
    color: white;
}

.register-btn:hover {
    background-color: #007bb5;
    transform: translateY(-2px);
}

/* --- Form specific styles (for login.php and register.php) - No Change --- */
.form-container {
    background-color: rgba(255, 255, 255, 0.9); /* Lighter background for the form itself */
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: #333; /* Darker text inside the form */
    text-align: left; /* Align form labels/inputs left */
    max-width: 400px; /* Adjust max width for forms */
    margin: auto; /* Center the form-container within its parent */
}

.form-container h2 {
    font-family: 'Pacifico', cursive;
    color: #4CAF50; /* Green heading for forms */
    font-size: 2.5em;
    margin-bottom: 25px;
    text-align: center;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #555;
}

.input-group input[type="text"],
.input-group input[type="password"] {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
    box-sizing: border-box; /* Include padding in width */
}

.input-group input:focus {
    outline: none;
    border-color: #008CBA;
    box-shadow: 0 0 5px rgba(0, 140, 186, 0.3);
}

.message {
    padding: 10px 15px;
    margin-bottom: 20px;
    border-radius: 5px;
    font-size: 0.95em;
    text-align: center;
    color: #fff;
}

.message.error {
    background-color: #f44336; /* Red for errors */
}

.message.success {
    background-color: #4CAF50; /* Green for success */
}

.switch-form-link {
    text-align: center;
    margin-top: 20px;
    font-size: 0.95em;
    color: #666; /* Darker text for links */
}

.switch-form-link a {
    color: #008CBA; /* Blue link color */
    text-decoration: none;
    font-weight: bold;
}

.switch-form-link a:hover {
    text-decoration: underline;
}

/* --- Chat Specific Styles (for chat.php) - MODIFIED --- */
.chat-wrapper {
    display: flex;
    flex-direction: column; /* Changed to column to stack header above content */
    min-height: 90vh; /* Make it take most of the viewport height */
    width: 95%; /* Adjust width to leave some space on larger screens */
    max-width: 1200px; /* Max width for the whole chat interface */
    margin: 0 auto;
    background-color: rgba(255, 255, 255, 0.95); /* Semi-transparent white background for the chat area */
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    overflow: hidden; /* Ensures content stays within rounded corners */
    margin-top: 20px; /* Add margin to separate from top */
    margin-bottom: 20px; /* Add margin to separate from bottom */
}

.chat-header {
    background-color: #008CBA; /* Blue header */
    color: white;
    padding: 20px;
    text-align: center;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 10px; /* Space between items if wrapped */
    flex-shrink: 0; /* Prevents header from shrinking */
}

.chat-header h1 {
    margin: 0;
    font-size: 2.2em;
    font-family: 'Pacifico', cursive;
    color: #FFD700;
}

.chat-header p {
    margin: 0;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logout-btn {
    background-color: #f44336; /* Red for logout */
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    text-decoration: none;
    font-size: 0.9em;
    transition: background-color 0.3s ease;
}

.logout-btn:hover {
    background-color: #da190b;
}

/* Chat Container - Flexbox for main layout (users and messages) - MODIFIED */
.chat-container {
    display: flex;
    flex-grow: 1; /* Allows it to take up remaining height below header */
    overflow: hidden; /* Contains the scrollable content */
}

/* Side Panel for Users */
.side-panel {
    width: 250px; /* Fixed width for side panel */
    background-color: #f0f2f5; /* Light grey background */
    padding: 20px;
    border-right: 1px solid #ddd;
    overflow-y: auto; /* Scroll for many users */
    color: #333;
    flex-shrink: 0; /* Prevents shrinking on smaller screens */
}

.side-panel h2 {
    font-size: 1.5em;
    color: #008CBA;
    margin-top: 0;
    margin-bottom: 20px;
}

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

.user-item {
    padding: 12px 10px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-size: 1.1em;
    border-radius: 5px;
    margin-bottom: 5px;
}

.user-item:last-child {
    border-bottom: none;
}

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

.user-item.active {
    background-color: #008CBA;
    color: white;
    font-weight: bold;
}

/* Main Chat Area */
.main-chat-area {
    flex-grow: 1; /* Takes up remaining width */
    display: flex;
    flex-direction: column; /* Stack messages box and input box */
    background-color: #e5ddd5; /* Chat background color (WhatsApp-like) */
}

.messages-box {
    flex-grow: 1; /* Takes up available space for messages */
    padding: 20px;
    overflow-y: auto; /* Scroll for messages */
    display: flex; /* Use flexbox for messages to push oldest to top */
    flex-direction: column; /* Arrange messages vertically */
}

.messages-box .no-user-selected,
.messages-box .no-messages,
.messages-box .error {
    text-align: center;
    color: #777;
    margin-top: 50px;
    font-style: italic;
    width: 100%; /* Ensure these messages take full width */
}


/* Individual Message Styles - MODIFIED COLORS */
.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 15px;
    margin-bottom: 10px;
    word-wrap: break-word; /* Prevent long words from overflowing */
    line-height: 1.4;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    color: #ff1a1a; /* Default text color for messages */
}

.message-sender {
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.8); /* Lighter sender name on colored bubbles */
}

.message p {
    margin: 0;
}

.message-time {
    font-size: 0.75em;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 5px;
    display: block;
    text-align: right; /* Time on the right within the bubble */
}

.message.sent {
    background-color: #4CAF50; /* Green for sent messages */
    align-self: flex-end; /* Align to the right */
    border-bottom-right-radius: 2px; /* Pointy edge for sent */
}

.message.received {
    background-color: #008CBA; /* Blue for received messages */
    align-self: flex-start; /* Align to the left */
    border-bottom-left-radius: 2px; /* Pointy edge for received */
}


/* Message Input Area - No Change */
.message-input-box {
    padding: 15px;
    background-color: #f0f2f5;
    border-top: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0; /* Prevents shrinking on smaller screens */
}

.message-input-box.hidden {
    display: none;
}

.chatting-with {
    font-size: 1.1em;
    font-weight: bold;
    color: #555;
    margin: 0;
    text-align: left;
}

#selected-user-name {
    color: #008CBA;
}

#message-text {
    width: calc(100% - 20px); /* Adjust for padding */
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
    resize: vertical; /* Allow vertical resizing */
    box-sizing: border-box;
    margin-bottom: 10px; /* Space between textarea and button */
}

#send-message-btn {
    align-self: flex-end; /* Align button to the right */
    padding: 10px 20px;
    font-size: 1em;
    background-color: #4CAF50;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#send-message-btn:hover {
    background-color: #45a049;
}


/* Media Queries for Responsiveness */
@media (max-width: 768px) {
    /* General adjustments for smaller screens */
    body {
        padding: 10px;
    }

    .container {
        padding: 30px 20px;
        max-width: 95%;
    }

    .header h1 {
        font-size: 2.2em;
    }

    .header p {
        font-size: 1em;
    }

    .btn {
        font-size: 1.1em;
        padding: 12px 20px;
    }

    /* Chat specific adjustments */
    .chat-wrapper {
        min-height: 95vh;
        width: 100%;
        margin: 0;
        border-radius: 0; /* Remove border-radius on small screens for full width */
    }

    .chat-header {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }

    .chat-header h1 {
        font-size: 1.8em;
    }

    .chat-header p {
        font-size: 0.9em;
    }

    .chat-container {
        flex-direction: column; /* Stack panels on smaller screens */
    }

    .side-panel {
        width: 100%; /* Full width for side panel on small screens */
        border-right: none;
        border-bottom: 1px solid #ddd; /* Add bottom border */
        max-height: 200px; /* Limit height of user list on mobile */
    }

    .user-item {
        font-size: 1em;
        padding: 10px;
    }

    .messages-box {
        padding: 15px;
    }

    .message {
        max-width: 85%; /* Allow messages to be a bit wider on small screens */
    }

    .message-sender {
        font-size: 0.8em;
    }

    .message-time {
        font-size: 0.7em;
    }

    .message-input-box {
        padding: 10px;
    }

    #message-text {
        width: 100%;
        padding: 10px;
    }

    #send-message-btn {
        padding: 8px 15px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    /* Further adjustments for very small screens */
    body {
        padding: 5px;
    }

    .container {
        padding: 25px 15px;
    }

    .header h1 {
        font-size: 2em;
    }

    .header p {
        font-size: 0.9em;
    }

    .form-container {
        padding: 15px;
    }

    .form-container h2 {
        font-size: 2em;
    }

    .input-group label,
    .input-group input[type="text"],
    .input-group input[type="password"] {
        font-size: 0.9em;
        padding: 10px;
    }

    /* Chat specific adjustments for very small screens */
    .chat-header h1 {
        font-size: 1.6em;
    }

    .chat-header p {
        font-size: 0.8em;
    }

    .logout-btn {
        padding: 6px 12px;
        font-size: 0.8em;
    }

    .side-panel h2 {
        font-size: 1.3em;
    }

    .user-item {
        font-size: 0.9em;
        padding: 8px;
    }

    .messages-box {
        padding: 10px;
    }

    .message {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    .message-sender {
        font-size: 0.8em;
    }

    .message-time {
        font-size: 0.7em;
    }

    #message-text {
        font-size: 0.9em;
        padding: 8px;
    }

    #send-message-btn {
        font-size: 0.8em;
        padding: 6px 12px;
    }
}