<!DOCTYPE html>
<html>

<head>
    <title>{{ stage }} Reports</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='index.css') }}">
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f0f2f5;
            margin: 0;
            padding: 0;
        }

        .container {
            max-width: 960px;
            margin: 40px auto;
            padding: 30px;
            background-color: #fff;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }

        h2 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
            font-size: 28px;
        }

        form {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 15px;
            margin-bottom: 30px;
            flex-wrap: wrap;
        }

        label {
            font-weight: 600;
            font-size: 16px;
        }

        select {
            padding: 8px 14px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 6px;
            outline: none;
            transition: border 0.2s;
        }

        select:focus {
            border-color: #007bff;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            font-size: 15px;
        }

        th,
        td {
            padding: 12px;
            border: 1px solid #ddd;
            text-align: left;
        }

        th {
            background-color: #007bff;
            color: white;
        }

        tr:nth-child(even) td {
            background-color: #f9fbfc;
        }

        tr:hover td {
            background-color: #eef5ff;
        }

        .btn-download {
            background-color: #28a745;
            color: white;
            border: none;
            padding: 7px 14px;
            border-radius: 5px;
            text-decoration: none;
            font-size: 14px;
            cursor: pointer;
            transition: background-color 0.2s;
        }

        .btn-download:hover {
            background-color: #218838;
        }

        .no-data {
            text-align: center;
            color: #777;
            font-size: 16px;
            margin-top: 20px;
        }

        /* Back button styling */
        .back-btn {
            display: inline-block;
            margin-bottom: 20px;
            padding: 10px 18px;
            background: #6c757d;
            color: white;
            font-size: 15px;
            font-weight: 600;
            border-radius: 6px;
            text-decoration: none;
            transition: background 0.3s ease;
        }

        .back-btn:hover {
            background: #5a6268;
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- Back to Dashboard Button -->
<!--        <a href="{{ url_for('index') }}" class="back-btn">← Back to Dashboard</a>-->

        <h2>{{ stage }} Reports</h2>

        <form method="GET">
            <input type="hidden" name="stage" value="{{ stage }}">
            <label for="year">Select Year:</label>
            <select name="year" id="year" onchange="this.form.submit()">
                <option value="">-- All Years --</option>
                {% for y in years %}
                <option value="{{ y }}" {% if y==request.args.get('year') %}selected{% endif %}>{{ y }}</option>
                {% endfor %}
            </select>
        </form>

        {% if documents %}
        <table>
            <thead>
                <tr>
                    <th>Year</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                {% for doc in documents %}
                <tr>
                    <td>{{ doc.year }}</td>
                    <td>
                        <a class="btn-download" href="{{ url_for('download_report', doc_id=doc.id) }}">Download</a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <p class="no-data">No reports found for this selection.</p>
        {% endif %}
    </div>
</body>

</html>