<div>
    <div class="mb-6">
        <h1 class="text-2xl font-bold text-gray-900">{{ $title }}</h1>
        <a href="{{ route('territori.index') }}" class="text-sm text-indigo-600 hover:text-indigo-800">← Torna alla lista</a>
    </div>

    <form wire:submit="save" class="bg-white rounded-xl shadow-sm border border-gray-200 p-6 space-y-5 max-w-2xl">
        <div class="grid grid-cols-1 sm:grid-cols-2 gap-5">
            <div>
                <label class="block text-sm font-medium text-gray-700">Numero *</label>
                <input wire:model="numero" type="text" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 text-sm">
                @error('numero') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700">Zona</label>
                <select wire:model="zona_id" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 text-sm">
                    <option value="">-- Nessuna --</option>
                    @foreach($zone as $zona)
                        <option value="{{ $zona->id }}">{{ $zona->nome }}</option>
                    @endforeach
                </select>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700">Tipologia</label>
                <select wire:model="tipologia_id" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 text-sm">
                    <option value="">-- Nessuna --</option>
                    @foreach($tipologie as $tipologia)
                        <option value="{{ $tipologia->id }}">{{ $tipologia->nome }}</option>
                    @endforeach
                </select>
            </div>
            <div class="flex items-center gap-3 pt-6">
                <input wire:model="prioritario" type="checkbox" id="prioritario" class="h-4 w-4 text-indigo-600 border-gray-300 rounded">
                <label for="prioritario" class="text-sm text-gray-700">Prioritario (manuale)</label>
            </div>
        </div>

        <div>
            <label class="block text-sm font-medium text-gray-700">Note</label>
            <textarea wire:model="note" rows="3" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 text-sm"></textarea>
        </div>

        <div>
            <label class="block text-sm font-medium text-gray-700">Confini</label>
            <textarea wire:model="confini" rows="3" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 text-sm"></textarea>
        </div>

        <div>
            <label class="block text-sm font-medium text-gray-700">PDF Territorio</label>
            <input wire:model="pdf" type="file" accept=".pdf" class="mt-1 block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100">
            @error('pdf') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror

            @if($isEdit && $this->territorio->pdf_path)
                <div class="mt-2 flex items-center gap-2 text-sm">
                    <span class="text-green-600">PDF presente</span>
                    <button type="button" wire:click="removePdf" wire:confirm="Rimuovere il PDF?" class="text-red-600 hover:text-red-800 text-xs underline">Rimuovi PDF</button>
                </div>
            @endif
        </div>

        <div class="flex gap-3 pt-2">
            <a href="{{ route('territori.index') }}" class="px-4 py-2.5 rounded-lg text-sm font-medium text-gray-700 bg-gray-100 hover:bg-gray-200 transition">Annulla</a>
            <button type="submit" class="px-6 py-2.5 rounded-lg text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 transition">
                {{ $isEdit ? 'Aggiorna' : 'Crea' }}
            </button>
        </div>
    </form>
</div>
