:root {
    --primary: #8b5cf6;
    --primary-light: #a78bfa;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --msg-sent: #7c3aed;
    --msg-received: #334155;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    background: radial-gradient(circle at top left, #1e1b4b, #0f172a);
}

#app {
    height: 100%;
}

.view {
    height: 100%;
    display: flex;
    transition: opacity 0.3s ease;
}

.hidden {
    display: none !important;
}

/* --- LOGIN VIEW --- */
#login-view {
    justify-content: center;
    align-items: center;
}

.login-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 48px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
    text-align: center;
    animation: fadeIn 0.6s ease-out;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.brand i {
    font-size: 42px;
    color: var(--primary);
}

.brand h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 40px;
}

.input-group {
    text-align: left;
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.input-group input {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    color: white;
    font-family: inherit;
    transition: border-color 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

#login-btn {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, background 0.2s;
    margin-top: 10px;
}

#login-btn:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
}

/* --- CHAT VIEW --- */
#chat-view {
    background: rgba(15, 23, 42, 0.4);
}

/* Sidebar */
.sidebar {
    width: 360px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.2);
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-tabs {
    display: flex;
    padding: 0 24px 20px;
    gap: 8px;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--glass-bg);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn i {
    font-size: 16px;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.tab-content.hidden {
    display: none;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.user-info h3 {
    font-size: 15px;
    font-weight: 600;
}

.status-online {
    font-size: 12px;
    color: #10b981;
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-online::before {
    content: '';
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
}

#logout-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: color 0.2s;
}

#logout-btn:hover {
    color: #ef4444;
}

.search-bar {
    padding: 0 24px 24px;
    position: relative;
}

.search-bar i {
    position: absolute;
    left: 40px;
    top: 12px;
    color: var(--text-muted);
}

.search-bar input {
    width: 100%;
    background: var(--glass-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 16px 10px 44px;
    color: white;
    font-family: inherit;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
}

.conv-item {
    padding: 16px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.conv-item:hover {
    background: var(--glass-bg);
}

.conv-item.active {
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.conv-item .avatar {
    width: 50px;
    height: 50px;
    background: #334155;
    box-shadow: none;
}

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

.conv-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.conv-name-row h4 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-time {
    font-size: 11px;
    color: var(--text-muted);
}

.conv-last-msg {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.empty-icon {
    width: 80px;
    height: 80px;
    background: var(--glass-bg);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: var(--primary);
    margin-bottom: 24px;
}

.empty-state h2 {
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(15, 23, 42, 0.2);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 14px;
}

.status-text {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.chat-actions button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    padding: 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.chat-actions button:hover {
    background: var(--glass-bg);
    color: var(--text-main);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    animation: messageSlide 0.3s ease-out;
}

.message.sent {
    align-self: flex-end;
    background: var(--msg-sent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--msg-received);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
}

.chat-footer {
    padding: 24px 32px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(15, 23, 42, 0.2);
}

.attach-btn {
    background: var(--glass-bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#message-form {
    flex: 1;
    display: flex;
    gap: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 6px 6px 6px 16px;
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-family: inherit;
    font-size: 15px;
}

#message-input:focus {
    outline: none;
}

#send-btn {
    background: var(--primary);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: transform 0.2s;
}

#send-btn:hover {
    transform: scale(1.05);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes messageSlide {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- MODALS --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    width: 100%;
    max-width: 450px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    animation: fadeIn 0.3s ease-out;
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

#close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.users-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.user-item:hover {
    background: var(--glass-bg);
}

.user-item .avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
}

.user-name {
    font-weight: 600;
    font-size: 15px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

#new-chat-btn {
    background: var(--glass-bg);
    border: 1px solid var(--border);
    color: var(--primary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s, transform 0.2s;
}

#new-chat-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.05);
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}


.loading-messages, .empty-messages, .error-messages {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    padding: 40px;
}

.error-messages {
    color: #ef4444;
}
