:root {
    --bg-color: #0f172a;
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --message-own-bg: #6366f1;
    --message-other-bg: #334155;
    --font-family: 'Outfit', sans-serif;
    --success-color: #10b981;
    --error-color: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-family);
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(236, 72, 153, 0.15) 0%, transparent 20%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
}

/* Glass Effect */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Auth Screen */
#auth-screen {
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.auth-card {
    padding: 3rem;
    border-radius: 20px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    position: relative;
    overflow: hidden;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: all 0.3s ease;
}

.auth-form.hidden {
    display: none;
}

.auth-card h1 {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.auth-card p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

input {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 12px;
    color: white;
    outline: none;
    transition: all 0.3s ease;
}

input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

button {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

button:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.switch-auth {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.switch-auth a {
    color: var(--accent-color);
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}

.error-msg {
    color: var(--error-color);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

/* Chat Screen */
#chat-screen {
    padding: 2rem;
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.sidebar {
    width: 280px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    height: calc(100vh - 4rem);
}

.sidebar-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info {
    font-size: 0.9rem;
    font-weight: 600;
}

#logout-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

#logout-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#contact-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.contact-item {
    padding: 0.75rem;
    border-radius: 10px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.contact-item:hover,
.contact-item.active {
    background: rgba(255, 255, 255, 0.1);
}

.contact-item .unread-badge {
    position: absolute;
    right: 10px;
    background: var(--accent-color);
    color: white;
    font-size: 0.7rem;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
    /* Hidden by default */
}

.contact-item.has-unread .unread-badge {
    display: flex;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #ec4899);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.main-chat {
    flex: 1;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4rem);
    overflow: hidden;
}

.chat-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-title {
    font-weight: 600;
    font-size: 1.1rem;
}

#typing-indicator {
    font-size: 0.85rem;
    color: var(--accent-color);
    min-height: 1.2em;
}

#messages-container {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 70%;
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    line-height: 1.5;
    position: relative;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.own {
    align-self: flex-end;
    background: var(--message-own-bg);
    border-bottom-right-radius: 4px;
}

.message.other {
    align-self: flex-start;
    background: var(--message-other-bg);
    border-bottom-left-radius: 4px;
}

.message .sender {
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
    opacity: 0.8;
    display: block;
}

.system-message {
    align-self: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

#chat-form {
    padding: 1.5rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
}

#chat-form input {
    flex: 1;
}

#chat-form button {
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-icon {
    width: 20px;
    height: 20px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    #chat-screen {
        padding: 0;
        height: 100vh;
        flex-direction: column;
    }

    .sidebar {
        display: none;
        /* Hide sidebar on mobile for simplicity, or make it toggleable */
    }

    .sidebar.active {
        display: flex;
        position: absolute;
        z-index: 10;
        width: 100%;
        background: var(--bg-color);
    }

    .main-chat {
        border-radius: 0;
        height: 100%;
    }
}