<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="refresh" content="30">
    <title>Turnos List · {{ nest_name }}</title>
    <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }

        body {
            font-family: system-ui, -apple-system, sans-serif;
            background: #111827;
            color: #f3f4f6;
            min-height: 100vh;
            padding: 1rem;
        }

        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0.5rem 0 1rem;
            border-bottom: 1px solid #374151;
            margin-bottom: 1rem;
        }

        h1 {
            font-size: 1.25rem;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .nest-badge {
            font-size: 0.7rem;
            background: #374151;
            padding: 0.2rem 0.5rem;
            border-radius: 4px;
            color: #9ca3af;
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 1rem;
        }

        .total {
            font-size: 1.5rem;
            font-weight: 700;
            color: #60a5fa;
        }

        .view-toggle a {
            color: #6b7280;
            text-decoration: none;
            font-size: 0.8rem;
            padding: 0.3rem 0.6rem;
            border-radius: 4px;
        }
        .view-toggle a:hover { background: #374151; }
        .view-toggle a.active { background: #374151; color: #f3f4f6; }

        /* Table */
        table {
            width: 100%;
            border-collapse: collapse;
            font-size: 0.85rem;
        }

        th {
            text-align: left;
            padding: 0.5rem;
            color: #9ca3af;
            font-weight: 500;
            border-bottom: 1px solid #374151;
        }

        td {
            padding: 0.5rem;
            border-bottom: 1px solid #1f2937;
        }

        tr:hover td {
            background: #1f2937;
        }

        .state-badge {
            display: inline-block;
            padding: 0.2rem 0.5rem;
            border-radius: 4px;
            font-size: 0.75rem;
            font-weight: 500;
        }

        .vet { color: #60a5fa; }
        .petowner { color: #d1d5db; }
        .id { color: #6b7280; font-family: monospace; }
        .age { color: #6b7280; }
        .age.warn { color: #fbbf24; }
        .age.old { color: #f87171; }

        .indicator {
            display: inline-block;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-right: 0.25rem;
        }
        .indicator.paid { background: #22c55e; }
        .indicator.scheduled { background: #3b82f6; }

        .empty {
            text-align: center;
            color: #6b7280;
            padding: 3rem;
        }

        footer {
            margin-top: 1rem;
            padding-top: 1rem;
            border-top: 1px solid #374151;
            font-size: 0.7rem;
            color: #6b7280;
            display: flex;
            justify-content: space-between;
        }
    </style>
</head>
<body>
    <header>
        <h1>
            Turnos
            <span class="nest-badge">{{ nest_name }}</span>
        </h1>
        <div class="header-right">
            <div class="view-toggle">
                <a href="?view=pipeline">Pipeline</a>
                <a href="?view=list" class="active">List</a>
            </div>
            <div class="total">{{ total }}</div>
        </div>
    </header>

    {% if total == 0 %}
    <div class="empty">No hay solicitudes activas</div>
    {% else %}
    <table>
        <thead>
            <tr>
                <th>#</th>
                <th>Estado</th>
                <th>Veterinario</th>
                <th>Cliente</th>
                <th>Flags</th>
                <th>Edad</th>
            </tr>
        </thead>
        <tbody>
            {% for item in items %}
            <tr>
                <td class="id">{{ item.id }}</td>
                <td>
                    <span class="state-badge" style="background: {{ item.state_color }}20; color: {{ item.state_color }};">
                        {{ item.state_label }}
                    </span>
                </td>
                <td class="vet">{{ item.vet }}</td>
                <td class="petowner">{{ item.petowner }}</td>
                <td>
                    {% if item.is_paid %}<span class="indicator paid" title="Pagado"></span>{% endif %}
                    {% if item.is_scheduled %}<span class="indicator scheduled" title="Coordinado"></span>{% endif %}
                </td>
                <td class="age {{ item.age_class }}">{{ item.age_hours }}h</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% endif %}

    <footer>
        <span>Auto-refresh 30s</span>
        <span><a href="/health" style="color: #6b7280;">/health</a></span>
    </footer>
</body>
</html>
