<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ report_name }}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .header {
            background-color: #4F46E5;
            color: white;
            padding: 20px;
            border-radius: 5px 5px 0 0;
        }
        .content {
            background-color: #f9fafb;
            padding: 20px;
            border: 1px solid #e5e7eb;
        }
        .summary {
            background-color: white;
            padding: 15px;
            margin: 15px 0;
            border-radius: 5px;
            border-left: 4px solid #4F46E5;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            background-color: white;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #e5e7eb;
        }
        th {
            background-color: #f3f4f6;
            font-weight: bold;
        }
        .footer {
            margin-top: 20px;
            padding: 15px;
            background-color: #f3f4f6;
            border-radius: 0 0 5px 5px;
            font-size: 12px;
            color: #6b7280;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>{{ report_name }}</h1>
        {% if custom_field_name and custom_field_value %}
        <p>Filter: {{ custom_field_name }} = {{ custom_field_value }}</p>
        {% endif %}
    </div>
    
    <div class="content">
        <div class="summary">
            <h2>Summary</h2>
            {% if report_data.summary %}
            <p><strong>Total Entries:</strong> {{ report_data.summary.get('total_entries', 0) }}</p>
            {% if report_data.summary.get('total_hours') %}
            <p><strong>Total Hours:</strong> {{ "%.2f"|format(report_data.summary.get('total_hours', 0)) }}</p>
            {% endif %}
            {% if report_data.summary.get('unpaid_only') %}
            <p><strong>Unpaid Hours Only:</strong> Yes</p>
            {% endif %}
            {% endif %}
        </div>
        
        {% if report_data.data and report_data.data|length > 0 %}
        <h2>Report Data</h2>
        <table>
            <thead>
                <tr>
                    {% for key in report_data.data[0].keys() %}
                    <th>{{ key|title|replace('_', ' ') }}</th>
                    {% endfor %}
                </tr>
            </thead>
            <tbody>
                {% for row in report_data.data %}
                <tr>
                    {% for key, value in row.items() %}
                    <td>
                        {% if value is number %}
                            {{ "%.2f"|format(value) if value % 1 else value|int }}
                        {% else %}
                            {{ value or '' }}
                        {% endif %}
                    </td>
                    {% endfor %}
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <p>No data found for this report.</p>
        {% endif %}
    </div>
    
    <div class="footer">
        <p>Generated at: {{ generated_at|user_datetime if generated_at else 'N/A' }}</p>
        <p>This is an automated report from TimeTracker.</p>
    </div>
</body>
</html>
