/* ============================================================
   Messages page
   ============================================================ */

.messages-page {
    padding-block: 28px 56px;
}

.chat {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    height: min(680px, calc(100vh - 170px));
    min-height: 440px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}


/* Conversation list */

.chat-list {
    min-width: 0;
    overflow-y: auto;
    border-inline-end: 1px solid var(--line);
}

.chat-list h2 {
    margin: 0;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    font-size: 16px;
}

.chat-item {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    width: 100%;
    padding: 13px 16px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: none;
    text-align: start;
    cursor: pointer;
}

.chat-item:hover,
.chat-item.on {
    background: var(--soft);
}

.chat-item .text {
    flex: 1;
    min-width: 0;
}

.chat-item .name {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

.chat-item time {
    flex: none;
    font-size: 12px;
    font-weight: 400;
    color: var(--muted);
}

.chat-item .about,
.chat-item .last {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-item .about {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}

.chat-item .last {
    font-size: 13px;
    color: var(--muted);
}

.chat-item .last.unread {
    color: var(--fg);
    font-weight: 700;
}


/* Open conversation */

.thread {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.thread-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 11px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.thread-head .who {
    flex: 1;
    min-width: 0;
}

.thread-head .who b {
    display: block;
}

.thread-head .who span {
    font-size: 12.5px;
    color: var(--muted);
}

.back {
    display: none;
    padding: 0 6px 0 0;
    border: 0;
    background: none;
    font-size: 20px;
    cursor: pointer;
}

.thread-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 18px;
    overflow-y: auto;
    background: var(--bg);
}

.bubble {
    max-width: 72%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14.5px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.bubble time {
    display: block;
    margin-top: 3px;
    font-size: 10.5px;
    opacity: 0.65;
}

.bubble.me {
    align-self: flex-end;
    border-end-end-radius: 4px;
    background: var(--accent);
    color: var(--accent-ink);
}

.bubble.them {
    align-self: flex-start;
    border: 1px solid var(--line);
    border-end-start-radius: 4px;
    background: var(--surface);
}

.thread-form {
    display: flex;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid var(--line);
}

.thread-form input {
    flex: 1;
}

.placeholder {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 24px;
    color: var(--muted);
    text-align: center;
}


/* Signed-out screen */

.gate {
    max-width: 560px;
    margin: 40px auto;
    padding: 40px 28px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    text-align: center;
}

.gate h2 {
    margin: 12px 0 8px;
    font-size: 22px;
}

.gate p {
    margin: 0 0 20px;
    color: var(--muted);
}


/* Phones: show either the list or the open chat */

@media (max-width: 760px) {
    .chat {
        grid-template-columns: 1fr;
        height: calc(100vh - 190px);
    }

    .chat.has-thread .chat-list {
        display: none;
    }

    .chat:not(.has-thread) .thread {
        display: none;
    }

    .back {
        display: block;
    }

    .bubble {
        max-width: 86%;
    }
}
