:root {
    --primary: #00a884;
    --bg-color: #d1d7db;
    --card-bg: rgba(255, 255, 255, 0.9);
    --text-primary: #111b21;
    --text-secondary: #54656f;
    --sidebar-bg: rgba(255, 255, 255, 0.95);
    --header-bg: #f0f2f5;
    --chat-bg: #efeae2;
    --input-bg: #ffffff;
    --border-color: #e9edef;
    --sent-bg: #d9fdd3;
    --received-bg: #ffffff;
    --shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

body.dark-mode {
    --primary: #00a884;
    --bg-color: #111b21;
    --card-bg: rgba(34, 46, 53, 0.9);
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --sidebar-bg: rgba(17, 27, 33, 0.95);
    --header-bg: #202c33;
    --chat-bg: #0b141a;
    --input-bg: #2a3942;
    --border-color: #222e35;
    --sent-bg: #005c4b;
    --received-bg: #202c33;
    --shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #00a884 0%, #128c7e 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-primary);
    overflow: hidden;
}

/* Login Screen */
.login-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.auth-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.auth-tabs button {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 5px 15px;
    width: auto;
}

.auth-tabs button.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    font-weight: bold;
}

.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    text-align: center;
    width: 350px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.login-card h2 {
    color: var(--text-primary);
    margin-bottom: 10px;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.login-card input {
    width: 100%;
    padding: 12px 15px;
    margin: 10px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.3s;
}

.login-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.1);
}

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    margin-top: 10px;
    transition: transform 0.2s, background 0.3s;
}

.login-card button:hover {
    background: #008c6f;
    transform: translateY(-2px);
}

.hidden {
    display: none !important;
}

/* Main App */
.app-container {
    width: 95%;
    height: 95vh;
    max-width: 1600px;
    display: flex;
    background: var(--sidebar-bg);
    box-shadow: var(--shadow);
    border-radius: 16px;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

/* Sidebar */
.sidebar {
    width: 35%;
    max-width: 400px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
}

.header {
    height: 60px;
    background: var(--header-bg);
    display: flex;
    align-items: center;
    padding: 0 16px;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #dfe5e7;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 12px;
    color: white;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.header span {
    font-weight: 600;
    color: var(--text-primary);
}

.icon-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.search-bar {
    padding: 10px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
}

.search-bar input {
    width: 100%;
    padding: 8px 15px;
    background: var(--header-bg);
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    outline: none;
    font-size: 0.9rem;
}

.contact-list {
    flex: 1;
    overflow-y: auto;
    background: var(--sidebar-bg);
}

.contact {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.contact:hover {
    background: var(--header-bg);
}

.contact.active {
    background: var(--header-bg);
}

.avatar {
    width: 45px;
    /* Slightly smaller for sleekness */
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 15px;
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-info .name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 2px;
}

.contact-info .last-msg {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
}

/* CSS Background Pattern */
.chat-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.06;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
}

body.dark-mode .chat-area::before {
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-header {
    height: 60px;
    background: var(--header-bg);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    z-index: 1;
    justify-content: space-between;
}

.chat-info {
    margin-left: 10px;
}

.chat-info .name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.chat-info .status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.messages-container {
    flex: 1;
    padding: 20px 60px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* Tighter bubble gap */
    position: relative;
    z-index: 1;
}

.message-bubble {
    max-width: 65%;
    padding: 6px 10px 8px 10px;
    border-radius: 8px;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
    line-height: 1.4;
    word-wrap: break-word;
    color: #111b21;
}

body.dark-mode .message-bubble {
    color: #e9edef;
}

.message-bubble.sent {
    background: var(--sent-bg);
    align-self: flex-end;
    border-top-right-radius: 0;
}

.message-bubble.received {
    background: var(--received-bg);
    align-self: flex-start;
    border-top-left-radius: 0;
}

.message-bubble .time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    float: right;
    margin-left: 10px;
    margin-top: 5px;
    margin-bottom: -4px;
    /* Alignment fix */
}

.input-area {
    min-height: 62px;
    background: var(--header-bg);
    display: flex;
    align-items: center;
    padding: 10px 20px;
    border-top: 1px solid var(--border-color);
    z-index: 1;
}

.input-area input {
    flex: 1;
    padding: 12px 15px;
    border: none;
    border-radius: 8px;
    margin-right: 10px;
    outline: none;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.send-btn {
    background: var(--primary);
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 12px;
    /* Softer icon */
    font-size: 1.3rem;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.send-btn:hover {
    background: #008c6f;
    transform: scale(1.05);
}

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--chat-bg);
    color: var(--text-secondary);
    text-align: center;
}

.welcome-screen .icon {
    font-size: 5rem;
    margin-bottom: 20px;
    opacity: 0.3;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }

    100% {
        transform: translateY(0px);
    }
}

.welcome-screen h2 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-weight: 300;
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .app-container {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }

    .sidebar {
        width: 100%;
        max-width: none;
        display: flex;
        /* Default show sidebar */
    }

    .chat-area {
        display: none;
        /* Hide chat area initially on mobile */
        width: 100%;
    }

    /* When a chat is active, hide sidebar and show chat */
    .app-container.chat-active .sidebar {
        display: none;
    }

    .app-container.chat-active .chat-area {
        display: flex;
    }

    /* Add a back button for mobile */
    .chat-header .back-btn {
        display: block;
        margin-right: 10px;
        font-size: 1.2rem;
        cursor: pointer;
        background: none;
        border: none;
        color: var(--text-primary);
    }
}

.back-btn {
    display: none;
    /* Hidden on desktop */
}