<?php
session_start();
if(!isset($_SESSION['id'])){
    header("Location: ../index.php");
    exit();
}
include("../conexion.php");
?>

<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nueva Categoría</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

<style>
    :root {
        --primary: #EC407A;
        --primary-dark: #D81B60;
        --primary-light: #FCE4EC;
    }
    
    body {
        background: linear-gradient(135deg, #FFF5F7 0%, #FCE4EC 100%);
        min-height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        padding: 20px;
    }
    
    .card-modern {
        background: white;
        border-radius: 24px;
        padding: 40px 45px;
        max-width: 700px;
        width: 100%;
        box-shadow: 0 20px 60px rgba(236, 64, 122, 0.15);
        border: 1px solid rgba(236, 64, 122, 0.05);
        transition: all 0.3s ease;
        margin: 0 auto;
    }
    .card-modern:hover {
        box-shadow: 0 25px 70px rgba(236, 64, 122, 0.2);
        transform: translateY(-2px);
    }
    
    .card-header-custom {
        text-align: center;
        margin-bottom: 35px;
        padding-bottom: 25px;
        border-bottom: 2px solid #f0f0f0;
        position: relative;
    }
    .card-header-custom .icon-circle {
        width: 70px;
        height: 70px;
        background: linear-gradient(135deg, #EC407A, #D81B60);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 15px;
        font-size: 28px;
        color: white;
        box-shadow: 0 8px 25px rgba(236, 64, 122, 0.3);
    }
    .card-header-custom h2 {
        font-weight: 700;
        color: #2d3748;
        font-size: 1.8rem;
        margin: 0;
    }
    .card-header-custom p {
        color: #718096;
        font-size: 0.95rem;
        margin: 5px 0 0 0;
    }
    
    .form-group-custom {
        margin-bottom: 20px;
    }
    .form-group-custom .form-label {
        font-weight: 600;
        color: #2d3748;
        font-size: 0.9rem;
        margin-bottom: 6px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .form-group-custom .form-label i {
        color: #EC407A;
        width: 18px;
    }
    .form-group-custom .form-label .required-star {
        color: #EC407A;
        font-weight: 700;
    }
    
    .form-group-custom .form-control,
    .form-group-custom .form-select {
        border-radius: 12px;
        border: 2px solid #e8ecf1;
        padding: 12px 16px;
        transition: all 0.3s ease;
        background: #fafbfc;
        font-size: 0.95rem;
    }
    .form-group-custom .form-control:focus,
    .form-group-custom .form-select:focus {
        border-color: #EC407A;
        background: white;
        box-shadow: 0 0 0 4px rgba(236, 64, 122, 0.12);
    }
    .form-group-custom .form-control::placeholder {
        color: #b0b8c4;
        font-size: 0.9rem;
    }
    
    .form-group-custom .input-icon-wrapper {
        position: relative;
    }
    .form-group-custom .input-icon-wrapper i {
        position: absolute;
        left: 14px;
        top: 50%;
        transform: translateY(-50%);
        color: #a0aec0;
        font-size: 1rem;
        transition: all 0.3s ease;
        pointer-events: none;
    }
    .form-group-custom .input-icon-wrapper .form-control {
        padding-left: 42px;
    }
    .form-group-custom .input-icon-wrapper .form-control:focus + i {
        color: #EC407A;
    }
    
    .btn-group-custom {
        display: flex;
        gap: 12px;
        margin-top: 30px;
        flex-wrap: wrap;
    }
    
    .btn-primary-custom {
        background: linear-gradient(135deg, #EC407A, #D81B60);
        border: none;
        padding: 14px 35px;
        border-radius: 12px;
        font-weight: 600;
        transition: all 0.3s ease;
        color: white;
        font-size: 0.95rem;
        letter-spacing: 0.3px;
        box-shadow: 0 4px 15px rgba(236, 64, 122, 0.3);
        flex: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
    }
    .btn-primary-custom:hover {
        background: linear-gradient(135deg, #D81B60, #c2185b);
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(236, 64, 122, 0.4);
        color: white;
    }
    
    .btn-secondary-custom {
        border-radius: 12px;
        padding: 14px 30px;
        font-weight: 600;
        transition: all 0.3s ease;
        border: 2px solid #e2e8f0;
        background: white;
        color: #4a5568;
        flex: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        text-decoration: none;
    }
    .btn-secondary-custom:hover {
        background: #f7fafc;
        border-color: #cbd5e0;
        transform: translateY(-2px);
        color: #2d3748;
    }
    
    .help-text {
        font-size: 0.8rem;
        color: #a0aec0;
        margin-top: 4px;
        display: flex;
        align-items: center;
        gap: 4px;
    }
    .help-text i {
        font-size: 0.7rem;
    }
    
    @media (max-width: 600px) {
        .card-modern {
            padding: 25px 20px;
        }
        .btn-group-custom {
            flex-direction: column;
        }
        .btn-primary-custom, .btn-secondary-custom {
            flex: none;
            width: 100%;
        }
        .card-header-custom h2 {
            font-size: 1.4rem;
        }
    }
</style>
</head>
<body>

<div class="card-modern">
    <!-- Header -->
    <div class="card-header-custom">
        <div class="icon-circle">
            <i class="fas fa-tags"></i>
        </div>
        <h2><i class="fas fa-tags me-2" style="color:#EC407A;"></i>Nueva Categoría</h2>
        <p>Registra una nueva categoría en el sistema</p>
    </div>

    <!-- ===== FORMULARIO CON ACTION CORREGIDO ===== -->
    <form action="guardar.php" method="POST">
        
        <!-- Nombre -->
        <div class="form-group-custom">
            <label class="form-label">
                <i class="fas fa-tag"></i> Nombre de la Categoría <span class="required-star">*</span>
            </label>
            <div class="input-icon-wrapper">
                <i class="fas fa-tag"></i>
                <input type="text" class="form-control" name="nombre" placeholder="Ej: Cascos, Guantes, Luces..." required>
            </div>
        </div>

        <!-- Descripción -->
        <div class="form-group-custom">
            <label class="form-label">
                <i class="fas fa-align-left"></i> Descripción <span class="required-star">*</span>
            </label>
            <div class="input-icon-wrapper">
                <i class="fas fa-align-left"></i>
                <textarea class="form-control" name="descripcion" rows="4" placeholder="Breve descripción de la categoría" required></textarea>
            </div>
            <div class="help-text">
                <i class="fas fa-info-circle"></i> Describe brevemente la categoría
            </div>
        </div>

        <!-- Botones -->
        <div class="btn-group-custom">
            <button type="submit" class="btn-primary-custom">
                <i class="fas fa-save"></i> Guardar Categoría
            </button>
            <a href="listar.php" class="btn-secondary-custom">
                <i class="fas fa-times"></i> Cancelar
            </a>
        </div>
    </form>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>