* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #111;
    min-height: 100vh;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #075e54, #128c7e);
}

.login-box {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

.login-box h1 { font-size: 1.4rem; margin-bottom: .25rem; }
.subtitle { color: #667; margin-bottom: 1.5rem; }

label { display: block; margin-bottom: .4rem; font-size: .9rem; color: #444; }

input[type="password"], textarea {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: .75rem;
    font-size: 1rem;
    font-family: inherit;
}

button {
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: .75rem 1.25rem;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
}

button:hover { background: #1da851; }
button:disabled { opacity: .6; cursor: not-allowed; }

.login-box button { width: 100%; margin-top: 1rem; }

.alert {
    padding: .75rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: .9rem;
}

.alert.error { background: #fde8e8; color: #b42318; }
.hidden { display: none; }

.topbar {
    background: #075e54;
    color: #fff;
    padding: .75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar .muted { opacity: .8; margin-left: .75rem; font-size: .85rem; }
.logout { color: #fff; text-decoration: none; font-size: .9rem; }

.app {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - 48px);
}

.sidebar {
    background: #fff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.badge {
    background: #25d366;
    color: #fff;
    font-size: .75rem;
    padding: .15rem .5rem;
    border-radius: 999px;
}

.conversation-list { overflow-y: auto; flex: 1; }

.conversation-item {
    display: block;
    padding: .9rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none;
    color: inherit;
}

.conversation-item:hover { background: #f7f7f7; }
.conversation-item.active { background: #e7f8ef; }

.conv-name { font-weight: 600; margin-bottom: .2rem; }
.conv-preview { font-size: .85rem; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: .75rem; color: #999; margin-top: .25rem; }

.chat {
    display: flex;
    flex-direction: column;
    background: #e5ddd5;
}

.chat-header {
    background: #fff;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e0e0e0;
}

.chat-header h2 { font-size: 1.1rem; }
.muted { color: #667; font-size: .85rem; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.message { display: flex; flex-direction: column; max-width: 70%; }
.message.in { align-self: flex-start; }
.message.out { align-self: flex-end; }

.bubble {
    padding: .6rem .85rem;
    border-radius: 8px;
    line-height: 1.4;
    word-break: break-word;
}

.message.in .bubble { background: #fff; }
.message.out .bubble { background: #dcf8c6; }

.message .time { font-size: .7rem; color: #888; margin-top: .2rem; padding: 0 .25rem; }
.message.out .time { text-align: right; }

.reply-form {
    background: #f0f0f0;
    padding: 1rem;
    display: flex;
    gap: .75rem;
    align-items: flex-end;
}

.reply-form textarea { flex: 1; resize: vertical; min-height: 44px; }
.reply-form button { flex-shrink: 0; }

.empty, .empty-chat {
    padding: 2rem;
    text-align: center;
    color: #666;
    line-height: 1.6;
}

.empty-chat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-error { margin: 0 1rem 1rem; }

@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { max-height: 40vh; }
}
