:root {
    --bg: #15171c;
    --bg-sidebar: #181b21;
    --bg-chat: #1c1f26;
    --panel: #232831;
    --border: #2c323d;
    --text: #e6e9ef;
    --text-dim: #8a93a3;
    --text-faint: #5b6472;
    --accent: #7c83ff;
    --accent-hover: #8f95ff;
    --accent-soft: rgba(124, 131, 255, 0.14);
    --font-display: 'Bricolage Grotesque', sans-serif;
    --font-body: 'Hanken Grotesk', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ---------- Chat layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
}

.brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 24px;
    letter-spacing: -0.02em;
    padding: 4px 8px 22px;
    display: flex;
    align-items: center;
    gap: 9px;
}
.brand::before {
    content: "";
    width: 16px; height: 16px;
    border-radius: 5px;
    background: linear-gradient(135deg, var(--accent), #b06cff);
    box-shadow: 0 0 12px rgba(124, 131, 255, 0.5);
}

.sidebar__section { margin-bottom: 22px; }
.sidebar__label {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    display: block;
    margin: 0 8px 8px;
}

.field { display: flex; gap: 6px; }
.field input {
    flex: 1;
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 11px;
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--font-body);
    transition: border-color .15s, background .15s;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus { outline: none; border-color: var(--accent); background: #20242c; }
.field button {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0 13px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-body);
    transition: .15s;
}
.field button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Search ---------- */
.search-results { margin-top: 6px; }

/* ---------- Conversation list ---------- */
.room-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 42vh;
    overflow-y: auto;
}
.room-list__item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--text-dim);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.room-list__name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.room-badge {
    flex-shrink: 0;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);

}

.room-list__item:hover { background: var(--panel); color: var(--text); }
.room-list__item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}
.room-list:empty::after {
    content: "No conversations yet";
    display: block;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text-faint);
}
.room-list::-webkit-scrollbar { width: 6px; }
.room-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.room-list__item .room-list__avatar {
    width: 36px;
    height: 36px;
}
.room-list__item .room-list__avatar.msg-avatar--initial {
    font-size: 14px;
}

/* ---------- Create group ---------- */
.create-btn { width: 100%; }
.create-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}
.create-panel input {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 11px;
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--font-body);
    transition: border-color .15s;
}
.create-panel input::placeholder { color: var(--text-faint); }
.create-panel input:focus { outline: none; border-color: var(--accent); }
.seg {
    display: flex;
    gap: 4px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
}
.seg__btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 7px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-body);
    transition: .15s;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active { background: var(--accent); color: #fff; }

.sidebar__footer {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.user { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.user__dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #3ddc97;
    box-shadow: 0 0 8px #3ddc97;
}
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal__card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}
.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 16px;
}
.modal__close { background: none; border: none; color: var(--text-dim); font-size: 22px; line-height: 1; cursor: pointer; }
.modal__close:hover { color: var(--text); }
.modal__body { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.modal__input {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 11px 13px;
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color .15s;
}
.modal__input::placeholder { color: var(--text-faint); }
.modal__input:focus { outline: none; border-color: var(--accent); }
.modal__textarea { resize: vertical; min-height: 64px; }
.group-photo-pick {
    align-self: center;
    position: relative;
    width: 84px; height: 84px;
    border-radius: 50%;
    background: var(--panel);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    overflow: hidden;
}
.group-photo-pick__img { width: 100%; height: 100%; object-fit: cover; }
.group-photo-pick__placeholder { font-size: 26px; color: var(--text-dim); }
.modal__error {
    background: rgba(255, 107, 107, 0.12);
    border: 1px solid rgba(255, 107, 107, 0.4);
    color: #ff9b9b;
    padding: 9px 11px;
    border-radius: 9px;
    font-size: 13px;
}
.modal__done-text { color: var(--text-dim); font-size: 14px; line-height: 1.4; }
.avatar-upload { position: relative; cursor: pointer; display: inline-flex; align-items: center; }
.footer-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
}
.footer-avatar--empty {
    display: flex; align-items: center; justify-content: center;
    background: var(--panel);
    color: var(--text-dim);
    font-size: 18px;
    font-weight: 600;
    line-height: 1;
}
.avatar-upload__badge {
    position: absolute;
    right: -3px; bottom: -3px;
    width: 15px; height: 15px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 9px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--bg-sidebar);
    opacity: 0;
    transition: opacity .15s;
}
.avatar-upload:hover .avatar-upload__badge { opacity: 1; }
.logout { color: var(--text-faint); font-size: 13px; text-decoration: none; transition: color .15s; }
.logout:hover { color: #ff6b6b; }

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    margin-right: 14px;
    line-height: 1;
}
.backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 20;
}

.chat { flex: 1; display: flex; flex-direction: column; background: var(--bg-chat); min-width: 0; position: relative; }
.chat__header {
    height: 60px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 16px;
    position: relative;
    z-index: 2;
}
.app:not(.chat-active) .chat__header { border-bottom: none; }

.messages {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ---------- Empty state ---------- */
.empty-state {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 24px;
    text-align: center;
}
.empty-state__img {
    width: 260px;
    max-width: 70%;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.4);
}
.empty-state__text {
    color: var(--text-dim);
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
}

/* ---------- Messages with avatars ---------- */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 75%;
    align-self: flex-start;          /* other people → left */
    animation: msgIn .18s ease-out;
}
.message-row--own {
    flex-direction: row-reverse;     /* you → right, avatar on the right */
    align-self: flex-end;
}

.msg-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}
.msg-avatar--initial {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    color: #fff;
}

.message {
    display: flex;
    flex-direction: column;
    padding: 8px 13px;
    border-radius: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    min-width: 0;
}
.message--own {
    background: var(--accent);
    border-color: var(--accent);
}

.message__sender {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 2px;
    font-family: var(--font-display);
}
.message__text { font-size: 14px; line-height: 1.55; color: var(--text); overflow-wrap: anywhere; }
.message__time {
    font-size: 10px;
    color: var(--text-faint);
    align-self: flex-end;
    margin-top: 3px;
}
.message--own .message__time { color: rgba(255, 255, 255, 0.65); }
.message--own .message__sender { color: rgba(255, 255, 255, 0.8); }
.message--own .message__text { color: #fff; }
.system {
    align-self: center;
    font-size: 12px;
    color: var(--text-faint);
    padding: 5px 0;
    text-align: center;
}

.composer { flex-shrink: 0; padding: 16px 24px 22px; display: flex; gap: 10px; }
.composer input {
    flex: 1;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 13px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color .15s;
}
.composer input::placeholder { color: var(--text-faint); }
.composer input:focus { outline: none; border-color: var(--accent); }
.composer button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0 22px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    font-family: var(--font-body);
    transition: .15s;
}
.composer button:hover { background: var(--accent-hover); }
.composer button:active { transform: translateY(1px); }

@keyframes msgIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

/* ---------- Auth / login ---------- */
.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at 30% 20%, rgba(124, 131, 255, 0.08), transparent 60%), var(--bg);
}
.auth__card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 34px 30px;
}
.auth__brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 30px;
    letter-spacing: -0.02em;
    text-align: center;
    margin-bottom: 4px;
}
.auth__tagline { text-align: center; color: var(--text-faint); font-size: 13px; margin-bottom: 28px; }
.auth__form { display: flex; flex-direction: column; gap: 10px; }
.auth__label {
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    margin-bottom: 2px;
}
.auth__form input {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color .15s;
}
.auth__form input::placeholder { color: var(--text-faint); }
.auth__form input:focus { outline: none; border-color: var(--accent); }
.btn {
    padding: 12px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    font-family: var(--font-body);
    border: 1px solid transparent;
    transition: .15s;
    margin-top: 4px;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.auth__toggle {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 4px;
    background: none;
    border: none;
    color: var(--accent);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: color .15s;
}
.auth__toggle:hover { color: var(--accent-hover); text-decoration: underline; }

.auth__alert {
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.auth__alert--error {
    background: rgba(255, 107, 107, 0.12);
    border-color: rgba(255, 107, 107, 0.4);
    color: #ff9b9b;
}
.auth__alert--ok {
    background: rgba(61, 220, 151, 0.12);
    border-color: rgba(61, 220, 151, 0.4);
    color: #6ee7b0;
}
.auth__divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--text-faint);
    font-size: 12px;
    margin: 22px 0;
}
.auth__divider::before, .auth__divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth__divider span { padding: 0 12px; }

.chat__title { cursor: pointer; }
.seg__btn:disabled { opacity: 0.5; cursor: default; }
.modal__input:read-only { opacity: 0.7; cursor: default; }
.btn--danger { background: #e0484d; color: #fff; }
.btn--danger:hover { background: #f25a5f; }
.header-action {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
}
.header-action:hover { color: #ff6b6b; }
/* ---------- Responsive (narrow screens) ---------- */
@media (max-width: 760px) {
    .menu-btn { display: inline-flex; align-items: center; }

    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        width: 78%;
        max-width: 300px;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 2px 0 18px rgba(0, 0, 0, 0.4);
    }
    .app.sidebar-open .sidebar { transform: translateX(0); }
    .app.sidebar-open .backdrop { display: block; }

    .message-row { max-width: 88%; }
    .messages { padding: 16px; }
    .composer { padding: 12px 16px 18px; }
    .chat__header { padding: 0 16px; }
}