:root {
    --accent: #2AABEE;
    --accent-dark: #229ED9;
    --bg-sidebar: #ffffff;
    --bg-app: #eef2f5;
    --border: #e4e7eb;
    --text-main: #1a1d21;
    --text-muted: #8b95a1;
    --bubble-in: #ffffff;
    --bubble-out: #effdde;
    --danger: #e53e3e;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-main);
    background: var(--bg-app);
}

/* ===== Login screen ===== */
.login-body {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
}

.login-card {
    background: #fff;
    padding: 40px 36px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.login-logo { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--text-muted); font-size: 14px; margin: 0 0 20px; }

.login-card input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
}
.login-card input:focus { border-color: var(--accent); }

.login-card button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
}
.login-card button:hover { background: var(--accent-dark); }

.login-error {
    background: #fdecec;
    color: var(--danger);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    width: 100%;
    margin-bottom: 12px;
}

/* ===== App layout ===== */
.app {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 360px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.sidebar-title { font-size: 18px; font-weight: 700; }

.logout-btn {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    padding: 6px;
    border-radius: 8px;
}
.logout-btn:hover { background: var(--bg-app); color: var(--danger); }

.client-list {
    flex: 1;
    overflow-y: auto;
}

.empty-hint {
    padding: 24px 20px;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
}

.client-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f2f3f5;
}
.client-item:hover { background: #f7f9fa; }
.client-item.active { background: #e8f4fd; }

.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

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

.client-top-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

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

.client-time { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

.client-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

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

.unread-badge {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
}

/* ===== Chat panel ===== */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-app);
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
}
.chat-empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }

.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.chat-header-name { font-weight: 700; font-size: 15px; }
.chat-header-sub { font-size: 12px; color: var(--text-muted); }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bubble {
    max-width: 60%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
    position: relative;
}

.bubble.in {
    align-self: flex-start;
    background: var(--bubble-in);
    border-bottom-left-radius: 4px;
}

.bubble.out {
    align-self: flex-end;
    background: var(--bubble-out);
    border-bottom-right-radius: 4px;
}

.bubble-meta {
    display: block;
    font-size: 10.5px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.bubble.failed { border: 1px solid var(--danger); }
.bubble.failed .bubble-meta { color: var(--danger); }

.message-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 20px;
    background: #fff;
    border-top: 1px solid var(--border);
}

.message-form textarea {
    flex: 1;
    resize: none;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    line-height: 1.4;
}
.message-form textarea:focus { border-color: var(--accent); }

.message-form button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}
.message-form button:hover { background: var(--accent-dark); }
.message-form button:disabled { background: var(--text-muted); cursor: default; }

/* ===== Scrollbars ===== */
.client-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 6px; }
.client-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb {
    background: #d3d8dd;
    border-radius: 3px;
}

/* ===== Responsive ===== */
@media (max-width: 760px) {
    .sidebar { position: absolute; z-index: 5; height: 100%; width: 100%; }
    .sidebar.hidden { display: none; }
    .app { position: relative; }
}
