.chat-page {
    display: grid;
    grid-template-columns: minmax(240px, 320px) 1fr;
    gap: 1rem;
    min-height: 70vh;
}

.chat-sidebar,
.chat-thread {
    background: color-mix(in srgb, var(--gray-50) 90%, white);
    border: 1px solid color-mix(in srgb, var(--gray-300) 70%, transparent);
    border-radius: 0.75rem;
    overflow: hidden;
}

.dark .chat-sidebar,
.dark .chat-thread {
    background: color-mix(in srgb, var(--gray-900) 80%, black);
    border-color: color-mix(in srgb, var(--gray-700) 80%, transparent);
}

.chat-sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid color-mix(in srgb, var(--gray-300) 70%, transparent);
}

.chat-sidebar-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.chat-history-hint {
    margin: 0;
    font-size: 0.75rem;
    color: color-mix(in srgb, var(--gray-500) 90%, transparent);
}

.chat-conversation-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem;
    max-height: calc(70vh - 5rem);
    overflow-y: auto;
}

.chat-conversation-item {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    border-radius: 0.5rem;
    padding: 0.75rem;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-conversation-item:hover,
.chat-conversation-item.is-active {
    background: color-mix(in srgb, var(--primary-500) 12%, transparent);
}

.chat-conversation-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.chat-conversation-preview {
    color: var(--gray-500);
    font-size: 0.8rem;
}

.chat-unread-badge {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    min-width: 1.25rem;
    height: 1.25rem;
    border-radius: 999px;
    background: var(--primary-600);
    color: white;
    font-size: 0.7rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.35rem;
}

.chat-thread {
    display: flex;
    flex-direction: column;
    min-height: 70vh;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-bubble {
    max-width: min(80%, 36rem);
    padding: 0.75rem 0.9rem;
    border-radius: 0.75rem;
    background: color-mix(in srgb, var(--gray-200) 80%, white);
    align-self: flex-start;
}

.chat-bubble.is-mine {
    align-self: flex-end;
    background: color-mix(in srgb, var(--primary-500) 18%, white);
}

.dark .chat-bubble {
    background: color-mix(in srgb, var(--gray-700) 70%, black);
}

.dark .chat-bubble.is-mine {
    background: color-mix(in srgb, var(--primary-500) 30%, black);
}

.chat-bubble-meta {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.35rem;
    font-size: 0.75rem;
    opacity: 0.8;
}

.chat-bubble p {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-composer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid color-mix(in srgb, var(--gray-300) 70%, transparent);
}

.chat-empty,
.chat-empty-thread {
    padding: 1.25rem;
    color: var(--gray-500);
    font-size: 0.9rem;
}

@media (max-width: 900px) {
    .chat-page {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        max-height: 40vh;
    }
}
