:root {
    color-scheme: light dark;
    --bg: #0f1419;
    --panel: #1a2332;
    --text: #e7ecf3;
    --muted: #9aa7b2;
    --accent: #3b82f6;
    --danger: #f87171;
    --in: #22c55e;
    --out: #a78bfa;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f6f8;
        --panel: #ffffff;
        --text: #111827;
        --muted: #6b7280;
    }
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--panel);
    border-bottom: 1px solid rgba(125, 145, 165, 0.25);
}

.topbar h1 {
    margin: 0.25rem 0 0;
    font-size: 1.25rem;
}

.filters {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.filters a {
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
}

.filters a.active {
    background: rgba(59, 130, 246, 0.2);
}

.logout {
    margin-left: 0.5rem;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
}

.centered {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.card {
    background: var(--panel);
    border: 1px solid rgba(125, 145, 165, 0.25);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 420px;
    width: 100%;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

input, textarea, button {
    font: inherit;
}

input, textarea {
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    border: 1px solid rgba(125, 145, 165, 0.35);
    background: var(--bg);
    color: var(--text);
}

button {
    padding: 0.55rem 1rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}

button:hover {
    filter: brightness(1.05);
}

.muted {
    color: var(--muted);
    font-size: 0.9rem;
}

.error {
    color: var(--danger);
}

.banner {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
}

.threads {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(125, 145, 165, 0.25);
}

.threads th, .threads td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid rgba(125, 145, 165, 0.15);
}

.threads th {
    font-size: 0.85rem;
    color: var(--muted);
}

.snippet {
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pill {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    text-transform: capitalize;
}

.pill-messenger {
    background: rgba(34, 197, 94, 0.2);
}

.pill-comment {
    background: rgba(167, 139, 250, 0.25);
}

.badge {
    display: inline-block;
    min-width: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.75rem;
    text-align: center;
}

.back {
    display: inline-block;
    margin-bottom: 0.35rem;
}

.timeline {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.msg {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: 1px solid rgba(125, 145, 165, 0.2);
    background: var(--panel);
}

.msg-in {
    border-left: 3px solid var(--in);
}

.msg-out {
    border-left: 3px solid var(--out);
}

.msg .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.composer h2 {
    margin-top: 0;
    font-size: 1rem;
}

.messenger-layout {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 1rem;
    min-height: calc(100vh - 84px);
}

.thread-list-panel,
.thread-placeholder {
    background: var(--panel);
    border: 1px solid rgba(125, 145, 165, 0.25);
    border-radius: 12px;
}

.thread-list-head {
    padding: 0.9rem 1rem 0.6rem;
    border-bottom: 1px solid rgba(125, 145, 165, 0.18);
}

.thread-list-head h2 {
    margin: 0 0 0.2rem;
    font-size: 1.05rem;
}

.thread-list {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
}

.thread-item {
    display: block;
    border: 1px solid rgba(125, 145, 165, 0.2);
    border-radius: 10px;
    padding: 0.65rem;
    background: rgba(125, 145, 165, 0.07);
}

.thread-item:hover {
    background: rgba(59, 130, 246, 0.12);
    text-decoration: none;
}

.thread-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.thread-item h3 {
    margin: 0.55rem 0 0.35rem;
    font-size: 0.98rem;
    color: var(--text);
}

.thread-item-snippet {
    margin: 0;
}

.thread-placeholder {
    display: grid;
    place-content: center;
    text-align: center;
    padding: 1rem;
}

.chat-shell {
    max-width: 980px;
}

.timeline {
    max-height: calc(100vh - 350px);
    overflow-y: auto;
    padding-right: 0.35rem;
}

.msg {
    max-width: 78%;
}

.msg-in {
    margin-right: auto;
}

.msg-out {
    margin-left: auto;
    background: rgba(59, 130, 246, 0.16);
}

.error-banner {
    background: rgba(248, 113, 113, 0.2);
    border-color: rgba(248, 113, 113, 0.45);
}

@media (max-width: 900px) {
    .messenger-layout {
        grid-template-columns: 1fr;
    }

    .thread-list {
        max-height: none;
    }

    .timeline {
        max-height: calc(100vh - 380px);
    }
}
