<!-- Apply Template Modal -->
<div class="modal fade" id="applyTemplateModal" tabindex="-1" aria-labelledby="applyTemplateModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="applyTemplateModalLabel">Apply Template</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="applyTemplateForm">
                    <input type="hidden" name="person" value="{{ person }}">
                    <input type="hidden" name="date" value="{{ current_date.isoformat() }}">
                    <div class="mb-3">
                        <label class="form-label">Select Template</label>
                        <select class="form-control" name="template_id" required>
                            <option value="">Choose template...</option>
                            {% for template in templates %}
                            <option value="{{ template.id }}">{{ template.name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="alert alert-warning">
                        <strong>Warning:</strong> This will replace all meals currently tracked for this day.
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-primary" onclick="submitApplyTemplate()">Apply Template</button>
            </div>
        </div>
    </div>
</div>