/* --- Import Google Font --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

/* --- Keyframes for Animation --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Global & Body Styling --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #1a1a2e; /* Dark blue/purple background */
    color: #f0f0f0;
}

/* --- Main Chat Container --- */
.chat-container {
    background-color: rgba(31, 31, 58, 0.9); /* Slightly lighter dark blue */
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    width: 95%;
    max-width: 700px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- Frosted Glass Header --- */
header {
    background-color: rgba(31, 31, 58, 0.75); /* Translucent background */
    backdrop-filter: blur(10px); /* The "frosted glass" effect */
    -webkit-backdrop-filter: blur(10px); /* For Safari */
    color: white;
    padding: 1rem 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
}

/* --- User Profile & Auth Buttons in Header --- */
.user-area { display: flex; align-items: center; gap: 12px; }
#user-pic { width: 40px; height: 40px; border-radius: 50%; border: 2px solid #8e2de2; }
#user-name { font-size: 0.9rem; font-weight: 500; }

#sign-in-button, #sign-out-button {
    background: linear-gradient(to right, #8e2de2, #4a00e0);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}
#sign-in-button:hover, #sign-out-button:hover { 
    box-shadow: 0 0 15px rgba(142, 45, 226, 0.6); 
    transform: translateY(-2px); 
}

/* --- Messages Display Area with Geometric Pattern --- */
.messages-area {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background-color: #161625;
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* --- Individual Message Styling --- */
.message {
    padding: 0.75rem 1.25rem;
    border-radius: 22px;
    max-width: 75%;
    word-wrap: break-word;
    line-height: 1.5;
    animation: fadeInUp 0.4s ease-in-out;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.message:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.message .sender {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.85rem;
}

/* 'Received' Message Style */
.message.received {
    background-color: #2d2d44;
    color: #f0f0f0;
    align-self: flex-start;
    border-bottom-left-radius: 6px;
}
.message.received .sender { color: #bdbdbd; }

/* 'Sent' Message Style with Glowing Gradient */
.message.sent {
    background: linear-gradient(135deg, #4a00e0, #8e2de2);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 20px rgba(142, 45, 226, 0.4);
}
.message.sent .sender { color: rgba(255, 255, 255, 0.9); }

/* --- Meta info (time + status) --- */
.message .meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    font-size: 0.75rem;
    opacity: 0.75;
}

.message .time {
    color: #ccc;
}

.message .status {
    margin-left: 8px;
    color: #a3a3ff;
    font-weight: 500;
}

/* --- Typing Indicator --- */
.typing-indicator {
    text-align: left;
    color: #bdbdbd;
    font-size: 0.85rem;
    font-style: italic;
    margin-left: 1.5rem;
    margin-bottom: 0.5rem;
    min-height: 1.2em;
    transition: opacity 0.2s ease;
}

/* --- Message Input Form Area --- */
.input-area {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(31, 31, 58, 0.9);
}

#message-input {
    flex-grow: 1;
    padding: 0.75rem 1.25rem;
    border: 2px solid #3a3a5a;
    border-radius: 25px;
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    background-color: #161625;
    color: #f0f0f0;
    transition: all 0.2s ease-in-out;
}
#message-input:focus {
    outline: none;
    border-color: #8e2de2;
    box-shadow: 0 0 0 3px rgba(142, 45, 226, 0.25);
}
#message-input::placeholder { color: #888; }

#send-button {
    background: linear-gradient(to right, #8e2de2, #4a00e0);
    color: white;
    border: none;
    border-radius: 25px;
    padding: 0.75rem 1.75rem;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
    transition: all 0.2s ease-in-out;
}
#send-button:hover {
    box-shadow: 0 0 20px rgba(142, 45, 226, 0.7);
    transform: scale(1.05);
}

fieldset[disabled] #message-input { background-color: #1f1f3a; }

/* --- Scrollbar Styling --- */
.messages-area::-webkit-scrollbar {
    width: 8px;
}
.messages-area::-webkit-scrollbar-track {
    background: #161625;
}
.messages-area::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #8e2de2, #4a00e0);
    border-radius: 4px;
}

/* --- Responsive Tweaks --- */
@media (max-width: 600px) {
    header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
    .input-area {
        padding: 0.75rem;
    }
}
