* {
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f3f4f6;
    --border: #e5e7eb;
    --text: #111827;
    --muted: #6b7280;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 10px 35px rgba(0,0,0,.08);
}

.logo {
    font-size: 45px;
    text-align: center;
}

.login-card h1 {
    text-align: center;
    margin: 8px 0;
}

.muted,
.demo-note {
    color: var(--muted);
    text-align: center;
}

label {
    display: block;
    margin-top: 18px;
    margin-bottom: 7px;
    font-weight: 600;
}

input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 13px 14px;
    font-size: 15px;
    outline: none;
}

input:focus {
    border-color: var(--primary);
}

.primary-btn {
    width: 100%;
    margin-top: 22px;
    border: 0;
    border-radius: 10px;
    padding: 13px;
    color: white;
    background: var(--primary);
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
}

.primary-btn:hover {
    background: var(--primary-dark);
}

.alert {
    background: #fee2e2;
    color: #991b1b;
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 18px;
}

.chat-app {
    width: 100%;
    height: 100vh;
    display: flex;
    overflow: hidden;
    background: white;
}

.sidebar {
    width: 320px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: #fff;
}

.sidebar-header {
    min-height: 82px;
    padding: 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.app-title {
    font-size: 18px;
    font-weight: bold;
}

.current-user {
    margin-top: 5px;
    font-size: 12px;
    color: var(--muted);
}

.logout-btn {
    font-size: 12px;
    text-decoration: none;
    color: #dc2626;
}

.users-title {
    padding: 18px 18px 8px;
    font-size: 12px;
    font-weight: bold;
    color: var(--muted);
    text-transform: uppercase;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 18px;
    text-decoration: none;
    color: var(--text);
}

.user-item:hover,
.user-item.active {
    background: #eff6ff;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #dbeafe;
    color: #1d4ed8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

.user-name {
    font-weight: 600;
}

.user-username {
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

.chat-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-header {
    height: 82px;
    padding: 15px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-name {
    font-weight: bold;
}

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

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    margin-right: 4px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 25px;
    background: #f9fafb;
}

.message-row {
    display: flex;
    margin-bottom: 12px;
}

.message-row.mine {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(70%, 500px);
    padding: 10px 13px;
    border-radius: 15px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.mine .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.theirs .message-bubble {
    border-bottom-left-radius: 4px;
}

.message-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.4;
}

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

.message-form {
    display: flex;
    gap: 10px;
    padding: 15px;
    border-top: 1px solid var(--border);
    background: white;
}

.message-form input {
    flex: 1;
}

.message-form button {
    width: 48px;
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    font-size: 20px;
    cursor: pointer;
}

.message-form button:disabled {
    opacity: .5;
}

.no-messages,
.loading,
.empty-chat {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    text-align: center;
}

.no-messages div,
.empty-icon {
    font-size: 42px;
    margin-bottom: 10px;
}

.no-messages p {
    margin: 0 0 4px;
    color: var(--text);
    font-weight: 600;
}

.no-messages small {
    color: var(--muted);
}

@media (max-width: 700px) {
    .sidebar {
        width: 230px;
    }

    .message-bubble {
        max-width: 85%;
    }
}

@media (max-width: 520px) {
    .sidebar {
        width: 90px;
    }

    .sidebar-header {
        justify-content: center;
    }

    .sidebar-header > div {
        display: none;
    }

    .logout-btn {
        font-size: 11px;
    }

    .users-title {
        display: none;
    }

    .user-item {
        justify-content: center;
        padding: 12px 5px;
    }

    .user-item > div:last-child {
        display: none;
    }
}