/* Base styles for dark theme and centering */
html, body {
    height: 100%; /* Ensure html and body take full viewport height */
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif; /* Using Inter font */
    background-color: #1a1a1a; /* Dark background for the whole page */
    overflow: hidden; /* Prevent body scrolling, as the chat container will handle its own scrolling */
}

/* Main chat container */
.chat-container {
    width: 100%;
    max-width: 450px; /* Typical phone width */
    height: 100vh; /* Changed to 100vh as requested */
    
    /* Make the chat container fixed to the viewport, filling it */
    position: fixed;
    top: 0;
    left: 50%; /* Center horizontally */
    transform: translateX(-50%); /* Adjust for centering */
    
    display: flex;
    flex-direction: column;
    background-color: #262626; /* Dark background for the chat container */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); /* Darker shadow for depth */
    border-radius: 12px; /* Rounded corners for the main container */
    overflow: hidden; /* Ensure content respects border-radius and internal scrolling */

    /* Add responsive adjustments for larger screens to center the fixed container */
    @media (min-width: 768px) {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        height: 90vh; /* Adjust height for desktop view */
        max-height: 800px; /* Max height for desktop */
        width: 450px; /* Keep consistent width on desktop */
    }
}

/* Header styling */
.chat-header {
    display: flex;
    align-items: center;
    padding: 15px;
    background-color: #1a1a1a; /* Darker background for the header */
    color: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); /* Darker shadow */
    z-index: 10;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.profile-pic {
    width: 40px;
    height: 40px;
    background-image: url('https://placehold.co/40x40/0084ff/ffffff?text=E'); /* Placeholder, replace with actual Ellie avatar */
    background-size: cover;
    background-position: center;
    border-radius: 50%;
    margin-right: 10px;
    border: 2px solid #333; /* Darker border for the profile picture */
}

.header-info {
    flex-grow: 1; /* Allows it to take available space */
    display: flex;
    flex-direction: column;
}

.header-info .name {
    font-weight: bold;
    font-size: 1.1em;
}

.header-info .status {
    font-size: 0.8em;
    opacity: 0.8;
    color: #22c55e; /* Green for online status, stands out on dark */
}

.logout-button {
    background-color: #ef4444; /* Red for logout button, common and clear */
    color: white;
    border: none;
    border-radius: 15px;
    padding: 8px 15px;
    font-size: 0.9em;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-left: 15px;
}

.logout-button:hover {
    background-color: #dc2626; /* Darker red on hover */
}

/* Chat Area */
.chat-area {
    flex-grow: 1; /* Allows chat area to take up remaining space */
    padding: 15px;
    overflow-y: auto; /* Scroll messages if they overflow */
    background-color: #1a1a1a; /* Dark background for chat area */
    display: flex;
    flex-direction: column; /* Messages stack vertically */
    overscroll-behavior-y: contain; /* Prevents body scroll when chat area scrolls */
}

/* Custom scrollbar for chat area (for desktop/browser consistency) */
.chat-area::-webkit-scrollbar {
    width: 8px;
}

.chat-area::-webkit-scrollbar-track {
    background-color: #262626; /* Darker scrollbar track */
}

.chat-area::-webkit-scrollbar-thumb {
    background-color: #4a4a4a; /* Dark gray scrollbar thumb */
    border-radius: 4px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
    background-color: #5a5a5a; /* Lighter gray on hover */
}

.message {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
    max-width: 80%; /* Limits message width */
    animation: fadeIn 0.3s ease-out; /* Fade in animation for messages */
}

.message.user {
    align-self: flex-end; /* User messages on the right */
    align-items: flex-end; /* Align timestamp/status to the right */
}

.message.ellie {
    align-self: flex-start; /* Ellie messages on the left */
    align-items: flex-start; /* Align timestamp to the left */
}

.message-bubble {
    padding: 10px 15px;
    border-radius: 18px; /* More rounded corners for bubbles (Instagram-like) */
    line-height: 1.4;
    word-wrap: break-word; /* Ensure long words break */
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2); /* Subtle, slightly darker shadow */
}

.message.user .message-bubble {
    background-color: #0084ff; /* Instagram blue for user messages */
    color: white;
    /* Slightly less rounded on the bottom-right for user, typical chat bubble shape */
    border-bottom-right-radius: 4px;
}

.message.ellie .message-bubble {
    background-color: #363636; /* Dark gray for Ellie's messages */
    color: #e0e0e0; /* Light text on dark bubble */
    /* Slightly less rounded on the bottom-left for Ellie, typical chat bubble shape */
    border-bottom-left-radius: 4px;
}

/* New style for images within chat bubbles */
.chat-image {
    max-width: 100%; /* Ensure image fits within the bubble */
    height: auto; /* Maintain aspect ratio */
    border-radius: 8px; /* Rounded corners for the image itself */
    display: block; /* Remove extra space below image */
    margin-top: 5px; /* Add a little space if there's text above it */
    margin-bottom: 5px; /* Add a little space if there's text below it */
}

.timestamp {
    font-size: 0.7em;
    color: #a0a0a0; /* Lighter gray for timestamps on dark background */
    margin-top: 3px;
    padding: 0 5px; /* Adjust padding for better spacing */
}

.message-status {
    font-size: 0.7em;
    color: #a0a0a0; /* Lighter gray for message status */
    margin-top: 3px;
    margin-left: 5px; /* For user messages, status is to the right */
}

.message.user .message-status {
    color: #a0c0ff; /* Lighter blue for checkmarks on dark user bubbles */
}
.message.user .message-status.read {
    color: #63b3ed; /* A more distinct blue for read status */
}


/* Typing Indicator */
.typing-indicator-container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 10px;
    padding: 8px 15px;
    background-color: #363636; /* Dark gray for typing indicator bubble */
    border-radius: 18px; /* Rounded corners */
    max-width: 100px; /* Small width for indicator bubble */
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: #0084ff; /* Matching user message color for dots */
    border-radius: 50%;
    margin: 0 2px;
    animation: bounce 1.2s infinite ease-in-out;
    display: inline-block; /* Ensure dots are in line */
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.1s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.2s;
}

/* Keyframe animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}


/* Input Area */
.chat-input-area {
    display: flex;
    padding: 10px;
    background-color: #262626; /* Dark background for input area */
    border-top: 1px solid #363636; /* Darker border at the top */
    flex-shrink: 0; /* Prevent input area from shrinking */
}

#message-input {
    flex-grow: 1;
    padding: 10px 15px;
    border: none;
    border-radius: 20px; /* Rounded input field */
    background-color: #363636; /* Dark background for input field */
    color: #e0e0e0; /* Light text color for input */
    font-size: 1em;
    margin-right: 10px;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3); /* Inner shadow for depth */
}

/* Placeholder styling for input field */
#message-input::placeholder {
    color: #a0a0a0; /* Lighter gray for placeholder text */
    opacity: 1; /* Firefox default is lower opacity */
}

#send-button {
    background-color: #0084ff; /* Instagram blue for send button */
    color: white;
    border: none;
    border-radius: 20px; /* Rounded send button */
    padding: 10px 20px;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#send-button:hover {
    background-color: #0073e6; /* Darker blue on hover */
}

#send-button:disabled {
    background-color: #4a4a4a; /* Darker gray for disabled state */
    cursor: not-allowed;
}

/* --- Authentication Styles --- */
.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 30px;
    background-color: #262626; /* Dark background for auth container */
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5); /* Darker shadow */
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%; /* Take full height of parent if needed on mobile */
    box-sizing: border-box; /* Include padding in height calculation */

    /* Fixed positioning for centering on all screens */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.auth-container h2 {
    color: #0084ff; /* Instagram blue for title */
    margin-bottom: 25px;
    font-size: 1.8em;
}

.auth-form {
    width: 100%;
    padding: 20px;
    border: 1px solid #363636; /* Darker border */
    border-radius: 8px;
    margin-bottom: 20px;
}

.auth-form h3 {
    color: #e0e0e0; /* Light text for form title */
    margin-bottom: 20px;
    font-size: 1.4em;
}

.auth-form input[type="text"],
.auth-form input[type="password"] {
    width: calc(100% - 20px); /* Adjust width for padding */
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #4a4a4a; /* Darker border for inputs */
    border-radius: 25px; /* Rounded inputs */
    font-size: 1em;
    outline: none;
    background-color: #363636; /* Dark background for inputs */
    color: #e0e0e0; /* Light text color for inputs */
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3); /* Inner shadow for depth */
}

/* Placeholder styles for auth inputs */
.auth-form input[type="text"]::placeholder,
.auth-form input[type="password"]::placeholder {
    color: #a0a0a0;
    opacity: 1;
}

.auth-form button {
    width: 100%;
    padding: 12px;
    background-color: #0084ff; /* Instagram blue for buttons */
    color: white;
    border: none;
    border-radius: 25px; /* Rounded buttons */
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-top: 10px;
}

.auth-form button:hover {
    background-color: #0073e6; /* Darker blue on hover */
}

.auth-form p {
    margin-top: 15px;
    font-size: 0.9em;
    color: #a0a0a0; /* Lighter gray for descriptive text */
}

.auth-form a {
    color: #0084ff; /* Instagram blue for links */
    text-decoration: none;
    font-weight: bold;
}

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

.error-message {
    color: #ef4444; /* Red for error messages */
    font-size: 0.9em;
    margin-top: 10px;
}

.success-message {
    color: #22c55e; /* Green for success messages */
    font-size: 0.9em;
    margin-top: 10px;
}
