<div class="flex justify-between items-center mb-4">
    <h3 class="text-lg font-bold text-cyber-accent">{{ sp.hostname }}</h3>
    <button onclick="document.getElementById('edit-panel').style.display='none'" class="text-gray-500 hover:text-white text-xl">&times;</button>
</div>

<form method="POST" action="/specifics/{{ sp.id }}/save" class="space-y-4">

    <!-- Type + Groupe -->
    <div class="grid grid-cols-3 gap-3">
        <div>
            <label class="text-xs text-gray-500">Type application</label>
            <select name="app_type" class="w-full">
                <option value="">-</option>
                {% for t in app_types %}<option value="{{ t }}" {% if t == sp.app_type %}selected{% endif %}>{{ t }}</option>{% endfor %}
            </select>
        </div>
        <div>
            <label class="text-xs text-gray-500">Groupe d'ordre</label>
            <input type="text" name="patch_order_group" value="{{ sp.patch_order_group or '' }}" placeholder="BOC_SAP" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Ordre stop</label>
            <input type="number" name="stop_order" value="{{ sp.stop_order or '' }}" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Ordre start</label>
            <input type="number" name="reboot_order" value="{{ sp.reboot_order or '' }}" class="w-full">
        </div>
    </div>
    <div class="grid grid-cols-3 gap-3">
        <div>
            <label class="text-xs text-gray-500">Groupe vague</label>
            <input type="text" name="patch_wave_group" value="{{ sp.patch_wave_group or '' }}" placeholder="DNS-AD, SMTP..." class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Vague (1 ou 2)</label>
            <input type="number" name="patch_wave" value="{{ sp.patch_wave or '' }}" min="1" max="9" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Délai entre vagues (jours)</label>
            <input type="number" name="patch_wave_delay_days" value="{{ sp.patch_wave_delay_days or '1' }}" min="1" class="w-full">
        </div>
    </div>
    <div>
        <label class="text-xs text-gray-500">Note ordre</label>
        <input type="text" name="reboot_order_note" value="{{ sp.reboot_order_note or '' }}" class="w-full">
    </div>

    <!-- Commandes -->
    <h4 class="text-xs text-cyber-accent font-bold uppercase pt-2">Commandes</h4>
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Stop command</label>
            <textarea name="stop_command" rows="2" class="w-full font-mono text-xs">{{ sp.stop_command or '' }}</textarea>
        </div>
        <div>
            <label class="text-xs text-gray-500">Start command</label>
            <textarea name="start_command" rows="2" class="w-full font-mono text-xs">{{ sp.start_command or '' }}</textarea>
        </div>
    </div>
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Stop user</label>
            <input type="text" name="stop_user" value="{{ sp.stop_user or '' }}" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Start user</label>
            <input type="text" name="start_user" value="{{ sp.start_user or '' }}" class="w-full">
        </div>
    </div>
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Cmd avant patch</label>
            <textarea name="cmd_before_patch" rows="2" class="w-full font-mono text-xs">{{ sp.cmd_before_patch or '' }}</textarea>
        </div>
        <div>
            <label class="text-xs text-gray-500">Cmd apres patch</label>
            <textarea name="cmd_after_patch" rows="2" class="w-full font-mono text-xs">{{ sp.cmd_after_patch or '' }}</textarea>
        </div>
    </div>
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Cmd avant reboot</label>
            <textarea name="cmd_before_reboot" rows="2" class="w-full font-mono text-xs">{{ sp.cmd_before_reboot or '' }}</textarea>
        </div>
        <div>
            <label class="text-xs text-gray-500">Cmd apres reboot</label>
            <textarea name="cmd_after_reboot" rows="2" class="w-full font-mono text-xs">{{ sp.cmd_after_reboot or '' }}</textarea>
        </div>
    </div>

    <!-- Flags -->
    <h4 class="text-xs text-cyber-accent font-bold uppercase pt-2">Flags</h4>
    <div class="grid grid-cols-4 gap-3">
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="auto_restart" {% if sp.auto_restart %}checked{% endif %}> Auto-restart</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="is_cluster" {% if sp.is_cluster %}checked{% endif %}> Cluster</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="is_db" {% if sp.is_db %}checked{% endif %}> BDD</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="is_middleware" {% if sp.is_middleware %}checked{% endif %}> Middleware</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="kernel_update_blocked" {% if sp.kernel_update_blocked %}checked{% endif %}> Kernel bloque</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="sentinel" {% if sp.sentinel_disable_required %}checked{% endif %}> Desactiver S1</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="ip_fwd" {% if sp.ip_forwarding_required %}checked{% endif %}> IP Forwarding</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="rolling" {% if sp.rolling_update %}checked{% endif %}> Rolling update</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="has_agent_special" {% if sp.has_agent_special %}checked{% endif %}> Agent special</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="has_service_critical" {% if sp.has_service_critical %}checked{% endif %}> Service critique</label>
        <label class="flex items-center gap-2 text-xs"><input type="checkbox" name="needs_manual_step" {% if sp.needs_manual_step %}checked{% endif %}> Etape manuelle</label>
    </div>

    <!-- Details flags -->
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Cluster role</label>
            <input type="text" name="cluster_role" value="{{ sp.cluster_role or '' }}" placeholder="master/slave/node" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Cluster note</label>
            <input type="text" name="cluster_note" value="{{ sp.cluster_note or '' }}" class="w-full">
        </div>
    </div>
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Type BDD</label>
            <input type="text" name="db_type" value="{{ sp.db_type or '' }}" placeholder="PostgreSQL, Oracle..." class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Note BDD</label>
            <input type="text" name="db_note" value="{{ sp.db_note or '' }}" class="w-full">
        </div>
    </div>
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Type Middleware</label>
            <input type="text" name="mw_type" value="{{ sp.mw_type or '' }}" placeholder="Tomcat, JBoss..." class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Note Middleware</label>
            <input type="text" name="mw_note" value="{{ sp.mw_note or '' }}" class="w-full">
        </div>
    </div>
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Kernel block reason</label>
            <input type="text" name="kernel_block_reason" value="{{ sp.kernel_block_reason or '' }}" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Rolling update note</label>
            <input type="text" name="rolling_note" value="{{ sp.rolling_update_note or '' }}" class="w-full">
        </div>
    </div>
    <div class="grid grid-cols-3 gap-3">
        <div>
            <label class="text-xs text-gray-500">Reboot delay (min)</label>
            <input type="number" name="reboot_delay" value="{{ sp.reboot_delay_minutes or '' }}" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">Reboot interval min (min)</label>
            <input type="number" name="reboot_min_interval" value="{{ sp.reboot_min_interval_minutes or '' }}" class="w-full">
        </div>
        <div>
            <label class="text-xs text-gray-500">No reboot reason</label>
            <input type="text" name="no_reboot" value="{{ sp.no_reboot_reason or '' }}" class="w-full">
        </div>
    </div>

    <!-- Notes speciales -->
    <div>
        <label class="text-xs text-gray-500">Agent note</label>
        <input type="text" name="agent_note" value="{{ sp.agent_note or '' }}" class="w-full">
    </div>
    <div>
        <label class="text-xs text-gray-500">Service critique note</label>
        <input type="text" name="service_note" value="{{ sp.service_note or '' }}" class="w-full">
    </div>
    <div>
        <label class="text-xs text-gray-500">Etape manuelle detail</label>
        <textarea name="manual_step_detail" rows="2" class="w-full text-xs">{{ sp.manual_step_detail or '' }}</textarea>
    </div>

    <!-- Excludes -->
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="text-xs text-gray-500">Extra excludes (yum)</label>
            <input type="text" name="extra_excludes" value="{{ sp.extra_excludes or '' }}" placeholder="sdcss-kmod*,node*" class="w-full font-mono text-xs">
        </div>
        <div>
            <label class="text-xs text-gray-500">Patch excludes</label>
            <input type="text" name="patch_excludes" value="{{ sp.patch_excludes or '' }}" class="w-full font-mono text-xs">
        </div>
    </div>

    <!-- Note generale -->
    <div>
        <label class="text-xs text-gray-500">Note generale</label>
        <textarea name="note" rows="3" class="w-full text-xs">{{ sp.note or '' }}</textarea>
    </div>

    <div class="flex gap-2 pt-2">
        <button type="submit" class="btn-primary px-6 py-2 text-sm">Sauvegarder</button>
        <button type="button" onclick="document.getElementById('edit-panel').style.display='none'" class="btn-sm bg-cyber-border text-gray-300 px-4 py-2">Annuler</button>
    </div>
</form>
