<div class="max-w-3xl mx-auto">
    <div class="flex items-center gap-3 mb-6"><a href="?page=documents" 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">Upload Document</h1></div>
    <form method="POST" action="?page=documents&action=store" enctype="multipart/form-data" class="space-y-6"><?= CSRF::field() ?>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div class="md:col-span-2"><label class="block text-sm font-medium text-gray-700 mb-1">Title <span class="text-red-500">*</span></label><input type="text" name="title" value="<?= htmlspecialchars(old('title', '')) ?>" required class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"></div>
                <div><label class="block text-sm font-medium text-gray-700 mb-1">Category</label>
                    <select name="category" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"><option value="">Select</option>
                    <?php foreach (['lease'=>'Lease','application'=>'Application','notice'=>'Notice','invoice'=>'Invoice','receipt'=>'Receipt','inspection'=>'Inspection','tax'=>'Tax Document','insurance'=>'Insurance','w9'=>'W-9','photo'=>'Photo','other'=>'Other'] as $v=>$l): ?><option value="<?= $v ?>"><?= $l ?></option><?php endforeach; ?></select></div>
                <div><label class="block text-sm font-medium text-gray-700 mb-1">Expiry Date</label><input type="date" name="expiry_date" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"></div>
                <div><label class="block text-sm font-medium text-gray-700 mb-1">Attach To</label>
                    <select name="documentable_type" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"><option value="">None</option><option value="property">Property</option><option value="tenant">Tenant</option><option value="lease">Lease</option><option value="vendor">Vendor</option></select></div>
                <div><label class="block text-sm font-medium text-gray-700 mb-1">Entity ID</label><input type="number" name="documentable_id" value="<?= $_GET['entity_id'] ?? '' ?>" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500" placeholder="ID of property/tenant/etc"></div>
                <div class="md:col-span-2">
                    <label class="block text-sm font-medium text-gray-700 mb-1">File</label>
                    <div class="border-2 border-dashed border-gray-300 rounded-lg p-6 text-center hover:border-indigo-400 transition">
                        <svg class="mx-auto w-10 h-10 text-gray-400 mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/></svg>
                        <input type="file" name="file" class="text-sm text-gray-600">
                        <p class="text-xs text-gray-400 mt-1">PDF, DOC, DOCX, XLS, XLSX, JPG, PNG up to 10MB</p>
                    </div>
                </div>
            </div>
            <div class="mt-4"><label class="block text-sm font-medium text-gray-700 mb-1">Description</label><textarea name="description" rows="2" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"></textarea></div>
        </div>
        <div class="flex justify-end gap-3"><a href="?page=documents" class="px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 text-sm font-medium">Cancel</a><button type="submit" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 text-sm font-medium">Upload</button></div>
    </form>
</div>
