<div class="max-w-4xl mx-auto">
    <div class="flex items-center justify-between mb-6">
        <div class="flex items-center gap-3">
            <a href="?page=owners" class="text-gray-400 hover:text-gray-600"><svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/></svg></a>
            <h1 class="text-2xl font-bold text-gray-900"><?= htmlspecialchars($owner['name']) ?></h1>
        </div>
        <div class="flex gap-2">
            <a href="?page=owners&action=edit&id=<?= $owner['id'] ?>" class="px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 text-sm font-medium">Edit</a>
            <form method="POST" action="?page=owners&action=delete&id=<?= $owner['id'] ?>" onsubmit="return confirm('Delete this owner?')">
                <?= CSRF::field() ?><button class="px-4 py-2 border border-red-300 text-red-600 rounded-lg hover:bg-red-50 text-sm font-medium">Delete</button>
            </form>
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-5">
            <p class="text-xs font-medium text-gray-500 uppercase">Income</p>
            <p class="text-2xl font-bold text-green-600 mt-1"><?= formatMoney($income ?? 0) ?></p>
        </div>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-5">
            <p class="text-xs font-medium text-gray-500 uppercase">Expenses</p>
            <p class="text-2xl font-bold text-red-600 mt-1"><?= formatMoney($expenses ?? 0) ?></p>
        </div>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-5">
            <p class="text-xs font-medium text-gray-500 uppercase">Net</p>
            <p class="text-2xl font-bold text-gray-900 mt-1"><?= formatMoney(($income ?? 0) - ($expenses ?? 0)) ?></p>
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
            <h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">Contact</h3>
            <dl class="space-y-3 text-sm">
                <div class="flex justify-between"><dt class="text-gray-500">Email</dt><dd class="font-medium"><?= htmlspecialchars($owner['email'] ?? '-') ?></dd></div>
                <div class="flex justify-between"><dt class="text-gray-500">Phone</dt><dd class="font-medium"><?= htmlspecialchars($owner['phone'] ?? '-') ?></dd></div>
                <div class="flex justify-between"><dt class="text-gray-500">Address</dt><dd class="font-medium text-right"><?= htmlspecialchars(trim(($owner['address'] ?? '').' '.($owner['city'] ?? '').' '.($owner['state'] ?? '').' '.($owner['zip'] ?? ''))) ?: '-' ?></dd></div>
            </dl>
        </div>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
            <h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">Properties (<?= count($properties) ?>)</h3>
            <?php if (!empty($properties)): ?>
                <div class="space-y-2">
                    <?php foreach ($properties as $p): ?>
                        <a href="?page=properties&action=show&id=<?= $p['id'] ?>" class="flex items-center justify-between p-3 rounded-lg hover:bg-gray-50 transition">
                            <span class="font-medium text-gray-900 text-sm"><?= htmlspecialchars($p['name']) ?></span>
                            <span class="text-xs text-gray-500"><?= htmlspecialchars($p['city'] ?? '') ?></span>
                        </a>
                    <?php endforeach; ?>
                </div>
            <?php else: ?><p class="text-gray-400 text-sm">No properties assigned</p><?php endif; ?>
        </div>
    </div>

    <?php if ($owner['notes']): ?>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
            <h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-3">Notes</h3>
            <p class="text-sm text-gray-700 whitespace-pre-line"><?= htmlspecialchars($owner['notes']) ?></p>
        </div>
    <?php endif; ?>
</div>
