{% if finding.type == "text" %}
<div id="finding-{{ finding.id }}" class="finding">
    <div class="finding-header">{{ finding.title }}</div>
    {% if finding.body %}<div class="finding-body">{{ finding.body | markdown }}</div>{% endif %}
    {% if finding.context %}
    <div class="finding-meta">{{ finding.context }}</div>
    {% endif %}
    <textarea data-bind="responses.{{ finding.id }}" data-on:blur="@post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', answer: $responses['{{ finding.id }}']})" placeholder="Type your answer..."></textarea>
</div>
{% elif finding.type == "triage" %}
<div id="finding-{{ finding.id }}" class="finding"
     data-signals='{{ {"responses": {finding.id ~ "_complexity": saved_responses.get(finding.id ~ "_complexity", finding.complexity.value) if saved_responses is defined else finding.complexity.value}} | tojson }}'>
    <div class="finding-header">{{ finding.title }}</div>
    {% if finding.body %}<div class="finding-body">{{ finding.body | markdown }}</div>{% endif %}
    {% if finding.severity or finding.confidence or finding.category %}
    <div class="finding-meta">
        {% if finding.location %}<code>{{ finding.location.file }}{% if finding.location.line %}:{{ finding.location.line }}{% endif %}</code> | {% endif %}
        Severity: <span class="badge badge-{{ finding.severity }}">{{ finding.severity }}</span> |
        Confidence: <span class="badge">{{ finding.confidence }}</span> |
        Category: {{ finding.category }}
    </div>
    {% elif finding.location %}
    <div class="finding-meta">
        <code>{{ finding.location.file }}{% if finding.location.line %}:{{ finding.location.line }}{% endif %}</code>
    </div>
    {% endif %}
    <div class="complexity-selector" role="radiogroup" aria-label="Fix complexity">
        <span class="complexity-label">Complexity:</span>
        <button class="complexity-btn" data-complexity="simple" data-attr:aria-pressed="$responses['{{ finding.id }}_complexity'] === 'simple'" data-class:selected="$responses['{{ finding.id }}_complexity'] === 'simple'" data-on:click="$responses['{{ finding.id }}_complexity'] = 'simple'; @post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', complexity: 'simple'})" type="button">Simple</button>
        <button class="complexity-btn" data-complexity="standard" data-attr:aria-pressed="$responses['{{ finding.id }}_complexity'] === 'standard'" data-class:selected="$responses['{{ finding.id }}_complexity'] === 'standard'" data-on:click="$responses['{{ finding.id }}_complexity'] = 'standard'; @post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', complexity: 'standard'})" type="button">Standard</button>
        <button class="complexity-btn" data-complexity="complex" data-attr:aria-pressed="$responses['{{ finding.id }}_complexity'] === 'complex'" data-class:selected="$responses['{{ finding.id }}_complexity'] === 'complex'" data-on:click="$responses['{{ finding.id }}_complexity'] = 'complex'; @post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', complexity: 'complex'})" type="button">Complex</button>
    </div>
    <div class="action-group">
        <button class="action-btn" data-action="accept" data-class:selected="$responses.{{ finding.id }} === 'accept'" data-on:click="$responses.{{ finding.id }} = 'accept'; @post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', action: 'accept'})" type="button">Accept</button>
        <button class="action-btn" data-action="drop" data-class:selected="$responses.{{ finding.id }} === 'drop'" data-on:click="$responses.{{ finding.id }} = 'drop'; @post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', action: 'drop'})" type="button">Drop</button>
        <button class="action-btn" data-action="downgrade" data-class:selected="$responses.{{ finding.id }} === 'downgrade'" data-on:click="$responses.{{ finding.id }} = 'downgrade'; @post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', action: 'downgrade'})" type="button">Downgrade</button>
        <button class="action-btn" data-action="discuss" data-class:selected="$responses.{{ finding.id }} === 'discuss'" data-on:click="$responses.{{ finding.id }} = 'discuss'; @post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', action: 'discuss'})" type="button">Discuss</button>
    </div>
    {% if finding.options %}
    <div class="triage-options">
        <div class="triage-options-label">Suggested approaches:</div>
        {% for option in finding.options %}
        <label class="option-card">
            <input type="radio" name="approach-{{ finding.id }}" data-bind="responses.{{ finding.id }}_approach" value="{{ option.label }}" data-on:change="@post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', selected: $responses['{{ finding.id }}_approach']})">
            <div class="option-content">
                <div class="option-label">{{ option.label }}</div>
                <div class="option-description">{{ option.description }}</div>
            </div>
        </label>
        {% endfor %}
        <label class="option-card">
            <input type="radio" name="approach-{{ finding.id }}" data-bind="responses.{{ finding.id }}_approach" value="__other__" data-on:change="@post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', selected: $responses['{{ finding.id }}_approach']})">
            <div class="option-content">
                <div class="option-label">Other</div>
                <div class="option-description">Describe a different approach</div>
            </div>
        </label>
        <div data-show="$responses['{{ finding.id }}_approach'] === '__other__'" style="margin-top: 0.5rem;">
            <textarea data-bind="responses.{{ finding.id }}_approach_other" data-on:blur="@post('/{{ session_id }}/save-response', {step_id: $step_id, finding_id: '{{ finding.id }}', selected: $responses['{{ finding.id }}_approach'], other_text: $responses['{{ finding.id }}_approach_other']})" placeholder="Describe your preferred approach..."></textarea>
        </div>
    </div>
    {% endif %}
</div>
{% elif finding.type == "evaluation" %}
<div id="finding-{{ finding.id }}" class="finding evaluation-finding">
    <div class="finding-header">{{ finding.title }}</div>
    {% if finding.body %}<div class="finding-body">{{ finding.body | markdown }}</div>{% endif %}
    <table class="eval-table">
        <thead><tr><th>Criterion</th><th>Rating</th><th>Justification</th></tr></thead>
        <tbody>
        {% for c in finding.criteria %}
        <tr>
            <td>{{ c.name }}</td>
            <td><span class="badge badge-{{ c.rating }}">{{ c.rating }}</span></td>
            <td>{{ c.justification }}</td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
    {% if finding.litmus_tests %}
    <table class="eval-table">
        <thead><tr><th>Litmus Test</th><th>Result</th></tr></thead>
        <tbody>
        {% for lt in finding.litmus_tests %}
        <tr><td>{{ lt.name }}</td><td>{{ lt.result }}</td></tr>
        {% endfor %}
        </tbody>
    </table>
    {% endif %}
    {% if finding.warnings %}
    <table class="eval-table">
        <thead><tr><th>Warning Sign</th><th>Found?</th><th>Details</th></tr></thead>
        <tbody>
        {% for w in finding.warnings %}
        <tr>
            <td>{{ w.name }}</td>
            <td>{% if w.found %}<span class="badge badge-warn-yes">Yes</span>{% else %}No{% endif %}</td>
            <td>{{ w.details }}</td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
    {% endif %}
    <div class="finding-meta">Informational — no response needed</div>
</div>
{% endif %}
