/* public/style.css */
body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #333;
    overflow-y: scroll; /* Allow scrolling for long chat histories */
}

.chat-container {
    background-color: #fff;
    border-radius: 15px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 20px 0; /* Add some margin top/bottom */
    min-height: 80vh; /* Ensure it takes up a good portion of the viewport */
}

.chat-header {
    background-color: #4997f5;
    color: white;
    padding: 15px 20px;
    text-align: center;
    font-size: 1.8em;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
    margin: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* --- Modal Styling (General for Username and Image) --- */
.modal {
    display: flex; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1000; /* 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.6); /* Black w/ opacity */
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    color: #4CAF50;
    margin-bottom: 20px;
    font-size: 1.5em;
}

#username-input {
    width: calc(100% - 20px);
    padding: 12px;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    box-sizing: border-box;
}

#start-chat-btn {
    background-color: #4CAF50;
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1em;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

#start-chat-btn:hover {
    background-color: #45a049;
    transform: translateY(-2px);
}

/* Image Modal Specifics */
.modal-content-image {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    object-fit: contain; /* Ensure the image fits within the modal without cropping */
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.close-button {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}


/* --- Chat Interface --- */
.messages-display {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #e9ebee;
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px; /* Space between messages */
    max-height: calc(80vh - 180px); /* Adjust based on header and input area height */
    min-height: 300px; /* Minimum height for scrollable area */
}

.message-bubble {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 15px;
    border-radius: 12px;
    max-width: 80%;
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    position: relative; /* For reply and delete buttons */
}

.message-bubble.my-message {
    align-self: flex-end;
    background-color: #DCF8C6; /* Light green for self messages */
    border-bottom-right-radius: 2px;
}

.message-bubble.other-message {
    align-self: flex-start;
    background-color: #FFFFFF; /* White for other messages */
    border-bottom-left-radius: 2px;
}

.message-sender {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.message-content {
    font-size: 1em;
    line-height: 1.4;
}

.message-timestamp {
    font-size: 0.75em;
    color: #888;
    text-align: right;
    margin-top: 5px;
}

/* Unique colors for other users */
/* These will be applied dynamically via JS */
.color-0 { background-color: #E0F7FA; } /* Light Cyan */
.color-1 { background-color: #FFF3E0; } /* Light Orange */
.color-2 { background-color: #F3E5F5; } /* Light Purple */
.color-3 { background-color: #E8F5E9; } /* Light Green */
.color-4 { background-color: #FBE9E7; } /* Light Red */
.color-5 { background-color: #E1F5FE; } /* Light Blue */
.color-6 { background-color: #FFFDE7; } /* Light Yellow */
.color-7 { background-color: #FCE4EC; } /* Light Pink */
.color-8 { background-color: #EFEBE9; } /* Light Brown */
.color-9 { background-color: #ECEFF1; } /* Light Grey */


/* Deleted message styling */
.message-bubble.deleted .message-content {
    text-decoration: line-through;
    color: #999;
    font-style: italic;
}

/* Reply styling */
.reply-to-message {
    background-color: rgba(0, 0, 0, 0.05); /* Slightly darker background */
    border-left: 3px solid #4CAF50;
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.85em;
    color: #555;
    white-space: nowrap; /* Prevent wrapping */
    overflow: hidden; /* Hide overflow */
    text-overflow: ellipsis; /* Add ellipsis */
}

.reply-to-message strong {
    color: #333;
}

.reply-preview {
    background-color: #e0e0e0;
    padding: 10px 15px;
    border-radius: 8px;
    margin: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9em;
    color: #555;
}

.reply-preview #reply-content {
    flex-grow: 1;
    margin-right: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cancel-reply-btn {
    background: none;
    border: none;
    color: #777;
    cursor: pointer;
    font-size: 1.1em;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.cancel-reply-btn:hover {
    background-color: #ccc;
}

/* Message actions (reply, delete) */
.message-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    display: flex;
    gap: 5px;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s ease-in-out;
}

.message-bubble:hover .message-actions {
    opacity: 1; /* Show on hover */
}

.message-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8em;
    color: #777;
    padding: 5px;
    border-radius: 5px;
    transition: background-color 0.2s ease;
}

.message-action-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

/* Input Area */
.message-input-area {
    padding: 15px 20px;
    background-color: #f9f9f9;
    border-top: 1px solid #eee;
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
    position: relative; /* For emoji picker positioning */
}

.input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

#message-input {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 1em;
    outline: none;
    transition: border-color 0.3s ease;
}

#message-input:focus {
    border-color: #4CAF50;
}

.send-button {
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.2em;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.send-button:hover {
    background-color: #45a049;
    transform: scale(1.05);
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap; /* Allow buttons to wrap on smaller screens */
    justify-content: center;
}

.action-button {
    background-color: #f0f0f0;
    color: #555;
    border: 1px solid #ddd;
    padding: 10px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.action-button:hover {
    background-color: #e5e5e5;
    border-color: #ccc;
}

/* File/Voice message display */
.file-message a, .voice-message audio {
    display: block;
    margin-top: 5px;
}

.file-message a, .image-message .download-link {
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
}

.file-message a:hover, .image-message .download-link:hover {
    text-decoration: underline;
}

/* Image Thumbnail Styling */
.image-thumbnail {
    max-width: 150px; /* Thumbnail size */
    max-height: 150px;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 5px;
    object-fit: cover; /* Ensure image covers the area, cropping if necessary */
    border: 1px solid #ddd;
    transition: transform 0.2s ease;
}

.image-thumbnail:hover {
    transform: scale(1.02);
}

/* Emoji Picker Styling */
.emoji-picker-container {
    position: absolute;
    bottom: 100%; /* Position above the input area */
    left: 50%;
    transform: translateX(-50%);
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(8, 1fr); /* 8 emojis per row */
    gap: 5px;
    max-height: 200px; /* Limit height and make scrollable */
    overflow-y: auto;
    z-index: 900; /* Below modals */
    width: 90%; /* Adjust width for responsiveness */
    max-width: 300px;
}

.emoji-item {
    font-size: 1.5em;
    cursor: pointer;
    text-align: center;
    padding: 5px;
    border-radius: 5px;
    transition: background-color 0.2s ease;
}

.emoji-item:hover {
    background-color: #eee;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .chat-container {
        width: 100%;
        border-radius: 0;
        min-height: 100vh;
    }

    .chat-header {
        border-radius: 0;
    }

    .messages-display {
        padding: 15px;
        max-height: calc(100vh - 160px); /* Adjust for smaller screens */
    }

    .message-bubble {
        max-width: 95%;
        padding: 10px 12px;
    }

    .message-input-area {
        padding: 10px 15px;
    }

    .action-buttons {
        justify-content: space-around;
    }

    .action-button {
        flex-grow: 1; /* Allow buttons to take more space */
        text-align: center;
        justify-content: center;
    }

    .emoji-picker-container {
        grid-template-columns: repeat(6, 1fr); /* Fewer emojis per row on small screens */
        max-width: 250px;
    }
}
