/* --- Professional UI Foundation --- */
:root {
    /* Color Palette */
    --primary-color: #0078FF;
    --background-color: #f0f2f5;
    --surface-color: #ffffff;
    --text-color: #050505;
    --text-secondary-color: #65676B;
    --my-message-background: var(--primary-color);
    --other-message-background: #E4E6EB;
    
    /* Font & Spacing */
    --main-font: 'Inter', sans-serif;
    --border-radius: 18px;
    --padding-md: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--main-font);
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 10px;
}

.hidden {
    display: none !important;
}

#app-container {
    width: 100%;
    max-width: 800px;
    height: 100%;
    max-height: 95vh;
    background-color: var(--surface-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.screen {
    width: 100%;
    height: 100%;
}

/* --- Login Screen --- */
#login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
}
.login-box {
    text-align: center;
    padding: 40px;
}
#loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.logo {
    font-weight: 700;
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(45deg, var(--primary-color), #5832a8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.login-box p {
    color: var(--text-secondary-color);
    margin-bottom: 30px;
}
#login-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    background-color: #43464a; /* Restored Google Blue */
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}
#login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(66, 133, 244, 0.4);
}
.divider {
    color: var(--text-secondary-color);
    margin: 20px 0;
    font-weight: 500;
}
#guest-btn {
    background: none;
    border: 1px solid #ccc;
    color: var(--text-secondary-color);
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    width: 100%;
}
#guest-btn:hover {
    background-color: #f0f0f0;
    border-color: #a0a0a0;
}

/* --- Chat Screen --- */
#chat-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px var(--padding-md);
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
}
.chat-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}
#user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
}
#logout-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary-color);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}
#logout-btn:hover {
    background-color: #f0f0f0;
}

#messages-container {
    flex-grow: 1;
    padding: var(--padding-md);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#messages-container::-webkit-scrollbar {
    width: 8px;
}
#messages-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}
#messages-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
}
.message {
    padding: 10px 15px;
    border-radius: var(--border-radius);
    max-width: 100%; /* The wrapper now controls the max-width */
    overflow-wrap: break-word; /* This is the only breaking rule we need */
}

/* Also, add this rule for the message wrapper */
.message-wrapper {
    max-width: 75%;
    display: flex;
    flex-direction: column;
}

.my-message-row .message-timestamp {
    text-align: right;
}
.message-sender {
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--text-secondary-color);
}
.message-timestamp {
    font-size: 0.7rem;
    color: var(--text-secondary-color);
    margin-top: 4px;
}


.my-message .message {
    background: var(--my-message-background);
    color: white;
    border-bottom-right-radius: 4px;
}
.my-message .message-timestamp {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

.message-row {
    display: flex; /* This makes the row a flex container */
    margin-bottom: 5px; /* Adds a little space between rows */
}

.my-message-row {
    justify-content: flex-end; /* Pushes the message bubble to the right */
}

.other-message-row {
    justify-content: flex-start; /* Pushes the message bubble to the left */
}
.my-message-row .message {
    background-color: var(--my-message-background);
    color: white;
    border-bottom-right-radius: 4px;
}

.other-message-row .message {
    background-color: var(--other-message-background);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}
.other-message .message {
    background: var(--other-message-background);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

.chat-footer {
    padding: 15px var(--padding-md);
    border-top: 1px solid #ddd;
    background-color: #f9f9f9;
    flex-shrink: 0;
}

#message-form {
    display: flex;
    gap: 10px;
    align-items: center;
}
#message-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    padding: 12px 18px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
#message-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 120, 255, 0.2);
}
#message-form button {
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s ease-in-out;
}
#message-form button:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 120, 255, 0.4);
}

/* --- Responsive Design for Mobile --- */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    #app-container {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}