<div class="ext-content">
    <div style="display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px;margin-bottom:.25rem">
        <h2 class="ext-page-title" style="margin:0"><?= t('my_tasks') ?></h2>
        <a href="/help/external" style="font-size:.8rem;color:#6b7280;text-decoration:none;display:flex;align-items:center;gap:4px">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 015.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
            <?= t('help') ?>
        </a>
    </div>
    <p class="ext-subtitle"><?= t('project_label') ?>: <strong><?= htmlspecialchars($external['project_name']) ?></strong></p>

    <?php if (empty($tasks)): ?>
    <div class="empty-state">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" width="56" height="56" opacity=".3"><path d="M9 11l3 3L22 4"/><path d="M21 12v7a2 2 0 01-2 2H5a2 2 0 01-2-2V5a2 2 0 012-2h11"/></svg>
        <p><?= t('no_tasks_assigned') ?></p>
    </div>
    <?php else: ?>
    <div class="ext-task-list">
        <?php foreach ($tasks as $task): ?>
        <a href="/ext/<?= htmlspecialchars($token) ?>/task/<?= $task['id'] ?>" class="ext-task-card">
            <div class="ext-task-header">
                <span class="status-badge" style="--status-color:<?= htmlspecialchars($task['status_color'] ?? '#6b7280') ?>">
                    <?= htmlspecialchars($task['status_name'] ?? '—') ?>
                </span>
                <?php if ($task['due_date']): ?>
                <span class="task-due-sm <?= $task['due_date'] < date('Y-m-d') ? 'overdue' : ($task['due_date'] === date('Y-m-d') ? 'due-today' : '') ?>">
                    <?= htmlspecialchars(date('d.m.Y', strtotime($task['due_date']))) ?>
                </span>
                <?php endif; ?>
            </div>
            <div class="ext-task-title"><?= htmlspecialchars($task['title']) ?></div>
            <?php
                // Description is rich HTML in storage. The overview wants a short
                // plaintext teaser, so strip tags + collapse whitespace + decode
                // entities BEFORE we substring, otherwise tags would either render
                // (XSS) or appear as visible "<p>…</p>" garbage in the cell.
                $descPlain = trim((string)preg_replace('/\s+/u', ' ',
                    html_entity_decode(strip_tags((string)$task['description']), ENT_QUOTES | ENT_HTML5, 'UTF-8')
                ));
            ?>
            <?php if ($descPlain !== ''): ?>
            <div class="ext-task-desc"><?= htmlspecialchars(mb_substr($descPlain, 0, 120)) ?><?= mb_strlen($descPlain) > 120 ? '…' : '' ?></div>
            <?php endif; ?>
        </a>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>
</div>
