<div class="space-y-6">
    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
        <div class="flex justify-between items-start">
            <div>
                <h3 class="text-xl font-bold text-gray-900"><?= htmlspecialchars($order['title']) ?></h3>
                <p class="text-sm text-gray-500 mt-1">Recebido em
                    <?= date('d/m/Y H:i', strtotime($order['received_at'])) ?>
                </p>
            </div>
            <span
                class="px-3 py-1 rounded-full text-sm font-semibold <?= $order['type'] == 'block' ? 'bg-red-100 text-red-800' : 'bg-green-100 text-green-800' ?>">
                <?= $order['type'] == 'block' ? 'Bloqueio' : 'Desbloqueio' ?>
            </span>
        </div>
        <div class="mt-6 border-t border-gray-100 pt-4">
            <h4 class="text-sm font-medium text-gray-700">Conteúdo / Descrição</h4>
            <style>
                .prose a {
                    color: #2563eb;
                    text-decoration: underline;
                }

                .prose a:hover {
                    color: #1e40af;
                }
            </style>
            <div class="mt-2 text-gray-600 text-sm prose max-w-none">
                <?= \App\Utils\TextFormatter::formatContent($order['content'] ?? '') ?></div>
        </div>
    </div>

    <?php if (!empty($attachments)): ?>
    <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-100 bg-gray-50 flex items-center gap-2">
            <svg class="w-4 h-4 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01-.01.01m5.699-9.941-7.81 7.81a1.5 1.5 0 002.112 2.13" />
            </svg>
            <h3 class="text-sm font-semibold text-gray-800">Anexos (<?= count($attachments) ?>)</h3>
        </div>
        <ul class="divide-y divide-gray-100">
            <?php foreach ($attachments as $attachment): ?>
            <li class="flex items-center justify-between px-6 py-3 hover:bg-gray-50 transition-colors">
                <div class="flex items-center gap-3 min-w-0">
                    <svg class="w-4 h-4 text-gray-400 flex-shrink-0" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
                    </svg>
                    <span class="text-sm text-gray-800 truncate"><?= htmlspecialchars($attachment['original_name']) ?></span>
                    <?php if ($attachment['size']): ?>
                    <span class="text-xs text-gray-400 flex-shrink-0"><?= number_format($attachment['size'] / 1024, 1) ?> KB</span>
                    <?php endif; ?>
                </div>
                <a href="/admin/orders/attachments/<?= (int) $attachment['id'] ?>/download"
                   class="flex items-center gap-1 text-xs text-primary-600 hover:text-primary-800 font-medium flex-shrink-0 ml-4"
                   title="Baixar <?= htmlspecialchars($attachment['original_name']) ?>">
                    <svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />
                    </svg>
                    Baixar
                </a>
            </li>
            <?php endforeach; ?>
        </ul>
    </div>
    <?php endif; ?>

    <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-100 bg-gray-50">
            <h3 class="text-lg font-semibold text-gray-800">Domínios Afetados (<?= count($items) ?>)</h3>
        </div>
        <div class="overflow-x-auto max-h-96">
            <table class="w-full text-left border-collapse">
                <thead class="bg-gray-50 sticky top-0">
                    <tr>
                        <th class="px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider">Domínio</th>
                        <th class="px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider">Ação Nesta
                            Ordem</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100">
                    <?php foreach ($items as $item): ?>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-3 text-sm font-mono text-gray-900"><?= htmlspecialchars($item['name']) ?>
                            </td>
                            <td class="px-6 py-3 text-sm">
                                <span
                                    class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full <?= $item['action'] == 'block' ? 'bg-red-100 text-red-800' : 'bg-green-100 text-green-800' ?>">
                                    <?= $item['action'] == 'block' ? 'Bloquear' : 'Desbloquear' ?>
                                </span>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>