:root {
    --ink: #1d1914;
    --muted: #6d645b;
    --paper: #f3eee6;
    --panel: #fffdf9;
    --line: #e4d9cc;
    --green: #1b5c45;
    --green-deep: #123d2e;
    --mint: #e6f3ec;
    --clay: #9c4221;
    --shadow: 0 18px 40px rgba(48, 32, 16, 0.08);
    --sans: "Source Sans 3", "Segoe UI", sans-serif;
    --serif: Newsreader, "Iowan Old Style", Palatino, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--sans);
    color: var(--ink);
    background:
        radial-gradient(1200px 400px at 10% -10%, #efe4d2 0%, transparent 55%),
        var(--paper);
}
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 18px 22px 8px;
}
.top-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.whoami { color: var(--muted); font-size: 0.92rem; }
.ghost, #logout-form button.ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--green-deep);
    text-decoration: none;
    cursor: pointer;
}
.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    text-decoration: none;
}
.brand strong {
    display: block;
    font-family: var(--serif);
    font-size: 1.7rem;
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1;
}
.brand small { color: var(--muted); }
.mark {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--green-deep);
    color: #f6f1e7;
    font-family: var(--serif);
    font-weight: 650;
}
#sync-form button, .composer button {
    background: var(--green);
    color: #f7fbf8;
    border: 0;
    border-radius: 999px;
    min-height: 44px;
    padding: 0 18px;
    cursor: pointer;
}
#sync-form button[disabled], .composer button[disabled] { opacity: 0.7; cursor: progress; }
button:focus-visible, a:focus-visible, textarea:focus-visible {
    outline: 3px solid #d8a15a;
    outline-offset: 2px;
}

.banner {
    margin: 8px 22px 0;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fde8df;
    color: #6d2712;
}
.banner.ok { background: var(--mint); color: var(--green-deep); }

.shell {
    display: grid;
    grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
    gap: 16px;
    padding: 16px 22px 12px;
    min-height: calc(100vh - 150px);
}
.list-pane, .thread-pane {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    min-height: 540px;
}
.list-pane { overflow: hidden; display: flex; flex-direction: column; }
.filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}
.chip {
    flex: 0 0 auto;
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 12px;
    background: #fff;
    line-height: 1.15;
}
.chip span { display: block; color: var(--muted); font-size: 0.82rem; }
.chip.is-on { background: var(--green-deep); color: #f6f1e7; border-color: var(--green-deep); }
.chip.is-on span { color: #d5e7dc; }
.conv-list { list-style: none; margin: 0; padding: 6px; overflow: auto; }
.conv {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    padding: 12px;
    border-radius: 16px;
    text-decoration: none;
}
.conv.is-current, .conv:hover { background: #f7f1e7; }
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--mint);
    color: var(--green-deep);
    font-weight: 600;
}
.conv-top, .conv-channel, .conv-preview { display: flex; }
.conv-top { justify-content: space-between; gap: 8px; font-weight: 600; }
.conv-top time, .conv-channel, .conv-preview { color: var(--muted); font-weight: 400; font-size: 0.92rem; }
.conv-copy { min-width: 0; display: grid; gap: 2px; }
.conv-preview {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.unread {
    width: 9px;
    height: 9px;
    margin-top: 8px;
    border-radius: 50%;
    background: var(--clay);
}
.empty-list, .thread-placeholder {
    padding: 28px 22px;
}
.empty-list h2, .thread-placeholder h2, .thread-head h2 {
    font-family: var(--serif);
    font-weight: 650;
    letter-spacing: -0.03em;
    margin: 0 0 8px;
}
.empty-list p, .thread-placeholder p { color: var(--muted); margin: 0 0 10px; }

.thread-pane { display: flex; flex-direction: column; min-width: 0; }
.thread-head {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.thread-head p { margin: 0; color: var(--muted); }
.back-link { color: var(--green); font-weight: 600; text-decoration: none; }
.channel-pill {
    text-align: right;
    background: var(--mint);
    color: var(--green-deep);
    border-radius: 14px;
    padding: 8px 10px;
    font-size: 0.92rem;
}
.channel-pill span { display: block; color: var(--muted); }
.thread-stream { flex: 1; overflow: auto; padding: 16px; background: linear-gradient(#fbf8f3, #f7f3ec); }
.state-loading, .state-empty { color: var(--muted); margin: 0 0 12px; }
.state-loading { display: none; }
body.is-loading .state-loading { display: block; }
body.is-loading .bubbles { opacity: 0.35; }
.bubbles { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.bubble {
    max-width: min(68ch, 85%);
    padding: 10px 12px;
    border-radius: 16px;
    background: white;
    border: 1px solid var(--line);
}
.bubble.out { margin-left: auto; background: var(--mint); border-color: #cfe3d6; }
.bubble .who { display: block; font-size: 0.78rem; color: var(--muted); }
.bubble p { margin: 4px 0; white-space: pre-wrap; }
.bubble time { color: var(--muted); font-size: 0.78rem; }
.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--line);
}
.composer textarea {
    resize: vertical;
    min-height: 52px;
    border-radius: 14px;
    border: 1px solid var(--line);
    padding: 10px 12px;
    background: #fff;
}
.composer-error, .sig-hint { grid-column: 1 / -1; margin: 0; }
.composer-error { color: var(--clay); }
.sig-hint { color: var(--muted); font-size: 0.88rem; }
.foot {
    padding: 4px 22px 18px;
    color: var(--muted);
    font-size: 0.88rem;
}
.foot p { margin: 2px 0; }

@media (max-width: 800px) {
    .topbar, .shell, .banner, .foot { padding-left: 12px; padding-right: 12px; }
    .shell { grid-template-columns: 1fr; min-height: auto; }
    .list-pane, .thread-pane { min-height: calc(100vh - 180px); }
    body.list-open .thread-pane { display: none; }
    body.thread-open .list-pane { display: none; }
    .thread-head { grid-template-columns: auto 1fr; }
    .channel-pill { grid-column: 1 / -1; text-align: left; }
    .bubble { max-width: 92%; }
    .back-link { display: inline-flex; min-height: 44px; align-items: center; }
}
@media (min-width: 801px) {
    .thread-head .back-link, .thread-placeholder .back-link { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto; transition: none !important; }
}

.setup-body { background: var(--paper); }
.setup {
    width: min(640px, calc(100% - 28px));
    margin: 28px auto 48px;
}
.setup h1, .setup h2 {
    font-family: var(--serif);
    font-weight: 650;
    letter-spacing: -0.03em;
    margin: 0 0 8px;
}
.setup .lede, .setup .hint { color: var(--muted); }
.setup-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 16px;
    margin: 14px 0;
    box-shadow: var(--shadow);
}
.setup label { display: grid; gap: 6px; margin: 10px 0; font-weight: 600; }
.setup input, .setup textarea, .setup select {
    font: inherit;
    font-weight: 400;
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px 12px;
    background: #fff;
}
.setup textarea { min-height: 88px; resize: vertical; }
.setup-actions { margin: 12px 0 20px; }
.setup .banner { margin: 12px 0; }
.setup button.danger {
    background: transparent;
    color: var(--clay);
    border: 1px solid var(--line);
}
.setup form + form { margin-top: 8px; }
.setup button, .setup-go {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin-top: 8px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: var(--green);
    color: #f7fbf8;
    text-decoration: none;
    cursor: pointer;
}
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 6px 0; }
.checks .ok { color: var(--green-deep); }
.checks .bad { color: var(--clay); }
.webhook-url {
    font-family: var(--serif);
    font-size: 1.25rem;
    background: var(--mint);
    border-radius: 12px;
    padding: 12px;
    word-break: break-all;
}
