{
  "id": 148,
  "slug": "threaded-split-discussion",
  "name": "Threaded Split-View Discussion Reader",
  "kind": "ui",
  "family": "Communication & Triage",
  "sourceSite": {
    "name": "Zulip",
    "url": "https://zulip.com/",
    "verifiedStatus": 200
  },
  "tagline": "Topic-threaded team discussion workspace with unread stream badges, live reply composer, emoji reactions, and mobile drill-down.",
  "whyUnique": "Organizes high-volume team chat into discrete named topics rather than chaotic chronological streams, letting readers resolve, bookmark, and reply in parallel while drilling down cleanly on phones.",
  "theme": "light",
  "mobileStrength": "native-first",
  "tags": [
    "threaded-chat",
    "split-view",
    "discussions",
    "team-communication",
    "reactions",
    "topic-streams"
  ],
  "bestFor": [
    "Async engineering and open-source team chat",
    "Community forums and Q&A workspaces",
    "Customer support and incident rooms",
    "Course and cohort discussion boards"
  ],
  "palette": [
    {
      "role": "canvas",
      "hex": "#F7F6F2",
      "name": "Sandstone Mist"
    },
    {
      "role": "surface",
      "hex": "#FFFFFF",
      "name": "Thread White"
    },
    {
      "role": "ink",
      "hex": "#1A1E2C",
      "name": "Deep Indigo Ink"
    },
    {
      "role": "accent",
      "hex": "#4338CA",
      "name": "Zulip Indigo"
    },
    {
      "role": "muted",
      "hex": "#646B7D",
      "name": "Stream Gray"
    }
  ],
  "typography": {
    "display": "Inter",
    "body": "Inter",
    "mono": "JetBrains Mono",
    "googleFontsUrl": "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap",
    "scaleNotes": "17px topic header, 14.5px/1.6 message prose, 12px stream tag pills, 11px mono unread counters."
  },
  "layoutNotes": "320px topic/stream list on the left + fluid threaded conversation view with sticky reply composer on the right; single-pane drill-down with Back button below 820px.",
  "interactionNotes": "Filter by stream, click any topic to clear its unread badge, toggle emoji reactions, mark a topic Resolved or Bookmarked, and post live replies into the thread.",
  "mobileNotes": "Promotes the topic feed and active thread into full-screen views on 390px with a clear '← Topics' header button and a thumb-friendly bottom reply bar.",
  "agentGuardrails": {
    "do": [
      "Always display the stream/channel badge alongside each topic title for instant context.",
      "Allow one-tap reaction toggling and explicit Resolved status toggling on threads.",
      "Use full-screen list-to-thread drill-down on viewports under 820px."
    ],
    "dont": [
      "Never bury the reply composer inside a secondary modal when reading a thread.",
      "Avoid mixing unrelated topics into a single unthreaded firehose."
    ]
  },
  "demoFile": "demos/threaded-split-discussion.html",
  "thumbDesktop": "thumbs/threaded-split-discussion-desktop.webp",
  "thumbMobile": "thumbs/threaded-split-discussion-mobile.webp",
  "urls": {
    "page": "https://templates.michaelpitts.net/t/threaded-split-discussion",
    "markdown": "https://templates.michaelpitts.net/t/threaded-split-discussion.md",
    "api": "https://templates.michaelpitts.net/api/templates/threaded-split-discussion",
    "demo": "https://templates.michaelpitts.net/demos/threaded-split-discussion.html",
    "thumbDesktop": "https://templates.michaelpitts.net/thumbs/threaded-split-discussion-desktop.webp",
    "thumbMobile": "https://templates.michaelpitts.net/thumbs/threaded-split-discussion-mobile.webp"
  },
  "agentPrompt": "Design & build using template #148 \"Threaded Split-View Discussion Reader\" (ui / Communication & Triage, light theme).\nFull AI blueprint & standalone starter code: https://templates.michaelpitts.net/t/threaded-split-discussion.md\nLive demo: https://templates.michaelpitts.net/demos/threaded-split-discussion.html\nReal-world inspiration: Zulip (https://zulip.com/)\n\nCore aesthetic: Organizes high-volume team chat into discrete named topics rather than chaotic chronological streams, letting readers resolve, bookmark, and reply in parallel while drilling down cleanly on phones.\nPalette: canvas: #F7F6F2 (Sandstone Mist), surface: #FFFFFF (Thread White), ink: #1A1E2C (Deep Indigo Ink), accent: #4338CA (Zulip Indigo), muted: #646B7D (Stream Gray)\nTypography: Display=\"Inter\", Body=\"Inter\", Mono=\"JetBrains Mono\"\nLayout: 320px topic/stream list on the left + fluid threaded conversation view with sticky reply composer on the right; single-pane drill-down with Back button below 820px.\nInteractions: Filter by stream, click any topic to clear its unread badge, toggle emoji reactions, mark a topic Resolved or Bookmarked, and post live replies into the thread.\nMobile: Promotes the topic feed and active thread into full-screen views on 390px with a clear '← Topics' header button and a thumb-friendly bottom reply bar.\n\nGuardrails:\n- DO: Always display the stream/channel badge alongside each topic title for instant context.\n- DO: Allow one-tap reaction toggling and explicit Resolved status toggling on threads.\n- DO: Use full-screen list-to-thread drill-down on viewports under 820px.\n- DON'T: Never bury the reply composer inside a secondary modal when reading a thread.\n- DON'T: Avoid mixing unrelated topics into a single unthreaded firehose.",
  "sourceCode": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Strata Forum — Threaded Split-View Discussion</title>\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n<link href=\"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap\" rel=\"stylesheet\">\n<style>\n  :root {\n    --bg: #F6F3EC;\n    --surface: #FFFFFF;\n    --sand: #EFEAE0;\n    --indigo: #3730A3;\n    --indigo-soft: #EEF2FF;\n    --indigo-mid: #4F46E5;\n    --ink: #1C1B22;\n    --muted: #656372;\n    --border: rgba(28, 27, 34, 0.11);\n    --green: #0F766E;\n    --green-soft: #CCFBF1;\n    --amber: #B45309;\n    --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;\n  }\n\n  * { box-sizing: border-box; margin: 0; padding: 0; }\n\n  html, body {\n    height: 100%;\n    background: var(--bg);\n    color: var(--ink);\n    font-family: var(--sans);\n    -webkit-font-smoothing: antialiased;\n    overflow: hidden;\n  }\n\n  .shell {\n    display: grid;\n    grid-template-rows: 56px 1fr;\n    height: 100vh;\n    width: 100vw;\n    overflow: hidden;\n  }\n\n  .header {\n    background: var(--surface);\n    border-bottom: 1px solid var(--border);\n    padding: 0 18px;\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 12px;\n  }\n\n  .brand {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n  }\n\n  .brand-icon {\n    width: 30px;\n    height: 30px;\n    border-radius: 8px;\n    background: var(--indigo);\n    color: #fff;\n    display: grid;\n    place-items: center;\n    font-weight: 700;\n    font-size: 0.85rem;\n  }\n\n  .brand h1 {\n    font-size: 1rem;\n    font-weight: 700;\n    letter-spacing: -0.01em;\n  }\n\n  .stream-tabs {\n    display: flex;\n    align-items: center;\n    gap: 6px;\n    overflow-x: auto;\n    scrollbar-width: none;\n  }\n  .stream-tabs::-webkit-scrollbar { display: none; }\n\n  .stream-chip {\n    min-height: 38px;\n    padding: 0 12px;\n    border-radius: 999px;\n    border: 1px solid var(--border);\n    background: var(--bg);\n    color: var(--muted);\n    font-family: inherit;\n    font-size: 0.8rem;\n    font-weight: 500;\n    cursor: pointer;\n    white-space: nowrap;\n    transition: all 0.14s ease;\n  }\n\n  .stream-chip.active {\n    background: var(--indigo);\n    color: #fff;\n    border-color: var(--indigo);\n  }\n\n  /* Split Pane */\n  .split {\n    display: grid;\n    grid-template-columns: 356px 1fr;\n    min-height: 0;\n    overflow: hidden;\n  }\n\n  /* Left Feed */\n  .feed-pane {\n    background: var(--bg);\n    border-right: 1px solid var(--border);\n    display: flex;\n    flex-direction: column;\n    min-height: 0;\n  }\n\n  .feed-subhead {\n    padding: 12px 14px;\n    border-bottom: 1px solid var(--border);\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    font-size: 0.78rem;\n    color: var(--muted);\n  }\n\n  .feed-list {\n    flex: 1;\n    overflow-y: auto;\n    padding: 8px;\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n  }\n\n  .topic-item {\n    width: 100%;\n    text-align: left;\n    background: var(--surface);\n    border: 1px solid var(--border);\n    border-radius: 10px;\n    padding: 12px 13px;\n    cursor: pointer;\n    font-family: inherit;\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n    transition: border-color 0.14s ease, background 0.14s ease;\n  }\n\n  .topic-item:hover { border-color: rgba(79, 70, 229, 0.35); }\n  .topic-item.active {\n    background: var(--indigo-soft);\n    border-color: var(--indigo-mid);\n  }\n\n  .topic-top {\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 8px;\n  }\n\n  .stream-pill {\n    font-size: 0.7rem;\n    font-weight: 600;\n    color: var(--indigo);\n    background: rgba(79, 70, 229, 0.1);\n    padding: 2px 7px;\n    border-radius: 5px;\n  }\n\n  .topic-badges {\n    display: flex;\n    align-items: center;\n    gap: 6px;\n  }\n\n  .unread-dot {\n    min-width: 22px;\n    height: 20px;\n    padding: 0 6px;\n    border-radius: 999px;\n    background: var(--indigo-mid);\n    color: #fff;\n    font-size: 0.7rem;\n    font-weight: 700;\n    display: grid;\n    place-items: center;\n  }\n\n  .resolved-tag {\n    font-size: 0.68rem;\n    font-weight: 600;\n    color: var(--green);\n    background: var(--green-soft);\n    padding: 2px 6px;\n    border-radius: 4px;\n  }\n\n  .topic-title {\n    font-size: 0.9rem;\n    font-weight: 600;\n    color: var(--ink);\n    line-height: 1.3;\n  }\n\n  .topic-meta {\n    display: flex;\n    justify-content: space-between;\n    font-size: 0.75rem;\n    color: var(--muted);\n  }\n\n  /* Right Thread Pane */\n  .thread-pane {\n    background: var(--surface);\n    display: flex;\n    flex-direction: column;\n    min-height: 0;\n  }\n\n  .thread-head {\n    padding: 12px 20px;\n    border-bottom: 1px solid var(--border);\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 12px;\n    background: #FDFCFA;\n  }\n\n  .thread-head-left {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    min-width: 0;\n  }\n\n  .back-btn {\n    display: none;\n    min-width: 44px;\n    min-height: 44px;\n    border-radius: 8px;\n    border: 1px solid var(--border);\n    background: var(--surface);\n    color: var(--ink);\n    place-items: center;\n    cursor: pointer;\n  }\n\n  .thread-title-wrap {\n    min-width: 0;\n  }\n\n  .thread-title-wrap h2 {\n    font-size: 1.02rem;\n    font-weight: 700;\n    white-space: nowrap;\n    overflow: hidden;\n    text-overflow: ellipsis;\n  }\n\n  .thread-title-wrap p {\n    font-size: 0.76rem;\n    color: var(--muted);\n  }\n\n  .thread-actions {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    flex-shrink: 0;\n  }\n\n  .action-btn {\n    min-height: 40px;\n    padding: 0 12px;\n    border-radius: 8px;\n    border: 1px solid var(--border);\n    background: var(--surface);\n    color: var(--ink);\n    font-family: inherit;\n    font-size: 0.78rem;\n    font-weight: 600;\n    display: inline-flex;\n    align-items: center;\n    gap: 6px;\n    cursor: pointer;\n    transition: all 0.14s ease;\n  }\n\n  .action-btn:hover { background: var(--bg); }\n  .action-btn.resolved {\n    background: var(--green-soft);\n    border-color: var(--green);\n    color: var(--green);\n  }\n  .action-btn.bookmarked {\n    background: #FEF3C7;\n    border-color: var(--amber);\n    color: var(--amber);\n  }\n\n  .messages {\n    flex: 1;\n    overflow-y: auto;\n    padding: 18px 22px;\n    display: flex;\n    flex-direction: column;\n    gap: 16px;\n  }\n\n  .msg {\n    display: grid;\n    grid-template-columns: 36px 1fr;\n    gap: 12px;\n    align-items: start;\n  }\n\n  .avatar {\n    width: 36px;\n    height: 36px;\n    border-radius: 10px;\n    display: grid;\n    place-items: center;\n    font-size: 0.78rem;\n    font-weight: 700;\n    color: #fff;\n  }\n\n  .msg-body {\n    min-width: 0;\n  }\n\n  .msg-head {\n    display: flex;\n    align-items: baseline;\n    gap: 8px;\n    margin-bottom: 4px;\n    flex-wrap: wrap;\n  }\n\n  .msg-author { font-weight: 600; font-size: 0.88rem; }\n  .msg-role { font-size: 0.72rem; color: var(--muted); }\n  .msg-time { font-size: 0.72rem; color: var(--muted); margin-left: auto; }\n\n  .msg-text {\n    font-size: 0.9rem;\n    line-height: 1.56;\n    color: #292732;\n    margin-bottom: 8px;\n    white-space: pre-wrap;\n  }\n\n  .reactions {\n    display: flex;\n    align-items: center;\n    gap: 6px;\n    flex-wrap: wrap;\n  }\n\n  .react-btn {\n    min-height: 32px;\n    padding: 0 9px;\n    border-radius: 999px;\n    border: 1px solid var(--border);\n    background: var(--bg);\n    font-family: inherit;\n    font-size: 0.78rem;\n    color: var(--ink);\n    display: inline-flex;\n    align-items: center;\n    gap: 5px;\n    cursor: pointer;\n    transition: all 0.12s ease;\n  }\n\n  .react-btn:hover { border-color: var(--indigo-mid); }\n  .react-btn.reacted {\n    background: var(--indigo-soft);\n    border-color: var(--indigo-mid);\n    color: var(--indigo);\n    font-weight: 600;\n  }\n\n  /* Composer */\n  .composer {\n    border-top: 1px solid var(--border);\n    padding: 12px 20px 14px;\n    background: #FDFCFA;\n    display: flex;\n    gap: 10px;\n    align-items: flex-end;\n  }\n\n  .composer textarea {\n    flex: 1;\n    min-height: 44px;\n    max-height: 120px;\n    resize: vertical;\n    border: 1px solid var(--border);\n    border-radius: 10px;\n    padding: 10px 12px;\n    font-family: inherit;\n    font-size: 0.88rem;\n    background: var(--surface);\n    color: var(--ink);\n    outline: none;\n  }\n\n  .composer textarea:focus {\n    border-color: var(--indigo-mid);\n    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.14);\n  }\n\n  .send-btn {\n    min-height: 44px;\n    padding: 0 18px;\n    border-radius: 10px;\n    border: none;\n    background: var(--indigo);\n    color: #fff;\n    font-family: inherit;\n    font-size: 0.84rem;\n    font-weight: 600;\n    cursor: pointer;\n    flex-shrink: 0;\n  }\n\n  .send-btn:hover { background: var(--indigo-mid); }\n\n  @media (max-width: 820px) {\n    .header { padding: 0 12px; }\n    .brand h1 { font-size: 0.92rem; }\n    .split { grid-template-columns: 1fr; }\n    .split.mobile-thread .feed-pane { display: none; }\n    .split:not(.mobile-thread) .thread-pane { display: none; }\n    .back-btn { display: grid; }\n    .thread-head { padding: 10px 12px; }\n    .action-btn span { display: none; }\n    .action-btn { min-width: 44px; min-height: 44px; justify-content: center; padding: 0; }\n    .messages { padding: 14px 14px; }\n    .composer { padding: 10px 12px; }\n  }\n</style>\n</head>\n<body>\n<div class=\"shell\">\n  <header class=\"header\">\n    <div class=\"brand\">\n      <div class=\"brand-icon\">S</div>\n      <h1>Strata Discussions</h1>\n    </div>\n    <nav class=\"stream-tabs\" id=\"streamTabs\" aria-label=\"Filter by stream\"></nav>\n  </header>\n\n  <div class=\"split\" id=\"splitView\">\n    <aside class=\"feed-pane\" aria-label=\"Topic feed\">\n      <div class=\"feed-subhead\">\n        <span id=\"feedSummary\">5 active topics</span>\n        <span id=\"unreadTotal\">4 unread</span>\n      </div>\n      <div class=\"feed-list\" id=\"feedList\"></div>\n    </aside>\n\n    <main class=\"thread-pane\" aria-label=\"Selected discussion thread\">\n      <div class=\"thread-head\">\n        <div class=\"thread-head-left\">\n          <button class=\"back-btn\" id=\"backBtn\" type=\"button\" aria-label=\"Back to topics\">\n            <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M15 18l-6-6 6-6\"/></svg>\n          </button>\n          <div class=\"thread-title-wrap\">\n            <h2 id=\"threadTitle\">Topic</h2>\n            <p id=\"threadSub\">#stream &middot; 3 replies</p>\n          </div>\n        </div>\n        <div class=\"thread-actions\">\n          <button class=\"action-btn\" id=\"bookmarkBtn\" type=\"button\" aria-label=\"Bookmark topic\">\n            <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z\"/></svg>\n            <span id=\"bookmarkLabel\">Bookmark</span>\n          </button>\n          <button class=\"action-btn\" id=\"resolveBtn\" type=\"button\" aria-label=\"Resolve topic\">\n            <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M20 6L9 17l-5-5\"/></svg>\n            <span id=\"resolveLabel\">Resolve</span>\n          </button>\n        </div>\n      </div>\n\n      <div class=\"messages\" id=\"messagesList\" aria-live=\"polite\"></div>\n\n      <form class=\"composer\" id=\"replyForm\">\n        <textarea id=\"replyInput\" rows=\"1\" placeholder=\"Reply to this topic...\" aria-label=\"Write a reply\"></textarea>\n        <button class=\"send-btn\" type=\"submit\">Reply</button>\n      </form>\n    </main>\n  </div>\n</div>\n\n<script>\nconst TOPICS = [\n  {\n    id: 't1',\n    stream: 'engineering',\n    title: 'Zero-downtime Postgres 17 logical replication cutover',\n    unread: 2,\n    resolved: false,\n    bookmarked: true,\n    updated: '14m ago',\n    messages: [\n      {\n        id: 'm1', author: 'Maya Patel', initials: 'MP', color: '#4F46E5', role: 'Staff Infra', time: '09:12',\n        text: 'Dry run on staging completed with 140ms max replication lag. I propose we schedule the production cutover for Tuesday 06:00 UTC with a 15-minute write-freeze fallback.',\n        reactions: [{ emoji: '🚀', count: 4, reacted: true }, { emoji: '👀', count: 2, reacted: false }]\n      },\n      {\n        id: 'm2', author: 'Devon Brooks', initials: 'DB', color: '#0F766E', role: 'Backend Lead', time: '09:28',\n        text: 'Confirmed that pgbouncer connection draining handles the pause cleanly. One note: let us verify sequence sync on `invoice_ledger_id_seq` right before reopening writes.',\n        reactions: [{ emoji: '✅', count: 3, reacted: false }]\n      },\n      {\n        id: 'm3', author: 'Maya Patel', initials: 'MP', color: '#4F46E5', role: 'Staff Infra', time: '09:41',\n        text: 'Good catch — added `sync_sequences.sql` to step 4 of the runbook and verified it takes <80ms.',\n        reactions: [{ emoji: '🔥', count: 2, reacted: false }]\n      }\n    ]\n  },\n  {\n    id: 't2',\n    stream: 'design',\n    title: 'Tokenizing warm-sandstone surfaces for dark/light parity',\n    unread: 1,\n    resolved: false,\n    bookmarked: false,\n    updated: '42m ago',\n    messages: [\n      {\n        id: 'm4', author: 'Sora Kim', initials: 'SK', color: '#B45309', role: 'Design Systems', time: '08:50',\n        text: 'We reduced the neutral palette from 14 grays to 6 semantic surface roles (`canvas`, `elevated`, `sunken`, `hairline`). Contrast ratio on secondary captions now passes 5.2:1.',\n        reactions: [{ emoji: '✨', count: 5, reacted: true }]\n      },\n      {\n        id: 'm5', author: 'Liam Chen', initials: 'LC', color: '#7C3AED', role: 'Frontend Eng', time: '09:15',\n        text: 'Love the consolidation. Are we keeping `--border-strong` for keyboard focus rings or moving entirely to the indigo outline?',\n        reactions: [{ emoji: '👍', count: 2, reacted: false }]\n      }\n    ]\n  },\n  {\n    id: 't3',\n    stream: 'product',\n    title: 'Q3 self-serve annual billing proration edge cases',\n    unread: 1,\n    resolved: false,\n    bookmarked: false,\n    updated: '2h ago',\n    messages: [\n      {\n        id: 'm6', author: 'Nadia Okafor', initials: 'NO', color: '#BE185D', role: 'Product Mgr', time: '07:35',\n        text: 'When a workspace upgrades from Starter Monthly to Pro Annual mid-cycle, Stripe credits unused days automatically, but our in-app invoice preview was showing the full annual charge.',\n        reactions: [{ emoji: '🙏', count: 3, reacted: false }]\n      },\n      {\n        id: 'm7', author: 'Devon Brooks', initials: 'DB', color: '#0F766E', role: 'Backend Lead', time: '08:02',\n        text: 'Switching the preview modal to `invoices.retrieveUpcoming()` fixes this with exact tax + credit line items.',\n        reactions: [{ emoji: '✅', count: 4, reacted: true }]\n      }\n    ]\n  },\n  {\n    id: 't4',\n    stream: 'engineering',\n    title: 'CI build cache hit rate dropped to 61% after Node 22 bump',\n    unread: 0,\n    resolved: true,\n    bookmarked: false,\n    updated: 'Yesterday',\n    messages: [\n      {\n        id: 'm8', author: 'Liam Chen', initials: 'LC', color: '#7C3AED', role: 'Frontend Eng', time: 'Yesterday',\n        text: 'Found it: the lockfile hash key included the minor patch version of pnpm. Pinned cache key to `pnpm-lock.yaml` only — hit rate is back to 94% and median CI time dropped from 6m10s to 2m18s.',\n        reactions: [{ emoji: '🎉', count: 7, reacted: true }]\n      }\n    ]\n  },\n  {\n    id: 't5',\n    stream: 'design',\n    title: 'Mobile drill-down transitions for split-pane readers',\n    unread: 0,\n    resolved: false,\n    bookmarked: true,\n    updated: 'Yesterday',\n    messages: [\n      {\n        id: 'm9', author: 'Sora Kim', initials: 'SK', color: '#B45309', role: 'Design Systems', time: 'Yesterday',\n        text: 'On viewports <=820px, tapping a topic should drill directly into the thread with a 44px back button in the sticky header so the composer stays pinned above the keyboard.',\n        reactions: [{ emoji: '👍', count: 4, reacted: false }]\n      }\n    ]\n  }\n];\n\nconst STREAMS = ['all', 'engineering', 'design', 'product', 'bookmarked'];\nlet activeStream = 'all';\nlet activeTopicId = 't1';\n\nconst splitView = document.getElementById('splitView');\nconst streamTabs = document.getElementById('streamTabs');\nconst feedList = document.getElementById('feedList');\nconst feedSummary = document.getElementById('feedSummary');\nconst unreadTotal = document.getElementById('unreadTotal');\nconst threadTitle = document.getElementById('threadTitle');\nconst threadSub = document.getElementById('threadSub');\nconst messagesList = document.getElementById('messagesList');\nconst bookmarkBtn = document.getElementById('bookmarkBtn');\nconst bookmarkLabel = document.getElementById('bookmarkLabel');\nconst resolveBtn = document.getElementById('resolveBtn');\nconst resolveLabel = document.getElementById('resolveLabel');\nconst replyForm = document.getElementById('replyForm');\nconst replyInput = document.getElementById('replyInput');\n\nfunction getVisibleTopics() {\n  if (activeStream === 'all') return TOPICS;\n  if (activeStream === 'bookmarked') return TOPICS.filter(t => t.bookmarked);\n  return TOPICS.filter(t => t.stream === activeStream);\n}\n\nfunction getActiveTopic() {\n  return TOPICS.find(t => t.id === activeTopicId) || TOPICS[0];\n}\n\nfunction renderStreams() {\n  streamTabs.innerHTML = '';\n  STREAMS.forEach(st => {\n    const b = document.createElement('button');\n    b.type = 'button';\n    b.className = 'stream-chip' + (activeStream === st ? ' active' : '');\n    b.textContent = st === 'all' ? 'All Streams' : st === 'bookmarked' ? 'Bookmarked' : `#${st}`;\n    b.addEventListener('click', () => {\n      activeStream = st;\n      renderStreams();\n      renderFeed();\n    });\n    streamTabs.appendChild(b);\n  });\n}\n\nfunction renderFeed() {\n  const list = getVisibleTopics();\n  const totalUnread = TOPICS.reduce((acc, t) => acc + t.unread, 0);\n  feedSummary.textContent = `${list.length} ${list.length === 1 ? 'topic' : 'topics'}`;\n  unreadTotal.textContent = `${totalUnread} unread`;\n\n  feedList.innerHTML = '';\n  list.forEach(t => {\n    const btn = document.createElement('button');\n    btn.type = 'button';\n    btn.className = 'topic-item' + (t.id === activeTopicId ? ' active' : '');\n    btn.innerHTML = `\n      <div class=\"topic-top\">\n        <span class=\"stream-pill\">#${t.stream}</span>\n        <div class=\"topic-badges\">\n          ${t.resolved ? '<span class=\"resolved-tag\">Resolved</span>' : ''}\n          ${t.unread > 0 ? `<span class=\"unread-dot\">${t.unread}</span>` : ''}\n        </div>\n      </div>\n      <div class=\"topic-title\">${t.title}</div>\n      <div class=\"topic-meta\">\n        <span>${t.messages.length} ${t.messages.length === 1 ? 'message' : 'messages'}${t.bookmarked ? ' · ★' : ''}</span>\n        <span>${t.updated}</span>\n      </div>\n    `;\n    btn.addEventListener('click', () => openTopic(t.id));\n    feedList.appendChild(btn);\n  });\n}\n\nfunction openTopic(id) {\n  activeTopicId = id;\n  const topic = getActiveTopic();\n  topic.unread = 0;\n  splitView.classList.add('mobile-thread');\n  renderFeed();\n  renderThread();\n}\n\nfunction renderThread() {\n  const topic = getActiveTopic();\n  threadTitle.textContent = topic.title;\n  threadSub.textContent = `#${topic.stream} · ${topic.messages.length} messages · ${topic.resolved ? 'Resolved' : 'Open'}`;\n\n  bookmarkBtn.classList.toggle('bookmarked', topic.bookmarked);\n  bookmarkLabel.textContent = topic.bookmarked ? 'Bookmarked' : 'Bookmark';\n  resolveBtn.classList.toggle('resolved', topic.resolved);\n  resolveLabel.textContent = topic.resolved ? 'Resolved' : 'Resolve';\n\n  messagesList.innerHTML = '';\n  topic.messages.forEach(m => {\n    const row = document.createElement('article');\n    row.className = 'msg';\n    row.innerHTML = `\n      <div class=\"avatar\" style=\"background:${m.color}\">${m.initials}</div>\n      <div class=\"msg-body\">\n        <div class=\"msg-head\">\n          <span class=\"msg-author\">${m.author}</span>\n          <span class=\"msg-role\">${m.role}</span>\n          <span class=\"msg-time\">${m.time}</span>\n        </div>\n        <div class=\"msg-text\"></div>\n        <div class=\"reactions\"></div>\n      </div>\n    `;\n    row.querySelector('.msg-text').textContent = m.text;\n\n    const reactWrap = row.querySelector('.reactions');\n    m.reactions.forEach((r) => {\n      const rb = document.createElement('button');\n      rb.type = 'button';\n      rb.className = 'react-btn' + (r.reacted ? ' reacted' : '');\n      rb.innerHTML = `<span>${r.emoji}</span><span>${r.count}</span>`;\n      rb.addEventListener('click', () => {\n        r.reacted = !r.reacted;\n        r.count += r.reacted ? 1 : -1;\n        renderThread();\n      });\n      reactWrap.appendChild(rb);\n    });\n\n    const addReact = document.createElement('button');\n    addReact.type = 'button';\n    addReact.className = 'react-btn';\n    addReact.textContent = '+ 👍';\n    addReact.setAttribute('aria-label', 'Add thumbs up reaction');\n    addReact.addEventListener('click', () => {\n      const existing = m.reactions.find(r => r.emoji === '👍');\n      if (existing) {\n        if (!existing.reacted) { existing.reacted = true; existing.count++; }\n      } else {\n        m.reactions.push({ emoji: '👍', count: 1, reacted: true });\n      }\n      renderThread();\n    });\n    reactWrap.appendChild(addReact);\n\n    messagesList.appendChild(row);\n  });\n}\n\nbookmarkBtn.addEventListener('click', () => {\n  const topic = getActiveTopic();\n  topic.bookmarked = !topic.bookmarked;\n  renderFeed();\n  renderThread();\n});\n\nresolveBtn.addEventListener('click', () => {\n  const topic = getActiveTopic();\n  topic.resolved = !topic.resolved;\n  renderFeed();\n  renderThread();\n});\n\ndocument.getElementById('backBtn').addEventListener('click', () => {\n  splitView.classList.remove('mobile-thread');\n});\n\nreplyForm.addEventListener('submit', (e) => {\n  e.preventDefault();\n  const text = replyInput.value.trim();\n  if (!text) return;\n  const topic = getActiveTopic();\n  topic.messages.push({\n    id: 'm-' + Date.now(),\n    author: 'You',\n    initials: 'YO',\n    color: '#3730A3',\n    role: 'Product Eng',\n    time: 'Just now',\n    text,\n    reactions: []\n  });\n  topic.updated = 'Just now';\n  replyInput.value = '';\n  renderFeed();\n  renderThread();\n  messagesList.scrollTop = messagesList.scrollHeight;\n});\n\nrenderStreams();\nrenderFeed();\nrenderThread();\n</script>\n</body>\n</html>\n"
}
