{% if user_message %}
<div class="chat-message user">
  <div class="msg-meta">YOU // {{ timestamp }}</div>
  <div class="msg-body">{{ user_message | e }}</div>
</div>
{% endif %}
{% if response %}
<div class="chat-message agent">
  <div class="msg-meta">TIMMY // {{ timestamp }}</div>
  <div class="msg-body timmy-md">{{ response | e }}</div>
</div>
<script>
  (function() {
    var el = document.currentScript.previousElementSibling.querySelector('.timmy-md');
    if (el && typeof marked !== 'undefined' && typeof DOMPurify !== 'undefined') {
      el.innerHTML = DOMPurify.sanitize(marked.parse(el.textContent));
    }
  })();
</script>
{% elif error %}
<div class="chat-message error-msg">
  <div class="msg-meta">SYSTEM // {{ timestamp }}</div>
  <div class="msg-body">{{ error | e }}</div>
</div>
{% endif %}
{% if memory_hits %}
<div class="nexus-memory-hits" id="nexus-memory-panel" hx-swap-oob="true">
  <div class="nexus-memory-label">// LIVE MEMORY CONTEXT</div>
  {% for hit in memory_hits %}
  <div class="nexus-memory-hit">
    <span class="nexus-memory-type">{{ hit.memory_type }}</span>
    <span class="nexus-memory-content">{{ hit.content | e }}</span>
  </div>
  {% endfor %}
</div>
{% endif %}
