<?php
/**
 * Plugin Name: Manualidades Lili MVP
 * Description: Estilos y pequeños ajustes visuales para la primera versión de la tienda Manualidades Lili.
 * Version: 1.0.0
 * Author: Flatlogic
 */
if (!defined('ABSPATH')) { exit; }
add_action('wp_enqueue_scripts', function () {
    $css = <<<CSS
:root{--lili-primary:#9b4d35;--lili-secondary:#e9a84b;--lili-bg:#fff8ef;--lili-surface:#ffffff;--lili-text:#2f241f;--lili-muted:#74655e;--lili-mint:#8fb9a8;--lili-blush:#f4d5c4;}
body{background:var(--lili-bg);color:var(--lili-text);} 
.wp-site-blocks{background:radial-gradient(circle at 10% 5%,rgba(233,168,75,.18),transparent 24rem),radial-gradient(circle at 92% 12%,rgba(143,185,168,.22),transparent 26rem),var(--lili-bg);} 
a{color:var(--lili-primary);} .wp-block-site-title a{font-weight:900;text-decoration:none;letter-spacing:-.03em;color:var(--lili-primary)!important;}
.wp-block-navigation a{font-weight:650;text-decoration:none}.wp-block-navigation a:hover{color:var(--lili-primary)!important}
.lili-shell{border-radius:34px;box-shadow:0 30px 80px rgba(89,49,32,.16);overflow:hidden;border:1px solid rgba(155,77,53,.12)}
.lili-hero{position:relative;overflow:hidden;border-radius:34px;background:linear-gradient(135deg,#fff7e8 0%,#f3cfb8 46%,#d4e5d9 100%);padding:clamp(36px,7vw,86px)!important;}
.lili-hero:before{content:"";position:absolute;right:-80px;top:-80px;width:280px;height:280px;border-radius:999px;background:repeating-conic-gradient(from 20deg,#9b4d35 0 10deg,#e9a84b 10deg 20deg,#8fb9a8 20deg 30deg);opacity:.18}.lili-hero:after{content:"✂︎  ✿  🧶";position:absolute;right:clamp(18px,5vw,70px);bottom:28px;font-size:clamp(30px,6vw,70px);opacity:.28;letter-spacing:.18em;}
.lili-kicker{display:inline-flex;gap:.45rem;align-items:center;background:#fff;border:1px solid rgba(155,77,53,.14);border-radius:999px;padding:.5rem .85rem;font-size:.86rem;font-weight:800;color:var(--lili-primary);box-shadow:0 10px 25px rgba(89,49,32,.08)}
.lili-hero h1{font-size:clamp(2.7rem,7vw,5.8rem);line-height:.92;letter-spacing:-.065em;margin:.35em 0 .25em;font-weight:950;color:#44271d;max-width:900px}.lili-lead{font-size:clamp(1.08rem,2vw,1.35rem);line-height:1.65;color:#5d4b43;max-width:760px}.wp-block-button__link,.button,.wc-block-components-button,.woocommerce a.button,.woocommerce button.button,.woocommerce input.button{border-radius:999px!important;background:linear-gradient(135deg,var(--lili-primary),#c06a42)!important;color:#fff!important;font-weight:850!important;border:0!important;box-shadow:0 14px 30px rgba(155,77,53,.25)!important;padding:.9rem 1.25rem!important}.wp-block-button.is-style-outline .wp-block-button__link{background:#fff!important;color:var(--lili-primary)!important;border:1px solid rgba(155,77,53,.25)!important;box-shadow:0 10px 22px rgba(89,49,32,.08)!important}
.lili-card{background:rgba(255,255,255,.82);border:1px solid rgba(155,77,53,.12);border-radius:26px;padding:clamp(20px,3vw,34px);box-shadow:0 18px 45px rgba(89,49,32,.09);height:100%;}.lili-card h3{margin-top:.6rem}.lili-icon{width:58px;height:58px;border-radius:18px;display:grid;place-items:center;background:linear-gradient(135deg,#ffe5c2,#f5c7b4);font-size:1.65rem}.lili-band{background:#3b2a24;color:#fff;border-radius:30px;padding:clamp(28px,5vw,56px)!important}.lili-band a{color:#ffe0ad}.lili-product{background:#fff;border-radius:28px;overflow:hidden;border:1px solid rgba(155,77,53,.13);box-shadow:0 18px 45px rgba(89,49,32,.1)}.lili-product-img{min-height:210px;display:grid;place-items:center;font-size:4rem;background:linear-gradient(135deg,#ffecd1,#f5c7b4 52%,#d6eadf)}.lili-product-body{padding:22px}.lili-price{color:var(--lili-primary);font-size:1.35rem;font-weight:900}.lili-note{color:var(--lili-muted);font-size:.95rem}.lili-contact-box{background:#fff;border-radius:28px;padding:28px;border:1px dashed rgba(155,77,53,.35)}
.woocommerce ul.products li.product,.wc-block-grid__product{background:#fff;border-radius:24px;padding:18px!important;box-shadow:0 12px 30px rgba(89,49,32,.08);border:1px solid rgba(155,77,53,.1)}.woocommerce-loop-product__title{font-weight:850;color:#3b2a24}.price{color:var(--lili-primary)!important;font-weight:900!important}.woocommerce div.product{background:#fff;border-radius:28px;padding:clamp(20px,4vw,44px);box-shadow:0 16px 50px rgba(89,49,32,.08)}
footer,.wp-block-template-part{color:var(--lili-text)}
@media(max-width:700px){.lili-hero{padding:32px!important;border-radius:24px}.lili-hero:after{display:none}.lili-shell{border-radius:24px}}
CSS;
    wp_register_style('manualidades-lili-mvp', false, [], '1.0.0');
    wp_enqueue_style('manualidades-lili-mvp');
    wp_add_inline_style('manualidades-lili-mvp', $css);
});
add_action('admin_notices', function () {
    if (!current_user_can('manage_woocommerce')) { return; }
    echo '<div class="notice notice-info"><p><strong>Manualidades Lili:</strong> la primera versión incluye catálogo, carrito y checkout. Para cobrar con tarjeta/PayPal conecta una pasarela real desde WooCommerce → Ajustes → Pagos.</p></div>';
});


add_action('init', function () {
    register_post_type('lili_inquiry', [
        'labels' => ['name' => 'Consultas Lili', 'singular_name' => 'Consulta Lili', 'menu_name' => 'Consultas Lili'],
        'public' => false,
        'show_ui' => true,
        'show_in_menu' => true,
        'capability_type' => 'post',
        'supports' => ['title', 'editor'],
        'menu_icon' => 'dashicons-email-alt2',
    ]);
});
add_shortcode('lili_contact_form', function () {
    $sent = false;
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['lili_contact_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['lili_contact_nonce'])), 'lili_contact')) {
        $name = sanitize_text_field(wp_unslash($_POST['lili_name'] ?? ''));
        $email = sanitize_email(wp_unslash($_POST['lili_email'] ?? ''));
        $topic = sanitize_text_field(wp_unslash($_POST['lili_topic'] ?? 'Pedido personalizado'));
        $message = sanitize_textarea_field(wp_unslash($_POST['lili_message'] ?? ''));
        if ($name && $email && $message) {
            $content = "Nombre: {$name}\nEmail: {$email}\nTema: {$topic}\n\nMensaje:\n{$message}";
            wp_insert_post([
                'post_type' => 'lili_inquiry',
                'post_status' => 'publish',
                'post_title' => 'Consulta de ' . $name . ' - ' . current_time('Y-m-d H:i'),
                'post_content' => $content,
            ]);
            $sent = true;
        }
    }
    ob_start();
    if ($sent) {
        echo '<div class="lili-contact-box"><h3>¡Gracias! Hemos recibido tu consulta.</h3><p>Manualidades Lili revisará tu mensaje y te responderá para coordinar detalles, personalización o entrega.</p></div>';
    }
    ?>
    <form class="lili-contact-box" method="post">
        <?php wp_nonce_field('lili_contact', 'lili_contact_nonce'); ?>
        <p><label>Nombre<br><input required name="lili_name" type="text" style="width:100%;padding:14px;border-radius:14px;border:1px solid #e0c5b4"></label></p>
        <p><label>Email<br><input required name="lili_email" type="email" style="width:100%;padding:14px;border-radius:14px;border:1px solid #e0c5b4"></label></p>
        <p><label>Tema<br><select name="lili_topic" style="width:100%;padding:14px;border-radius:14px;border:1px solid #e0c5b4"><option>Pedido personalizado</option><option>Pregunta sobre un producto</option><option>Entrega / envío</option><option>Colaboración</option></select></label></p>
        <p><label>Mensaje<br><textarea required name="lili_message" rows="5" style="width:100%;padding:14px;border-radius:14px;border:1px solid #e0c5b4"></textarea></label></p>
        <p><button class="wp-block-button__link" type="submit">Enviar consulta</button></p>
    </form>
    <?php
    return ob_get_clean();
});
