.chat {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    max-width: 22rem;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0.5rem 0.75rem;
}

.chat-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
}

.chat-indicator[data-connected="true"] {
    background: #479f61;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-wrap: anywhere;
    scrollbar-gutter: stable;
    /* extend to the box edge so the scrollbar sits on the border, not over messages. */
    margin-right: -0.75rem;
    padding-right: 0.75rem;
    padding-bottom: 0.75rem;
}

.chat-empty {
    color: #777;
}

.chat-message {
    box-sizing: border-box;
    width: fit-content;
    max-width: 94%;
    margin-bottom: 0.5rem;
    border: 1px solid #e5e5e5;
    border-radius: 2px;
    padding: 0.25rem 0.5rem;
    background: #f7f7f7;
    line-height: 1.4;
}

.chat-message:last-child {
    margin-bottom: 0;
}

.chat-message-own {
    margin-left: auto;
    border-color: #dfe3ef;
    background: #f3f5fb;
}

.chat-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    column-gap: 0.5rem;
    margin-bottom: 3px;
    font-size: 11px;
}

.chat-author {
    font-weight: 600;
    color: var(--user-color);
}

.chat-message time {
    font-size: 8px;
    color: #666;
    white-space: nowrap;
}

.chat-text {
    white-space: pre-wrap;
}

.chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 0.5rem;
    flex-shrink: 0;
    margin-top: 0.5rem;
}

.chat-form textarea {
    box-sizing: border-box;
    width: 100%;
    field-sizing: content;
    min-height: 2rem;
    max-height: 6rem;
    resize: none;
    padding: 0.375rem 0.5rem;
    font: inherit;
}

.chat-form button {
    align-self: stretch;
    border: 1px solid #999;
    border-radius: 0;
    padding: 0.25rem 0.8rem;
    background: #fff;
    color: #333;
    cursor: pointer;
}

.chat-form button:enabled:hover {
    background: #f3f5fb;
    border-color: #5264a6;
}

.chat-form button:focus-visible {
    outline: 2px solid #5264a6;
    outline-offset: 2px;
}

.chat-form button:disabled {
    color: #777;
    cursor: wait;
}

.chat-status {
    grid-column: 1 / -1;
    flex-shrink: 0;
    color: #c00;
}

.chat-status:empty {
    display: none;
}
