<?php
$deliverabilitySettings = $deliverabilitySettings ?? [];
$complianceSnapshot = $complianceSnapshot ?? ['checks' => [], 'passed' => 0, 'total' => 0, 'score' => 0, 'risk' => 'healthy'];
$reputationSummary = $reputationSummary ?? ['avg_inbox_rate' => 0, 'avg_spam_rate' => 0, 'avg_complaint_rate' => 0];
$eventWebhookSummary = $eventWebhookSummary ?? ['total_count' => 0, 'verified_count' => 0, 'replayed_count' => 0, 'last_event_at' => null];
$automationStats = $automationStats ?? ['active_count' => 0, 'total_count' => 0, 'webhook_count' => 0, 'last_run_at' => null];
$healthSummary = $healthSummary ?? [];
$queueStats = $queueStats ?? [];
$suppressionSummary = $suppressionSummary ?? [];
$privacyMaskPii = setting_value('privacy_mask_pii', '1');
$privacySensitivity = setting_value('privacy_default_sensitivity', 'standard');
$privacyExportAdmin = setting_value('privacy_export_requires_admin', '1');
$marketplaceWebhookSecret = setting_value('marketplace_webhook_secret', '');
$powerFeatures = [
    'Drag-and-drop folders, labels, Focused/Other routing, saved views, and Outlook-style reading panes.',
    'Pin, mute, claim, archive, snooze, and sensitivity controls on email conversations.',
    'Collision-resistant shared mailbox workflows with approvals, SLA states, and internal notes.',
    'AI operator assist for summaries, risk hints, and suggested replies directly in Mail Center.',
    'Provider failover planning, safe launch thresholds, holdbacks, and recovery queue operations.',
];
?>
<section class="workspace-hero">
    <div>
        <h2>Commercial Campaign Command Center</h2>
        <p>V16.4 brings the full roadmap together: deliverability, automation, shared inbox operations, campaign safety controls, webhook observability, customer context, privacy governance, power-user mailbox controls, AI assist, and marketplace integrations.</p>
    </div>
    <div class="workspace-actions">
        <a class="btn secondary small" href="index.php?route=messages/campaignDashboard">Campaign Dashboard</a>
        <a class="btn secondary small" href="index.php?route=messages/mailCenter">Mail Center</a>
        <a class="btn secondary small" href="index.php?route=settings/diagnostics">Diagnostics</a>
    </div>
</section>

<section class="cards four compact-stats">
    <div class="card stat"><h3>Compliance Score</h3><p><?= number_format((float)($complianceSnapshot['score'] ?? 0), 1) ?>%</p><span><?= (int)($complianceSnapshot['passed'] ?? 0) ?>/<?= (int)($complianceSnapshot['total'] ?? 0) ?> deliverability checks passing</span></div>
    <div class="card stat alt"><h3>Inbox Readiness</h3><p><?= number_format((float)($reputationSummary['avg_inbox_rate'] ?? 0), 1) ?>%</p><span>Average inbox rate across saved snapshots</span></div>
    <div class="card stat alt"><h3>Automation Rules</h3><p><?= (int)($automationStats['active_count'] ?? 0) ?></p><span><?= (int)($automationStats['total_count'] ?? 0) ?> total · <?= (int)($automationStats['webhook_count'] ?? 0) ?> webhook rules</span></div>
    <div class="card stat alt"><h3>Webhook Events</h3><p><?= (int)($eventWebhookSummary['total_count'] ?? 0) ?></p><span><?= (int)($eventWebhookSummary['verified_count'] ?? 0) ?> verified · last <?= e($eventWebhookSummary['last_event_at'] ?? 'never') ?></span></div>
</section>

<section class="grid two">
    <div class="card">
        <div class="toolbar"><h2>1. Deliverability + Compliance Suite</h2><span class="badge <?= e($complianceSnapshot['risk'] ?? 'healthy') ?>"><?= e(ucfirst((string)($complianceSnapshot['risk'] ?? 'healthy'))) ?></span></div>
        <p class="muted">Capture the sending domain, DNS plan, unsubscribe posture, warm-up profile, and campaign guardrails in one place.</p>
        <form method="post" action="index.php?route=messages/saveCommercialCampaignSettings" class="stacked-panel">
            <?= csrf_input() ?>
            <div class="form-grid two">
                <input name="deliverability_domain" placeholder="Sending domain" value="<?= e($deliverabilitySettings['domain'] ?? '') ?>">
                <input name="deliverability_dkim_selector" placeholder="DKIM selector" value="<?= e($deliverabilitySettings['dkim_selector'] ?? '') ?>">
                <input name="deliverability_spf_include" placeholder="SPF include" value="<?= e($deliverabilitySettings['spf_include'] ?? '') ?>">
                <input name="deliverability_return_path_domain" placeholder="Return-path domain" value="<?= e($deliverabilitySettings['return_path_domain'] ?? '') ?>">
                <input name="deliverability_tracking_domain" placeholder="Tracking domain" value="<?= e($deliverabilitySettings['tracking_domain'] ?? '') ?>">
                <select name="deliverability_dmarc_policy">
                    <?php foreach (['none','quarantine','reject'] as $policy): ?>
                        <option value="<?= e($policy) ?>" <?= ($deliverabilitySettings['dmarc_policy'] ?? 'quarantine') === $policy ? 'selected' : '' ?>>DMARC <?= e($policy) ?></option>
                    <?php endforeach; ?>
                </select>
                <input name="deliverability_bimi_svg_url" placeholder="BIMI SVG URL" value="<?= e($deliverabilitySettings['bimi_svg_url'] ?? '') ?>">
                <input name="deliverability_warmup_profile" placeholder="Warm-up profile" value="<?= e($deliverabilitySettings['warmup_profile'] ?? '') ?>">
                <select name="deliverability_one_click_unsubscribe">
                    <option value="1" <?= ($deliverabilitySettings['one_click_unsubscribe'] ?? '1') === '1' ? 'selected' : '' ?>>One-click unsubscribe enabled</option>
                    <option value="0" <?= ($deliverabilitySettings['one_click_unsubscribe'] ?? '') === '0' ? 'selected' : '' ?>>One-click unsubscribe disabled</option>
                </select>
                <select name="deliverability_alerts_enabled">
                    <option value="1" <?= ($deliverabilitySettings['alerts_enabled'] ?? '1') === '1' ? 'selected' : '' ?>>Complaint alerts enabled</option>
                    <option value="0" <?= ($deliverabilitySettings['alerts_enabled'] ?? '') === '0' ? 'selected' : '' ?>>Complaint alerts disabled</option>
                </select>
                <input name="campaign_safe_launch_batch_size" type="number" min="10" step="10" placeholder="Safe launch batch" value="<?= e($deliverabilitySettings['safe_launch_batch_size'] ?? '50') ?>">
                <input name="campaign_holdback_percent" type="number" min="0" max="50" step="1" placeholder="Holdback %" value="<?= e($deliverabilitySettings['holdback_percent'] ?? '5') ?>">
                <input name="campaign_domain_throttle_json" placeholder='{"gmail.com":50}' value="<?= e($deliverabilitySettings['domain_throttle_json'] ?? '') ?>">
                <input name="campaign_seed_list_json" placeholder='["seed@example.com"]' value="<?= e($deliverabilitySettings['seed_list_json'] ?? '') ?>">
                <select name="campaign_provider_failover_transport">
                    <?php foreach (['sendgrid_api' => 'SendGrid API', 'smtp' => 'SMTP', 'php_mail' => 'PHP mail()'] as $value => $label): ?>
                        <option value="<?= e($value) ?>" <?= ($deliverabilitySettings['provider_failover_transport'] ?? 'sendgrid_api') === $value ? 'selected' : '' ?>>Fail over to <?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <button class="btn primary">Save deliverability settings</button>
        </form>
        <div class="metric-strip mt-12">
            <?php foreach (($complianceSnapshot['checks'] ?? []) as $key => $passed): ?>
                <div class="metric-chip"><strong><?= $passed ? '✓' : '•' ?></strong><span class="small muted"><?= e(str_replace('_', ' ', ucfirst((string)$key))) ?></span></div>
            <?php endforeach; ?>
        </div>
    </div>
    <div class="card">
        <div class="toolbar"><h2>Recommended DNS Records</h2><span class="badge">SPF · DKIM · DMARC · BIMI</span></div>
        <table>
            <thead><tr><th>Type</th><th>Host</th><th>Value</th><th>Purpose</th></tr></thead>
            <tbody>
            <?php foreach (($dnsRecords ?? []) as $record): ?>
                <tr>
                    <td><?= e($record['type'] ?? '') ?></td>
                    <td><code><?= e($record['host'] ?? '') ?></code></td>
                    <td><code><?= e($record['value'] ?? '') ?></code></td>
                    <td><?= e($record['purpose'] ?? '') ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <div class="alert-list mt-12">
            <?php foreach (($deliverabilityAlerts ?? []) as $alert): ?>
                <article class="alert-tile <?= e($alert['severity']) ?>">
                    <strong><?= e($alert['title']) ?></strong>
                    <div class="small muted"><?= e($alert['detail']) ?></div>
                </article>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section class="grid two">
    <div class="card">
        <div class="toolbar"><h2>2. Rules + Automation Engine</h2><span class="badge">If / Then</span></div>
        <form method="post" action="index.php?route=messages/saveAutomationRule" class="stacked-panel">
            <?= csrf_input() ?>
            <div class="form-grid two">
                <input name="name" placeholder="Rule name" required>
                <select name="trigger_event">
                    <option value="message_received">Message received</option>
                    <option value="event_webhook">Event webhook</option>
                </select>
                <select name="condition_channel">
                    <option value="">Any channel</option>
                    <option value="email">Email</option>
                    <option value="sms">SMS</option>
                </select>
                <input name="condition_contains" placeholder="Body or subject contains">
                <input name="condition_from_domain" placeholder="From domain equals">
                <input name="sort_order" type="number" value="100" placeholder="Sort order">
                <select name="action_move_folder">
                    <option value="">Keep current folder</option>
                    <?php foreach (($mailFolders ?? []) as $folder): ?>
                        <option value="<?= e($folder['key']) ?>"><?= e($folder['display_name'] ?? $folder['name']) ?></option>
                    <?php endforeach; ?>
                </select>
                <select name="action_apply_label">
                    <option value="">No label</option>
                    <?php foreach (($mailLabels ?? []) as $label): ?>
                        <option value="<?= e($label['label_key']) ?>"><?= e($label['name']) ?></option>
                    <?php endforeach; ?>
                </select>
                <select name="action_assign_user_id">
                    <option value="0">No owner</option>
                    <?php foreach (($users ?? []) as $user): ?>
                        <option value="<?= (int)$user['id'] ?>"><?= e($user['name']) ?></option>
                    <?php endforeach; ?>
                </select>
                <select name="action_shared_mailbox_id">
                    <option value="0">No shared mailbox</option>
                    <?php foreach (($sharedMailboxes ?? []) as $mailbox): ?>
                        <option value="<?= (int)$mailbox['id'] ?>"><?= e($mailbox['name']) ?></option>
                    <?php endforeach; ?>
                </select>
                <select name="action_focus_bucket">
                    <option value="">Keep bucket</option>
                    <option value="focused">Focused</option>
                    <option value="other">Other</option>
                </select>
                <input name="action_snooze_hours" type="number" min="0" step="1" placeholder="Snooze hours">
                <select name="action_set_mail_transport">
                    <option value="">Keep current mail transport</option>
                    <option value="sendgrid_api">Set SendGrid API</option>
                    <option value="smtp">Set SMTP</option>
                    <option value="php_mail">Set PHP mail()</option>
                </select>
                <select name="action_sensitivity_level">
                    <option value="">Keep sensitivity</option>
                    <option value="standard">Standard</option>
                    <option value="confidential">Confidential</option>
                    <option value="regulated">Regulated</option>
                </select>
            </div>
            <div class="form-grid two">
                <label class="permission-pill"><input type="checkbox" name="action_pause_campaign" value="1"> <span>Pause campaign when matched</span></label>
                <label class="permission-pill"><input type="checkbox" name="action_force_queue" value="1"> <span>Force queue a fresh processing job</span></label>
                <label class="permission-pill"><input type="checkbox" name="action_create_followup_task" value="1"> <span>Create follow-up task</span></label>
                <input name="action_followup_title" placeholder="Follow-up task title">
                <label class="permission-pill"><input type="checkbox" name="is_active" value="1" checked> <span>Rule active</span></label>
            </div>
            <button class="btn primary">Save automation rule</button>
        </form>
    </div>
    <div class="card">
        <div class="toolbar"><h2>Active Automation Rules</h2><span class="badge"><?= (int)($automationStats['active_count'] ?? 0) ?> active</span></div>
        <table>
            <thead><tr><th>Name</th><th>Trigger</th><th>Last Run</th><th>Status</th><th></th></tr></thead>
            <tbody>
            <?php foreach (($automationRules ?? []) as $rule): ?>
                <tr>
                    <td><strong><?= e($rule['name']) ?></strong><div class="small muted"><?= e(substr((string)($rule['condition_json'] ?? ''), 0, 90)) ?></div></td>
                    <td><?= e($rule['trigger_event'] ?? '') ?></td>
                    <td><?= e($rule['last_run_at'] ?? 'Never') ?></td>
                    <td><?= !empty($rule['is_active']) ? 'Active' : 'Paused' ?></td>
                    <td><a class="btn secondary small" href="index.php?route=messages/toggleAutomationRule&id=<?= (int)$rule['id'] ?>"><?= !empty($rule['is_active']) ? 'Pause' : 'Activate' ?></a></td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($automationRules)): ?><tr><td colspan="5" class="muted">No automation rules yet.</td></tr><?php endif; ?>
            </tbody>
        </table>
        <p class="muted small">Use automation rules to route mail, assign owners, apply labels, pause campaigns, switch providers, or create follow-up tasks when events arrive.</p>
    </div>
</section>

<section class="grid two">
    <div class="card">
        <div class="toolbar"><h2>3. Shared Inbox Operations</h2><span class="badge">Mail Center</span></div>
        <div class="metric-strip">
            <div class="metric-chip"><strong><?= count($sharedMailboxes ?? []) ?></strong><span class="small muted">shared mailboxes</span></div>
            <div class="metric-chip"><strong><?= count($users ?? []) ?></strong><span class="small muted">assignable users</span></div>
            <div class="metric-chip"><strong><?= (int)($healthSummary['unique_open_count'] ?? 0) ?></strong><span class="small muted">recent unique opens</span></div>
        </div>
        <ul class="clean-list small compact-list mt-12">
            <li>Focused / Other organization, saved views, pinned threads, and muted conversations.</li>
            <li>Assignment, claim ownership, SLA states, internal notes, and approval workflow.</li>
            <li>Shared mailbox routing and contact-aware conversation context.</li>
        </ul>
        <p><a class="btn secondary small" href="index.php?route=messages/mailCenter">Open Mail Center</a></p>
    </div>
    <div class="card">
        <div class="toolbar"><h2>4. Campaign Command Center</h2><span class="badge">Safety + Recovery</span></div>
        <div class="metric-strip">
            <div class="metric-chip"><strong><?= (int)($queueStats['queued_jobs'] ?? 0) ?></strong><span class="small muted">queued jobs</span></div>
            <div class="metric-chip"><strong><?= (int)($queueStats['failed_jobs'] ?? 0) ?></strong><span class="small muted">failed jobs</span></div>
            <div class="metric-chip"><strong><?= (int)($suppressionSummary['email_total'] ?? 0) ?></strong><span class="small muted">suppressed email addresses</span></div>
        </div>
        <ul class="clean-list small compact-list mt-12">
            <li>Safe launch mode uses the batch size and holdback settings saved above.</li>
            <li>Domain throttles and seed lists help protect warm-up and inbox placement.</li>
            <li>Use Start / Pause / Stop / Restart / Force Queue from Campaign Reports for live operations.</li>
        </ul>
        <div class="workspace-actions mt-12">
            <a class="btn secondary small" href="index.php?route=messages/campaignReports">Open Campaign Reports</a>
            <a class="btn secondary small" href="index.php?route=messages/campaignDashboard">Open Dashboard</a>
        </div>
    </div>
</section>

<section class="grid two">
    <div class="card">
        <div class="toolbar"><h2>5. Event Ingestion + Observability</h2><span class="badge">Webhooks</span></div>
        <div class="metric-strip">
            <div class="metric-chip"><strong><?= (int)($eventWebhookSummary['verified_count'] ?? 0) ?></strong><span class="small muted">verified events</span></div>
            <div class="metric-chip"><strong><?= (int)($eventWebhookSummary['replayed_count'] ?? 0) ?></strong><span class="small muted">replayed / reviewed</span></div>
            <div class="metric-chip"><strong><?= e($eventWebhookSummary['last_event_at'] ?? 'Never') ?></strong><span class="small muted">last event</span></div>
        </div>
        <table class="mt-12">
            <thead><tr><th>Provider</th><th>Event</th><th>Signature</th><th>Replay</th><th>Created</th></tr></thead>
            <tbody>
            <?php foreach (($eventWebhookLogs ?? []) as $log): ?>
                <tr>
                    <td><?= e($log['provider'] ?? '') ?></td>
                    <td><?= e($log['event_type'] ?? '') ?></td>
                    <td><?= e($log['signature_status'] ?? '') ?></td>
                    <td><?= e($log['replay_status'] ?? '') ?></td>
                    <td><?= e($log['created_at'] ?? '') ?></td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($eventWebhookLogs)): ?><tr><td colspan="5" class="muted">No webhook events captured yet.</td></tr><?php endif; ?>
            </tbody>
        </table>
        <p><a class="btn secondary small" href="index.php?route=settings/diagnostics">Open Diagnostics</a></p>
    </div>
    <div class="card">
        <div class="toolbar"><h2>6. Customer 360 + Pipeline Linkage</h2><span class="badge">Context</span></div>
        <table>
            <thead><tr><th>Campaign</th><th>Sent</th><th>Opens</th><th>Clicks</th><th>Bounces</th></tr></thead>
            <tbody>
            <?php foreach (($campaignComparison ?? []) as $row): ?>
                <tr>
                    <td><?= e($row['name']) ?></td>
                    <td><?= (int)($row['sent_recipients'] ?? 0) ?></td>
                    <td><?= (int)($row['unique_open_count'] ?? 0) ?></td>
                    <td><?= (int)($row['unique_click_count'] ?? 0) ?></td>
                    <td><?= (int)($row['bounced_count'] ?? 0) ?></td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($campaignComparison)): ?><tr><td colspan="5" class="muted">No campaign context yet.</td></tr><?php endif; ?>
            </tbody>
        </table>
        <p class="muted small mt-12">Mail Center now keeps campaign linkage, CRM context, internal notes, and workflow ownership beside each thread so operators can work from one place.</p>
    </div>
</section>

<section class="grid two">
    <div class="card">
        <div class="toolbar"><h2>7. Privacy + Governance</h2><span class="badge">Enterprise controls</span></div>
        <form method="post" action="index.php?route=messages/saveCommercialCampaignSettings" class="stacked-panel">
            <?= csrf_input() ?>
            <div class="form-grid two">
                <select name="privacy_mask_pii">
                    <option value="1" <?= (string)$privacyMaskPii === '1' ? 'selected' : '' ?>>Mask PII in exports / logs</option>
                    <option value="0" <?= (string)$privacyMaskPii === '0' ? 'selected' : '' ?>>Do not mask PII</option>
                </select>
                <select name="privacy_default_sensitivity">
                    <?php foreach (['standard','confidential','regulated'] as $value): ?>
                        <option value="<?= e($value) ?>" <?= (string)$privacySensitivity === $value ? 'selected' : '' ?>>Default sensitivity: <?= e(ucfirst($value)) ?></option>
                    <?php endforeach; ?>
                </select>
                <select name="privacy_export_requires_admin">
                    <option value="1" <?= (string)$privacyExportAdmin === '1' ? 'selected' : '' ?>>Exports require admin</option>
                    <option value="0" <?= (string)$privacyExportAdmin === '0' ? 'selected' : '' ?>>Allow manager exports</option>
                </select>
                <input name="marketplace_webhook_secret" placeholder="Webhook secret" value="<?= e($marketplaceWebhookSecret) ?>">
            </div>
            <button class="btn primary">Save privacy + governance</button>
        </form>
        <p class="muted small">Use sensitivity levels on conversations, audit logs, connector scopes, and admin-gated exports to protect regulated data.</p>
    </div>
    <div class="card">
        <div class="toolbar"><h2>8. Mailbox Power Features</h2><span class="badge">Operator speed</span></div>
        <ul class="clean-list small compact-list">
            <?php foreach ($powerFeatures as $feature): ?>
                <li><?= e($feature) ?></li>
            <?php endforeach; ?>
        </ul>
        <p><a class="btn secondary small" href="index.php?route=messages/mailCenter">Launch Mail Center</a></p>
    </div>
</section>

<section class="grid two">
    <div class="card">
        <div class="toolbar"><h2>9. AI Assist Layer</h2><span class="badge">Operator guidance</span></div>
        <div class="alert-tile info">
            <strong>AI assist is wired into Mail Center.</strong>
            <div class="small muted">Operators now get conversation summaries, risk hints, recommended next actions, and suggested replies inside the 3-pane mailbox.</div>
        </div>
        <ul class="clean-list small compact-list mt-12">
            <li>Reply coaching for revenue, compliance, and urgent threads.</li>
            <li>Suggested follow-ups and routing hints for shared inbox teams.</li>
            <li>Campaign context beside the thread so operators can answer with full history.</li>
        </ul>
    </div>
    <div class="card">
        <div class="toolbar"><h2>10. Marketplace + External Integrations</h2><span class="badge">Connectors</span></div>
        <form method="post" action="index.php?route=settings/saveConnector" class="stacked-panel">
            <?= csrf_input() ?>
            <div class="form-grid two">
                <select name="connector_key">
                    <?php foreach (($connectorCatalog ?? []) as $connector): ?>
                        <option value="<?= e($connector['key']) ?>"><?= e($connector['name']) ?> — <?= e($connector['scope']) ?></option>
                    <?php endforeach; ?>
                </select>
                <input name="name" placeholder="Display name" required>
                <input name="base_url" placeholder="Base URL or tenant URL">
                <input name="auth_type" placeholder="Auth type (oauth2, bearer, basic)" value="oauth2">
                <input name="access_token" placeholder="Token / client secret">
                <input name="config_json" placeholder="JSON config or scopes">
                <label class="permission-pill"><input type="checkbox" name="is_active" value="1" checked> <span>Connector active</span></label>
            </div>
            <button class="btn primary">Save connector</button>
        </form>
        <table class="mt-12">
            <thead><tr><th>Connector</th><th>Scope</th><th>Status</th></tr></thead>
            <tbody>
            <?php foreach (($connectors ?? []) as $connector): ?>
                <tr>
                    <td><strong><?= e($connector['name'] ?? $connector['connector_key']) ?></strong><div class="small muted"><?= e($connector['connector_key'] ?? '') ?></div></td>
                    <td><?= e($connector['config_json'] ?? '—') ?></td>
                    <td><?= !empty($connector['is_active']) ? 'Active' : 'Paused' ?></td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($connectors)): ?><tr><td colspan="3" class="muted">No connectors configured yet.</td></tr><?php endif; ?>
            </tbody>
        </table>
    </div>
</section>

<section class="grid two">
    <div class="card">
        <div class="toolbar"><h2>Sender Profiles</h2><span class="badge">Aliases + outbound identity</span></div>
        <form method="post" action="index.php?route=settings/saveSenderProfile" class="stacked-panel">
            <?= csrf_input() ?>
            <div class="form-grid two">
                <input name="name" placeholder="Display name" required>
                <input name="alias_email" placeholder="Alias email" required>
                <input name="reply_to_email" placeholder="Reply-to email">
                <input name="signature_html" placeholder="Signature HTML or text">
                <label class="permission-pill"><input type="checkbox" name="is_active" value="1" checked> <span>Profile active</span></label>
            </div>
            <button class="btn secondary">Save sender profile</button>
        </form>
    </div>
    <div class="card">
        <div class="toolbar"><h2>Active Sender Profiles</h2><span class="badge"><?= count($senderProfiles ?? []) ?></span></div>
        <table>
            <thead><tr><th>Display name</th><th>Alias</th><th>Reply-To</th><th>Status</th></tr></thead>
            <tbody>
            <?php foreach (($senderProfiles ?? []) as $profile): ?>
                <tr>
                    <td><?= e($profile['display_name'] ?? '') ?></td>
                    <td><?= e($profile['alias_email'] ?? '') ?></td>
                    <td><?= e($profile['reply_to_email'] ?? '—') ?></td>
                    <td><?= !empty($profile['is_active']) ? 'Active' : 'Paused' ?></td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($senderProfiles)): ?><tr><td colspan="4" class="muted">No sender profiles configured yet.</td></tr><?php endif; ?>
            </tbody>
        </table>
    </div>
</section>
