<?php
/**
 * Plugin Name: Agency Custom Colors
 * Description: Injects custom branding colors into the site.
 */

// 1. Register Palette in the Editor
add_action( 'after_setup_theme', function() {
    add_theme_support( 'editor-color-palette', array(
        array( 'name' => 'Agency Navy', 'slug' => 'agency-navy', 'color' => '#0A2540' ),
        array( 'name' => 'Agency Purple', 'slug' => 'agency-purple', 'color' => '#635BFF' ),
        array( 'name' => 'Agency Teal', 'slug' => 'agency-teal', 'color' => '#00D4B6' ),
        array( 'name' => 'Agency Orange', 'slug' => 'agency-orange', 'color' => '#FF7A59' ),
        array( 'name' => 'Agency Light', 'slug' => 'agency-light', 'color' => '#F7F9FC' ),
    ) );
}, 100 );

// 2. Output CSS variables and overrides
add_action( 'wp_head', function() {
    ?>
    <style>
        :root {
            --wp--preset--color--agency-navy: #0A2540;
            --wp--preset--color--agency-purple: #635BFF;
            --wp--preset--color--agency-teal: #00D4B6;
            --wp--preset--color--agency-orange: #FF7A59;
            --wp--preset--color--agency-light: #F7F9FC;
            
            /* Override global layout widths to be wider */
            --wp--custom--layout--content-size: 900px;
            --wp--custom--layout--wide-size: 1400px;
            --wp--style--global--content-size: 900px !important;
            --wp--style--global--wide-size: 1400px !important;
        }

        /* Apply global coloring */
        body {
            background-color: var(--wp--preset--color--agency-light);
            background-image: linear-gradient(135deg, rgba(99, 91, 255, 0.08) 0%, rgba(0, 212, 182, 0.08) 100%);
            background-attachment: fixed;
        }

        h1, h2, h3, h4, h5, h6,
        .wp-block-heading,
        .wp-block-site-title a {
            color: var(--wp--preset--color--agency-navy) !important;
        }

        a {
            color: var(--wp--preset--color--agency-purple);
            text-decoration: none;
        }
        a:hover {
            color: var(--wp--preset--color--agency-teal);
        }

        .wp-block-button__link,
        .wp-element-button,
        .wpcf7-submit {
            background-color: var(--wp--preset--color--agency-purple) !important;
            color: #ffffff !important;
            border: none !important;
            border-radius: 6px !important;
            padding: 0.8rem 1.5rem !important;
            text-decoration: none !important;
            transition: all 0.3s ease;
        }

        .wp-block-button__link:hover,
        .wp-element-button:hover,
        .wpcf7-submit:hover {
            background-color: var(--wp--preset--color--agency-navy) !important;
            color: #ffffff !important;
        }

        /* Utility classes for editor */
        .has-agency-navy-color { color: var(--wp--preset--color--agency-navy) !important; }
        .has-agency-navy-background-color { background-color: var(--wp--preset--color--agency-navy) !important; }
        .has-agency-purple-color { color: var(--wp--preset--color--agency-purple) !important; }
        .has-agency-purple-background-color { background-color: var(--wp--preset--color--agency-purple) !important; }
        .has-agency-teal-color { color: var(--wp--preset--color--agency-teal) !important; }
        .has-agency-teal-background-color { background-color: var(--wp--preset--color--agency-teal) !important; }
        .has-agency-orange-color { color: var(--wp--preset--color--agency-orange) !important; }
        .has-agency-orange-background-color { background-color: var(--wp--preset--color--agency-orange) !important; }
        .has-agency-light-color { color: var(--wp--preset--color--agency-light) !important; }
        .has-agency-light-background-color { background-color: var(--wp--preset--color--agency-light) !important; }

        /* Modern Contact Form 7 Styles */
        .wpcf7 {
            background-color: #ffffff;
            padding: 2.5rem;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(10, 37, 64, 0.08);
            max-width: 600px;
            margin: 0 auto;
        }

        .wpcf7 label {
            display: block;
            font-weight: 600;
            color: var(--wp--preset--color--agency-navy);
            margin-bottom: 0.5rem;
            font-size: 0.95rem;
        }

        .wpcf7 input[type="text"],
        .wpcf7 input[type="email"],
        .wpcf7 input[type="tel"],
        .wpcf7 textarea {
            width: 100%;
            padding: 0.9rem;
            border: 1px solid #d1d5db;
            border-radius: 6px;
            background-color: #f9fafb;
            font-size: 1rem;
            color: #374151;
            margin-bottom: 1.5rem;
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
            box-sizing: border-box;
        }

        .wpcf7 input[type="text"]:focus,
        .wpcf7 input[type="email"]:focus,
        .wpcf7 input[type="tel"]:focus,
        .wpcf7 textarea:focus {
            outline: none;
            border-color: var(--wp--preset--color--agency-purple);
            box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.15);
            background-color: #ffffff;
        }

        .wpcf7 textarea {
            min-height: 120px;
            resize: vertical;
        }

        .wpcf7-submit {
            width: 100%;
            font-size: 1.05rem !important;
            font-weight: 600 !important;
            padding: 1rem 1.5rem !important;
            margin-top: 0.5rem;
        }

        .wpcf7-not-valid-tip {
            color: var(--wp--preset--color--agency-orange) !important;
            font-size: 0.85rem;
            margin-top: -1.2rem;
            margin-bottom: 1.5rem;
            display: block;
        }
        
        .wpcf7 form.invalid .wpcf7-response-output,
        .wpcf7 form.unaccepted .wpcf7-response-output,
        .wpcf7 form.payment-required .wpcf7-response-output {
            border-color: var(--wp--preset--color--agency-orange) !important;
        }

        .wpcf7 form.sent .wpcf7-response-output {
            border-color: var(--wp--preset--color--agency-teal) !important;
        }
    </style>
    <?php
}, 100 );
