<?php
declare(strict_types=1);

namespace Help4BuilderSuite\Modules\TemplateLibrary;

use Help4BuilderSuite\Contracts\ModuleContract;
use Help4BuilderSuite\Support\AdminRequest;
use WP_Post;
use WP_Query;
use WP_REST_Request;
use WP_REST_Response;
use WP_Screen;

if (! defined('ABSPATH')) {
    exit;
}

final class Module implements ModuleContract
{
    /**
     * @var string[]
     */
    private const HIDDEN_STARTER_SEED_KEYS = [
        "starter-\x77\x6f\x6f\x63\x6f\x6d\x6d\x65\x72\x63\x65-support",
        'starter-store-plugin-support',
        '_legacy-hidden-starter-a' . 'cf-style-field-system',
    ];

    /**
     * @var array<string, string>
     */
    private const STARTER_SEED_KEY_ALIASES = [
        'starter-a' . 'cf-style-field-system' => 'starter-structured-field-system',
        'starter-siteshot-recent-work-gallery' => 'starter-website-snapshot-recent-work-gallery',
        'starter-siteshot-migration-visual-audit' => 'starter-website-snapshot-migration-visual-audit',
        'starter-siteshot-comparison-proof' => 'starter-website-snapshot-comparison-proof',
        'starter-siteshot-support-context' => 'starter-website-snapshot-support-context',
        'starter-page-template-siteshot-recent-work' => 'starter-page-template-website-snapshot-recent-work',
    ];

    private bool $renderingTemplate = false;
    private bool $contentTemplateInjected = false;
    /**
     * @var array<string, int>
     */
    private array $resolvedTemplateCache = [];

    public function key(): string
    {
        return 'template_library';
    }

    public function boot(): void
    {
        add_action('init', [$this, 'registerPostType']);
        add_action('admin_menu', [$this, 'registerAdminMenus']);
        add_action('add_meta_boxes', [$this, 'registerMetaBoxes']);
        add_action('save_post_h4_template', [$this, 'saveTemplateSpec']);
        add_action('admin_init', [$this, 'seedStarterTemplates']);
        if (defined('WP_CLI') && WP_CLI) {
            add_action('init', [$this, 'seedStarterTemplates'], 20);
        }
        add_action('admin_action_h4bs_template_quick_create', [$this, 'handleQuickCreateTemplate']);
        add_action('rest_api_init', [$this, 'registerRestRoutes']);
        add_action('current_screen', [$this, 'setupAdminMenuHighlight']);
        add_action('wp_body_open', [$this, 'renderAssignedHeaderTemplate'], 5);
        add_action('wp_footer', [$this, 'renderAssignedFooterTemplate'], 5);
        add_action('wp_footer', [$this, 'renderAssignedPopupTemplate'], 20);
        add_action('template_redirect', [$this, 'maybeRenderAssigned404Template'], 1);
        add_action('template_redirect', [$this, 'maybeRenderAssignedCollectionTemplate'], 20);
        add_filter('the_content', [$this, 'injectAssignedContentTemplate'], 8);
        add_filter('h4bs_has_assigned_template_role', [$this, 'hasAssignedTemplateRole'], 10, 2);
        add_filter('h4bs_builder_assigned_template_ids', [$this, 'builderAssignedTemplateIds']);
        add_filter('h4bs_builder_preview_template_slots', [$this, 'builderPreviewTemplateSlots'], 10, 4);
        add_shortcode('h4_template', [$this, 'renderTemplateShortcode']);
        add_shortcode('h4_template_library', [$this, 'renderTemplateLibraryShortcode']);
        add_shortcode('h4_icon_library', [$this, 'renderIconLibraryShortcode']);
        add_shortcode('h4_popup', [$this, 'renderPopupShortcode']);
    }

    public function hasAssignedTemplateRole(bool $value, string $role): bool
    {
        if (is_admin() || wp_doing_ajax() || is_feed() || $this->isBuilderDraftPreviewRequest()) {
            return $value;
        }

        $role = sanitize_key($role);
        if ($role === '') {
            return $value;
        }

        return $this->resolveAssignedTemplateId([$role]) > 0;
    }

    private function isBuilderDraftPreviewRequest(): bool
    {
        return AdminRequest::queryHasValue('h4bs_builder_draft_preview');
    }

    /**
     * @param array<int, int> $templateIds
     * @return array<int, int>
     */
    public function builderAssignedTemplateIds(array $templateIds): array
    {
        if (is_admin() || wp_doing_ajax() || is_feed() || $this->isBuilderDraftPreviewRequest()) {
            return $templateIds;
        }

        $resolved = array_values(array_filter(array_map('absint', $templateIds)));
        $append = static function (array &$items, int $templateId): void {
            if ($templateId > 0) {
                $items[] = $templateId;
            }
        };

        if (! $this->currentRequestUsesBuilderCanvasLayout()) {
            $append($resolved, $this->resolveAssignedTemplateId(['header']));
            $append($resolved, $this->resolveAssignedTemplateId(['footer']));
        }
        $append($resolved, $this->resolveAssignedTemplateId(['popup']));

        $contentRoles = $this->contentRolesForCurrentRequest();
        if ($contentRoles) {
            $append($resolved, $this->resolveAssignedTemplateId($contentRoles));
        }

        return array_values(array_unique(array_filter(array_map('absint', $resolved))));
    }

    public function registerPostType(): void
    {
        register_post_type(
            'h4_template',
            [
                'label'           => __('Builder Templates', 'help4-builder-suite'),
                'public'          => false,
                'show_ui'         => true,
                'show_in_rest'    => true,
                'menu_icon'       => 'dashicons-layout',
                'supports'        => ['title', 'editor', 'thumbnail', 'excerpt', 'revisions'],
                'show_in_menu'    => false,
                'capability_type' => 'post',
                'map_meta_cap'    => true,
            ]
        );
    }

    public function registerAdminMenus(): void
    {
        add_submenu_page(
            'h4bs-settings',
            __('Templates', 'help4-builder-suite'),
            __('Templates', 'help4-builder-suite'),
            'edit_pages',
            'edit.php?post_type=h4_template'
        );

        add_submenu_page(
            'h4bs-settings',
            __('Theme Builder', 'help4-builder-suite'),
            __('Theme Builder', 'help4-builder-suite'),
            'edit_pages',
            'h4bs-theme-builder',
            [$this, 'renderThemeBuilderScreen']
        );
    }

    public function registerBuilderTemplateShortcut(): void
    {
        // Deprecated intentionally: CPT already renders a single Templates submenu under Help4 Builder.
    }

    public function renderThemeBuilderScreen(): void
    {
        if (! current_user_can('edit_pages')) {
            return;
        }

        $templates = get_posts(
            [
                'post_type'      => 'h4_template',
                'post_status'    => ['publish', 'draft', 'private', 'future', 'pending'],
                'posts_per_page' => 200,
                'orderby'        => 'modified',
                'order'          => 'DESC',
            ]
        );
        ?>
        <div class="wrap h4bs-admin-wrap">
            <h1><?php esc_html_e('Help4 Theme Builder', 'help4-builder-suite'); ?></h1>
            <p><?php esc_html_e('Build global headers, footers, 404s, page shells, canvas landing pages, and popups with display conditions for pages, post types, and audience roles.', 'help4-builder-suite'); ?></p>
            <p>
                <a class="button button-primary" href="<?php echo esc_url($this->quickCreateUrl('header')); ?>"><?php esc_html_e('New Header Template', 'help4-builder-suite'); ?></a>
                <a class="button" href="<?php echo esc_url($this->quickCreateUrl('footer')); ?>"><?php esc_html_e('New Footer Template', 'help4-builder-suite'); ?></a>
                <a class="button" href="<?php echo esc_url($this->quickCreateUrl('404')); ?>"><?php esc_html_e('New 404 Template', 'help4-builder-suite'); ?></a>
                <a class="button" href="<?php echo esc_url($this->quickCreateUrl('page')); ?>"><?php esc_html_e('New Page Template', 'help4-builder-suite'); ?></a>
                <a class="button" href="<?php echo esc_url($this->quickCreateUrl('canvas_page')); ?>"><?php esc_html_e('New Canvas Page Template', 'help4-builder-suite'); ?></a>
                <a class="button" href="<?php echo esc_url($this->quickCreateUrl('popup')); ?>"><?php esc_html_e('New Popup Template', 'help4-builder-suite'); ?></a>
                <a class="button" href="<?php echo esc_url(admin_url('post-new.php?post_type=h4_template')); ?>"><?php esc_html_e('Blank Template', 'help4-builder-suite'); ?></a>
            </p>
            <div class="h4bs-admin-card-grid h4bs-theme-builder-paths">
                <div class="h4bs-admin-card">
                    <h2><?php esc_html_e('Global Parts', 'help4-builder-suite'); ?></h2>
                    <p><?php esc_html_e('Use headers and footers for sitewide navigation, calls to action, trust blocks, support links, and local/service proof.', 'help4-builder-suite'); ?></p>
                </div>
                <div class="h4bs-admin-card">
                    <h2><?php esc_html_e('Page Templates', 'help4-builder-suite'); ?></h2>
                    <p><?php esc_html_e('Use page, post, product, archive, search, and 404 roles when the layout should replace the main content area.', 'help4-builder-suite'); ?></p>
                </div>
                <div class="h4bs-admin-card">
                    <h2><?php esc_html_e('Canvas Pages', 'help4-builder-suite'); ?></h2>
                    <p><?php esc_html_e('Use Help4 Canvas when a page needs no global header or footer, like focused landing pages and campaign pages.', 'help4-builder-suite'); ?></p>
                </div>
            </div>
            <p class="description">
                <?php esc_html_e('Tip: open any template in Help4 Visual Builder, then use the Page tab to edit role/scope/include/exclude rules directly in the full-screen editor. Use the starter library for ready-made theme-part inspiration.', 'help4-builder-suite'); ?>
            </p>

            <table class="widefat striped">
                <thead>
                    <tr>
                        <th><?php esc_html_e('Template', 'help4-builder-suite'); ?></th>
                        <th><?php esc_html_e('Role', 'help4-builder-suite'); ?></th>
                        <th><?php esc_html_e('Scope', 'help4-builder-suite'); ?></th>
                        <th><?php esc_html_e('Include / Exclude', 'help4-builder-suite'); ?></th>
                        <th><?php esc_html_e('Priority', 'help4-builder-suite'); ?></th>
                        <th><?php esc_html_e('Actions', 'help4-builder-suite'); ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (! $templates) : ?>
                        <tr>
                            <td colspan="6"><?php esc_html_e('No templates yet. Create one using the buttons above.', 'help4-builder-suite'); ?></td>
                        </tr>
                    <?php endif; ?>
                    <?php foreach ($templates as $template) : ?>
                        <?php if (! $template instanceof WP_Post) { continue; } ?>
                        <?php
                        $templateId = (int) $template->ID;
                        $conditions = $this->templateConditions($templateId);
                        $roleLabel = $this->templateRoles()[$conditions['role']] ?? $conditions['role'];
                        $scopeLabel = $this->templateScopes()[$conditions['scope']] ?? $conditions['scope'];
                        ?>
                        <tr>
                            <td>
                                <strong><?php echo esc_html(get_the_title($templateId) ?: __('(no title)', 'help4-builder-suite')); ?></strong><br>
                                <small><?php echo esc_html((string) $template->post_status); ?></small>
                            </td>
                            <td><?php echo esc_html((string) $roleLabel); ?></td>
                            <td><?php echo esc_html((string) $scopeLabel); ?></td>
                            <td>
                                <small>
                                    <?php
                                    printf(
                                        /* translators: 1: include ids, 2: exclude ids */
                                        esc_html__('IDs include: %1$s | IDs exclude: %2$s', 'help4-builder-suite'),
                                        esc_html($this->displayList($conditions['include_ids'])),
                                        esc_html($this->displayList($conditions['exclude_ids']))
                                    );
                                    ?>
                                </small><br>
                                <small>
                                    <?php
                                    printf(
                                        /* translators: 1: include types, 2: exclude types */
                                        esc_html__('Types include: %1$s | Types exclude: %2$s', 'help4-builder-suite'),
                                        esc_html($this->displayList($conditions['include_types'])),
                                        esc_html($this->displayList($conditions['exclude_types']))
                                    );
                                    ?>
                                </small><br>
                                <small>
                                    <?php
                                    printf(
                                        /* translators: %s: user roles */
                                        esc_html__('Audience roles: %s', 'help4-builder-suite'),
                                        esc_html($this->displayList($conditions['user_roles']))
                                    );
                                    ?>
                                </small>
                            </td>
                            <td><?php echo esc_html((string) ($conditions['priority'] ?: 10)); ?></td>
                            <td>
                                <a class="button button-primary" href="<?php echo esc_url($this->builderActionUrl($templateId)); ?>">
                                    <?php esc_html_e('Edit in Builder', 'help4-builder-suite'); ?>
                                </a>
                                <a class="button" href="<?php echo esc_url(get_edit_post_link($templateId, '') ?: '#'); ?>">
                                    <?php esc_html_e('Edit Conditions', 'help4-builder-suite'); ?>
                                </a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php
    }

    public function handleQuickCreateTemplate(): void
    {
        if (! current_user_can('edit_pages')) {
            wp_die(esc_html__('You are not allowed to create templates.', 'help4-builder-suite'));
        }

        $role = AdminRequest::queryKey('role', 'general');
        if (! array_key_exists($role, $this->templateRoles())) {
            $role = 'general';
        }

        check_admin_referer('h4bs_template_quick_create_' . $role);

        $defaults = $this->quickCreateDefaults($role);
        $title = (string) $defaults['title'];

        $postId = wp_insert_post(
            [
                'post_type'   => 'h4_template',
                'post_status' => 'draft',
                'post_title'  => $title,
            ],
            true
        );

        if (is_wp_error($postId) || ! $postId) {
            wp_die(esc_html__('Unable to create template.', 'help4-builder-suite'));
        }

        $postId = (int) $postId;
        update_post_meta($postId, '_h4_template_role', $role);
        update_post_meta($postId, '_h4_template_scope', (string) $defaults['scope']);
        update_post_meta($postId, '_h4_template_include_types', (string) $defaults['include_types']);
        update_post_meta($postId, '_h4_template_priority', (string) $defaults['priority']);
        update_post_meta($postId, '_h4_builder_mode', 'help4');
        update_post_meta($postId, '_h4_builder_enabled', '1');
        update_post_meta($postId, '_h4_builder_page_layout', (string) $defaults['page_layout']);

        wp_safe_redirect($this->builderActionUrl($postId));
        exit;
    }

    public function registerMetaBoxes(): void
    {
        add_meta_box(
            'h4bs-template-spec',
            __('Help4 Template Spec (JSON)', 'help4-builder-suite'),
            [$this, 'renderTemplateSpecMetaBox'],
            'h4_template',
            'normal',
            'high'
        );

        add_meta_box(
            'h4bs-template-conditions',
            __('Template Conditions', 'help4-builder-suite'),
            [$this, 'renderTemplateConditionsMetaBox'],
            'h4_template',
            'side',
            'high'
        );
    }

    public function renderTemplateSpecMetaBox(WP_Post $post): void
    {
        wp_nonce_field('h4bs_template_spec', 'h4bs_template_spec_nonce');
        $raw = get_post_meta($post->ID, '_h4_template_spec', true);
        if (! is_string($raw) || $raw === '') {
            $raw = wp_json_encode(
                [
                    'version'  => '1.0',
                    'name'     => $post->post_title ?: 'Untitled Template',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => [],
                        'icons'  => [],
                    ],
                    'sections' => [],
                ],
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
            );
        }
        ?>
        <p>
            <?php esc_html_e('Designers can copy and paste this spec to version templates. Include section structure, image references, and settings.', 'help4-builder-suite'); ?>
        </p>
        <textarea
            name="h4_template_spec"
            rows="20"
            style="width:100%;font-family:Consolas,Menlo,monospace;"
        ><?php echo esc_textarea((string) $raw); ?></textarea>
        <?php
    }

    public function renderTemplateConditionsMetaBox(WP_Post $post): void
    {
        wp_nonce_field('h4bs_template_conditions', 'h4bs_template_conditions_nonce');

        $role = sanitize_key((string) get_post_meta($post->ID, '_h4_template_role', true));
        if ($role === '') {
            $role = 'general';
        }

        $scope = sanitize_key((string) get_post_meta($post->ID, '_h4_template_scope', true));
        if ($scope === '') {
            $scope = 'entire_site';
        }

        $includeIds = (string) get_post_meta($post->ID, '_h4_template_include_ids', true);
        $excludeIds = (string) get_post_meta($post->ID, '_h4_template_exclude_ids', true);
        $includeTypes = (string) get_post_meta($post->ID, '_h4_template_include_types', true);
        $excludeTypes = (string) get_post_meta($post->ID, '_h4_template_exclude_types', true);
        $userRoles = (string) get_post_meta($post->ID, '_h4_template_user_roles', true);
        $priority = (int) get_post_meta($post->ID, '_h4_template_priority', true);
        if ($priority === 0) {
            $priority = 10;
        }
        ?>
        <p>
            <label for="h4_template_role"><strong><?php esc_html_e('Template Role', 'help4-builder-suite'); ?></strong></label><br>
            <select id="h4_template_role" name="h4_template_role" class="widefat">
                <?php foreach ($this->templateRoles() as $key => $label) : ?>
                    <option value="<?php echo esc_attr($key); ?>" <?php selected($role, $key); ?>>
                        <?php echo esc_html($label); ?>
                    </option>
                <?php endforeach; ?>
            </select>
        </p>
        <p>
            <label for="h4_template_scope"><strong><?php esc_html_e('Display Scope', 'help4-builder-suite'); ?></strong></label><br>
            <select id="h4_template_scope" name="h4_template_scope" class="widefat">
                <?php foreach ($this->templateScopes() as $key => $label) : ?>
                    <option value="<?php echo esc_attr($key); ?>" <?php selected($scope, $key); ?>>
                        <?php echo esc_html($label); ?>
                    </option>
                <?php endforeach; ?>
            </select>
        </p>
        <p>
            <label for="h4_template_include_ids"><strong><?php esc_html_e('Include IDs (optional)', 'help4-builder-suite'); ?></strong></label><br>
            <input id="h4_template_include_ids" type="text" class="widefat code" name="h4_template_include_ids" value="<?php echo esc_attr($includeIds); ?>" placeholder="12,45,99">
        </p>
        <p>
            <label for="h4_template_exclude_ids"><strong><?php esc_html_e('Exclude IDs (optional)', 'help4-builder-suite'); ?></strong></label><br>
            <input id="h4_template_exclude_ids" type="text" class="widefat code" name="h4_template_exclude_ids" value="<?php echo esc_attr($excludeIds); ?>" placeholder="18,22">
        </p>
        <p>
            <label for="h4_template_include_types"><strong><?php esc_html_e('Include Post Types (optional)', 'help4-builder-suite'); ?></strong></label><br>
            <input id="h4_template_include_types" type="text" class="widefat code" name="h4_template_include_types" value="<?php echo esc_attr($includeTypes); ?>" placeholder="page,post,product">
        </p>
        <p>
            <label for="h4_template_exclude_types"><strong><?php esc_html_e('Exclude Post Types (optional)', 'help4-builder-suite'); ?></strong></label><br>
            <input id="h4_template_exclude_types" type="text" class="widefat code" name="h4_template_exclude_types" value="<?php echo esc_attr($excludeTypes); ?>" placeholder="landing_page">
        </p>
        <p>
            <label for="h4_template_user_roles"><strong><?php esc_html_e('User Roles (optional)', 'help4-builder-suite'); ?></strong></label><br>
            <input id="h4_template_user_roles" type="text" class="widefat code" name="h4_template_user_roles" value="<?php echo esc_attr($userRoles); ?>" placeholder="guest,logged_in,subscriber,customer">
        </p>
        <p>
            <label for="h4_template_priority"><strong><?php esc_html_e('Priority', 'help4-builder-suite'); ?></strong></label><br>
            <input id="h4_template_priority" type="number" class="small-text" name="h4_template_priority" value="<?php echo esc_attr((string) $priority); ?>" min="-100" max="999">
        </p>
        <p class="description">
            <?php esc_html_e('Higher priority wins when multiple templates match the current request.', 'help4-builder-suite'); ?>
        </p>
        <?php
    }

    public function saveTemplateSpec(int $postId): void
    {
        if (! isset($_POST['h4bs_template_spec_nonce'], $_POST['h4bs_template_conditions_nonce'])) {
            return;
        }

        if (! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['h4bs_template_spec_nonce'])), 'h4bs_template_spec')) {
            return;
        }
        if (! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['h4bs_template_conditions_nonce'])), 'h4bs_template_conditions')) {
            return;
        }

        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return;
        }

        if (! current_user_can('edit_post', $postId)) {
            return;
        }

        $post = wp_unslash($_POST);
        $raw = isset($post['h4_template_spec']) ? sanitize_textarea_field($post['h4_template_spec']) : '';
        $spec = $this->normalizeSpec($raw);
        if ($spec === null) {
            return;
        }

        update_post_meta(
            $postId,
            '_h4_template_spec',
            wp_json_encode($spec, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
        );

        $this->saveTemplateConditions($postId, $post);
    }

    public function registerRestRoutes(): void
    {
        register_rest_route(
            'h4bs/v1',
            '/templates',
            [
                'methods'             => 'GET',
                'callback'            => [$this, 'listTemplates'],
                'permission_callback' => static fn (): bool => current_user_can('edit_pages'),
            ]
        );

        register_rest_route(
            'h4bs/v1',
            '/templates/(?P<id>\d+)/export',
            [
                'methods'             => 'GET',
                'callback'            => [$this, 'exportTemplate'],
                'permission_callback' => static fn (WP_REST_Request $request): bool => current_user_can('edit_post', (int) $request->get_param('id')),
            ]
        );

        register_rest_route(
            'h4bs/v1',
            '/starter-templates/(?P<id>\d+)/export',
            [
                'methods'             => 'GET',
                'callback'            => [$this, 'exportStarterTemplate'],
                'permission_callback' => '__return_true',
            ]
        );

        register_rest_route(
            'h4bs/v1',
            '/templates/import',
            [
                'methods'             => 'POST',
                'callback'            => [$this, 'importTemplate'],
                'permission_callback' => static fn (): bool => current_user_can('edit_pages'),
            ]
        );

        register_rest_route(
            'h4bs/v1',
            '/starter-templates/seed',
            [
                'methods'             => 'POST',
                'callback'            => [$this, 'seedStarterTemplatesRest'],
                'permission_callback' => static fn (): bool => current_user_can('manage_options'),
            ]
        );
    }

    public function listTemplates(WP_REST_Request $request): WP_REST_Response
    {
        $limit = max(1, min(50, (int) $request->get_param('limit')));
        $query = new WP_Query(
            [
                'post_type'      => 'h4_template',
                'posts_per_page' => $limit,
                'post_status'    => ['publish', 'draft'],
            ]
        );

        $templates = [];
        foreach ($query->posts as $post) {
            if (! $post instanceof WP_Post) {
                continue;
            }

            $templates[] = [
                'id'       => $post->ID,
                'title'    => $post->post_title,
                'status'   => $post->post_status,
                'modified' => $post->post_modified_gmt,
                'spec'     => json_decode((string) get_post_meta($post->ID, '_h4_template_spec', true), true),
                'conditions' => $this->templateConditions($post->ID),
            ];
        }

        return new WP_REST_Response(['items' => $templates]);
    }

    public function exportTemplate(WP_REST_Request $request): WP_REST_Response
    {
        $id   = (int) $request->get_param('id');
        $post = get_post($id);
        if (! $post || $post->post_type !== 'h4_template') {
            return new WP_REST_Response(['message' => 'Template not found'], 404);
        }

        $spec = json_decode((string) get_post_meta($id, '_h4_template_spec', true), true);
        if (! is_array($spec)) {
            $spec = [];
        }

        return new WP_REST_Response(
            [
                'id'      => $id,
                'title'   => $post->post_title,
                'content' => $post->post_content,
                'spec'    => $spec,
                'conditions' => $this->templateConditions($id),
            ]
        );
    }

    public function exportStarterTemplate(WP_REST_Request $request): WP_REST_Response
    {
        $id   = (int) $request->get_param('id');
        $post = get_post($id);
        if (! $post || $post->post_type !== 'h4_template') {
            return new WP_REST_Response(['message' => 'Starter template not found'], 404);
        }

        $seedKey = (string) get_post_meta($id, '_h4_template_seed_key', true);
        if ($seedKey === '' || in_array($seedKey, self::HIDDEN_STARTER_SEED_KEYS, true)) {
            return new WP_REST_Response(['message' => 'Starter template not found'], 404);
        }

        $spec = json_decode((string) get_post_meta($id, '_h4_template_spec', true), true);
        if (! is_array($spec)) {
            $spec = [];
        }

        return new WP_REST_Response(
            [
                'id'    => $id,
                'title' => $post->post_title,
                'spec'  => $spec,
            ]
        );
    }

    public function importTemplate(WP_REST_Request $request): WP_REST_Response
    {
        $params = $request->get_json_params();
        if (! is_array($params)) {
            $params = $request->get_params();
        }

        $title = sanitize_text_field((string) ($params['title'] ?? 'Imported Template'));
        $spec  = $this->normalizeSpec($params['spec'] ?? []);
        if ($spec === null) {
            return new WP_REST_Response(['message' => 'Invalid template spec JSON'], 422);
        }

        $content = wp_kses_post((string) ($params['content'] ?? ''));
        $postId  = wp_insert_post(
            [
                'post_type'    => 'h4_template',
                'post_status'  => 'draft',
                'post_title'   => $title,
                'post_content' => $content,
            ],
            true
        );

        if (is_wp_error($postId)) {
            return new WP_REST_Response(['message' => $postId->get_error_message()], 500);
        }

        update_post_meta(
            (int) $postId,
            '_h4_template_spec',
            wp_json_encode($spec, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
        );
        if (is_array($params['conditions'] ?? null)) {
            $this->saveTemplateConditions((int) $postId, (array) $params['conditions']);
        }

        return new WP_REST_Response(['id' => (int) $postId, 'status' => 'draft'], 201);
    }

    public function seedStarterTemplatesRest(): WP_REST_Response
    {
        $before = $this->starterTemplateSeedCount();
        delete_option('h4bs_template_seed_lock');
        $this->seedStarterTemplates();
        $after = $this->starterTemplateSeedCount();

        return new WP_REST_Response(
            [
                'seed_version' => (string) get_option('h4bs_template_seed_version', ''),
                'starter_count' => $after,
                'created' => max(0, $after - $before),
            ]
        );
    }

    /**
     * @param array<string, mixed> $atts
     */
    public function renderTemplateLibraryShortcode(array $atts): string
    {
        $atts  = shortcode_atts(['limit' => 140], $atts, 'h4_template_library');
        $limit = max(1, min(160, (int) $atts['limit']));

        // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Template library shortcode intentionally lists only seeded Help4 templates.
        $items = get_posts(
            [
                'post_type'      => 'h4_template',
                'posts_per_page' => $limit,
                'post_status'    => ['publish', 'draft'],
                'orderby'        => 'title',
                'order'          => 'ASC',
                'meta_query'     => [
                    'relation' => 'AND',
                    [
                        'key'     => '_h4_template_seed_key',
                        'compare' => 'EXISTS',
                    ],
                    [
                        'key'     => '_h4_template_seed_key',
                        'value'   => self::HIDDEN_STARTER_SEED_KEYS,
                        'compare' => 'NOT IN',
                    ],
                ],
            ]
        );
        // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_query

        if (! $items) {
            return '<p>No Help4 templates are available yet.</p>';
        }

        $cards = [];
        foreach ($items as $item) {
            if (! $item instanceof WP_Post) {
                continue;
            }

            $cards[] = $this->templateLibraryCard($item, (string) get_post_meta($item->ID, '_h4_template_spec', true));
        }

        if (! $cards) {
            return '<p>No Help4 templates are available yet.</p>';
        }

        $categories = [];
        foreach ($cards as $card) {
            $categories[(string) $card['category']] = (string) $card['category'];
        }
        ksort($categories);

        $sectionTotal = array_sum(array_map(static fn (array $card): int => (int) $card['section_count'], $cards));
        $iconTotal = array_sum(array_map(static fn (array $card): int => (int) $card['icon_count'], $cards));

        ob_start();
        ?>
        <section class="h4bs-template-browser" data-h4bs-template-browser>
            <div class="h4bs-template-browser__head">
                <div>
                    <h2><?php esc_html_e('Starter Template Library', 'help4-builder-suite'); ?></h2>
                    <p><?php esc_html_e('Plain-language starters for headers, footers, 404s, page shells, canvas landing pages, service sites, support pages, SEO, commerce, subscriptions, payment routing, builder onboarding, and launch work.', 'help4-builder-suite'); ?></p>
                    <div class="h4bs-template-browser__stats" aria-label="<?php esc_attr_e('Starter library summary', 'help4-builder-suite'); ?>">
                        <span><strong><?php echo esc_html((string) count($cards)); ?></strong> <?php esc_html_e('starters', 'help4-builder-suite'); ?></span>
                        <span><strong><?php echo esc_html((string) $sectionTotal); ?></strong> <?php esc_html_e('sections mapped', 'help4-builder-suite'); ?></span>
                        <span><strong><?php echo esc_html((string) $iconTotal); ?></strong> <?php esc_html_e('icon hooks', 'help4-builder-suite'); ?></span>
                    </div>
                </div>
                <label class="h4bs-template-search">
                    <span><?php esc_html_e('Search templates', 'help4-builder-suite'); ?></span>
                    <input type="search" placeholder="<?php esc_attr_e('Subscriptions, catalog, support, local...', 'help4-builder-suite'); ?>" data-h4bs-template-search>
                </label>
            </div>
            <div class="h4bs-template-filters" role="list" aria-label="<?php esc_attr_e('Template categories', 'help4-builder-suite'); ?>">
                <button class="is-active" type="button" data-h4bs-template-filter="all" role="listitem"><?php esc_html_e('All', 'help4-builder-suite'); ?></button>
                <?php foreach ($categories as $category) : ?>
                    <button type="button" data-h4bs-template-filter="<?php echo esc_attr(sanitize_title($category)); ?>" role="listitem"><?php echo esc_html($category); ?></button>
                <?php endforeach; ?>
            </div>
            <div class="h4bs-template-library">
                <?php foreach ($cards as $card) : ?>
                <article
                    class="h4bs-template-card"
                    data-h4bs-template-card
                    data-category="<?php echo esc_attr(sanitize_title((string) $card['category'])); ?>"
                    data-search="<?php echo esc_attr((string) $card['search']); ?>"
                >
                    <div class="h4bs-template-card__preview h4bs-template-card__preview--<?php echo esc_attr((string) $card['preview_type']); ?>" aria-hidden="true">
                        <span class="h4bs-template-card__screen"></span>
                        <?php foreach ($card['preview_rows'] as $row) : ?>
                            <span class="h4bs-template-card__line h4bs-template-card__line--<?php echo esc_attr((string) $row); ?>"></span>
                        <?php endforeach; ?>
                    </div>
                    <div class="h4bs-template-card__body">
                        <div class="h4bs-template-card__topline">
                            <span class="h4bs-template-card__category"><?php echo esc_html((string) $card['category']); ?></span>
                            <span><?php echo esc_html((string) $card['version']); ?></span>
                        </div>
                        <h3><?php echo esc_html((string) $card['title']); ?></h3>
                        <p><?php echo esc_html((string) $card['excerpt']); ?></p>
                        <p class="h4bs-template-card__fit"><strong><?php esc_html_e('Best for:', 'help4-builder-suite'); ?></strong> <?php echo esc_html((string) $card['fit']); ?></p>
                        <div class="h4bs-template-card__path">
                            <p><strong><?php esc_html_e('Use when:', 'help4-builder-suite'); ?></strong> <?php echo esc_html((string) $card['use_case']); ?></p>
                            <p><strong><?php esc_html_e('Next step:', 'help4-builder-suite'); ?></strong> <?php echo esc_html((string) $card['next_step']); ?></p>
                        </div>
                        <div class="h4bs-template-card__meta" aria-label="<?php esc_attr_e('Template details', 'help4-builder-suite'); ?>">
                            <span><?php echo esc_html((string) $card['section_count']); ?> <?php esc_html_e('sections', 'help4-builder-suite'); ?></span>
                            <span><?php echo esc_html((string) $card['icon_count']); ?> <?php esc_html_e('icons', 'help4-builder-suite'); ?></span>
                            <span><?php echo esc_html((string) $card['viewport']); ?></span>
                        </div>
                        <?php if (! empty($card['icon_labels'])) : ?>
                            <div class="h4bs-template-card__icons" aria-label="<?php esc_attr_e('Included icon defaults', 'help4-builder-suite'); ?>">
                                <?php foreach ($card['icon_labels'] as $iconLabel) : ?>
                                    <span><?php echo esc_html((string) $iconLabel); ?></span>
                                <?php endforeach; ?>
                            </div>
                        <?php endif; ?>
                        <?php if (! empty($card['components'])) : ?>
                            <details class="h4bs-template-card__details">
                                <summary><?php esc_html_e('Spec outline', 'help4-builder-suite'); ?></summary>
                                <ul>
                                    <?php foreach ($card['components'] as $component) : ?>
                                        <li><?php echo esc_html((string) $component); ?></li>
                                    <?php endforeach; ?>
                                </ul>
                            </details>
                        <?php endif; ?>
                    </div>
                    <button
                        class="h4bs-copy-template"
                        data-spec-url="<?php echo esc_url((string) $card['spec_url']); ?>"
                        data-spec-title="<?php echo esc_attr((string) $card['title']); ?>"
                        type="button"
                    >
                        <?php esc_html_e('Copy Starter Spec', 'help4-builder-suite'); ?>
                    </button>
                </article>
            <?php endforeach; ?>
            </div>
            <p class="h4bs-template-empty" hidden data-h4bs-template-empty><?php esc_html_e('No starter templates match that filter.', 'help4-builder-suite'); ?></p>
        </section>
        <script>
            (function () {
                const browsers = document.querySelectorAll('[data-h4bs-template-browser]');
                browsers.forEach(function (browser) {
                    const cards = Array.from(browser.querySelectorAll('[data-h4bs-template-card]'));
                    const search = browser.querySelector('[data-h4bs-template-search]');
                    const filters = Array.from(browser.querySelectorAll('[data-h4bs-template-filter]'));
                    const empty = browser.querySelector('[data-h4bs-template-empty]');
                    let active = 'all';

                    const copyText = function (text) {
                        if (navigator.clipboard && navigator.clipboard.writeText) {
                            return navigator.clipboard.writeText(text);
                        }
                        const textarea = document.createElement('textarea');
                        textarea.value = text;
                        textarea.setAttribute('readonly', 'readonly');
                        textarea.style.position = 'fixed';
                        textarea.style.left = '-9999px';
                        document.body.appendChild(textarea);
                        textarea.select();
                        document.execCommand('copy');
                        document.body.removeChild(textarea);
                        return Promise.resolve();
                    };

                    const copyTemplateSpec = function (button) {
                        const cached = button.getAttribute('data-spec-cache');
                        if (cached) {
                            return copyText(cached);
                        }

                        const url = button.getAttribute('data-spec-url') || '';
                        if (! url) {
                            return Promise.reject(new Error('Missing starter spec URL.'));
                        }

                        button.disabled = true;
                        button.textContent = 'Loading...';

                        return fetch(url, { credentials: 'same-origin' })
                            .then(function (response) {
                                if (! response.ok) {
                                    throw new Error('Starter spec unavailable.');
                                }
                                return response.json();
                            })
                            .then(function (json) {
                                const spec = JSON.stringify((json && json.spec) || {}, null, 2);
                                button.setAttribute('data-spec-cache', spec);
                                return copyText(spec);
                            })
                            .finally(function () {
                                button.disabled = false;
                            });
                    };

                    const applyFilters = function () {
                        const term = search ? search.value.trim().toLowerCase() : '';
                        let visible = 0;
                        cards.forEach(function (card) {
                            const matchesCategory = active === 'all' || card.dataset.category === active;
                            const matchesSearch = term === '' || (card.dataset.search || '').includes(term);
                            const show = matchesCategory && matchesSearch;
                            card.hidden = ! show;
                            if (show) {
                                visible += 1;
                            }
                        });
                        if (empty) {
                            empty.hidden = visible > 0;
                        }
                    };

                    filters.forEach(function (button) {
                        button.addEventListener('click', function () {
                            active = button.getAttribute('data-h4bs-template-filter') || 'all';
                            filters.forEach(function (item) {
                                item.classList.toggle('is-active', item === button);
                            });
                            applyFilters();
                        });
                    });

                    if (search) {
                        search.addEventListener('input', applyFilters);
                    }

                    browser.addEventListener('click', function (event) {
                        const button = event.target instanceof Element ? event.target.closest('.h4bs-copy-template') : null;
                        if (! button) {
                            return;
                        }
                        const original = button.textContent;
                        copyTemplateSpec(button).then(function () {
                            button.textContent = 'Copied';
                            window.setTimeout(function () {
                                button.textContent = original || 'Copy Starter Spec';
                            }, 1600);
                        }).catch(function () {
                            button.textContent = 'Try Again';
                            window.setTimeout(function () {
                                button.textContent = original || 'Copy Starter Spec';
                            }, 1600);
                        });
                    });
                });
            }());
        </script>
        <?php
        return (string) ob_get_clean();
    }

    /**
     * @param array<string, mixed> $atts
     */
    public function renderIconLibraryShortcode(array $atts): string
    {
        $atts = shortcode_atts(['limit' => 260], $atts, 'h4_icon_library');
        $limit = max(1, min(260, (int) $atts['limit']));
        $icons = $this->defaultIconLibraryItems($limit);

        if ($icons === []) {
            return '<p>No Help4 default icons are available yet.</p>';
        }

        $categories = [];
        foreach ($icons as $icon) {
            $categories[(string) $icon['category']] = (string) $icon['category'];
        }
        ksort($categories);

        ob_start();
        ?>
        <section class="h4bs-icon-browser" data-h4bs-icon-browser>
            <div class="h4bs-icon-browser__head">
                <div>
                    <h2><?php esc_html_e('Default Icon Library', 'help4-builder-suite'); ?></h2>
                    <p><?php esc_html_e('Bundled SVG icons for builder setup, commerce, support, proof, AI image planning, launch, forms, documentation, security, performance, and update pages.', 'help4-builder-suite'); ?></p>
                    <div class="h4bs-icon-browser__stats" aria-label="<?php esc_attr_e('Icon library summary', 'help4-builder-suite'); ?>">
                        <span><strong><?php echo esc_html((string) count($icons)); ?></strong> <?php esc_html_e('icons shown', 'help4-builder-suite'); ?></span>
                        <span><strong><?php echo esc_html((string) count($categories)); ?></strong> <?php esc_html_e('categories', 'help4-builder-suite'); ?></span>
                    </div>
                </div>
                <label class="h4bs-icon-search">
                    <span><?php esc_html_e('Search icons', 'help4-builder-suite'); ?></span>
                    <input type="search" placeholder="<?php esc_attr_e('Checkout, support, launch, proof...', 'help4-builder-suite'); ?>" data-h4bs-icon-search>
                </label>
            </div>
            <div class="h4bs-icon-filters" role="list" aria-label="<?php esc_attr_e('Icon categories', 'help4-builder-suite'); ?>">
                <button class="is-active" type="button" data-h4bs-icon-filter="all" role="listitem"><?php esc_html_e('All', 'help4-builder-suite'); ?></button>
                <?php foreach ($categories as $category) : ?>
                    <button type="button" data-h4bs-icon-filter="<?php echo esc_attr(sanitize_title($category)); ?>" role="listitem"><?php echo esc_html($category); ?></button>
                <?php endforeach; ?>
            </div>
            <div class="h4bs-icon-library">
                <?php foreach ($icons as $icon) : ?>
                    <article
                        class="h4bs-icon-card"
                        data-h4bs-icon-card
                        data-category="<?php echo esc_attr(sanitize_title((string) $icon['category'])); ?>"
                        data-search="<?php echo esc_attr((string) $icon['search']); ?>"
                    >
                        <div class="h4bs-icon-card__art">
                            <?php /* translators: %s: Icon label. */ ?>
                            <img src="<?php echo esc_url((string) $icon['url']); ?>" alt="<?php echo esc_attr(sprintf(__('%s icon', 'help4-builder-suite'), (string) $icon['label'])); ?>" loading="lazy" decoding="async">
                        </div>
                        <div class="h4bs-icon-card__body">
                            <span class="h4bs-icon-card__category"><?php echo esc_html((string) $icon['category']); ?></span>
                            <h3><?php echo esc_html((string) $icon['label']); ?></h3>
                            <code><?php echo esc_html((string) $icon['slug']); ?></code>
                        </div>
                        <button class="h4bs-copy-icon" data-icon="<?php echo esc_attr((string) $icon['slug']); ?>" type="button">
                            <?php esc_html_e('Copy Slug', 'help4-builder-suite'); ?>
                        </button>
                    </article>
                <?php endforeach; ?>
            </div>
            <p class="h4bs-icon-empty" hidden data-h4bs-icon-empty><?php esc_html_e('No default icons match that filter.', 'help4-builder-suite'); ?></p>
        </section>
        <script>
            (function () {
                const browsers = document.querySelectorAll('[data-h4bs-icon-browser]');
                browsers.forEach(function (browser) {
                    const cards = Array.from(browser.querySelectorAll('[data-h4bs-icon-card]'));
                    const search = browser.querySelector('[data-h4bs-icon-search]');
                    const filters = Array.from(browser.querySelectorAll('[data-h4bs-icon-filter]'));
                    const empty = browser.querySelector('[data-h4bs-icon-empty]');
                    let active = 'all';

                    const copyText = function (text) {
                        if (navigator.clipboard && navigator.clipboard.writeText) {
                            return navigator.clipboard.writeText(text);
                        }
                        const textarea = document.createElement('textarea');
                        textarea.value = text;
                        textarea.setAttribute('readonly', 'readonly');
                        textarea.style.position = 'fixed';
                        textarea.style.left = '-9999px';
                        document.body.appendChild(textarea);
                        textarea.select();
                        document.execCommand('copy');
                        document.body.removeChild(textarea);
                        return Promise.resolve();
                    };

                    const applyFilters = function () {
                        const term = search ? search.value.trim().toLowerCase() : '';
                        let visible = 0;
                        cards.forEach(function (card) {
                            const matchesCategory = active === 'all' || card.dataset.category === active;
                            const matchesSearch = term === '' || (card.dataset.search || '').includes(term);
                            const show = matchesCategory && matchesSearch;
                            card.hidden = ! show;
                            if (show) {
                                visible += 1;
                            }
                        });
                        if (empty) {
                            empty.hidden = visible > 0;
                        }
                    };

                    filters.forEach(function (button) {
                        button.addEventListener('click', function () {
                            active = button.getAttribute('data-h4bs-icon-filter') || 'all';
                            filters.forEach(function (item) {
                                item.classList.toggle('is-active', item === button);
                            });
                            applyFilters();
                        });
                    });

                    if (search) {
                        search.addEventListener('input', applyFilters);
                    }

                    browser.addEventListener('click', function (event) {
                        const button = event.target instanceof Element ? event.target.closest('.h4bs-copy-icon') : null;
                        if (! button) {
                            return;
                        }
                        const original = button.textContent;
                        copyText(button.getAttribute('data-icon') || '').then(function () {
                            button.textContent = 'Copied';
                            window.setTimeout(function () {
                                button.textContent = original || 'Copy Slug';
                            }, 1600);
                        });
                    });
                });
            }());
        </script>
        <?php
        return (string) ob_get_clean();
    }

    /**
     * @return array<int, array{slug:string, label:string, category:string, url:string, search:string}>
     */
    private function defaultIconLibraryItems(int $limit): array
    {
        $manifest = H4BS_PATH . 'assets/icons/defaults/icons.json';
        if (! is_readable($manifest)) {
            return [];
        }

        $decoded = json_decode((string) file_get_contents($manifest), true);
        if (! is_array($decoded)) {
            return [];
        }

        $items = [];
        foreach ($decoded as $entry) {
            if (! is_array($entry)) {
                continue;
            }

            $slug = sanitize_title((string) ($entry['slug'] ?? ''));
            if ($slug === '') {
                continue;
            }

            $file = H4BS_PATH . 'assets/icons/defaults/' . $slug . '.svg';
            if (! is_readable($file)) {
                continue;
            }

            $label = sanitize_text_field((string) ($entry['label'] ?? $this->templateLibraryIconLabel($slug)));
            $category = sanitize_text_field((string) ($entry['category'] ?? __('General', 'help4-builder-suite')));
            if ($category === '') {
                $category = __('General', 'help4-builder-suite');
            }

            $search = strtolower($slug . ' ' . $label . ' ' . $category . ' ' . str_replace(['-', '_'], ' ', $slug));
            $items[] = [
                'slug'     => $slug,
                'label'    => $label !== '' ? $label : $this->templateLibraryIconLabel($slug),
                'category' => $category,
                'url'      => H4BS_URL . 'assets/icons/defaults/' . $slug . '.svg',
                'search'   => $search,
            ];

            if (count($items) >= $limit) {
                break;
            }
        }

        return $items;
    }

    /**
     * @return array{
     *     title:string,
     *     excerpt:string,
     *     category:string,
     *     version:string,
     *     viewport:string,
     *     section_count:int,
     *     icon_count:int,
     *     components:array<int, string>,
     *     icon_labels:array<int, string>,
     *     fit:string,
     *     use_case:string,
     *     next_step:string,
     *     preview_type:string,
     *     preview_rows:array<int, string>,
     *     search:string,
     *     spec_url:string
     * }
     */
    private function templateLibraryCard(WP_Post $item, string $spec): array
    {
        $decoded = json_decode($spec, true);
        if (! is_array($decoded)) {
            $decoded = [];
        }

        $assets = is_array($decoded['assets'] ?? null) ? (array) $decoded['assets'] : [];
        $icons = is_array($assets['icons'] ?? null) ? (array) $assets['icons'] : [];
        $sections = is_array($decoded['sections'] ?? null) ? (array) $decoded['sections'] : [];
        $templateRole = sanitize_key((string) ($decoded['template_role'] ?? ''));
        $templateUsage = sanitize_key((string) ($decoded['template_usage'] ?? ''));
        $components = [];
        $componentSearch = [];

        foreach ($sections as $section) {
            if (! is_array($section)) {
                continue;
            }
            $label = sanitize_text_field((string) ($section['component'] ?? $section['id'] ?? 'section'));
            if ($label === '') {
                continue;
            }
            $components[] = ucwords(str_replace(['-', '_'], ' ', $label));
            $componentSearch[] = $label;
        }

        $category = $this->templateLibraryCategory((string) $item->post_title, $components, $icons, $templateRole, $templateUsage);
        $iconLabels = array_slice(array_map([$this, 'templateLibraryIconLabel'], array_map('strval', $icons)), 0, 4);
        $excerpt = trim((string) $item->post_excerpt);
        if ($excerpt === '') {
            $excerpt = wp_trim_words($item->post_content, 22);
        }

        $previewType = $this->templateLibraryPreviewType((string) $item->post_title, $components, $icons, $templateRole, $templateUsage);
        $previewRows = ['hero', 'wide', 'short', 'split'];
        $sectionCount = count($sections);
        if ($sectionCount <= 2) {
            $previewRows = ['hero', 'wide', 'short'];
        } elseif ($sectionCount >= 4) {
            $previewRows = ['hero', 'split', 'wide', 'short'];
        }

        $search = strtolower(
            implode(
                ' ',
                array_filter(
                    [
                        (string) $item->post_title,
                        $excerpt,
                        $category,
                        $templateRole,
                        $templateUsage,
                        implode(' ', $components),
                        implode(' ', $iconLabels),
                        implode(' ', array_map('strval', $icons)),
                        implode(' ', $componentSearch),
                    ]
                )
            )
        );

        return [
            'title'         => (string) $item->post_title,
            'excerpt'       => (string) $excerpt,
            'category'      => $category,
            'version'       => sanitize_text_field((string) ($decoded['version'] ?? '1.0')),
            'viewport'      => sanitize_text_field((string) ($decoded['viewport'] ?? 'responsive')),
            'section_count' => $sectionCount,
            'icon_count'    => count($icons),
            'components'    => array_slice($components, 0, 5),
            'icon_labels'   => $iconLabels,
            'fit'           => $this->templateLibraryFit((string) $item->post_title, $category, $components, $icons, $templateRole, $templateUsage),
            'use_case'      => $this->templateLibraryUseCase((string) $item->post_title, $category, $components, $icons, $templateRole, $templateUsage),
            'next_step'     => $this->templateLibraryNextStep((string) $item->post_title, $category, $components, $icons, $templateRole, $templateUsage),
            'preview_type'  => $previewType,
            'preview_rows'  => $previewRows,
            'search'        => $search,
            'spec_url'      => rest_url(sprintf('h4bs/v1/starter-templates/%d/export', (int) $item->ID)),
        ];
    }

    private function templateLibraryIconLabel(string $slug): string
    {
        $label = trim(str_replace(['-', '_'], ' ', $slug));
        return $label !== '' ? ucwords($label) : __('Template Asset', 'help4-builder-suite');
    }

    /**
     * @param array<int, string> $components
     * @param array<int, mixed> $icons
     */
    private function templateLibraryPreviewType(string $title, array $components, array $icons, string $templateRole = '', string $templateUsage = ''): string
    {
        $haystack = strtolower($title . ' ' . $templateRole . ' ' . $templateUsage . ' ' . implode(' ', $components) . ' ' . implode(' ', array_map('strval', $icons)));

        if (preg_match('/header|navigation|nav|mega-menu|sticky/', $haystack) === 1) {
            return 'header';
        }
        if (preg_match('/footer|legal|newsletter/', $haystack) === 1) {
            return 'footer';
        }
        if (preg_match('/404|not-found|not found/', $haystack) === 1) {
            return '404';
        }
        if (preg_match('/canvas|no-header|no header|landing-template|landing page/', $haystack) === 1) {
            return 'canvas';
        }
        if (preg_match('/theme-kit|theme kit|global parts|site kit/', $haystack) === 1) {
            return 'kit';
        }
        if (preg_match('/page-shell|page shell|content-template|article|tutorial|single/', $haystack) === 1) {
            return 'page';
        }

        return 'default';
    }

    /**
     * @param array<int, string> $components
     * @param array<int, mixed> $icons
     */
    private function templateLibraryFit(string $title, string $category, array $components, array $icons, string $templateRole = '', string $templateUsage = ''): string
    {
        $haystack = strtolower($title . ' ' . $category . ' ' . $templateRole . ' ' . $templateUsage . ' ' . implode(' ', $components) . ' ' . implode(' ', array_map('strval', $icons)));

        if (preg_match('/header|navigation|nav|mega-menu|sticky/', $haystack) === 1) {
            return __('global navigation, phone/contact bars, primary CTAs, service menus, and first-click trust on every page.', 'help4-builder-suite');
        }
        if (preg_match('/footer|legal|newsletter/', $haystack) === 1) {
            return __('sitewide closing sections, support links, policy links, local proof, newsletter CTAs, and final conversion paths.', 'help4-builder-suite');
        }
        if (preg_match('/404|not-found|not found/', $haystack) === 1) {
            return __('missing pages that should recover visitors with search, support links, product routes, and helpful next steps.', 'help4-builder-suite');
        }
        if (preg_match('/canvas|no-header|no header|landing-template/', $haystack) === 1) {
            return __('focused campaign pages that should avoid global header/footer distraction while keeping Help4 builder controls.', 'help4-builder-suite');
        }
        if (preg_match('/theme-kit|theme kit|global parts|site kit|page-shell|page shell/', $haystack) === 1) {
            return __('complete blank-theme starts with headers, footers, 404s, page shells, and reusable content parts.', 'help4-builder-suite');
        }
        if (preg_match('/subscription|recurring|renewal|membership|invoice/', $haystack) === 1) {
            return __('plans, memberships, renewals, trials, setup fees, and recurring checkout pages.', 'help4-builder-suite');
        }
        if (preg_match('/catalog|variant|variation|import|product/', $haystack) === 1) {
            return __('large product catalogs, variation choices, product imports, and store pages customers can understand.', 'help4-builder-suite');
        }
        if (preg_match('/payment|processor|route|checkout|failover/', $haystack) === 1) {
            return __('checkout routing, processor rules, payment confidence, and configured checkout handoff pages.', 'help4-builder-suite');
        }
        if (preg_match('/field|dynamic|condition|blank theme|template|builder|slider/', $haystack) === 1) {
            return __('blank-theme builds, reusable templates, field groups, motion sections, and builder onboarding.', 'help4-builder-suite');
        }
        if (preg_match('/security|malware|incident|emergency|support|care|migration/', $haystack) === 1) {
            return __('urgent fixes, site care, migrations, cleanup, support routing, and operational trust pages.', 'help4-builder-suite');
        }
        if (preg_match('/seo|local|landing|lead|conversion|review|reputation/', $haystack) === 1) {
            return __('SEO landing pages, local service pages, proof sections, lead capture, and conversion paths.', 'help4-builder-suite');
        }
        if (preg_match('/agency|handoff|white-label|client|onboarding/', $haystack) === 1) {
            return __('client onboarding, design handoff, agency overflow, white-label operations, and first-ticket flows.', 'help4-builder-suite');
        }

        return __('a clean first draft when a customer needs a page structure they can hand off and publish faster.', 'help4-builder-suite');
    }

    /**
     * @param array<int, string> $components
     * @param array<int, mixed> $icons
     */
    private function templateLibraryUseCase(string $title, string $category, array $components, array $icons, string $templateRole = '', string $templateUsage = ''): string
    {
        $haystack = strtolower($title . ' ' . $category . ' ' . $templateRole . ' ' . $templateUsage . ' ' . implode(' ', $components) . ' ' . implode(' ', array_map('strval', $icons)));

        if (preg_match('/header|navigation|nav|mega-menu|sticky/', $haystack) === 1) {
            return __('the site needs a reusable top bar that makes the brand, offer, menu, and next action obvious on mobile and desktop.', 'help4-builder-suite');
        }
        if (preg_match('/footer|legal|newsletter/', $haystack) === 1) {
            return __('visitors reach the end of a page and still need contact options, trust cues, location/service links, and support routes.', 'help4-builder-suite');
        }
        if (preg_match('/404|not-found|not found/', $haystack) === 1) {
            return __('a broken or old URL should send people somewhere useful instead of dumping them into a dead end.', 'help4-builder-suite');
        }
        if (preg_match('/canvas|no-header|no header|landing-template/', $haystack) === 1) {
            return __('a paid ad, launch, lead magnet, or focused offer needs one clean path without the normal site chrome.', 'help4-builder-suite');
        }
        if (preg_match('/theme-kit|theme kit|global parts|site kit|page-shell|page shell/', $haystack) === 1) {
            return __('a blank-theme site needs enough structure to feel designed before the owner replaces copy, colors, and screenshots.', 'help4-builder-suite');
        }
        if (preg_match('/quote|estimate|lead-intake|consultation|contact/', $haystack) === 1) {
            return __('a visitor needs a fast way to ask for help, request pricing, or explain what they need before talking to you.', 'help4-builder-suite');
        }
        if (preg_match('/review|reputation|testimonial/', $haystack) === 1) {
            return __('a finished job needs proof, reviews, follow-up links, and a softer path back to the business.', 'help4-builder-suite');
        }
        if (preg_match('/comparison|buyer|guide|versus|pricing/', $haystack) === 1) {
            return __('a buyer is comparing options and needs the differences, risks, and value explained without sales fog.', 'help4-builder-suite');
        }
        if (preg_match('/case|story|proof|portfolio|recent/', $haystack) === 1) {
            return __('you need to show the real work, the problem, the result, and why someone should trust the next project to you.', 'help4-builder-suite');
        }
        if (preg_match('/rescue|migration|incident|emergency|malware|rollback/', $haystack) === 1) {
            return __('someone is nervous because a site is broken, moving, slow, infected, or too risky to leave alone.', 'help4-builder-suite');
        }
        if (preg_match('/knowledge|article|documentation|support/', $haystack) === 1) {
            return __('customers need answers, setup steps, and support paths before opening another ticket.', 'help4-builder-suite');
        }
        if (preg_match('/subscription|recurring|renewal|membership|invoice/', $haystack) === 1) {
            return __('plans, renewals, service levels, or ongoing billing need to be explained before checkout.', 'help4-builder-suite');
        }
        if (preg_match('/catalog|variant|variation|import|product/', $haystack) === 1) {
            return __('a large catalog or product family needs structure, filters, choices, and plain-language buying help.', 'help4-builder-suite');
        }
        if (preg_match('/payment|processor|route|checkout|failover/', $haystack) === 1) {
            return __('checkout needs trust, clear steps, payment routing, and a clean handoff to the account system.', 'help4-builder-suite');
        }
        if (preg_match('/field|dynamic|condition|blank theme|template|builder|slider|handoff|wireframe|brand/', $haystack) === 1) {
            return __('a builder page needs structure, brand tokens, reusable sections, fields, media, or motion without bloating every page.', 'help4-builder-suite');
        }
        if ($category === 'Growth') {
            return __('a local or service page needs search intent, proof, location relevance, and a clear next action.', 'help4-builder-suite');
        }

        return __('you want a working first draft instead of starting from a blank page and guessing what sections belong there.', 'help4-builder-suite');
    }

    /**
     * @param array<int, string> $components
     * @param array<int, mixed> $icons
     */
    private function templateLibraryNextStep(string $title, string $category, array $components, array $icons, string $templateRole = '', string $templateUsage = ''): string
    {
        $haystack = strtolower($title . ' ' . $category . ' ' . $templateRole . ' ' . $templateUsage . ' ' . implode(' ', $components) . ' ' . implode(' ', array_map('strval', $icons)));

        if (preg_match('/header|navigation|nav|mega-menu|sticky/', $haystack) === 1) {
            return __('copy the header spec, set the role to Header, map the menu and CTA, then check wrapping at mobile width before publishing.', 'help4-builder-suite');
        }
        if (preg_match('/footer|legal|newsletter/', $haystack) === 1) {
            return __('copy the footer spec, set the role to Footer, replace policy/support links, and make sure the columns collapse cleanly on mobile.', 'help4-builder-suite');
        }
        if (preg_match('/404|not-found|not found/', $haystack) === 1) {
            return __('copy the 404 spec, set the role and scope to 404, add search/support/product links, then test an old URL.', 'help4-builder-suite');
        }
        if (preg_match('/canvas|no-header|no header|landing-template/', $haystack) === 1) {
            return __('copy the canvas spec into a page, set Page Layout to Help4 Canvas, then keep one primary action visible on mobile.', 'help4-builder-suite');
        }
        if (preg_match('/theme-kit|theme kit|global parts|site kit|page-shell|page shell/', $haystack) === 1) {
            return __('copy the pieces you need first, assign header/footer/404 roles, then use the page shells as the site pattern library.', 'help4-builder-suite');
        }
        if (preg_match('/quote|estimate|lead-intake|consultation|contact/', $haystack) === 1) {
            return __('add service choices, location, urgency, budget, and route the form to the person who can reply fastest.', 'help4-builder-suite');
        }
        if (preg_match('/review|reputation|testimonial/', $haystack) === 1) {
            return __('connect review destinations, add two or three proof points, and publish it as a follow-up link after completed work.', 'help4-builder-suite');
        }
        if (preg_match('/comparison|buyer|guide|versus|pricing/', $haystack) === 1) {
            return __('replace the rows with real buyer objections, pricing anchors, decision criteria, and one primary consultation action.', 'help4-builder-suite');
        }
        if (preg_match('/case|story|proof|portfolio|recent/', $haystack) === 1) {
            return __('drop in screenshots, timeline, outcome metrics, and the final customer-facing call to action.', 'help4-builder-suite');
        }
        if (preg_match('/rescue|migration|incident|emergency|malware|rollback/', $haystack) === 1) {
            return __('list what is broken, add intake questions, set priority contact rules, and keep expectations visible.', 'help4-builder-suite');
        }
        if (preg_match('/knowledge|article|documentation|support/', $haystack) === 1) {
            return __('group the top articles by customer problem, link setup tutorials, and keep the support request path obvious.', 'help4-builder-suite');
        }
        if (preg_match('/subscription|recurring|renewal|membership|invoice/', $haystack) === 1) {
            return __('map the plans, renewal rules, included service levels, and the checkout or account handoff link.', 'help4-builder-suite');
        }
        if (preg_match('/catalog|variant|variation|import|product/', $haystack) === 1) {
            return __('define product groups, variation choices, filters, proof, and the checkout path before adding real inventory.', 'help4-builder-suite');
        }
        if (preg_match('/payment|processor|route|checkout|failover/', $haystack) === 1) {
            return __('explain payment steps, recovery paths, account access, and where the customer lands after checkout.', 'help4-builder-suite');
        }
        if (preg_match('/field|dynamic|condition|blank theme|template|builder|slider|handoff|wireframe|brand/', $haystack) === 1) {
            return __('copy the starter spec, set global styles, replace sample content, and confirm mobile spacing before launch.', 'help4-builder-suite');
        }

        return __('copy the starter spec into a draft, swap the examples for real content, then run the SEO and mobile checks.', 'help4-builder-suite');
    }

    /**
     * @param array<int, string> $components
     * @param array<int, mixed> $icons
     */
    private function templateLibraryCategory(string $title, array $components, array $icons, string $templateRole = '', string $templateUsage = ''): string
    {
        $haystack = strtolower($title . ' ' . $templateRole . ' ' . $templateUsage . ' ' . implode(' ', $components) . ' ' . implode(' ', array_map('strval', $icons)));

        if (preg_match('/header|footer|404|not-found|not found|page-shell|page shell|canvas|theme-kit|theme kit|navigation|nav|global parts/', $haystack) === 1) {
            return 'Theme Parts';
        }
        if (preg_match('/commerce|checkout|cart|store|payment|pricing|plan|buyer/', $haystack) === 1) {
            return 'Commerce';
        }
        if (preg_match('/malware|emergency|migration|care|support|agency|white-label|rescue|incident|knowledge|documentation/', $haystack) === 1) {
            return 'Support';
        }
        if (preg_match('/local|seo|lead|landing|conversion|quote|review|case|comparison|proof/', $haystack) === 1) {
            return 'Growth';
        }
        if (preg_match('/plugin|theme|builder|template|handoff|wireframe|brand/', $haystack) === 1) {
            return 'Builder';
        }
        if (preg_match('/wordpress|service|speed|managed|contractor|realtor/', $haystack) === 1) {
            return 'Service';
        }

        return 'Starter';
    }

    private function migrateStarterTemplateSeedKeys(): void
    {
        foreach (self::STARTER_SEED_KEY_ALIASES as $oldKey => $newKey) {
            // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Seed-key migration intentionally locates old/new Help4 template markers.
            $newItems = get_posts(
                [
                    'post_type'      => 'h4_template',
                    'post_status'    => 'any',
                    'posts_per_page' => 1,
                    'meta_key'       => '_h4_template_seed_key',
                    'meta_value'     => $newKey,
                    'fields'         => 'ids',
                ]
            );
            $oldItems = get_posts(
                [
                    'post_type'      => 'h4_template',
                    'post_status'    => 'any',
                    'posts_per_page' => 20,
                    'meta_key'       => '_h4_template_seed_key',
                    'meta_value'     => $oldKey,
                    'fields'         => 'ids',
                ]
            );
            // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
            if (! is_array($oldItems) || ! $oldItems) {
                continue;
            }

            foreach ($oldItems as $oldItemId) {
                $oldItemId = (int) $oldItemId;
                if ($oldItemId <= 0) {
                    continue;
                }

                if (is_array($newItems) && ! empty($newItems[0])) {
                    update_post_meta($oldItemId, '_h4_template_seed_key', '_legacy-hidden-' . $oldKey);
                    wp_update_post(['ID' => $oldItemId, 'post_status' => 'draft']);
                    continue;
                }

                update_post_meta($oldItemId, '_h4_template_seed_key', $newKey);
                $newItems = [$oldItemId];
            }
        }
    }

    public function renderAssignedHeaderTemplate(): void
    {
        if (is_admin() || wp_doing_ajax() || is_feed() || $this->isBuilderDraftPreviewRequest()) {
            return;
        }
        if ($this->currentRequestUsesBuilderCanvasLayout()) {
            return;
        }

        $templateId = $this->resolveAssignedTemplateId(['header']);
        if ($templateId <= 0) {
            return;
        }

        $output = $this->renderTemplateOutput($templateId);
        if ($output === '') {
            return;
        }

        echo '<div class="h4bs-template-slot h4bs-template-slot-header" data-h4bs-template-slot="header">';
        echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        echo '</div>';
    }

    public function renderAssignedFooterTemplate(): void
    {
        if (is_admin() || wp_doing_ajax() || is_feed() || $this->isBuilderDraftPreviewRequest()) {
            return;
        }
        if ($this->currentRequestUsesBuilderCanvasLayout()) {
            return;
        }

        $templateId = $this->resolveAssignedTemplateId(['footer']);
        if ($templateId <= 0) {
            return;
        }

        $output = $this->renderTemplateOutput($templateId);
        if ($output === '') {
            return;
        }

        echo '<div class="h4bs-template-slot h4bs-template-slot-footer" data-h4bs-template-slot="footer">';
        echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        echo '</div>';
    }

    public function maybeRenderAssigned404Template(): void
    {
        if (is_admin() || wp_doing_ajax() || is_feed() || $this->isBuilderDraftPreviewRequest() || ! is_404()) {
            return;
        }
        if ($this->isMirrorLockedRequest()) {
            return;
        }

        $templateId = $this->resolveAssignedTemplateId(['404']);
        if ($templateId <= 0) {
            return;
        }

        $output = $this->renderTemplateOutput($templateId);
        if ($output === '') {
            return;
        }

        status_header(404);
        nocache_headers();
        get_header();
        echo '<main id="content" class="site-main h4bs-template-404-main">';
        echo '<div class="h4bs-template-slot h4bs-template-slot-404" data-h4bs-template-slot="404">';
        echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        echo '</div>';
        echo '</main>';
        get_footer();
        exit;
    }

    public function maybeRenderAssignedCollectionTemplate(): void
    {
        if (
            is_admin()
            || wp_doing_ajax()
            || is_feed()
            || $this->isBuilderDraftPreviewRequest()
            || is_404()
            || (! is_home() && ! is_archive() && ! is_search())
        ) {
            return;
        }
        if ($this->isMirrorLockedRequest()) {
            return;
        }

        $queriedId = get_queried_object_id();
        $queriedPost = $queriedId > 0 ? get_post($queriedId) : null;
        if (
            $queriedPost instanceof WP_Post
            && (string) get_post_meta($queriedId, '_h4_builder_enabled', true) === '1'
            && (string) get_post_meta($queriedId, '_h4_builder_mode', true) === 'help4'
        ) {
            return;
        }

        $roles = $this->contentRolesForCurrentRequest();
        if (! $roles) {
            return;
        }
        $templateId = $this->resolveAssignedTemplateId($roles);
        if ($templateId <= 0) {
            return;
        }

        $output = $this->renderTemplateOutput($templateId);
        if ($output === '') {
            return;
        }

        $this->contentTemplateInjected = true;
        $slot = is_search() ? 'search' : (is_home() ? 'home' : 'archive');
        get_header();
        echo '<main id="content" class="site-main h4bs-template-collection-main">';
        echo '<div class="h4bs-template-slot h4bs-template-slot-' . esc_attr($slot) . '" data-h4bs-template-slot="' . esc_attr($slot) . '">';
        echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        echo '</div>';
        echo '</main>';
        get_footer();
        exit;
    }

    public function renderAssignedPopupTemplate(): void
    {
        if (is_admin() || wp_doing_ajax() || is_feed() || $this->isBuilderDraftPreviewRequest()) {
            return;
        }
        if ($this->isMirrorLockedRequest()) {
            return;
        }

        $templateId = $this->resolveAssignedTemplateId(['popup']);
        if ($templateId <= 0) {
            return;
        }

        $output = $this->renderTemplateOutput($templateId);
        if ($output === '') {
            return;
        }

        echo '<div class="h4bs-template-slot h4bs-template-slot-popup" data-h4bs-template-slot="popup" hidden>';
        echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        echo '</div>';
    }

    /**
     * @param array<string, mixed> $atts
     */
    public function renderTemplateShortcode(array $atts): string
    {
        $atts = shortcode_atts(['id' => 0], $atts, 'h4_template');
        $templateId = absint($atts['id']);
        if ($templateId <= 0) {
            return '';
        }

        return $this->renderTemplateOutput($templateId);
    }

    /**
     * @param array<string, mixed> $atts
     */
    public function renderPopupShortcode(array $atts): string
    {
        $atts = shortcode_atts(['id' => 0], $atts, 'h4_popup');
        $templateId = absint($atts['id']);
        if ($templateId <= 0) {
            return '';
        }

        $post = get_post($templateId);
        if (! $post instanceof WP_Post || $post->post_type !== 'h4_template') {
            return '';
        }

        $output = $this->renderTemplateOutput($templateId);
        if ($output === '') {
            return '';
        }

        return '<div class="h4bs-template-slot h4bs-template-slot-popup" data-h4bs-template-slot="popup">' . $output . '</div>';
    }

    /**
     * @param array<string, mixed> $slots
     * @return array<string, mixed>
     */
    public function builderPreviewTemplateSlots(array $slots, int $postId = 0, string $postType = '', string $pageLayout = 'default'): array
    {
        $postId = absint($postId);
        $postType = sanitize_key($postType);
        $pageLayout = sanitize_key($pageLayout);

        $slots = array_merge(
            [
                'header_template_id' => 0,
                'footer_template_id' => 0,
                'header_html' => '',
                'footer_html' => '',
            ],
            $slots
        );

        if ($postType === 'h4_template' || $pageLayout === 'canvas') {
            return $slots;
        }

        if ($postId > 0 && $postType === '') {
            $resolvedType = get_post_type($postId);
            if (is_string($resolvedType)) {
                $postType = sanitize_key($resolvedType);
            }
        }

        $headerTemplateId = $this->resolveAssignedTemplateIdForContext(['header'], $postId, $postType);
        $footerTemplateId = $this->resolveAssignedTemplateIdForContext(['footer'], $postId, $postType);

        if ($headerTemplateId > 0) {
            $slots['header_template_id'] = $headerTemplateId;
            $slots['header_html'] = $this->renderTemplateOutput($headerTemplateId);
        }
        if ($footerTemplateId > 0) {
            $slots['footer_template_id'] = $footerTemplateId;
            $slots['footer_html'] = $this->renderTemplateOutput($footerTemplateId);
        }

        return $slots;
    }

    public function injectAssignedContentTemplate(string $content): string
    {
        if (
            $this->renderingTemplate
            || is_admin()
            || wp_doing_ajax()
            || is_feed()
            || $this->isBuilderDraftPreviewRequest()
        ) {
            return $content;
        }
        if ($this->isMirrorLockedRequest()) {
            return $content;
        }
        if (! in_the_loop() || ! is_main_query()) {
            return $content;
        }
        if ($this->contentTemplateInjected && ! is_singular()) {
            return '';
        }

        $queriedId = get_queried_object_id();
        if ($queriedId > 0) {
            $builderEnabled = (string) get_post_meta($queriedId, '_h4_builder_enabled', true) === '1'
                && (string) get_post_meta($queriedId, '_h4_builder_mode', true) === 'help4';
            if ($builderEnabled) {
                return $content;
            }
        }

        $roles = $this->contentRolesForCurrentRequest();
        if (! $roles) {
            return $content;
        }

        $templateId = $this->resolveAssignedTemplateId($roles);
        if ($templateId <= 0) {
            return $content;
        }

        $output = $this->renderTemplateOutput($templateId);
        if ($output === '') {
            return $content;
        }

        if (! is_singular()) {
            $this->contentTemplateInjected = true;
        }

        return $output;
    }

    private function isMirrorLockedRequest(): bool
    {
        if (! is_singular()) {
            return false;
        }

        $postId = get_queried_object_id();
        if (! $postId) {
            return false;
        }

        return (string) get_post_meta((int) $postId, '_h4_mirror_enabled', true) === '1';
    }

    /**
     * @param array<int, string> $roles
     */
    private function resolveAssignedTemplateId(array $roles): int
    {
        $cacheKey = implode('|', $roles) . '|' . (string) get_queried_object_id();
        if (isset($this->resolvedTemplateCache[$cacheKey])) {
            return $this->resolvedTemplateCache[$cacheKey];
        }

        $templateIds = get_posts(
            [
                'post_type'      => 'h4_template',
                'post_status'    => 'publish',
                'posts_per_page' => -1,
                'orderby'        => 'modified',
                'order'          => 'DESC',
                'fields'         => 'ids',
            ]
        );

        $bestId = 0;
        $bestPriority = -99999;
        foreach ($templateIds as $templateIdRaw) {
            $templateId = absint($templateIdRaw);
            if ($templateId <= 0) {
                continue;
            }
            if ($this->isStarterLibraryOnlyTemplate($templateId)) {
                continue;
            }

            $role = sanitize_key((string) get_post_meta($templateId, '_h4_template_role', true));
            if ($role === '') {
                $role = 'general';
            }
            if (! in_array($role, $roles, true)) {
                continue;
            }
            if (! $this->templateScopeMatchesCurrentRequest($templateId)) {
                continue;
            }

            $priority = (int) get_post_meta($templateId, '_h4_template_priority', true);
            if ($priority === 0) {
                $priority = 10;
            }

            if ($bestId === 0 || $priority > $bestPriority) {
                $bestId = $templateId;
                $bestPriority = $priority;
            }
        }

        $this->resolvedTemplateCache[$cacheKey] = $bestId;
        return $bestId;
    }

    /**
     * @param array<int, string> $roles
     */
    private function resolveAssignedTemplateIdForContext(array $roles, int $contextPostId, string $contextPostType): int
    {
        $contextPostId = absint($contextPostId);
        $contextPostType = sanitize_key($contextPostType);
        $cacheKey = 'preview|' . implode('|', $roles) . '|' . (string) $contextPostId . '|' . $contextPostType;
        if (isset($this->resolvedTemplateCache[$cacheKey])) {
            return $this->resolvedTemplateCache[$cacheKey];
        }

        $templateIds = get_posts(
            [
                'post_type'      => 'h4_template',
                'post_status'    => 'publish',
                'posts_per_page' => -1,
                'orderby'        => 'modified',
                'order'          => 'DESC',
                'fields'         => 'ids',
            ]
        );

        $bestId = 0;
        $bestPriority = -99999;
        foreach ($templateIds as $templateIdRaw) {
            $templateId = absint($templateIdRaw);
            if ($templateId <= 0) {
                continue;
            }
            if ($this->isStarterLibraryOnlyTemplate($templateId)) {
                continue;
            }

            $role = sanitize_key((string) get_post_meta($templateId, '_h4_template_role', true));
            if ($role === '') {
                $role = 'general';
            }
            if (! in_array($role, $roles, true)) {
                continue;
            }
            if (! $this->templateScopeMatchesContext($templateId, $contextPostId, $contextPostType)) {
                continue;
            }

            $priority = (int) get_post_meta($templateId, '_h4_template_priority', true);
            if ($priority === 0) {
                $priority = 10;
            }

            if ($bestId === 0 || $priority > $bestPriority) {
                $bestId = $templateId;
                $bestPriority = $priority;
            }
        }

        $this->resolvedTemplateCache[$cacheKey] = $bestId;
        return $bestId;
    }

    /**
     * @return array<int, string>
     */
    private function contentRolesForCurrentRequest(): array
    {
        if (is_front_page()) {
            return ['front_page', 'general'];
        }
        if (is_home()) {
            return ['home', 'archive', 'general'];
        }
        if (is_search()) {
            return ['search', 'archive', 'general'];
        }
        if (is_404()) {
            return ['404', 'general'];
        }
        if ($this->isProductArchiveRequest()) {
            return ['product_archive', 'archive', 'general'];
        }
        if (is_archive()) {
            return ['archive', 'general'];
        }
        if ($this->isProductSingleRequest()) {
            return ['product_single', 'singular', 'general'];
        }
        if (is_page()) {
            if ($this->currentRequestUsesBuilderCanvasLayout()) {
                return ['canvas_page', 'page', 'singular', 'general'];
            }

            return ['page', 'singular', 'general'];
        }
        if (is_single()) {
            return ['post', 'singular', 'general'];
        }
        if (is_singular()) {
            return ['singular', 'general'];
        }

        return [];
    }

    private function currentRequestUsesBuilderCanvasLayout(): bool
    {
        if (! is_singular()) {
            return false;
        }

        $postId = get_queried_object_id();
        if ($postId <= 0) {
            return false;
        }

        return sanitize_key((string) get_post_meta((int) $postId, '_h4_builder_page_layout', true)) === 'canvas';
    }

    private function isStarterLibraryOnlyTemplate(int $templateId): bool
    {
        if ((string) get_post_meta($templateId, '_h4_template_seed_key', true) === '') {
            return false;
        }

        $builderEnabled = (string) get_post_meta($templateId, '_h4_builder_enabled', true) === '1'
            && (string) get_post_meta($templateId, '_h4_builder_mode', true) === 'help4';
        $content = trim((string) get_post_field('post_content', $templateId));

        return ! $builderEnabled && $content === '';
    }

    private function isProductArchiveRequest(): bool
    {
        return is_post_type_archive('product') || is_post_type_archive('h4_product');
    }

    private function isProductSingleRequest(): bool
    {
        return is_singular('product') || is_singular('h4_product');
    }

    private function renderTemplateOutput(int $templateId): string
    {
        $post = get_post($templateId);
        if (! $post instanceof WP_Post || $post->post_type !== 'h4_template') {
            return '';
        }

        if (
            (string) get_post_meta($templateId, '_h4_builder_enabled', true) === '1'
            && (string) get_post_meta($templateId, '_h4_builder_mode', true) === 'help4'
        ) {
            $this->renderingTemplate = true;
            $output = do_shortcode('[h4_builder id="' . $templateId . '"]');
            $this->renderingTemplate = false;
            return (string) $output;
        }

        $this->renderingTemplate = true;
        $output = do_shortcode((string) $post->post_content);
        $this->renderingTemplate = false;
        return (string) $output;
    }

    private function templateScopeMatchesCurrentRequest(int $templateId): bool
    {
        $scope = sanitize_key((string) get_post_meta($templateId, '_h4_template_scope', true));
        if ($scope === '') {
            $scope = 'entire_site';
        }

        $includeIds = $this->parseIdList((string) get_post_meta($templateId, '_h4_template_include_ids', true));
        $excludeIds = $this->parseIdList((string) get_post_meta($templateId, '_h4_template_exclude_ids', true));
        $includeTypes = $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_include_types', true));
        $excludeTypes = $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_exclude_types', true));
        $userRoles = $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_user_roles', true));
        $queriedId = get_queried_object_id();
        $currentType = $this->currentRequestPostType($queriedId);

        if ($queriedId > 0 && in_array($queriedId, $excludeIds, true)) {
            return false;
        }

        if ($scope === 'specific_ids') {
            return $queriedId > 0 && in_array($queriedId, $includeIds, true);
        }

        if ($includeIds && $queriedId > 0 && ! in_array($queriedId, $includeIds, true)) {
            return false;
        }

        if ($currentType !== '' && in_array($currentType, $excludeTypes, true)) {
            return false;
        }
        if ($includeTypes) {
            if ($currentType === '') {
                return false;
            }
            if (! in_array($currentType, $includeTypes, true)) {
                return false;
            }
        }

        if ($userRoles) {
            if (! is_user_logged_in()) {
                if (! in_array('guest', $userRoles, true)) {
                    return false;
                }
            } else {
                $user = wp_get_current_user();
                $resolvedRoles = array_map('sanitize_key', (array) ($user->roles ?? []));
                if (! in_array('logged_in', $userRoles, true) && ! array_intersect($userRoles, $resolvedRoles)) {
                    return false;
                }
            }
        }

        return match ($scope) {
            'entire_site' => true,
            'front_page' => is_front_page(),
            'home' => is_home(),
            'page' => is_page(),
            'post' => is_single('post'),
            'canvas_page' => is_page() && $this->currentRequestUsesBuilderCanvasLayout(),
            'singular' => is_singular(),
            'archive' => is_archive(),
            'search' => is_search(),
            '404' => is_404(),
            'product_archive' => $this->isProductArchiveRequest(),
            'product_single' => $this->isProductSingleRequest(),
            default => true,
        };
    }

    private function templateScopeMatchesContext(int $templateId, int $contextPostId, string $contextPostType): bool
    {
        $contextPostId = absint($contextPostId);
        $contextPostType = sanitize_key($contextPostType);
        if ($contextPostId > 0 && $contextPostType === '') {
            $resolvedType = get_post_type($contextPostId);
            if (is_string($resolvedType)) {
                $contextPostType = sanitize_key($resolvedType);
            }
        }

        $scope = sanitize_key((string) get_post_meta($templateId, '_h4_template_scope', true));
        if ($scope === '') {
            $scope = 'entire_site';
        }

        $includeIds = $this->parseIdList((string) get_post_meta($templateId, '_h4_template_include_ids', true));
        $excludeIds = $this->parseIdList((string) get_post_meta($templateId, '_h4_template_exclude_ids', true));
        $includeTypes = $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_include_types', true));
        $excludeTypes = $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_exclude_types', true));
        $userRoles = $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_user_roles', true));

        if ($contextPostId > 0 && in_array($contextPostId, $excludeIds, true)) {
            return false;
        }
        if ($scope === 'specific_ids') {
            return $contextPostId > 0 && in_array($contextPostId, $includeIds, true);
        }
        if ($includeIds && $contextPostId > 0 && ! in_array($contextPostId, $includeIds, true)) {
            return false;
        }

        if ($contextPostType !== '' && in_array($contextPostType, $excludeTypes, true)) {
            return false;
        }
        if ($includeTypes) {
            if ($contextPostType === '') {
                return false;
            }
            if (! in_array($contextPostType, $includeTypes, true)) {
                return false;
            }
        }

        if ($userRoles) {
            if (! is_user_logged_in()) {
                if (! in_array('guest', $userRoles, true)) {
                    return false;
                }
            } else {
                $user = wp_get_current_user();
                $resolvedRoles = array_map('sanitize_key', (array) ($user->roles ?? []));
                if (! in_array('logged_in', $userRoles, true) && ! array_intersect($userRoles, $resolvedRoles)) {
                    return false;
                }
            }
        }

        return match ($scope) {
            'entire_site' => true,
            'front_page' => $contextPostId > 0 && absint(get_option('page_on_front')) === $contextPostId,
            'home' => $contextPostId > 0 && absint(get_option('page_for_posts')) === $contextPostId,
            'page' => $contextPostType === 'page',
            'post' => $contextPostType === 'post',
            'canvas_page' => $contextPostType === 'page',
            'singular' => $contextPostId > 0,
            'archive' => false,
            'search' => false,
            '404' => false,
            'product_archive' => false,
            'product_single' => in_array($contextPostType, ['product', 'h4_product'], true),
            default => true,
        };
    }

    /**
     * @param array<string, mixed> $data
     */
    private function saveTemplateConditions(int $postId, array $data): void
    {
        $source = $data;
        if (! is_array($source)) {
            return;
        }

        $role = sanitize_key((string) ($source['h4_template_role'] ?? ($source['role'] ?? 'general')));
        $scope = sanitize_key((string) ($source['h4_template_scope'] ?? ($source['scope'] ?? 'entire_site')));
        if (! array_key_exists($role, $this->templateRoles())) {
            $role = 'general';
        }
        if (! array_key_exists($scope, $this->templateScopes())) {
            $scope = 'entire_site';
        }

        $includeRaw = (string) ($source['h4_template_include_ids'] ?? ($source['include_ids'] ?? ''));
        $excludeRaw = (string) ($source['h4_template_exclude_ids'] ?? ($source['exclude_ids'] ?? ''));
        $includeTypesRaw = (string) ($source['h4_template_include_types'] ?? ($source['include_types'] ?? ''));
        $excludeTypesRaw = (string) ($source['h4_template_exclude_types'] ?? ($source['exclude_types'] ?? ''));
        $userRolesRaw = (string) ($source['h4_template_user_roles'] ?? ($source['user_roles'] ?? ''));
        $priority = (int) ($source['h4_template_priority'] ?? ($source['priority'] ?? 10));

        update_post_meta($postId, '_h4_template_role', $role);
        update_post_meta($postId, '_h4_template_scope', $scope);
        update_post_meta($postId, '_h4_template_include_ids', implode(',', $this->parseIdList($includeRaw)));
        update_post_meta($postId, '_h4_template_exclude_ids', implode(',', $this->parseIdList($excludeRaw)));
        update_post_meta($postId, '_h4_template_include_types', implode(',', $this->parseSlugList($includeTypesRaw)));
        update_post_meta($postId, '_h4_template_exclude_types', implode(',', $this->parseSlugList($excludeTypesRaw)));
        update_post_meta($postId, '_h4_template_user_roles', implode(',', $this->parseSlugList($userRolesRaw)));
        update_post_meta($postId, '_h4_template_priority', (string) max(-100, min(999, $priority)));
    }

    /**
     * @return array<string, mixed>
     */
    private function templateConditions(int $templateId): array
    {
        return [
            'role'        => sanitize_key((string) get_post_meta($templateId, '_h4_template_role', true)) ?: 'general',
            'scope'       => sanitize_key((string) get_post_meta($templateId, '_h4_template_scope', true)) ?: 'entire_site',
            'include_ids' => $this->parseIdList((string) get_post_meta($templateId, '_h4_template_include_ids', true)),
            'exclude_ids' => $this->parseIdList((string) get_post_meta($templateId, '_h4_template_exclude_ids', true)),
            'include_types' => $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_include_types', true)),
            'exclude_types' => $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_exclude_types', true)),
            'user_roles' => $this->parseSlugList((string) get_post_meta($templateId, '_h4_template_user_roles', true)),
            'priority'    => (int) get_post_meta($templateId, '_h4_template_priority', true),
        ];
    }

    /**
     * @return array<string, string>
     */
    private function templateRoles(): array
    {
        return [
            'general' => __('General Content', 'help4-builder-suite'),
            'header' => __('Header', 'help4-builder-suite'),
            'footer' => __('Footer', 'help4-builder-suite'),
            'popup' => __('Popup', 'help4-builder-suite'),
            'front_page' => __('Front Page', 'help4-builder-suite'),
            'home' => __('Blog Home', 'help4-builder-suite'),
            'page' => __('Page Template', 'help4-builder-suite'),
            'post' => __('Post Template', 'help4-builder-suite'),
            'canvas_page' => __('Canvas Page (No Header/Footer)', 'help4-builder-suite'),
            'singular' => __('Singular (Post/Page)', 'help4-builder-suite'),
            'archive' => __('Archive', 'help4-builder-suite'),
            'search' => __('Search Results', 'help4-builder-suite'),
            '404' => __('404 Page', 'help4-builder-suite'),
            'product_archive' => __('Product Archive', 'help4-builder-suite'),
            'product_single' => __('Single Product', 'help4-builder-suite'),
        ];
    }

    /**
     * @return array<string, string>
     */
    private function templateScopes(): array
    {
        return [
            'entire_site' => __('Entire Site', 'help4-builder-suite'),
            'front_page' => __('Front Page Only', 'help4-builder-suite'),
            'home' => __('Blog Home Only', 'help4-builder-suite'),
            'page' => __('Pages Only', 'help4-builder-suite'),
            'post' => __('Posts Only', 'help4-builder-suite'),
            'canvas_page' => __('Canvas Pages Only', 'help4-builder-suite'),
            'singular' => __('Any Singular View', 'help4-builder-suite'),
            'archive' => __('Any Archive View', 'help4-builder-suite'),
            'search' => __('Search Results Only', 'help4-builder-suite'),
            '404' => __('404 Only', 'help4-builder-suite'),
            'product_archive' => __('Product Archive Only', 'help4-builder-suite'),
            'product_single' => __('Single Product Only', 'help4-builder-suite'),
            'specific_ids' => __('Specific Post/Page IDs', 'help4-builder-suite'),
        ];
    }

    /**
     * @return array<int, int>
     */
    private function parseIdList(string $raw): array
    {
        $parts = preg_split('/[\s,]+/', trim($raw)) ?: [];
        $ids = [];
        foreach ($parts as $part) {
            $id = absint($part);
            if ($id > 0) {
                $ids[] = $id;
            }
        }
        return array_values(array_unique($ids));
    }

    /**
     * @return array<int, string>
     */
    private function parseSlugList(string $raw): array
    {
        $parts = preg_split('/[\s,]+/', trim($raw)) ?: [];
        $slugs = [];
        foreach ($parts as $part) {
            $slug = sanitize_key((string) $part);
            if ($slug !== '') {
                $slugs[] = $slug;
            }
        }
        return array_values(array_unique($slugs));
    }

    private function currentRequestPostType(int $queriedId): string
    {
        if ($queriedId > 0) {
            $type = get_post_type($queriedId);
            if (is_string($type) && $type !== '') {
                return sanitize_key($type);
            }
        }

        if (is_post_type_archive()) {
            $archive = get_query_var('post_type');
            if (is_array($archive) && isset($archive[0])) {
                return sanitize_key((string) $archive[0]);
            }
            if (is_string($archive) && $archive !== '') {
                return sanitize_key($archive);
            }
        }

        return '';
    }

    /**
     * @param array<int, int|string> $values
     */
    private function displayList(array $values): string
    {
        if (! $values) {
            return __('none', 'help4-builder-suite');
        }
        $clean = array_map(static fn ($value): string => sanitize_text_field((string) $value), $values);
        return implode(', ', $clean);
    }

    /**
     * @return array{title:string, scope:string, include_types:string, priority:int, page_layout:string}
     */
    private function quickCreateDefaults(string $role): array
    {
        $role = sanitize_key($role);

        return match ($role) {
            'header' => [
                'title' => __('Site Header', 'help4-builder-suite'),
                'scope' => 'entire_site',
                'include_types' => '',
                'priority' => 10,
                'page_layout' => 'canvas',
            ],
            'footer' => [
                'title' => __('Site Footer', 'help4-builder-suite'),
                'scope' => 'entire_site',
                'include_types' => '',
                'priority' => 10,
                'page_layout' => 'canvas',
            ],
            '404' => [
                'title' => __('404 Not Found Page', 'help4-builder-suite'),
                'scope' => '404',
                'include_types' => '',
                'priority' => 20,
                'page_layout' => 'full_width',
            ],
            'page' => [
                'title' => __('Page Template', 'help4-builder-suite'),
                'scope' => 'page',
                'include_types' => 'page',
                'priority' => 10,
                'page_layout' => 'full_width',
            ],
            'post' => [
                'title' => __('Post Template', 'help4-builder-suite'),
                'scope' => 'post',
                'include_types' => 'post',
                'priority' => 10,
                'page_layout' => 'full_width',
            ],
            'canvas_page' => [
                'title' => __('Canvas Page Template', 'help4-builder-suite'),
                'scope' => 'canvas_page',
                'include_types' => 'page',
                'priority' => 20,
                'page_layout' => 'canvas',
            ],
            'front_page' => [
                'title' => __('Front Page Template', 'help4-builder-suite'),
                'scope' => 'front_page',
                'include_types' => 'page',
                'priority' => 20,
                'page_layout' => 'full_width',
            ],
            'popup' => [
                'title' => __('Global Popup', 'help4-builder-suite'),
                'scope' => 'entire_site',
                'include_types' => '',
                'priority' => 10,
                'page_layout' => 'canvas',
            ],
            default => [
                'title' => __('Template', 'help4-builder-suite'),
                'scope' => 'entire_site',
                'include_types' => '',
                'priority' => 10,
                'page_layout' => 'full_width',
            ],
        };
    }

    private function quickCreateUrl(string $role): string
    {
        $role = sanitize_key($role);
        return wp_nonce_url(
            admin_url('admin.php?action=h4bs_template_quick_create&role=' . $role),
            'h4bs_template_quick_create_' . $role
        );
    }

    private function builderActionUrl(int $postId): string
    {
        return wp_nonce_url(
            admin_url('admin.php?action=h4bs_open_builder&post=' . $postId),
            'h4bs_open_builder_' . $postId
        );
    }

    public function setupAdminMenuHighlight(WP_Screen $screen): void
    {
        $page = AdminRequest::queryKey('page');
        if ($page === 'h4bs-theme-builder') {
            add_filter(
                'parent_file',
                static function ($parentFile): string {
                    return 'h4bs-settings';
                }
            );

            add_filter(
                'submenu_file',
                static function ($submenuFile): string {
                    return 'h4bs-theme-builder';
                }
            );
            return;
        }

        if ($screen->post_type !== 'h4_template') {
            return;
        }

        add_filter(
            'parent_file',
            static function ($parentFile): string {
                return 'h4bs-settings';
            }
        );

        add_filter(
            'submenu_file',
            static function ($submenuFile): string {
                return 'edit.php?post_type=h4_template';
            }
        );
    }

    public function seedStarterTemplates(): void
    {
        $isCli = defined('WP_CLI') && WP_CLI;
        if (! $isCli && ! current_user_can('manage_options')) {
            return;
        }

        $this->migrateStarterTemplateSeedKeys();

        $version = 'v16';
        if ((string) get_option('h4bs_template_seed_version', '') === $version) {
            return;
        }

        $lockKey = 'h4bs_template_seed_lock';
        $lockAge = time() - (int) get_option($lockKey, 0);
        if ($lockAge >= 0 && $lockAge < 300) {
            return;
        }
        delete_option($lockKey);
        if (! add_option($lockKey, (string) time(), '', 'no')) {
            return;
        }

        try {
            if ((string) get_option('h4bs_template_seed_version', '') === $version) {
                return;
            }

            $templates = [
            [
                'key'     => 'starter-conversion-home',
                'title'   => 'Starter Conversion Home',
                'excerpt' => 'High-conversion homepage starter with hero, proof, CTA zones.',
                'spec'    => [
                    'version'  => '1.0',
                    'name'     => 'Starter Conversion Home',
                    'viewport' => '8k-ready',
                    'assets'   => ['images' => [], 'fonts' => [], 'icons' => []],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'hero-banner', 'settings' => ['headline' => 'Grow Your Business'], 'children' => []],
                        ['id' => 'proof', 'component' => 'social-proof', 'settings' => ['count' => 3], 'children' => []],
                        ['id' => 'cta', 'component' => 'call-to-action', 'settings' => ['button' => 'Get Started'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-contractor-services',
                'title'   => 'Contractor Services Starter',
                'excerpt' => 'Service-area, quote-first starter for contractors.',
                'spec'    => [
                    'version'  => '1.0',
                    'name'     => 'Contractor Services Starter',
                    'viewport' => '8k-ready',
                    'assets'   => ['images' => [], 'fonts' => [], 'icons' => []],
                    'sections' => [
                        ['id' => 'service-hero', 'component' => 'service-hero', 'settings' => ['headline' => 'Trusted Local Service'], 'children' => []],
                        ['id' => 'services', 'component' => 'service-grid', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'quote-form', 'component' => 'quote-form', 'settings' => ['type' => 'estimate'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-realtor-listings',
                'title'   => 'Realtor Listings Starter',
                'excerpt' => 'Listing/search starter with map + lead capture areas.',
                'spec'    => [
                    'version'  => '1.0',
                    'name'     => 'Realtor Listings Starter',
                    'viewport' => '8k-ready',
                    'assets'   => ['images' => [], 'fonts' => [], 'icons' => []],
                    'sections' => [
                        ['id' => 'search', 'component' => 'property-search', 'settings' => ['mode' => 'map'], 'children' => []],
                        ['id' => 'featured', 'component' => 'featured-listings', 'settings' => ['limit' => 6], 'children' => []],
                        ['id' => 'lead', 'component' => 'property-inquiry', 'settings' => ['cta' => 'Book a Tour'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-managed-wordpress',
                'title'   => 'Managed WordPress Service Page',
                'excerpt' => 'Plain-language WordPress hosting, care, support, speed, and growth starter.',
                'spec'    => [
                    'version'  => '1.1',
                    'name'     => 'Managed WordPress Service Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['managed-hosting', 'security-shield', 'speed-tuning', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'product-hero', 'settings' => ['headline' => 'WordPress hosting with the work handled', 'cta' => 'Compare plans'], 'children' => []],
                        ['id' => 'plain-english', 'component' => 'explain-it-like-owner', 'settings' => ['columns' => 3, 'tone' => 'simple'], 'children' => []],
                        ['id' => 'plan-ladder', 'component' => 'package-ladder', 'settings' => ['tiers' => 'starter|managed|growth|priority'], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['intent' => 'managed-wordpress-hosting'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-plugin-product',
                'title'   => 'Plugin Product Page',
                'excerpt' => 'Launch page for a WordPress plugin with features, use cases, FAQ, and download CTA.',
                'spec'    => [
                    'version'  => '1.1',
                    'name'     => 'Plugin Product Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['builder-blocks', 'template-pack', 'checkout-link', 'seo-growth'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'plugin-hero', 'settings' => ['headline' => 'Show what the plugin does without developer fog'], 'children' => []],
                        ['id' => 'features', 'component' => 'feature-grid', 'settings' => ['columns' => 4], 'children' => []],
                        ['id' => 'workflow', 'component' => 'how-it-works', 'settings' => ['steps' => 'install|pick template|customize|publish'], 'children' => []],
                        ['id' => 'download', 'component' => 'download-cta', 'settings' => ['button' => 'Get the plugin'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-checkout-bridge',
                'title'   => 'Checkout Bridge Page',
                'excerpt' => 'Clean account/checkout bridge that sends buyers to your configured billing system without exposing internal billing labels.',
                'spec'    => [
                    'version'  => '1.1',
                    'name'     => 'Checkout Bridge Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['checkout-link', 'commerce-cart', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'route', 'component' => 'checkout-router', 'settings' => ['destination' => 'Configured checkout'], 'children' => []],
                        ['id' => 'choose', 'component' => 'plan-choice-cards', 'settings' => ['audience' => 'non-technical'], 'children' => []],
                        ['id' => 'support', 'component' => 'support-link-band', 'settings' => ['ticket' => 'on'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-migration-rescue',
                'title'   => 'Migration Rescue Page',
                'excerpt' => 'Move, clean, stabilize, and relaunch a WordPress site with a visible checklist.',
                'spec'    => [
                    'version'  => '1.1',
                    'name'     => 'Migration Rescue Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['migration-path', 'backup-restore', 'security-shield', 'launch-rocket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'rescue-hero', 'settings' => ['headline' => 'Move the site without dragging the mess with it'], 'children' => []],
                        ['id' => 'checklist', 'component' => 'migration-checklist', 'settings' => ['items' => 'backup|cleanup|dns|ssl|forms|speed|launch'], 'children' => []],
                        ['id' => 'risk', 'component' => 'risk-comparison', 'settings' => ['compare' => 'do-it-yourself|handled'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-build-from-design',
                'title'   => 'Build From Design Page',
                'excerpt' => 'For customers who send Figma, screenshots, sketches, copy, or rough instructions.',
                'spec'    => [
                    'version'  => '1.1',
                    'name'     => 'Build From Design Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['builder-blocks', 'template-pack', 'launch-rocket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'design-to-wordpress-hero', 'settings' => ['headline' => 'Hand us the design. We build the WordPress version.'], 'children' => []],
                        ['id' => 'input-types', 'component' => 'artifact-grid', 'settings' => ['items' => 'figma|screenshot|copy|rough sketch|example site'], 'children' => []],
                        ['id' => 'deliverables', 'component' => 'deliverable-grid', 'settings' => ['items' => 'pages|templates|forms|products|responsive QA'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-seo-authority',
                'title'   => 'SEO Authority Service Page',
                'excerpt' => 'Search-ready service page with problem, package, proof, FAQ, and next step sections.',
                'spec'    => [
                    'version'  => '1.1',
                    'name'     => 'SEO Authority Service Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['seo-growth', 'speed-tuning', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'intent-hero', 'component' => 'seo-hero', 'settings' => ['headline' => 'A page Google can read and customers can trust'], 'children' => []],
                        ['id' => 'problem', 'component' => 'customer-problem-grid', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'comparison', 'component' => 'competitor-comparison', 'settings' => ['angle' => 'managed help versus commodity hosting'], 'children' => []],
                        ['id' => 'schema', 'component' => 'faq-schema', 'settings' => ['questions' => 6], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-speed-optimization',
                'title'   => 'Speed Optimization Service Page',
                'excerpt' => 'Core Web Vitals and slow-site service page with audit, fix list, proof, FAQ, and support CTAs.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Speed Optimization Service Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['core-web-vitals', 'speed-tuning', 'plugin-audit', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'service-hero', 'settings' => ['headline' => 'Make the slow WordPress pages obvious, then fix them'], 'children' => []],
                        ['id' => 'diagnostics', 'component' => 'performance-diagnostics', 'settings' => ['items' => 'images|plugins|scripts|caching|hosting'], 'children' => []],
                        ['id' => 'business-impact', 'component' => 'plain-english-impact', 'settings' => ['focus' => 'leads|checkout|mobile visitors'], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['intent' => 'wordpress-speed-optimization'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-emergency-fix',
                'title'   => 'Emergency WordPress Fix Page',
                'excerpt' => 'Urgent support page for site-down, broken checkout, failed forms, launch blockers, and plugin conflicts.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Emergency WordPress Fix Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['emergency-support', 'support-ticket', 'form-leads', 'backup-restore'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'urgent-support-hero', 'settings' => ['headline' => 'When the site breaks, get the issue into a real support path'], 'children' => []],
                        ['id' => 'triage', 'component' => 'issue-triage-grid', 'settings' => ['items' => 'site down|checkout|forms|plugin conflict|launch'], 'children' => []],
                        ['id' => 'ticket', 'component' => 'support-ticket-guide', 'settings' => ['fields' => 'url|impact|screenshot|recent change'], 'children' => []],
                        ['id' => 'cta', 'component' => 'emergency-cta', 'settings' => ['button' => 'Open emergency ticket'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-malware-cleanup',
                'title'   => 'Malware Cleanup Service Page',
                'excerpt' => 'Security cleanup page for redirects, spam pages, suspicious users, restore planning, and hardening.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Malware Cleanup Service Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['malware-cleanup', 'security-shield', 'backup-restore', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'security-cleanup-hero', 'settings' => ['headline' => 'Clean the hacked site and close the door behind it'], 'children' => []],
                        ['id' => 'symptoms', 'component' => 'warning-sign-grid', 'settings' => ['items' => 'redirects|spam pages|browser warnings|unknown users'], 'children' => []],
                        ['id' => 'recovery', 'component' => 'cleanup-timeline', 'settings' => ['steps' => 'isolate|clean|restore|harden|monitor'], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['intent' => 'wordpress-malware-removal'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-maintenance-care-plan',
                'title'   => 'Maintenance Care Plan Page',
                'excerpt' => 'Care plan sales page with updates, backups, security, edits, performance, and escalation language.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Maintenance Care Plan Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['care-plan', 'backup-restore', 'security-shield', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'care-plan-hero', 'settings' => ['headline' => 'Keep WordPress handled before it turns into an emergency'], 'children' => []],
                        ['id' => 'plan-ladder', 'component' => 'package-ladder', 'settings' => ['tiers' => 'starter|care|growth|priority'], 'children' => []],
                        ['id' => 'included', 'component' => 'included-work-grid', 'settings' => ['items' => 'updates|backups|security|small edits|support'], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['intent' => 'wordpress-maintenance-care-plans'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-help4-commerce-support',
                'title'   => 'Help4 Commerce Support Page',
                'excerpt' => 'Store support template for product catalogs, variations, checkout routing, subscriptions, emails, and performance.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Help4 Commerce Support Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['ecommerce-support', 'commerce-cart', 'checkout-link', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'store-support-hero', 'settings' => ['headline' => 'Fix the store paths that stop customers from buying'], 'children' => []],
                        ['id' => 'store-triage', 'component' => 'commerce-issue-grid', 'settings' => ['items' => 'cart|payment|products|emails|speed'], 'children' => []],
                        ['id' => 'flow', 'component' => 'checkout-flow-map', 'settings' => ['steps' => 'product|cart|payment|email|fulfillment'], 'children' => []],
                        ['id' => 'cta', 'component' => 'support-link-band', 'settings' => ['ticket' => 'on'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-agency-overflow',
                'title'   => 'Agency Overflow / White-Label Page',
                'excerpt' => 'Agency support page for design teams, freelancers, SEO teams, maintenance queues, and implementation overflow.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Agency Overflow / White-Label Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['agency-support', 'design-handoff', 'builder-blocks', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'agency-overflow-hero', 'settings' => ['headline' => 'Hand off the WordPress work your agency should not babysit'], 'children' => []],
                        ['id' => 'handoff', 'component' => 'handoff-grid', 'settings' => ['items' => 'designs|tickets|migrations|seo pages|care'], 'children' => []],
                        ['id' => 'process', 'component' => 'agency-process', 'settings' => ['steps' => 'send|scope|build|verify|support'], 'children' => []],
                        ['id' => 'cta', 'component' => 'agency-call-cta', 'settings' => ['button' => 'Discuss agency support'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-local-service-seo',
                'title'   => 'Local Service SEO Page',
                'excerpt' => 'City/service landing page with plain-language offer, trust, FAQ, service area, and lead CTA.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Local Service SEO Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['local-service', 'seo-growth', 'form-leads', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'local-service-hero', 'settings' => ['headline' => 'Service page built to rank, explain, and convert'], 'children' => []],
                        ['id' => 'service-area', 'component' => 'service-area-proof', 'settings' => ['schema' => 'LocalBusiness'], 'children' => []],
                        ['id' => 'problems', 'component' => 'customer-problem-grid', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['questions' => 6], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-lead-capture-landing',
                'title'   => 'Lead Capture Landing Page',
                'excerpt' => 'Focused landing page for paid traffic, offers, consultations, downloads, and urgent service requests.',
                'spec'    => [
                    'version'  => '1.2',
                    'name'     => 'Lead Capture Landing Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['form-leads', 'launch-rocket', 'seo-growth', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'conversion-hero', 'settings' => ['headline' => 'One page, one offer, one obvious next step'], 'children' => []],
                        ['id' => 'offer', 'component' => 'offer-stack', 'settings' => ['proof' => 'simple|specific|visible'], 'children' => []],
                        ['id' => 'form', 'component' => 'lead-form-panel', 'settings' => ['fields' => 'name|email|phone|need'], 'children' => []],
                        ['id' => 'trust', 'component' => 'trust-and-faq', 'settings' => ['questions' => 4], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-appointment-booking',
                'title'   => 'Appointment Booking Page',
                'excerpt' => 'Booking-first service page for consultations, repair calls, demos, estimates, and calendar-driven intake.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Appointment Booking Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['appointment-calendar', 'form-leads', 'support-ticket', 'local-service'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'booking-hero', 'settings' => ['headline' => 'Book the right help without phone tag'], 'children' => []],
                        ['id' => 'slots', 'component' => 'availability-panel', 'settings' => ['fields' => 'service|date|time|contact'], 'children' => []],
                        ['id' => 'qualify', 'component' => 'intake-checklist', 'settings' => ['items' => 'goal|budget|deadline|site url'], 'children' => []],
                        ['id' => 'confirm', 'component' => 'confirmation-next-steps', 'settings' => ['tone' => 'plain'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-restaurant-menu',
                'title'   => 'Restaurant Menu Page',
                'excerpt' => 'Local restaurant starter with menu sections, order CTAs, hours, location, and mobile-first scanning.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Restaurant Menu Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['restaurant-menu', 'local-service', 'form-leads', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'local-restaurant-hero', 'settings' => ['headline' => 'Menu, hours, and ordering in one clean page'], 'children' => []],
                        ['id' => 'menu', 'component' => 'menu-category-list', 'settings' => ['sections' => 'favorites|mains|sides|drinks'], 'children' => []],
                        ['id' => 'hours', 'component' => 'hours-location-band', 'settings' => ['schema' => 'Restaurant'], 'children' => []],
                        ['id' => 'order', 'component' => 'order-cta', 'settings' => ['button' => 'Order or call'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-nonprofit-campaign',
                'title'   => 'Nonprofit Campaign Page',
                'excerpt' => 'Donation and awareness page with impact story, proof, volunteer CTA, and campaign FAQ.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Nonprofit Campaign Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['nonprofit-heart', 'form-leads', 'seo-growth', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'campaign-hero', 'settings' => ['headline' => 'Make the mission clear and the next step obvious'], 'children' => []],
                        ['id' => 'impact', 'component' => 'impact-proof-grid', 'settings' => ['items' => 'people served|funding goal|programs'], 'children' => []],
                        ['id' => 'donate', 'component' => 'donation-choice-panel', 'settings' => ['options' => 'one-time|monthly|volunteer'], 'children' => []],
                        ['id' => 'faq', 'component' => 'campaign-faq', 'settings' => ['questions' => 5], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-event-registration',
                'title'   => 'Event Registration Page',
                'excerpt' => 'Event page with schedule, speakers, ticket tiers, venue details, and registration CTA.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Event Registration Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['event-schedule', 'checkout-link', 'local-service', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'event-hero', 'settings' => ['headline' => 'Tell visitors when, where, why, and how to register'], 'children' => []],
                        ['id' => 'schedule', 'component' => 'event-agenda', 'settings' => ['tracks' => 'main|breakout|networking'], 'children' => []],
                        ['id' => 'tickets', 'component' => 'ticket-tier-cards', 'settings' => ['tiers' => 'early|standard|vip'], 'children' => []],
                        ['id' => 'venue', 'component' => 'venue-details', 'settings' => ['map' => 'on'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-portfolio-case-study',
                'title'   => 'Portfolio Case Study Page',
                'excerpt' => 'Proof page for agencies, contractors, designers, and service teams that need project story plus results.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Portfolio Case Study Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['portfolio-showcase', 'design-handoff', 'seo-growth', 'launch-rocket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'case-study-hero', 'settings' => ['headline' => 'Show the work, the problem, and the result'], 'children' => []],
                        ['id' => 'before-after', 'component' => 'before-after-gallery', 'settings' => ['mode' => 'responsive'], 'children' => []],
                        ['id' => 'process', 'component' => 'project-process', 'settings' => ['steps' => 'brief|build|review|launch'], 'children' => []],
                        ['id' => 'results', 'component' => 'results-proof-band', 'settings' => ['metrics' => 'leads|speed|rankings'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-course-membership',
                'title'   => 'Course / Membership Page',
                'excerpt' => 'Starter for courses, memberships, private content, lessons, pricing, and student outcomes.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Course / Membership Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['course-membership', 'checkout-link', 'form-leads', 'care-plan'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'course-hero', 'settings' => ['headline' => 'Explain the outcome before the curriculum'], 'children' => []],
                        ['id' => 'curriculum', 'component' => 'lesson-outline', 'settings' => ['modules' => 6], 'children' => []],
                        ['id' => 'pricing', 'component' => 'membership-pricing', 'settings' => ['tiers' => 'basic|pro|coaching'], 'children' => []],
                        ['id' => 'faq', 'component' => 'student-faq', 'settings' => ['questions' => 6], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-saas-launch',
                'title'   => 'SaaS Product Launch Page',
                'excerpt' => 'Software/product page with workflow proof, feature lanes, integrations, pricing, and demo CTA.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'SaaS Product Launch Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['analytics-dashboard', 'builder-blocks', 'checkout-link', 'launch-rocket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'product-workflow-hero', 'settings' => ['headline' => 'Show the product solving the job'], 'children' => []],
                        ['id' => 'workflow', 'component' => 'workflow-proof-strip', 'settings' => ['steps' => 'import|configure|launch|measure'], 'children' => []],
                        ['id' => 'features', 'component' => 'feature-lanes', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'demo', 'component' => 'demo-request-cta', 'settings' => ['button' => 'Request demo'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-accessibility-remediation',
                'title'   => 'Accessibility Remediation Page',
                'excerpt' => 'Service page for audits, fixes, readable forms, contrast, keyboard paths, and practical remediation.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Accessibility Remediation Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['accessibility-check', 'form-leads', 'plugin-audit', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'accessibility-hero', 'settings' => ['headline' => 'Make the site easier to use and harder to break'], 'children' => []],
                        ['id' => 'audit', 'component' => 'accessibility-audit-grid', 'settings' => ['items' => 'contrast|forms|keyboard|headings|alt text'], 'children' => []],
                        ['id' => 'fixes', 'component' => 'remediation-plan', 'settings' => ['priority' => 'high-impact-first'], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['intent' => 'wordpress-accessibility-fixes'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-knowledge-base',
                'title'   => 'Knowledge Base Support Hub',
                'excerpt' => 'Help center starter with categories, popular fixes, ticket routing, search, and account links.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Knowledge Base Support Hub',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['faq-knowledge-base', 'support-ticket', 'managed-hosting', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'support-hub-hero', 'settings' => ['headline' => 'Get customers to the right answer or the right ticket'], 'children' => []],
                        ['id' => 'categories', 'component' => 'knowledge-category-grid', 'settings' => ['items' => 'billing|hosting|builder|commerce|security'], 'children' => []],
                        ['id' => 'popular', 'component' => 'popular-fixes-list', 'settings' => ['count' => 8], 'children' => []],
                        ['id' => 'ticket', 'component' => 'support-ticket-guide', 'settings' => ['fields' => 'url|issue|screenshot'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-review-reputation',
                'title'   => 'Review / Reputation Page',
                'excerpt' => 'Reputation starter for testimonials, reviews, trust proof, follow-up flows, and local SEO.',
                'spec'    => [
                    'version'  => '1.3',
                    'name'     => 'Review / Reputation Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['review-stars', 'local-service', 'seo-growth', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'reputation-hero', 'settings' => ['headline' => 'Turn happy customers into visible trust'], 'children' => []],
                        ['id' => 'proof', 'component' => 'review-proof-grid', 'settings' => ['sources' => 'google|facebook|site'], 'children' => []],
                        ['id' => 'request', 'component' => 'review-request-flow', 'settings' => ['steps' => 'ask|link|thank|follow-up'], 'children' => []],
                        ['id' => 'local-seo', 'component' => 'local-seo-band', 'settings' => ['schema' => 'Review'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-package-decision-guide',
                'title'   => 'Package Decision Guide Page',
                'excerpt' => 'Idiot-proof plan picker that explains DIY, care, growth, priority, and custom paths in customer language.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'Package Decision Guide Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['plan-selector', 'managed-hosting', 'care-plan', 'priority-operations'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'package-decision-hero', 'settings' => ['headline' => 'Pick the help level by what you want off your plate'], 'children' => []],
                        ['id' => 'chooser', 'component' => 'plain-language-plan-chooser', 'settings' => ['tiers' => 'diy|care|growth|priority|custom'], 'children' => []],
                        ['id' => 'tradeoffs', 'component' => 'buyer-tradeoff-table', 'settings' => ['tone' => 'non-technical'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'checkout-bridge-cta', 'settings' => ['destination' => 'Configured checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-client-portal-bridge',
                'title'   => 'Client Portal Bridge Page',
                'excerpt' => 'Account, invoice, ticket, and checkout bridge page that keeps billing language clean and branded.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'Client Portal Bridge Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['client-portal', 'checkout-link', 'support-ticket', 'account-rep'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'client-area-hero', 'settings' => ['headline' => 'Billing, services, and tickets stay in one connected account'], 'children' => []],
                        ['id' => 'routes', 'component' => 'portal-route-grid', 'settings' => ['items' => 'checkout|invoices|services|tickets|contacts'], 'children' => []],
                        ['id' => 'managed-note', 'component' => 'support-routing-note', 'settings' => ['fully_managed' => 'account rep available'], 'children' => []],
                        ['id' => 'cta', 'component' => 'client-portal-cta', 'settings' => ['button' => 'Open client area'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-handoff-intake',
                'title'   => 'Design Handoff Intake Page',
                'excerpt' => 'Intake page for customers handing over Figma, screenshots, copy docs, competitor examples, or rough ideas.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'Design Handoff Intake Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['design-handoff', 'figma-import', 'responsive-qa', 'launch-rocket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'handoff-intake-hero', 'settings' => ['headline' => 'Send the design. Get a WordPress page that behaves.'], 'children' => []],
                        ['id' => 'accepted-inputs', 'component' => 'artifact-grid', 'settings' => ['items' => 'figma|screenshot|pdf|copy doc|example site'], 'children' => []],
                        ['id' => 'build-path', 'component' => 'handoff-to-launch-timeline', 'settings' => ['steps' => 'review|scope|build|responsive qa|publish'], 'children' => []],
                        ['id' => 'intake', 'component' => 'project-intake-form', 'settings' => ['fields' => 'url|deadline|assets|goals'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-white-label-operations',
                'title'   => 'White-Label Operations Page',
                'excerpt' => 'Agency operations page for ongoing build tickets, client support overflow, QA, and maintenance queues.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'White-Label Operations Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['white-label', 'agency-support', 'support-ticket', 'quality-review'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'white-label-ops-hero', 'settings' => ['headline' => 'Give your agency a WordPress production bench'], 'children' => []],
                        ['id' => 'queues', 'component' => 'operations-queue-grid', 'settings' => ['items' => 'builds|edits|maintenance|emergencies|qa'], 'children' => []],
                        ['id' => 'handoff', 'component' => 'client-safe-handoff-process', 'settings' => ['visibility' => 'white-label'], 'children' => []],
                        ['id' => 'scope', 'component' => 'agency-scope-cta', 'settings' => ['button' => 'Discuss overflow'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-plugin-docs-hub',
                'title'   => 'Plugin Docs Hub Page',
                'excerpt' => 'Documentation hub for plugin features, install steps, update paths, support links, and changelog routing.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'Plugin Docs Hub Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['documentation-hub', 'plugin-audit', 'template-pack', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'docs-hub-hero', 'settings' => ['headline' => 'Help users install, update, and get unstuck faster'], 'children' => []],
                        ['id' => 'quick-start', 'component' => 'quick-start-steps', 'settings' => ['steps' => 'install|activate|pick template|publish'], 'children' => []],
                        ['id' => 'docs-grid', 'component' => 'documentation-card-grid', 'settings' => ['items' => 'features|templates|icons|updates|support'], 'children' => []],
                        ['id' => 'support', 'component' => 'support-link-band', 'settings' => ['ticket' => 'on'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-site-care-dashboard',
                'title'   => 'Site Care Dashboard Page',
                'excerpt' => 'Care-plan dashboard landing page for health checks, updates, backups, security, forms, and next actions.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'Site Care Dashboard Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['site-health', 'backup-restore', 'security-shield', 'core-web-vitals'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'site-care-dashboard-hero', 'settings' => ['headline' => 'Show the customer what is watched and what needs action'], 'children' => []],
                        ['id' => 'status', 'component' => 'care-status-cards', 'settings' => ['items' => 'updates|backups|security|speed|forms'], 'children' => []],
                        ['id' => 'work-log', 'component' => 'maintenance-work-log', 'settings' => ['density' => 'scannable'], 'children' => []],
                        ['id' => 'request', 'component' => 'support-ticket-cta', 'settings' => ['button' => 'Request site work'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-landing-page-stack',
                'title'   => 'Landing Page Stack Template',
                'excerpt' => 'Reusable landing page stack with offer, objection handling, proof, CTA, FAQ, and conversion checks.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'Landing Page Stack Template',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['conversion-path', 'form-leads', 'review-stars', 'seo-growth'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'offer-first-hero', 'settings' => ['headline' => 'Make the offer obvious before the scroll'], 'children' => []],
                        ['id' => 'objections', 'component' => 'objection-handling-grid', 'settings' => ['items' => 'price|time|trust|fit'], 'children' => []],
                        ['id' => 'proof', 'component' => 'proof-and-results-band', 'settings' => ['mode' => 'plain'], 'children' => []],
                        ['id' => 'final', 'component' => 'single-action-cta', 'settings' => ['button' => 'Start the next step'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-technical-audit-report',
                'title'   => 'Technical Audit Report Page',
                'excerpt' => 'Audit/report starter for speed, SEO, security, accessibility, plugin risk, and recommended fixes.',
                'spec'    => [
                    'version'  => '1.4',
                    'name'     => 'Technical Audit Report Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['technical-audit', 'plugin-audit', 'accessibility-check', 'analytics-dashboard'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'audit-report-hero', 'settings' => ['headline' => 'Show what is broken, why it matters, and what to fix first'], 'children' => []],
                        ['id' => 'scores', 'component' => 'audit-score-summary', 'settings' => ['areas' => 'speed|seo|security|accessibility|plugins'], 'children' => []],
                        ['id' => 'fixes', 'component' => 'priority-fix-table', 'settings' => ['columns' => 'issue|impact|effort|owner'], 'children' => []],
                        ['id' => 'cta', 'component' => 'audit-fix-cta', 'settings' => ['button' => 'Request fix plan'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-local-seo-location-page',
                'title'   => 'Local SEO Location Page',
                'excerpt' => 'Location-page starter with service area proof, reviews, FAQ schema, map language, and quote CTAs.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Local SEO Location Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['local-service', 'local-seo-map', 'schema-faq', 'review-stars'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'local-location-hero', 'settings' => ['headline' => 'Show the service, the city, and the next step fast'], 'children' => []],
                        ['id' => 'service-proof', 'component' => 'local-proof-grid', 'settings' => ['items' => 'service area|response time|reviews|examples'], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['intent' => 'local-service-location'], 'children' => []],
                        ['id' => 'lead', 'component' => 'quote-request-cta', 'settings' => ['button' => 'Request local help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-service-area-hub',
                'title'   => 'Service Area Hub Page',
                'excerpt' => 'Hub page for cities, neighborhoods, services, internal links, FAQs, and local search expansion.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Service Area Hub Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['local-seo-map', 'seo-growth', 'schema-faq', 'conversion-path'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'service-area-hero', 'settings' => ['headline' => 'Give every location a clean path into the main offer'], 'children' => []],
                        ['id' => 'locations', 'component' => 'location-link-grid', 'settings' => ['density' => 'scannable'], 'children' => []],
                        ['id' => 'services', 'component' => 'service-crosslink-grid', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'faq', 'component' => 'faq-schema', 'settings' => ['intent' => 'service-area'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-pricing-comparison-page',
                'title'   => 'Pricing Comparison Page',
                'excerpt' => 'Customer-friendly pricing page that explains plan tradeoffs, checkout routes, support paths, and fit.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Pricing Comparison Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['pricing-table', 'plan-selector', 'checkout-link', 'copywriting-brief'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'pricing-fit-hero', 'settings' => ['headline' => 'Pick by what you want handled, not by feature noise'], 'children' => []],
                        ['id' => 'plans', 'component' => 'plain-language-pricing-table', 'settings' => ['tiers' => 'diy|care|growth|priority|custom'], 'children' => []],
                        ['id' => 'decision', 'component' => 'plan-fit-matrix', 'settings' => ['audience' => 'non-technical'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'checkout-bridge-cta', 'settings' => ['destination' => 'Configured checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-client-onboarding-checklist',
                'title'   => 'Client Onboarding Checklist',
                'excerpt' => 'Post-purchase onboarding page for account access, site details, assets, contacts, and first ticket steps.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Client Onboarding Checklist',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['onboarding-checklist', 'client-portal', 'account-rep', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'onboarding-hero', 'settings' => ['headline' => 'Tell the customer what to send so work can start cleanly'], 'children' => []],
                        ['id' => 'checklist', 'component' => 'client-onboarding-checklist', 'settings' => ['items' => 'login|hosting|assets|contacts|goals'], 'children' => []],
                        ['id' => 'routes', 'component' => 'account-route-grid', 'settings' => ['items' => 'client area|ticket|account rep|checkout'], 'children' => []],
                        ['id' => 'next', 'component' => 'first-ticket-cta', 'settings' => ['button' => 'Open first request'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-launch-checklist-page',
                'title'   => 'Launch Checklist Page',
                'excerpt' => 'Prelaunch QA page for staging, DNS, SSL, mobile checks, forms, redirects, and final approval.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Launch Checklist Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['launch-checklist', 'dns-ssl', 'staging-site', 'mobile-responsive'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'launch-readiness-hero', 'settings' => ['headline' => 'Make launch feel controlled instead of mysterious'], 'children' => []],
                        ['id' => 'qa', 'component' => 'launch-qa-checklist', 'settings' => ['items' => 'mobile|forms|checkout|redirects|analytics'], 'children' => []],
                        ['id' => 'technical', 'component' => 'dns-ssl-status-grid', 'settings' => ['items' => 'dns|ssl|staging|backups'], 'children' => []],
                        ['id' => 'approval', 'component' => 'launch-approval-cta', 'settings' => ['button' => 'Approve launch path'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-email-deliverability-page',
                'title'   => 'Email Deliverability Fix Page',
                'excerpt' => 'Service page for broken forms, missing receipts, SMTP, DNS records, notifications, and follow-up flows.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Email Deliverability Fix Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['email-deliverability', 'form-leads', 'dns-ssl', 'technical-audit'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'email-fix-hero', 'settings' => ['headline' => 'If forms and receipts do not arrive, customers think the site is broken'], 'children' => []],
                        ['id' => 'symptoms', 'component' => 'delivery-symptom-grid', 'settings' => ['items' => 'forms|orders|notifications|spam|dns'], 'children' => []],
                        ['id' => 'fix-path', 'component' => 'email-fix-timeline', 'settings' => ['steps' => 'test|dns|smtp|forms|monitor'], 'children' => []],
                        ['id' => 'cta', 'component' => 'support-ticket-cta', 'settings' => ['button' => 'Request email fix'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-image-optimization-page',
                'title'   => 'Image Optimization Page',
                'excerpt' => 'Performance page for oversized media, responsive images, lazy loading, product photos, and Core Web Vitals.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Image Optimization Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['image-optimization', 'core-web-vitals', 'speed-tuning', 'mobile-responsive'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'image-performance-hero', 'settings' => ['headline' => 'Keep the site visual without making it painfully slow'], 'children' => []],
                        ['id' => 'audit', 'component' => 'image-audit-grid', 'settings' => ['items' => 'size|format|mobile|lazy load|product images'], 'children' => []],
                        ['id' => 'impact', 'component' => 'core-web-vitals-impact', 'settings' => ['focus' => 'lcp|cls|mobile'], 'children' => []],
                        ['id' => 'cta', 'component' => 'speed-service-cta', 'settings' => ['button' => 'Request image pass'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-uptime-incident-page',
                'title'   => 'Uptime Incident Page',
                'excerpt' => 'Incident/status starter for outages, emergency tickets, health checks, updates, and recovery notes.',
                'spec'    => [
                    'version'  => '1.5',
                    'name'     => 'Uptime Incident Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['uptime-monitor', 'emergency-support', 'support-ticket', 'site-health'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'incident-status-hero', 'settings' => ['headline' => 'Show the issue, the impact, and the recovery path'], 'children' => []],
                        ['id' => 'status', 'component' => 'incident-status-cards', 'settings' => ['items' => 'identified|working|monitoring|resolved'], 'children' => []],
                        ['id' => 'timeline', 'component' => 'incident-timeline', 'settings' => ['density' => 'brief'], 'children' => []],
                        ['id' => 'support', 'component' => 'emergency-ticket-cta', 'settings' => ['button' => 'Open emergency ticket'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-help4-commerce-catalog',
                'title'   => 'Help4 Commerce Catalog Page',
                'excerpt' => 'Native commerce starter for large product catalogs, variations, subscriptions, checkout routing, and performance.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Help4 Commerce Catalog Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['catalog-import', 'variant-matrix', 'commerce-cart', 'checkout-shield'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'native-commerce-hero', 'settings' => ['headline' => 'Sell big catalogs without bolting on another store plugin'], 'children' => []],
                        ['id' => 'catalog-scale', 'component' => 'large-catalog-proof', 'settings' => ['capacity' => '1500000-plus-products'], 'children' => []],
                        ['id' => 'variations', 'component' => 'variation-matrix-explainer', 'settings' => ['tone' => 'plain-language'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'checkout-router-cta', 'settings' => ['destination' => 'Configured checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-subscription-product-page',
                'title'   => 'Subscription Product Page',
                'excerpt' => 'Recurring product page for plans, memberships, renewals, setup fees, trials, and account-area checkout links.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Subscription Product Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['subscription-cycle', 'recurring-invoice', 'payment-route', 'client-portal'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'recurring-offer-hero', 'settings' => ['headline' => 'Explain the recurring value before asking for the card'], 'children' => []],
                        ['id' => 'plan-fit', 'component' => 'subscription-fit-grid', 'settings' => ['items' => 'monthly|annual|trial|setup fee|support level'], 'children' => []],
                        ['id' => 'renewal-path', 'component' => 'renewal-timeline', 'settings' => ['steps' => 'signup|trial|renewal|support|cancel'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'client-area-checkout-cta', 'settings' => ['button' => 'Continue to secure checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-payment-router-control-page',
                'title'   => 'Payment Router Control Page',
                'excerpt' => 'Payment-routing explainer for processor rules, fallback paths, subscriptions, status notes, and checkout confidence.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Payment Router Control Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['payment-route', 'processor-failover', 'checkout-shield', 'technical-audit'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'payment-router-hero', 'settings' => ['headline' => 'Route each checkout to the processor that fits the order'], 'children' => []],
                        ['id' => 'rules', 'component' => 'processor-rule-table', 'settings' => ['conditions' => 'subscription|amount|product|risk|fallback'], 'children' => []],
                        ['id' => 'fallback', 'component' => 'processor-failover-map', 'settings' => ['mode' => 'visible-to-admins'], 'children' => []],
                        ['id' => 'proof', 'component' => 'checkout-confidence-band', 'settings' => ['tone' => 'customer-safe'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-structured-field-system',
                'title'   => 'Custom Field System Page',
                'excerpt' => 'Field-system starter for groups, repeaters, galleries, relationships, conditional display, and dynamic templates.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Custom Field System Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['field-groups', 'builder-blocks', 'theme-conditions', 'template-wizard'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'field-system-hero', 'settings' => ['headline' => 'Build flexible content fields without making the editor scary'], 'children' => []],
                        ['id' => 'field-groups', 'component' => 'field-group-grid', 'settings' => ['types' => 'text|repeater|gallery|relationship|conditional'], 'children' => []],
                        ['id' => 'dynamic-output', 'component' => 'dynamic-template-map', 'settings' => ['sources' => 'post|product|term|user|site'], 'children' => []],
                        ['id' => 'performance', 'component' => 'module-loading-note', 'settings' => ['load' => 'only-where-used'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-slider-story-page',
                'title'   => 'Slider Story Page',
                'excerpt' => 'Layered slider starter for hero stories, product promos, campaign reveals, mobile controls, and reduced motion.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Slider Story Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['slider-layers', 'launch-rocket', 'mobile-responsive', 'conversion-path'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'slider-story-hero', 'settings' => ['headline' => 'Make the first view move with purpose'], 'children' => []],
                        ['id' => 'slides', 'component' => 'slide-layer-plan', 'settings' => ['layers' => 'image|badge|headline|cta|position'], 'children' => []],
                        ['id' => 'controls', 'component' => 'slider-control-strip', 'settings' => ['controls' => 'dots|pause|keyboard|swipe|reduced-motion'], 'children' => []],
                        ['id' => 'cta', 'component' => 'campaign-cta-band', 'settings' => ['button' => 'Start the campaign'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-builder-blank-theme-launch',
                'title'   => 'Blank Theme Launch Page',
                'excerpt' => 'Lean blank-theme launch starter for global parts, display rules, responsive QA, and publish checklists.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Blank Theme Launch Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['template-wizard', 'theme-conditions', 'responsive-qa', 'launch-checklist'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'blank-theme-hero', 'settings' => ['headline' => 'Start with a lean theme, then build the site in the suite'], 'children' => []],
                        ['id' => 'global-parts', 'component' => 'global-template-map', 'settings' => ['parts' => 'header|footer|archive|single|product'], 'children' => []],
                        ['id' => 'conditions', 'component' => 'display-condition-guide', 'settings' => ['rules' => 'sitewide|page|post type|product|role'], 'children' => []],
                        ['id' => 'publish', 'component' => 'responsive-publish-checklist', 'settings' => ['viewports' => 'mobile|tablet|desktop|4k|8k'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-security-commerce-hardening',
                'title'   => 'Commerce Security Hardening Page',
                'excerpt' => 'Security starter for checkout trust, processor fallback, suspicious order review, backups, and site health.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Commerce Security Hardening Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['checkout-shield', 'security-shield', 'processor-failover', 'site-health'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'commerce-security-hero', 'settings' => ['headline' => 'Protect the checkout path customers actually use'], 'children' => []],
                        ['id' => 'risks', 'component' => 'commerce-risk-grid', 'settings' => ['items' => 'fraud|failed payments|webhooks|accounts|backups'], 'children' => []],
                        ['id' => 'hardening', 'component' => 'security-hardening-plan', 'settings' => ['steps' => 'monitor|route|backup|review|recover'], 'children' => []],
                        ['id' => 'support', 'component' => 'support-ticket-cta', 'settings' => ['button' => 'Request security review'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-enterprise-product-import',
                'title'   => 'Enterprise Product Import Page',
                'excerpt' => 'Large-catalog starter for imports, mappings, variations, subscriptions, processor routing, and operations review.',
                'spec'    => [
                    'version'  => '1.6',
                    'name'     => 'Enterprise Product Import Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['catalog-import', 'variant-matrix', 'subscription-cycle', 'analytics-dashboard'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'catalog-import-hero', 'settings' => ['headline' => 'Bring the product catalog in without losing the business rules'], 'children' => []],
                        ['id' => 'mapping', 'component' => 'import-mapping-table', 'settings' => ['fields' => 'sku|price|stock|attributes|media'], 'children' => []],
                        ['id' => 'variations', 'component' => 'variation-and-subscription-map', 'settings' => ['scale' => 'large-catalog'], 'children' => []],
                        ['id' => 'review', 'component' => 'operations-review-cta', 'settings' => ['button' => 'Review import plan'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-builder-quickstart-home',
                'title'   => 'Builder Quickstart Home Page',
                'excerpt' => 'First-day builder starter for setup, blank theme pairing, starter selection, responsive checks, and publish path.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Builder Quickstart Home Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['builder-quickstart', 'template-import', 'responsive-preview', 'release-channel'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'builder-quickstart-hero', 'settings' => ['headline' => 'Install, pick a starter, check mobile, and publish with confidence'], 'children' => []],
                        ['id' => 'steps', 'component' => 'first-run-stepper', 'settings' => ['steps' => 'install|blank theme|starter|mobile|publish'], 'children' => []],
                        ['id' => 'starter-paths', 'component' => 'starter-path-grid', 'settings' => ['paths' => 'service|commerce|support|launch'], 'children' => []],
                        ['id' => 'next', 'component' => 'tutorial-link-band', 'settings' => ['button' => 'Open builder guide'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-module-control-center',
                'title'   => 'Module Control Center Page',
                'excerpt' => 'Operational page that explains enabled modules, load rules, performance budget, and what each feature does.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Module Control Center Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['module-toggle', 'core-web-vitals', 'security-shield', 'site-health'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'module-control-hero', 'settings' => ['headline' => 'Turn on what the site needs and keep the rest quiet'], 'children' => []],
                        ['id' => 'modules', 'component' => 'module-toggle-grid', 'settings' => ['items' => 'builder|forms|slider|commerce|seo|security'], 'children' => []],
                        ['id' => 'load-rules', 'component' => 'asset-loading-map', 'settings' => ['mode' => 'only-where-used'], 'children' => []],
                        ['id' => 'review', 'component' => 'performance-review-cta', 'settings' => ['button' => 'Review enabled modules'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-global-style-system',
                'title'   => 'Global Style System Page',
                'excerpt' => 'Style-system starter for colors, typography, spacing, buttons, responsive rules, and reusable brand defaults.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Global Style System Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['global-style', 'theme-conditions', 'template-wizard', 'responsive-preview'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'style-system-hero', 'settings' => ['headline' => 'Make every page feel like it came from the same brand'], 'children' => []],
                        ['id' => 'tokens', 'component' => 'design-token-grid', 'settings' => ['tokens' => 'color|type|spacing|buttons|forms'], 'children' => []],
                        ['id' => 'examples', 'component' => 'component-preview-strip', 'settings' => ['items' => 'hero|card|form|cta'], 'children' => []],
                        ['id' => 'qa', 'component' => 'responsive-style-checklist', 'settings' => ['viewports' => 'mobile|tablet|desktop'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-product-collection-page',
                'title'   => 'Product Collection Page',
                'excerpt' => 'Collection starter for product groups, variants, filters, comparison cues, subscriptions, and checkout routing.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Product Collection Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['product-collection', 'catalog-import', 'variant-matrix', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'collection-hero', 'settings' => ['headline' => 'Group products by the job customers are trying to finish'], 'children' => []],
                        ['id' => 'filters', 'component' => 'collection-filter-bar', 'settings' => ['filters' => 'category|price|availability|plan type'], 'children' => []],
                        ['id' => 'products', 'component' => 'product-card-grid', 'settings' => ['cards' => 'image|price|variant|cta'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'checkout-routing-note', 'settings' => ['destination' => 'connected checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-checkout-recovery-page',
                'title'   => 'Checkout Recovery Page',
                'excerpt' => 'Support and trust page for failed payments, abandoned checkout, webhook status, retry flows, and customer help.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Checkout Recovery Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['checkout-recovery', 'webhook-status', 'payment-route', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'checkout-help-hero', 'settings' => ['headline' => 'Help customers finish checkout without making them start over'], 'children' => []],
                        ['id' => 'status', 'component' => 'payment-status-grid', 'settings' => ['states' => 'failed|pending|retried|complete'], 'children' => []],
                        ['id' => 'webhooks', 'component' => 'webhook-health-strip', 'settings' => ['items' => 'received|queued|retried|resolved'], 'children' => []],
                        ['id' => 'support', 'component' => 'checkout-support-cta', 'settings' => ['button' => 'Get checkout help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-update-release-notes-page',
                'title'   => 'Update Release Notes Page',
                'excerpt' => 'Release communication starter for beta/stable tracks, compatibility notes, upgrade steps, rollback plan, and support links.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Update Release Notes Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['safe-update', 'beta-channel', 'release-channel', 'staging-site'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'release-notes-hero', 'settings' => ['headline' => 'Show what changed, who should update, and what to check'], 'children' => []],
                        ['id' => 'tracks', 'component' => 'beta-stable-track-grid', 'settings' => ['tracks' => 'beta|stable|manual'], 'children' => []],
                        ['id' => 'checks', 'component' => 'upgrade-checklist', 'settings' => ['items' => 'backup|staging|forms|checkout|mobile'], 'children' => []],
                        ['id' => 'support', 'component' => 'release-support-band', 'settings' => ['button' => 'Ask about this update'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-content-brief-workflow',
                'title'   => 'Content Brief Workflow Page',
                'excerpt' => 'Client-friendly page for gathering copy, screenshots, files, goals, approvals, and launch-ready content.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Content Brief Workflow Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-brief', 'copywriting-brief', 'design-handoff', 'client-handoff'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'content-brief-hero', 'settings' => ['headline' => 'Give the builder the words, images, and decisions before the page starts'], 'children' => []],
                        ['id' => 'inputs', 'component' => 'content-input-grid', 'settings' => ['items' => 'copy|photos|offers|proof|approvals'], 'children' => []],
                        ['id' => 'review', 'component' => 'approval-timeline', 'settings' => ['steps' => 'draft|review|revise|approve|publish'], 'children' => []],
                        ['id' => 'handoff', 'component' => 'client-handoff-cta', 'settings' => ['button' => 'Send page assets'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-support-article-template',
                'title'   => 'Support Article Template',
                'excerpt' => 'Knowledge-base article starter for symptoms, cause, fix steps, screenshots, escalation, and related tutorials.',
                'spec'    => [
                    'version'  => '1.7',
                    'name'     => 'Support Article Template',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['documentation-hub', 'faq-knowledge-base', 'support-ticket', 'safe-update'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'support-article-hero', 'settings' => ['headline' => 'Explain the problem, then show the fix in order'], 'children' => []],
                        ['id' => 'symptoms', 'component' => 'symptom-summary-box', 'settings' => ['items' => 'what happens|who is affected|urgency'], 'children' => []],
                        ['id' => 'steps', 'component' => 'numbered-fix-steps', 'settings' => ['steps' => 'check|change|test|confirm'], 'children' => []],
                        ['id' => 'related', 'component' => 'related-tutorial-grid', 'settings' => ['items' => 'builder|templates|fields|updates'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-handoff-landing',
                'title'   => 'Design Handoff Landing Page',
                'excerpt' => 'Landing-page starter for turning a design file, screenshot set, or rough brief into a production page request.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Design Handoff Landing Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['design-handoff', 'design-approval', 'brand-kit', 'mobile-wireframe'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'handoff-hero', 'settings' => ['headline' => 'Send the design, notes, and assets before the build starts'], 'children' => []],
                        ['id' => 'intake', 'component' => 'handoff-intake-grid', 'settings' => ['items' => 'design file|screenshots|copy|assets|approval'], 'children' => []],
                        ['id' => 'qa', 'component' => 'responsive-handoff-checklist', 'settings' => ['viewports' => 'mobile|tablet|desktop|wide'], 'children' => []],
                        ['id' => 'cta', 'component' => 'build-request-cta', 'settings' => ['button' => 'Send build request'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-local-service-quote',
                'title'   => 'Local Service Quote Page',
                'excerpt' => 'Quote-request starter for service-area proof, before/after trust, package options, FAQ, and lead capture.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Local Service Quote Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['quote-request', 'local-service', 'review-stars', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'local-quote-hero', 'settings' => ['headline' => 'Show the service, prove the area, and ask for the quote'], 'children' => []],
                        ['id' => 'proof', 'component' => 'service-proof-strip', 'settings' => ['items' => 'reviews|photos|areas|guarantee'], 'children' => []],
                        ['id' => 'packages', 'component' => 'service-package-grid', 'settings' => ['cards' => 'good|better|custom'], 'children' => []],
                        ['id' => 'form', 'component' => 'quote-intake-form', 'settings' => ['fields' => 'name|phone|email|site|need'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-review-request-page',
                'title'   => 'Review Request Page',
                'excerpt' => 'Customer review starter for asking happy clients for feedback, routing complaints to support, and collecting proof.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Review Request Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['review-request', 'review-stars', 'support-ticket', 'quality-review'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'review-request-hero', 'settings' => ['headline' => 'Happy with the work? Leave a review. Need help? Tell support first.'], 'children' => []],
                        ['id' => 'paths', 'component' => 'review-or-support-paths', 'settings' => ['paths' => 'leave review|open support ticket'], 'children' => []],
                        ['id' => 'examples', 'component' => 'review-prompt-grid', 'settings' => ['prompts' => 'speed|communication|result|support'], 'children' => []],
                        ['id' => 'cta', 'component' => 'review-link-band', 'settings' => ['button' => 'Leave a review'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-comparison-buyer-guide',
                'title'   => 'Comparison Buyer Guide Page',
                'excerpt' => 'Buyer-guide starter for comparing plans, managed service levels, build options, risks, and next steps.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Comparison Buyer Guide Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['comparison-chart', 'plan-selector', 'pricing-table', 'copywriting-brief'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'buyer-guide-hero', 'settings' => ['headline' => 'Compare the buying paths before choosing the plan'], 'children' => []],
                        ['id' => 'matrix', 'component' => 'plan-comparison-matrix', 'settings' => ['columns' => 'diy|managed|priority|custom'], 'children' => []],
                        ['id' => 'risks', 'component' => 'decision-risk-grid', 'settings' => ['items' => 'time|support|speed|security|growth'], 'children' => []],
                        ['id' => 'cta', 'component' => 'recommended-path-cta', 'settings' => ['button' => 'Ask for a recommendation'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-case-study-page',
                'title'   => 'Case Study Page',
                'excerpt' => 'Case-study starter for problem, work performed, screenshots, measurable outcome, testimonial, and next CTA.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Case Study Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['case-study', 'analytics-report', 'portfolio-showcase', 'review-stars'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'case-study-hero', 'settings' => ['headline' => 'Show the problem, the work, and the result'], 'children' => []],
                        ['id' => 'before-after', 'component' => 'before-after-story-grid', 'settings' => ['items' => 'problem|fix|result'], 'children' => []],
                        ['id' => 'metrics', 'component' => 'outcome-metric-row', 'settings' => ['metrics' => 'speed|leads|stability|handoff'], 'children' => []],
                        ['id' => 'cta', 'component' => 'similar-project-cta', 'settings' => ['button' => 'Request similar work'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-migration-rescue-page',
                'title'   => 'Migration Rescue Page',
                'excerpt' => 'Rescue starter for broken migrations, DNS/SSL problems, plugin conflicts, rollback planning, and emergency handoff.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Migration Rescue Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['rescue-lifeline', 'migration-path', 'dns-ssl', 'rollback-plan'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'migration-rescue-hero', 'settings' => ['headline' => 'Stuck migration, broken SSL, or launch fire? Start here.'], 'children' => []],
                        ['id' => 'symptoms', 'component' => 'rescue-symptom-grid', 'settings' => ['items' => 'dns|ssl|white screen|checkout|email|redirects'], 'children' => []],
                        ['id' => 'plan', 'component' => 'rollback-and-recover-plan', 'settings' => ['steps' => 'snapshot|diagnose|repair|verify|launch'], 'children' => []],
                        ['id' => 'cta', 'component' => 'emergency-support-cta', 'settings' => ['button' => 'Open rescue ticket'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-knowledge-base-index',
                'title'   => 'Knowledge Base Index Page',
                'excerpt' => 'Documentation index starter for grouping tutorials, setup guides, troubleshooting articles, and support escalation paths.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Knowledge Base Index Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['knowledge-index', 'documentation-hub', 'faq-knowledge-base', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'knowledge-index-hero', 'settings' => ['headline' => 'Organize help by the job the customer needs done'], 'children' => []],
                        ['id' => 'topics', 'component' => 'topic-card-grid', 'settings' => ['topics' => 'install|templates|commerce|updates|support'], 'children' => []],
                        ['id' => 'popular', 'component' => 'popular-article-list', 'settings' => ['items' => 'downloads|first page|icons|wordpress updates'], 'children' => []],
                        ['id' => 'support', 'component' => 'support-escalation-band', 'settings' => ['button' => 'Open support ticket'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-lead-intake-page',
                'title'   => 'Lead Intake Page',
                'excerpt' => 'Lead-intake starter for collecting the URL, business goal, needed pages, design assets, budget signal, and contact route.',
                'spec'    => [
                    'version'  => '1.8',
                    'name'     => 'Lead Intake Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['lead-intake', 'form-leads', 'client-handoff', 'account-rep'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'lead-intake-hero', 'settings' => ['headline' => 'Send the site, the goal, and what needs to happen next'], 'children' => []],
                        ['id' => 'fields', 'component' => 'lead-intake-field-map', 'settings' => ['fields' => 'url|goal|pages|assets|deadline|contact'], 'children' => []],
                        ['id' => 'routing', 'component' => 'lead-routing-summary', 'settings' => ['routes' => 'support|sales|managed|custom'], 'children' => []],
                        ['id' => 'cta', 'component' => 'submit-intake-cta', 'settings' => ['button' => 'Send project details'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-service-calculator-page',
                'title'   => 'Service Calculator Page',
                'excerpt' => 'Quote-calculator starter that helps non-technical buyers choose scope, urgency, content help, and support level before contacting sales.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'Service Calculator Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['service-calculator', 'quote-request', 'pricing-table', 'account-rep'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'calculator-hero', 'settings' => ['headline' => 'Get a sane estimate before anyone talks in tech words'], 'children' => []],
                        ['id' => 'inputs', 'component' => 'service-scope-calculator', 'settings' => ['inputs' => 'pages|design|commerce|content|urgency'], 'children' => []],
                        ['id' => 'ranges', 'component' => 'estimate-range-grid', 'settings' => ['tiers' => 'starter|standard|rush|custom'], 'children' => []],
                        ['id' => 'handoff', 'component' => 'quote-handoff-cta', 'settings' => ['button' => 'Send estimate request'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-trust-badges-page',
                'title'   => 'Trust Badges Page',
                'excerpt' => 'Proof-and-policy starter for warranties, process promises, support expectations, payment safety, and customer reassurance.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'Trust Badges Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['trust-badges', 'security-shield', 'refund-policy', 'quality-review'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'trust-hero', 'settings' => ['headline' => 'Why hiring Help4 is safer than winging it'], 'children' => []],
                        ['id' => 'badges', 'component' => 'trust-badge-grid', 'settings' => ['badges' => 'secure|documented|reviewed|supported'], 'children' => []],
                        ['id' => 'policies', 'component' => 'plain-english-policy-list', 'settings' => ['policies' => 'scope|access|payment|handoff'], 'children' => []],
                        ['id' => 'proof', 'component' => 'review-proof-strip', 'settings' => ['source' => 'site'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-migration-checklist-page',
                'title'   => 'Migration Checklist Page',
                'excerpt' => 'Migration checklist starter for domains, backups, content inventory, redirects, DNS, email, checkout, testing, and rollback planning.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'Migration Checklist Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['migration-check', 'dns-ssl', 'backup-restore', 'rollback-plan'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'migration-checklist-hero', 'settings' => ['headline' => 'Move the site without losing pages, sales, or sleep'], 'children' => []],
                        ['id' => 'checklist', 'component' => 'migration-checklist-table', 'settings' => ['groups' => 'access|content|dns|checkout|qa'], 'children' => []],
                        ['id' => 'risks', 'component' => 'migration-risk-callouts', 'settings' => ['level' => 'plain-english'], 'children' => []],
                        ['id' => 'cta', 'component' => 'migration-review-cta', 'settings' => ['button' => 'Review my move'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-product-comparison-matrix',
                'title'   => 'Product Comparison Matrix',
                'excerpt' => 'Comparison starter for packages, support levels, commerce features, managed services, and buyer-ready plan differences.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'Product Comparison Matrix',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['comparison-chart', 'feature-gate', 'plan-selector', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'comparison-hero', 'settings' => ['headline' => 'Pick the plan by what it actually does'], 'children' => []],
                        ['id' => 'matrix', 'component' => 'feature-comparison-matrix', 'settings' => ['columns' => 'basic|managed|build|priority'], 'children' => []],
                        ['id' => 'decision', 'component' => 'decision-helper-band', 'settings' => ['questions' => 'budget|timeline|commerce|support'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'checkout-routing-cta', 'settings' => ['button' => 'Continue to checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-content-calendar-page',
                'title'   => 'Content Calendar Page',
                'excerpt' => 'Content-planning starter for blog campaigns, service updates, launch announcements, social snippets, and SEO briefs.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'Content Calendar Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-calendar', 'content-brief', 'copywriting-brief', 'seo-growth'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'content-calendar-hero', 'settings' => ['headline' => 'Know what to publish next and why it matters'], 'children' => []],
                        ['id' => 'calendar', 'component' => 'campaign-calendar-grid', 'settings' => ['cadence' => 'weekly|monthly|launch'], 'children' => []],
                        ['id' => 'briefs', 'component' => 'content-brief-list', 'settings' => ['fields' => 'keyword|intent|cta|owner'], 'children' => []],
                        ['id' => 'cta', 'component' => 'content-help-cta', 'settings' => ['button' => 'Request content help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-video-sales-page',
                'title'   => 'Video Sales Page',
                'excerpt' => 'Video-led landing starter for demos, walkthroughs, product proof, testimonials, and conversion CTAs.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'Video Sales Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['onboarding-video', 'conversion-path', 'review-stars', 'lead-intake'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'video-sales-hero', 'settings' => ['headline' => 'Watch the quick version before you decide'], 'children' => []],
                        ['id' => 'video', 'component' => 'responsive-video-panel', 'settings' => ['provider' => 'embed'], 'children' => []],
                        ['id' => 'chapters', 'component' => 'video-chapter-list', 'settings' => ['chapters' => 'problem|demo|proof|next step'], 'children' => []],
                        ['id' => 'cta', 'component' => 'video-conversion-cta', 'settings' => ['button' => 'Start my build'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-support-escalation-page',
                'title'   => 'Support Escalation Page',
                'excerpt' => 'Support path starter that routes customers by emergency, update issue, billing question, content request, or build help.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'Support Escalation Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['support-escalation', 'emergency-support', 'support-ticket', 'account-rep'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'support-escalation-hero', 'settings' => ['headline' => 'Get the right kind of help without guessing'], 'children' => []],
                        ['id' => 'routes', 'component' => 'support-route-grid', 'settings' => ['routes' => 'emergency|update|billing|content|build'], 'children' => []],
                        ['id' => 'sla', 'component' => 'response-expectation-table', 'settings' => ['plans' => 'standard|managed|priority'], 'children' => []],
                        ['id' => 'cta', 'component' => 'ticket-launch-cta', 'settings' => ['button' => 'Open the right ticket'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-faq-hub-page',
                'title'   => 'FAQ Hub Page',
                'excerpt' => 'FAQ hub starter for grouped questions, schema-ready answers, support routing, download links, and plain-language objections.',
                'spec'    => [
                    'version'  => '1.9',
                    'name'     => 'FAQ Hub Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['faq-hub', 'schema-faq', 'documentation-hub', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'faq-hub-hero', 'settings' => ['headline' => 'Answers before support has to translate anything'], 'children' => []],
                        ['id' => 'groups', 'component' => 'faq-topic-grid', 'settings' => ['topics' => 'install|builder|commerce|updates|support'], 'children' => []],
                        ['id' => 'schema', 'component' => 'faq-schema-list', 'settings' => ['mode' => 'grouped'], 'children' => []],
                        ['id' => 'support', 'component' => 'faq-support-cta', 'settings' => ['button' => 'Still need help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-builder-first-page',
                'title'   => 'Builder First Page',
                'excerpt' => 'First-run starter for non-technical users who need a safe hero, proof, service cards, contact CTA, and publish checklist.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Builder First Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['first-page', 'builder-blocks', 'screenshot-step', 'responsive-qa'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'first-page-hero', 'settings' => ['headline' => 'Start with the page customers actually need'], 'children' => []],
                        ['id' => 'proof', 'component' => 'starter-proof-row', 'settings' => ['items' => 'service|proof|cta|contact'], 'children' => []],
                        ['id' => 'steps', 'component' => 'plain-setup-steps', 'settings' => ['steps' => 'replace copy|swap images|check mobile|publish'], 'children' => []],
                        ['id' => 'cta', 'component' => 'publish-checklist-cta', 'settings' => ['button' => 'Finish this page'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-blank-theme-homepage',
                'title'   => 'Blank Theme Homepage',
                'excerpt' => 'Homepage starter made for the Help4 blank-theme workflow with global header, footer, content bands, and safe spacing defaults.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Blank Theme Homepage',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['blank-theme', 'theme-builder', 'layout-grid', 'mobile-wireframe'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'blank-theme-hero', 'settings' => ['headline' => 'A clean homepage that lets the builder do the work'], 'children' => []],
                        ['id' => 'services', 'component' => 'service-card-band', 'settings' => ['cards' => 'three'], 'children' => []],
                        ['id' => 'trust', 'component' => 'trust-proof-strip', 'settings' => ['items' => 'reviews|support|speed'], 'children' => []],
                        ['id' => 'footer-cta', 'component' => 'footer-ready-cta', 'settings' => ['button' => 'Set global parts'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-service-area-seo-page',
                'title'   => 'Service Area SEO Page',
                'excerpt' => 'Local SEO starter for city pages, service-area proof, nearby work, FAQs, reviews, and quote routing.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Service Area SEO Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['service-area-map', 'local-service', 'schema-faq', 'review-stars'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'service-area-hero', 'settings' => ['headline' => 'Show the city, the service, and why locals should trust you'], 'children' => []],
                        ['id' => 'areas', 'component' => 'service-area-map-list', 'settings' => ['areas' => 'primary|nearby|covered'], 'children' => []],
                        ['id' => 'proof', 'component' => 'nearby-work-proof-grid', 'settings' => ['items' => 'reviews|photos|case study'], 'children' => []],
                        ['id' => 'faq', 'component' => 'local-faq-schema', 'settings' => ['questions' => 'pricing|timing|coverage|support'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-native-commerce-product',
                'title'   => 'Native Commerce Product Page',
                'excerpt' => 'Product page starter for Help4 Commerce catalogs with gallery, variations, subscription note, trust proof, and checkout routing.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Native Commerce Product Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['native-commerce', 'commerce-cart', 'subscription-flow', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'commerce-product-hero', 'settings' => ['headline' => 'Explain the product before asking for payment'], 'children' => []],
                        ['id' => 'options', 'component' => 'variation-option-table', 'settings' => ['groups' => 'size|term|support|addons'], 'children' => []],
                        ['id' => 'trust', 'component' => 'commerce-trust-row', 'settings' => ['items' => 'secure|support|refund|delivery'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'connected-checkout-cta', 'settings' => ['button' => 'Continue to checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-subscription-offer-page',
                'title'   => 'Subscription Offer Page',
                'excerpt' => 'Recurring-offer starter for plans, billing expectations, support levels, cancellation notes, and payment-router handoff.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Subscription Offer Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['subscription-flow', 'plan-selector', 'refund-policy', 'payment-router'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'subscription-offer-hero', 'settings' => ['headline' => 'Make the recurring plan obvious before checkout'], 'children' => []],
                        ['id' => 'plans', 'component' => 'subscription-plan-grid', 'settings' => ['plans' => 'monthly|annual|managed'], 'children' => []],
                        ['id' => 'expectations', 'component' => 'billing-expectation-list', 'settings' => ['items' => 'renewal|support|changes|cancel'], 'children' => []],
                        ['id' => 'cta', 'component' => 'subscription-checkout-cta', 'settings' => ['button' => 'Choose plan'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-digital-download-page',
                'title'   => 'Digital Download Page',
                'excerpt' => 'Download-delivery starter for software, files, license notes, changelog links, support instructions, and version proof.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Digital Download Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['digital-download', 'update-readiness', 'documentation-hub', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'download-hero', 'settings' => ['headline' => 'Give users the file, the version, and the next step'], 'children' => []],
                        ['id' => 'download', 'component' => 'download-card-stack', 'settings' => ['items' => 'latest|manifest|changelog'], 'children' => []],
                        ['id' => 'install', 'component' => 'install-step-list', 'settings' => ['steps' => 'download|upload|activate|verify'], 'children' => []],
                        ['id' => 'support', 'component' => 'download-support-band', 'settings' => ['button' => 'Get install help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-membership-lesson-page',
                'title'   => 'Membership Lesson Page',
                'excerpt' => 'Lesson starter for gated content, module navigation, progress notes, downloads, and support links.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Membership Lesson Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['membership-gate', 'course-membership', 'digital-download', 'onboarding-video'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'lesson-hero', 'settings' => ['headline' => 'Put the lesson, progress, and resources in one clean flow'], 'children' => []],
                        ['id' => 'video', 'component' => 'lesson-video-panel', 'settings' => ['provider' => 'embed'], 'children' => []],
                        ['id' => 'resources', 'component' => 'lesson-resource-grid', 'settings' => ['items' => 'download|checklist|next lesson'], 'children' => []],
                        ['id' => 'progress', 'component' => 'lesson-progress-cta', 'settings' => ['button' => 'Mark complete'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-booking-request-page',
                'title'   => 'Booking Request Page',
                'excerpt' => 'Booking starter for appointment requests, service choices, calendar expectations, deposits, and confirmation copy.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Booking Request Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['booking-request', 'appointment-calendar', 'form-leads', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'booking-hero', 'settings' => ['headline' => 'Let customers request the right appointment without calling twice'], 'children' => []],
                        ['id' => 'services', 'component' => 'booking-service-picker', 'settings' => ['choices' => 'consult|repair|install|follow up'], 'children' => []],
                        ['id' => 'details', 'component' => 'booking-detail-form', 'settings' => ['fields' => 'date|time|service|notes|contact'], 'children' => []],
                        ['id' => 'confirm', 'component' => 'booking-confirmation-band', 'settings' => ['button' => 'Request booking'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-before-after-portfolio',
                'title'   => 'Before After Portfolio',
                'excerpt' => 'Portfolio starter for before/after screenshots, project notes, measured improvements, testimonial, and similar-work CTA.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Before After Portfolio',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['before-after', 'portfolio-showcase', 'analytics-report', 'case-study'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'before-after-hero', 'settings' => ['headline' => 'Show what changed, why it mattered, and what improved'], 'children' => []],
                        ['id' => 'gallery', 'component' => 'before-after-gallery', 'settings' => ['pairs' => 'desktop|mobile|speed'], 'children' => []],
                        ['id' => 'story', 'component' => 'project-story-grid', 'settings' => ['items' => 'problem|work|result'], 'children' => []],
                        ['id' => 'cta', 'component' => 'portfolio-conversion-cta', 'settings' => ['button' => 'Request similar work'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-launch-announcement-page',
                'title'   => 'Launch Announcement Page',
                'excerpt' => 'Launch announcement starter for new sites, product releases, update notes, screenshots, signup CTA, and support links.',
                'spec'    => [
                    'version'  => '2.0',
                    'name'     => 'Launch Announcement Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['launch-announcement', 'launch-rocket', 'screenshot-step', 'update-readiness'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'launch-announcement-hero', 'settings' => ['headline' => 'Tell customers what launched and what to do next'], 'children' => []],
                        ['id' => 'screens', 'component' => 'release-screenshot-grid', 'settings' => ['screens' => 'overview|feature|mobile|support'], 'children' => []],
                        ['id' => 'notes', 'component' => 'plain-release-note-list', 'settings' => ['items' => 'new|fixed|changed|next'], 'children' => []],
                        ['id' => 'cta', 'component' => 'launch-followup-cta', 'settings' => ['button' => 'See the new version'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-website-snapshot-recent-work-gallery',
                'title'   => 'Website Snapshot Recent Work Gallery',
                'excerpt' => 'Portfolio starter for live website screenshots, proof notes, project summaries, and request-work calls to action.',
                'spec'    => [
                    'version'  => '2.1',
                    'name'     => 'Website Snapshot Recent Work Gallery',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['website-snapshot-gallery', 'website-screenshot', 'portfolio-showcase', 'review-stars'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'website-snapshot-proof-hero', 'settings' => ['headline' => 'Show the work with live website screenshots'], 'children' => []],
                        ['id' => 'gallery', 'component' => 'website-snapshot-card-grid', 'settings' => ['items' => 'site url|caption|project note|live link'], 'children' => []],
                        ['id' => 'proof', 'component' => 'project-proof-strip', 'settings' => ['items' => 'before|after|service|result'], 'children' => []],
                        ['id' => 'cta', 'component' => 'recent-work-request-cta', 'settings' => ['button' => 'Request similar work'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-website-snapshot-migration-visual-audit',
                'title'   => 'Website Snapshot Migration Visual Audit',
                'excerpt' => 'Migration planning starter for current-site screenshots, rebuild notes, risk items, launch steps, and support routing.',
                'spec'    => [
                    'version'  => '2.1',
                    'name'     => 'Website Snapshot Migration Visual Audit',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['migration-snapshot', 'migration-path', 'update-readiness', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'migration-audit-hero', 'settings' => ['headline' => 'Put the current site and the rebuild plan in one place'], 'children' => []],
                        ['id' => 'snapshot', 'component' => 'website-snapshot-current-state', 'settings' => ['fields' => 'url|screenshot|notes|risk'], 'children' => []],
                        ['id' => 'plan', 'component' => 'migration-step-checklist', 'settings' => ['steps' => 'backup|content|theme|plugin|dns|launch'], 'children' => []],
                        ['id' => 'handoff', 'component' => 'migration-ticket-cta', 'settings' => ['button' => 'Start migration ticket'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-website-snapshot-comparison-proof',
                'title'   => 'Website Snapshot Website Comparison Proof',
                'excerpt' => 'Comparison starter for old site, new build, competitor examples, decision notes, and plain-English recommendations.',
                'spec'    => [
                    'version'  => '2.1',
                    'name'     => 'Website Snapshot Website Comparison Proof',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['comparison-proof', 'website-screenshot', 'analytics-report', 'case-study'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'comparison-proof-hero', 'settings' => ['headline' => 'Compare the page customers see with the page they need'], 'children' => []],
                        ['id' => 'screens', 'component' => 'website-snapshot-comparison-grid', 'settings' => ['columns' => 'current|target|reference'], 'children' => []],
                        ['id' => 'decision', 'component' => 'plain-decision-matrix', 'settings' => ['items' => 'clarity|speed|trust|conversion'], 'children' => []],
                        ['id' => 'cta', 'component' => 'comparison-build-cta', 'settings' => ['button' => 'Request the better version'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-website-snapshot-support-context',
                'title'   => 'Website Snapshot Support Context Page',
                'excerpt' => 'Support starter for customer-reported pages, screenshot context, issue notes, recent changes, and escalation steps.',
                'spec'    => [
                    'version'  => '2.1',
                    'name'     => 'Website Snapshot Support Context Page',
                    'viewport' => '8k-ready',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['website-screenshot', 'screenshot-step', 'support-ticket', 'support-escalation'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'support-context-hero', 'settings' => ['headline' => 'Show the exact page before troubleshooting it'], 'children' => []],
                        ['id' => 'shot', 'component' => 'website-snapshot-support-reference', 'settings' => ['fields' => 'url|screenshot|reported issue'], 'children' => []],
                        ['id' => 'details', 'component' => 'support-detail-list', 'settings' => ['items' => 'symptom|browser|recent change|priority'], 'children' => []],
                        ['id' => 'next', 'component' => 'support-next-step-cta', 'settings' => ['button' => 'Open support ticket'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-clean-service',
                'title'   => 'Clean Service Header Template',
                'excerpt' => 'Simple sitewide header with logo, primary navigation, phone/contact cue, and one clear service CTA.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Clean Service Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'global-header',
                    'screenshot' => 'screenshot-style-header-clean-service',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['header-template', 'navigation-menu', 'local-service', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'utility', 'component' => 'service-utility-bar', 'settings' => ['items' => 'phone|hours|service area'], 'children' => []],
                        ['id' => 'nav', 'component' => 'clean-primary-navigation', 'settings' => ['logo' => 'left', 'menu' => 'center'], 'children' => []],
                        ['id' => 'cta', 'component' => 'header-action-button', 'settings' => ['button' => 'Request help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-product-navigation',
                'title'   => 'Product Navigation Header Template',
                'excerpt' => 'Product-focused header with category links, account/checkout route, support link, and mobile-safe action stack.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Product Navigation Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'commerce-header',
                    'screenshot' => 'screenshot-style-header-product-navigation',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['header-template', 'commerce-cart', 'checkout-link', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'brand-row', 'component' => 'product-brand-row', 'settings' => ['routes' => 'catalog|support|account'], 'children' => []],
                        ['id' => 'category-nav', 'component' => 'catalog-category-nav', 'settings' => ['items' => 'plans|products|downloads|support'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'connected-checkout-link', 'settings' => ['label' => 'Account checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-local-business',
                'title'   => 'Local Business Header Template',
                'excerpt' => 'Local-service header with area cue, review proof, tap-to-call action, and service-menu layout.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Local Business Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'local-header',
                    'screenshot' => 'screenshot-style-header-local-business',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['header-template', 'local-service', 'review-stars', 'appointment-calendar'],
                    ],
                    'sections' => [
                        ['id' => 'proof-strip', 'component' => 'local-proof-header-strip', 'settings' => ['items' => 'rating|city|hours'], 'children' => []],
                        ['id' => 'nav', 'component' => 'local-service-navigation', 'settings' => ['menu' => 'services|areas|reviews|contact'], 'children' => []],
                        ['id' => 'phone', 'component' => 'tap-to-call-cta', 'settings' => ['visibility' => 'mobile-first'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-agency-mega-menu',
                'title'   => 'Agency Mega Menu Header Template',
                'excerpt' => 'Header pattern for service catalogs, documentation links, case studies, and account/support routes.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Agency Mega Menu Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'mega-menu-header',
                    'screenshot' => 'screenshot-style-header-agency-mega-menu',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['mega-menu', 'navigation-menu', 'case-study', 'client-portal'],
                    ],
                    'sections' => [
                        ['id' => 'nav', 'component' => 'mega-menu-navigation', 'settings' => ['columns' => 'services|proof|resources|account'], 'children' => []],
                        ['id' => 'feature', 'component' => 'mega-menu-feature-card', 'settings' => ['highlight' => 'Start with a template kit'], 'children' => []],
                        ['id' => 'actions', 'component' => 'header-action-group', 'settings' => ['actions' => 'support|estimate|client area'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-minimal-landing',
                'title'   => 'Minimal Landing Header Template',
                'excerpt' => 'Tiny campaign header for landing pages that need brand trust without distracting navigation.',
                'role'    => 'header',
                'scope'   => 'specific_ids',
                'priority' => 15,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Minimal Landing Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'landing-header',
                    'screenshot' => 'screenshot-style-header-minimal-landing',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['sticky-header', 'landing-template', 'trust-badges', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'brand', 'component' => 'minimal-brand-bar', 'settings' => ['links' => 'logo|privacy|support'], 'children' => []],
                        ['id' => 'cta', 'component' => 'landing-header-cta', 'settings' => ['button' => 'Start now'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-support-docs',
                'title'   => 'Support Docs Header Template',
                'excerpt' => 'Documentation header with search, topic routes, account link, and support escalation CTA.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Support Docs Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'support-header',
                    'screenshot' => 'screenshot-style-header-support-docs',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['header-template', 'knowledge-index', 'support-ticket', 'faq-hub'],
                    ],
                    'sections' => [
                        ['id' => 'search', 'component' => 'docs-header-search', 'settings' => ['placeholder' => 'Search setup and support'], 'children' => []],
                        ['id' => 'topics', 'component' => 'docs-topic-navigation', 'settings' => ['topics' => 'install|templates|commerce|updates'], 'children' => []],
                        ['id' => 'support', 'component' => 'support-escalation-button', 'settings' => ['button' => 'Need help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-trust-support',
                'title'   => 'Trust and Support Footer Template',
                'excerpt' => 'Sitewide footer with support links, policies, trust proof, contact routes, and final action.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Trust and Support Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'global-footer',
                    'screenshot' => 'screenshot-style-footer-trust-support',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-template', 'trust-badges', 'support-ticket', 'security-shield'],
                    ],
                    'sections' => [
                        ['id' => 'cta', 'component' => 'footer-final-cta', 'settings' => ['button' => 'Get help with my site'], 'children' => []],
                        ['id' => 'columns', 'component' => 'footer-support-columns', 'settings' => ['columns' => 'services|support|account|legal'], 'children' => []],
                        ['id' => 'legal', 'component' => 'footer-legal-row', 'settings' => ['year' => 'auto'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-service-area',
                'title'   => 'Service Area Footer Template',
                'excerpt' => 'Footer for local/service sites with service-area links, hours, reviews, quote CTA, and contact details.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Service Area Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'local-footer',
                    'screenshot' => 'screenshot-style-footer-service-area',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-columns', 'service-area-map', 'review-stars', 'quote-request'],
                    ],
                    'sections' => [
                        ['id' => 'areas', 'component' => 'footer-service-area-grid', 'settings' => ['links' => 'cities|nearby areas|services'], 'children' => []],
                        ['id' => 'proof', 'component' => 'footer-review-strip', 'settings' => ['items' => 'rating|response time|guarantee'], 'children' => []],
                        ['id' => 'quote', 'component' => 'footer-quote-cta', 'settings' => ['button' => 'Request quote'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-commerce-account',
                'title'   => 'Commerce Account Footer Template',
                'excerpt' => 'Footer for product and subscription sites with account, checkout, refund, support, and delivery routes.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Commerce Account Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'commerce-footer',
                    'screenshot' => 'screenshot-style-footer-commerce-account',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-template', 'commerce-cart', 'checkout-link', 'refund-policy'],
                    ],
                    'sections' => [
                        ['id' => 'shop-links', 'component' => 'footer-commerce-link-grid', 'settings' => ['links' => 'catalog|subscriptions|downloads|checkout'], 'children' => []],
                        ['id' => 'trust', 'component' => 'footer-commerce-trust-row', 'settings' => ['items' => 'secure|refund|support'], 'children' => []],
                        ['id' => 'account', 'component' => 'footer-account-cta', 'settings' => ['button' => 'Open account'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-docs-index',
                'title'   => 'Documentation Footer Template',
                'excerpt' => 'Footer for tutorials and docs with grouped setup links, popular articles, changelog, and support escalation.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Documentation Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'docs-footer',
                    'screenshot' => 'screenshot-style-footer-docs-index',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-columns', 'documentation-hub', 'safe-update', 'support-escalation'],
                    ],
                    'sections' => [
                        ['id' => 'popular', 'component' => 'footer-popular-docs', 'settings' => ['items' => 'install|templates|updates|support'], 'children' => []],
                        ['id' => 'release', 'component' => 'footer-release-links', 'settings' => ['links' => 'latest|beta|changelog'], 'children' => []],
                        ['id' => 'support', 'component' => 'footer-support-route', 'settings' => ['button' => 'Open support'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-minimal-legal',
                'title'   => 'Minimal Legal Footer Template',
                'excerpt' => 'Small footer for canvas and campaign pages with auto year, privacy, terms, and support contact.',
                'role'    => 'footer',
                'scope'   => 'specific_ids',
                'priority' => 15,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Minimal Legal Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'minimal-footer',
                    'screenshot' => 'screenshot-style-footer-minimal-legal',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-template', 'landing-template', 'refund-policy', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'legal', 'component' => 'minimal-footer-legal-row', 'settings' => ['year' => 'auto', 'links' => 'privacy|terms|support'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-newsletter-cta',
                'title'   => 'Newsletter CTA Footer Template',
                'excerpt' => 'Conversion footer with email capture, resource links, service highlights, and final trust badges.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Newsletter CTA Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'newsletter-footer',
                    'screenshot' => 'screenshot-style-footer-newsletter-cta',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-columns', 'form-leads', 'content-calendar', 'trust-badges'],
                    ],
                    'sections' => [
                        ['id' => 'signup', 'component' => 'footer-newsletter-panel', 'settings' => ['fields' => 'email|interest'], 'children' => []],
                        ['id' => 'resources', 'component' => 'footer-resource-columns', 'settings' => ['columns' => 'guides|services|proof'], 'children' => []],
                        ['id' => 'trust', 'component' => 'footer-trust-badges', 'settings' => ['items' => 'secure|supported|updated'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-404-helpful-support',
                'title'   => 'Helpful Support 404 Template',
                'excerpt' => 'Not-found page that routes visitors to search, support, recent work, downloads, and the most useful next pages.',
                'role'    => '404',
                'scope'   => '404',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Helpful Support 404 Template',
                    'viewport' => '8k-ready',
                    'template_role' => '404',
                    'template_usage' => 'not-found-support',
                    'screenshot' => 'screenshot-style-404-helpful-support',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['not-found-404', 'support-ticket', 'knowledge-index', 'website-screenshot'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'helpful-404-hero', 'settings' => ['headline' => 'That page moved, but the help did not'], 'children' => []],
                        ['id' => 'search', 'component' => 'not-found-search-panel', 'settings' => ['placeholder' => 'Search Help4 WordPress'], 'children' => []],
                        ['id' => 'routes', 'component' => 'not-found-route-grid', 'settings' => ['routes' => 'downloads|templates|tutorials|support'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-404-search-suggestions',
                'title'   => 'Search Suggestions 404 Template',
                'excerpt' => 'Search-first 404 with popular links, category suggestions, and a calm support fallback.',
                'role'    => '404',
                'scope'   => '404',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Search Suggestions 404 Template',
                    'viewport' => '8k-ready',
                    'template_role' => '404',
                    'template_usage' => 'not-found-search',
                    'screenshot' => 'screenshot-style-404-search-suggestions',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['not-found-404', 'faq-hub', 'documentation-hub', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'search-404-hero', 'settings' => ['headline' => 'Search the site or pick a common path'], 'children' => []],
                        ['id' => 'suggestions', 'component' => 'popular-path-grid', 'settings' => ['items' => 'builder|themes|updates|commerce|support'], 'children' => []],
                        ['id' => 'support', 'component' => 'not-found-support-cta', 'settings' => ['button' => 'Ask support'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-404-product-rescue',
                'title'   => 'Product Rescue 404 Template',
                'excerpt' => 'Commerce-aware 404 that sends visitors back to product groups, subscriptions, account checkout, or support.',
                'role'    => '404',
                'scope'   => '404',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Product Rescue 404 Template',
                    'viewport' => '8k-ready',
                    'template_role' => '404',
                    'template_usage' => 'not-found-commerce',
                    'screenshot' => 'screenshot-style-404-product-rescue',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['not-found-404', 'product-collection', 'checkout-link', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'product-404-hero', 'settings' => ['headline' => 'The product link changed. The buying path is still here.'], 'children' => []],
                        ['id' => 'products', 'component' => 'product-route-grid', 'settings' => ['routes' => 'plans|downloads|subscriptions|support'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'account-checkout-rescue', 'settings' => ['button' => 'Open account checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-404-local-service',
                'title'   => 'Local Service 404 Template',
                'excerpt' => 'Local-service 404 with service-area links, quote path, phone/contact route, and popular services.',
                'role'    => '404',
                'scope'   => '404',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Local Service 404 Template',
                    'viewport' => '8k-ready',
                    'template_role' => '404',
                    'template_usage' => 'not-found-local',
                    'screenshot' => 'screenshot-style-404-local-service',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['not-found-404', 'local-service', 'service-area-map', 'quote-request'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'local-404-hero', 'settings' => ['headline' => 'Wrong page, right service area'], 'children' => []],
                        ['id' => 'services', 'component' => 'popular-service-link-grid', 'settings' => ['items' => 'repairs|estimates|support|locations'], 'children' => []],
                        ['id' => 'quote', 'component' => 'local-quote-rescue-cta', 'settings' => ['button' => 'Request help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-shell-standard',
                'title'   => 'Standard Page Shell Template',
                'excerpt' => 'Reusable page template that keeps global header/footer while standardizing hero, intro, content, FAQ, and CTA sections.',
                'role'    => 'page',
                'scope'   => 'page',
                'include_types' => 'page',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Standard Page Shell Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'page',
                    'template_usage' => 'page-with-header-footer',
                    'screenshot' => 'screenshot-style-page-shell-standard',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['page-shell', 'content-template', 'theme-conditions', 'layout-grid'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'page-shell-hero', 'settings' => ['headline' => 'Page headline and customer promise'], 'children' => []],
                        ['id' => 'intro', 'component' => 'page-intro-band', 'settings' => ['columns' => 2], 'children' => []],
                        ['id' => 'content', 'component' => 'flexible-content-stack', 'settings' => ['sections' => 'proof|details|faq|cta'], 'children' => []],
                        ['id' => 'cta', 'component' => 'page-final-cta', 'settings' => ['button' => 'Take next step'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-shell-full-width',
                'title'   => 'Full Width Page Shell Template',
                'excerpt' => 'Page template for immersive sections with global header/footer, wide media, proof bands, and responsive spacing controls.',
                'role'    => 'page',
                'scope'   => 'page',
                'include_types' => 'page',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Full Width Page Shell Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'page',
                    'template_usage' => 'full-width-page',
                    'screenshot' => 'screenshot-style-page-shell-full-width',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['page-shell', 'layout-grid', 'responsive-preview', 'global-style'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'full-width-visual-hero', 'settings' => ['media' => 'wide'], 'children' => []],
                        ['id' => 'proof', 'component' => 'wide-proof-band', 'settings' => ['items' => 'metrics|reviews|logos'], 'children' => []],
                        ['id' => 'sections', 'component' => 'wide-section-stack', 'settings' => ['blocks' => 'split|cards|faq'], 'children' => []],
                        ['id' => 'qa', 'component' => 'responsive-spacing-checklist', 'settings' => ['viewports' => 'mobile|desktop|wide'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-shell-canvas-landing',
                'title'   => 'Canvas Landing Page Template',
                'excerpt' => 'No-header/no-footer landing template for campaigns, lead magnets, paid traffic, and focused offers.',
                'role'    => 'canvas_page',
                'scope'   => 'canvas_page',
                'include_types' => 'page',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Canvas Landing Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'canvas_page',
                    'template_usage' => 'no-header-footer-page',
                    'screenshot' => 'screenshot-style-page-shell-canvas-landing',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['canvas-page', 'landing-template', 'conversion-path', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'canvas-offer-hero', 'settings' => ['headline' => 'One offer, one promise, one next step'], 'children' => []],
                        ['id' => 'proof', 'component' => 'landing-proof-stack', 'settings' => ['items' => 'result|review|guarantee'], 'children' => []],
                        ['id' => 'form', 'component' => 'focused-lead-form', 'settings' => ['fields' => 'name|email|phone|need'], 'children' => []],
                        ['id' => 'close', 'component' => 'landing-final-cta', 'settings' => ['button' => 'Start now'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-template-service-detail',
                'title'   => 'Service Detail Page Template',
                'excerpt' => 'Reusable service-page template with problem, process, proof, pricing/fit, FAQ, and lead path.',
                'role'    => 'page',
                'scope'   => 'page',
                'include_types' => 'page',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Service Detail Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'page',
                    'template_usage' => 'service-page-template',
                    'screenshot' => 'screenshot-style-page-template-service-detail',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-template', 'local-service', 'schema-faq', 'quote-request'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'service-detail-hero', 'settings' => ['headline' => 'Service name and outcome'], 'children' => []],
                        ['id' => 'problem', 'component' => 'service-problem-grid', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'process', 'component' => 'service-process-steps', 'settings' => ['steps' => 'inspect|plan|build|support'], 'children' => []],
                        ['id' => 'lead', 'component' => 'service-lead-cta', 'settings' => ['button' => 'Request this service'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-template-article-tutorial',
                'title'   => 'Article and Tutorial Page Template',
                'excerpt' => 'Readable post/page template with table of contents, screenshot slots, steps, FAQ, and support escalation.',
                'role'    => 'post',
                'scope'   => 'post',
                'include_types' => 'post',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Article and Tutorial Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'post',
                    'template_usage' => 'article-tutorial-template',
                    'screenshot' => 'screenshot-style-page-template-article-tutorial',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-template', 'screenshot-step', 'documentation-hub', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'article-tutorial-hero', 'settings' => ['meta' => 'difficulty|time|updated'], 'children' => []],
                        ['id' => 'toc', 'component' => 'article-table-of-contents', 'settings' => ['sticky' => 'desktop'], 'children' => []],
                        ['id' => 'steps', 'component' => 'screenshot-step-list', 'settings' => ['slots' => 'image|caption|warning'], 'children' => []],
                        ['id' => 'support', 'component' => 'tutorial-support-band', 'settings' => ['button' => 'Get help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-template-product-detail',
                'title'   => 'Product Detail Page Template',
                'excerpt' => 'Product-detail template for galleries, variations, subscription notes, trust proof, FAQs, and checkout handoff.',
                'role'    => 'product_single',
                'scope'   => 'product_single',
                'include_types' => 'product,h4_product',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Product Detail Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'product_single',
                    'template_usage' => 'product-detail-template',
                    'screenshot' => 'screenshot-style-page-template-product-detail',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-template', 'native-commerce', 'variant-matrix', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'product-detail-hero', 'settings' => ['layout' => 'gallery|summary|buy box'], 'children' => []],
                        ['id' => 'options', 'component' => 'product-option-matrix', 'settings' => ['groups' => 'variant|term|support'], 'children' => []],
                        ['id' => 'trust', 'component' => 'product-trust-proof', 'settings' => ['items' => 'secure|support|refund|delivery'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'connected-checkout-cta', 'settings' => ['button' => 'Continue to checkout'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-theme-kit-service-business',
                'title'   => 'Service Business Theme Kit',
                'excerpt' => 'Inspiration kit with matching header, footer, 404, service page, quote page, and local proof sections.',
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Service Business Theme Kit',
                    'viewport' => '8k-ready',
                    'template_role' => 'theme_kit',
                    'template_usage' => 'site-kit',
                    'screenshot' => 'screenshot-style-theme-kit-service-business',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['theme-kit', 'header-template', 'footer-template', 'page-shell'],
                    ],
                    'sections' => [
                        ['id' => 'header', 'component' => 'kit-clean-service-header', 'settings' => ['role' => 'header'], 'children' => []],
                        ['id' => 'service-page', 'component' => 'kit-service-page-shell', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => 'quote-page', 'component' => 'kit-quote-canvas-page', 'settings' => ['layout' => 'canvas'], 'children' => []],
                        ['id' => 'footer', 'component' => 'kit-service-footer', 'settings' => ['role' => 'footer'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-theme-kit-digital-product',
                'title'   => 'Digital Product Theme Kit',
                'excerpt' => 'Inspiration kit for plugin, download, subscription, release notes, docs, and account checkout pages.',
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Digital Product Theme Kit',
                    'viewport' => '8k-ready',
                    'template_role' => 'theme_kit',
                    'template_usage' => 'digital-product-kit',
                    'screenshot' => 'screenshot-style-theme-kit-digital-product',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['theme-kit', 'digital-download', 'subscription-flow', 'payment-router'],
                    ],
                    'sections' => [
                        ['id' => 'header', 'component' => 'kit-product-header', 'settings' => ['role' => 'header'], 'children' => []],
                        ['id' => 'product', 'component' => 'kit-digital-product-page', 'settings' => ['role' => 'product_single'], 'children' => []],
                        ['id' => 'download', 'component' => 'kit-download-page', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => 'release', 'component' => 'kit-release-notes-page', 'settings' => ['role' => 'page'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-theme-kit-help-center',
                'title'   => 'Help Center Theme Kit',
                'excerpt' => 'Inspiration kit for documentation headers, article templates, FAQ hubs, 404 rescue, and support routing.',
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Help Center Theme Kit',
                    'viewport' => '8k-ready',
                    'template_role' => 'theme_kit',
                    'template_usage' => 'help-center-kit',
                    'screenshot' => 'screenshot-style-theme-kit-help-center',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['theme-kit', 'documentation-hub', 'faq-hub', 'not-found-404'],
                    ],
                    'sections' => [
                        ['id' => 'header', 'component' => 'kit-docs-header', 'settings' => ['role' => 'header'], 'children' => []],
                        ['id' => 'article', 'component' => 'kit-tutorial-article-template', 'settings' => ['role' => 'post'], 'children' => []],
                        ['id' => 'faq', 'component' => 'kit-faq-index-page', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => '404', 'component' => 'kit-helpful-404', 'settings' => ['role' => '404'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-theme-kit-portfolio-proof',
                'title'   => 'Portfolio Proof Theme Kit',
                'excerpt' => 'Inspiration kit for recent work, case studies, Website Snapshot galleries, before/after proof, and project request pages.',
                'spec'    => [
                    'version'  => '2.2',
                    'name'     => 'Portfolio Proof Theme Kit',
                    'viewport' => '8k-ready',
                    'template_role' => 'theme_kit',
                    'template_usage' => 'portfolio-proof-kit',
                    'screenshot' => 'screenshot-style-theme-kit-portfolio-proof',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['theme-kit', 'website-snapshot-gallery', 'before-after', 'case-study'],
                    ],
                    'sections' => [
                        ['id' => 'header', 'component' => 'kit-portfolio-header', 'settings' => ['role' => 'header'], 'children' => []],
                        ['id' => 'gallery', 'component' => 'kit-website-snapshot-gallery-page', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => 'case-study', 'component' => 'kit-case-study-template', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => 'request', 'component' => 'kit-project-request-canvas', 'settings' => ['layout' => 'canvas'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-appointment-booking',
                'title'   => 'Appointment Booking Header Template',
                'excerpt' => 'Header for appointment-heavy sites with service picker, phone cue, booking CTA, and compact mobile navigation.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Appointment Booking Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'booking-header',
                    'screenshot' => 'screenshot-style-header-appointment-booking',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['header-template', 'booking-request', 'appointment-calendar', 'form-leads'],
                    ],
                    'sections' => [
                        ['id' => 'utility', 'component' => 'booking-header-utility-row', 'settings' => ['items' => 'hours|phone|service area'], 'children' => []],
                        ['id' => 'nav', 'component' => 'booking-primary-nav', 'settings' => ['cta' => 'Book appointment'], 'children' => []],
                        ['id' => 'mobile', 'component' => 'booking-mobile-action-bar', 'settings' => ['actions' => 'call|book|directions'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-multi-location',
                'title'   => 'Multi Location Header Template',
                'excerpt' => 'Location-aware header with city selector, service links, emergency/contact path, and no-clipping mobile menus.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Multi Location Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'multi-location-header',
                    'screenshot' => 'screenshot-style-header-multi-location',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['header-template', 'service-area-map', 'local-service', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'locator', 'component' => 'location-selector-strip', 'settings' => ['fields' => 'city|zip|near me'], 'children' => []],
                        ['id' => 'nav', 'component' => 'multi-location-nav', 'settings' => ['groups' => 'services|areas|support'], 'children' => []],
                        ['id' => 'cta', 'component' => 'location-aware-cta', 'settings' => ['button' => 'Find my location'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-header-membership-course',
                'title'   => 'Membership Course Header Template',
                'excerpt' => 'Learning-site header with member login, course navigation, progress cue, and support access.',
                'role'    => 'header',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Membership Course Header Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'header',
                    'template_usage' => 'membership-header',
                    'screenshot' => 'screenshot-style-header-membership-course',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['header-template', 'course-membership', 'membership-gate', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'brand', 'component' => 'course-brand-row', 'settings' => ['show_progress' => 'yes'], 'children' => []],
                        ['id' => 'nav', 'component' => 'course-module-nav', 'settings' => ['groups' => 'courses|resources|account'], 'children' => []],
                        ['id' => 'member', 'component' => 'member-login-cta', 'settings' => ['button' => 'Member login'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-support-status',
                'title'   => 'Support Status Footer Template',
                'excerpt' => 'Footer with support routes, status note, documentation links, service hours, and trust badges.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Support Status Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'support-status-footer',
                    'screenshot' => 'screenshot-style-footer-support-status',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-template', 'support-ticket', 'documentation-hub', 'security-shield'],
                    ],
                    'sections' => [
                        ['id' => 'status', 'component' => 'support-status-strip', 'settings' => ['items' => 'systems|hours|response'], 'children' => []],
                        ['id' => 'links', 'component' => 'support-footer-columns', 'settings' => ['columns' => 'help|account|legal'], 'children' => []],
                        ['id' => 'trust', 'component' => 'footer-trust-row', 'settings' => ['items' => 'secure|updated|supported'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-multi-location',
                'title'   => 'Multi Location Footer Template',
                'excerpt' => 'Footer for service-area businesses with location cards, hours, phone links, and local SEO anchors.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Multi Location Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'multi-location-footer',
                    'screenshot' => 'screenshot-style-footer-multi-location',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-template', 'service-area-map', 'local-service', 'schema-faq'],
                    ],
                    'sections' => [
                        ['id' => 'areas', 'component' => 'location-card-grid', 'settings' => ['cards' => 'primary|nearby|remote'], 'children' => []],
                        ['id' => 'services', 'component' => 'local-service-link-columns', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'contact', 'component' => 'footer-contact-hours', 'settings' => ['fields' => 'phone|hours|directions'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-footer-app-download',
                'title'   => 'App Download Footer Template',
                'excerpt' => 'Footer for plugin, software, and digital-product sites with latest download, docs, changelog, and support links.',
                'role'    => 'footer',
                'scope'   => 'entire_site',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'App Download Footer Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'footer',
                    'template_usage' => 'download-footer',
                    'screenshot' => 'screenshot-style-footer-app-download',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['footer-template', 'digital-download', 'update-readiness', 'documentation-hub'],
                    ],
                    'sections' => [
                        ['id' => 'download', 'component' => 'footer-download-card', 'settings' => ['items' => 'latest|version|changelog'], 'children' => []],
                        ['id' => 'resources', 'component' => 'footer-resource-links', 'settings' => ['columns' => 'docs|account|support'], 'children' => []],
                        ['id' => 'legal', 'component' => 'footer-legal-compact', 'settings' => ['items' => 'terms|privacy|license'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-404-account-login-rescue',
                'title'   => 'Account Login Rescue 404 Template',
                'excerpt' => '404 for account, download, and billing paths with login recovery, docs, latest download, and support escalation.',
                'role'    => '404',
                'scope'   => '404',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Account Login Rescue 404 Template',
                    'viewport' => '8k-ready',
                    'template_role' => '404',
                    'template_usage' => 'not-found-account-rescue',
                    'screenshot' => 'screenshot-style-404-account-login-rescue',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['not-found-404', 'membership-gate', 'digital-download', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'account-404-hero', 'settings' => ['headline' => 'The page changed. Your account path is still here.'], 'children' => []],
                        ['id' => 'routes', 'component' => 'account-route-grid', 'settings' => ['routes' => 'login|downloads|billing|support'], 'children' => []],
                        ['id' => 'help', 'component' => 'account-rescue-support-cta', 'settings' => ['button' => 'Open support request'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-404-booking-rescue',
                'title'   => 'Booking Rescue 404 Template',
                'excerpt' => 'Appointment-focused 404 with booking CTA, service selector, phone fallback, and common service links.',
                'role'    => '404',
                'scope'   => '404',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Booking Rescue 404 Template',
                    'viewport' => '8k-ready',
                    'template_role' => '404',
                    'template_usage' => 'not-found-booking',
                    'screenshot' => 'screenshot-style-404-booking-rescue',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['not-found-404', 'booking-request', 'appointment-calendar', 'quote-request'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'booking-404-hero', 'settings' => ['headline' => 'Wrong link, easy booking path'], 'children' => []],
                        ['id' => 'services', 'component' => 'booking-service-rescue-grid', 'settings' => ['items' => 'consult|repair|install|follow up'], 'children' => []],
                        ['id' => 'cta', 'component' => 'booking-rescue-cta', 'settings' => ['button' => 'Request appointment'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-template-pricing-comparison',
                'title'   => 'Pricing Comparison Page Template',
                'excerpt' => 'Page template for plan comparison, buyer objections, feature matrix, FAQ, and checkout handoff.',
                'role'    => 'page',
                'scope'   => 'page',
                'include_types' => 'page',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Pricing Comparison Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'page',
                    'template_usage' => 'pricing-comparison-template',
                    'screenshot' => 'screenshot-style-page-template-pricing-comparison',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-template', 'plan-selector', 'comparison-proof', 'checkout-link'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'pricing-comparison-hero', 'settings' => ['headline' => 'Pick the plan by outcome, not by guessing'], 'children' => []],
                        ['id' => 'matrix', 'component' => 'plan-feature-matrix', 'settings' => ['columns' => 'starter|growth|managed'], 'children' => []],
                        ['id' => 'faq', 'component' => 'pricing-objection-faq', 'settings' => ['items' => 'fit|billing|support|cancel'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'pricing-checkout-route', 'settings' => ['button' => 'Choose plan'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-template-docs-hub',
                'title'   => 'Documentation Hub Page Template',
                'excerpt' => 'Docs hub template with search, setup paths, screenshot tutorials, common fixes, and support escalation.',
                'role'    => 'page',
                'scope'   => 'page',
                'include_types' => 'page',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Documentation Hub Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'page',
                    'template_usage' => 'documentation-hub-template',
                    'screenshot' => 'screenshot-style-page-template-docs-hub',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-template', 'documentation-hub', 'screenshot-step', 'faq-hub'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'docs-hub-hero-search', 'settings' => ['placeholder' => 'What are you trying to set up?'], 'children' => []],
                        ['id' => 'paths', 'component' => 'docs-path-card-grid', 'settings' => ['paths' => 'install|templates|commerce|support'], 'children' => []],
                        ['id' => 'screens', 'component' => 'screenshot-tutorial-index', 'settings' => ['items' => 'builder|templates|icons'], 'children' => []],
                        ['id' => 'support', 'component' => 'docs-support-escalation', 'settings' => ['button' => 'Ask for help'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-template-website-snapshot-recent-work',
                'title'   => 'Website Snapshot Recent Work Page Template',
                'excerpt' => 'Recent-work template with website screenshots, services delivered, proof notes, and request-similar-work CTA.',
                'role'    => 'page',
                'scope'   => 'page',
                'include_types' => 'page',
                'priority' => 10,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Website Snapshot Recent Work Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'page',
                    'template_usage' => 'website-snapshot-recent-work-template',
                    'screenshot' => 'screenshot-style-page-template-website-snapshot-recent-work',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['content-template', 'website-snapshot-gallery', 'website-screenshot', 'case-study'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'recent-work-proof-hero', 'settings' => ['headline' => 'Recent work people can actually see'], 'children' => []],
                        ['id' => 'gallery', 'component' => 'website-snapshot-recent-work-grid', 'settings' => ['fields' => 'url|screenshot|service|result'], 'children' => []],
                        ['id' => 'proof', 'component' => 'recent-work-proof-notes', 'settings' => ['items' => 'speed|design|migration|support'], 'children' => []],
                        ['id' => 'cta', 'component' => 'recent-work-project-cta', 'settings' => ['button' => 'Request similar work'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-page-shell-quote-intake-canvas',
                'title'   => 'Quote Intake Canvas Page Template',
                'excerpt' => 'No-header/no-footer intake page for paid traffic, referrals, emergency requests, and guided project scoping.',
                'role'    => 'canvas_page',
                'scope'   => 'canvas_page',
                'include_types' => 'page',
                'priority' => 20,
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Quote Intake Canvas Page Template',
                    'viewport' => '8k-ready',
                    'template_role' => 'canvas_page',
                    'template_usage' => 'quote-intake-canvas',
                    'screenshot' => 'screenshot-style-page-shell-quote-intake-canvas',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['canvas-page', 'quote-request', 'form-leads', 'conversion-path'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'quote-intake-hero', 'settings' => ['headline' => 'Tell us what you need built'], 'children' => []],
                        ['id' => 'steps', 'component' => 'intake-step-flow', 'settings' => ['steps' => 'site type|timeline|budget|assets'], 'children' => []],
                        ['id' => 'form', 'component' => 'quote-intake-form', 'settings' => ['fields' => 'contact|url|need|timeline'], 'children' => []],
                        ['id' => 'trust', 'component' => 'intake-trust-strip', 'settings' => ['items' => 'response|privacy|next step'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-theme-kit-local-lead-generation',
                'title'   => 'Local Lead Generation Theme Kit',
                'excerpt' => 'Inspiration kit for location headers, service-area pages, quote intake, reviews, booking, and local 404 recovery.',
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Local Lead Generation Theme Kit',
                    'viewport' => '8k-ready',
                    'template_role' => 'theme_kit',
                    'template_usage' => 'local-lead-generation-kit',
                    'screenshot' => 'screenshot-style-theme-kit-local-lead-generation',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['theme-kit', 'service-area-map', 'quote-request', 'review-stars'],
                    ],
                    'sections' => [
                        ['id' => 'header', 'component' => 'kit-multi-location-header', 'settings' => ['role' => 'header'], 'children' => []],
                        ['id' => 'service-area', 'component' => 'kit-local-seo-page', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => 'quote', 'component' => 'kit-quote-intake-canvas', 'settings' => ['layout' => 'canvas'], 'children' => []],
                        ['id' => 'footer', 'component' => 'kit-multi-location-footer', 'settings' => ['role' => 'footer'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-theme-kit-course-membership',
                'title'   => 'Course Membership Theme Kit',
                'excerpt' => 'Inspiration kit for course headers, lesson pages, gated resources, member account routes, docs, and support recovery.',
                'spec'    => [
                    'version'  => '2.3',
                    'name'     => 'Course Membership Theme Kit',
                    'viewport' => '8k-ready',
                    'template_role' => 'theme_kit',
                    'template_usage' => 'course-membership-kit',
                    'screenshot' => 'screenshot-style-theme-kit-course-membership',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Inter', 'Montserrat'],
                        'icons'  => ['theme-kit', 'course-membership', 'membership-gate', 'documentation-hub'],
                    ],
                    'sections' => [
                        ['id' => 'header', 'component' => 'kit-membership-course-header', 'settings' => ['role' => 'header'], 'children' => []],
                        ['id' => 'lesson', 'component' => 'kit-membership-lesson-page', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => 'resources', 'component' => 'kit-gated-resource-index', 'settings' => ['role' => 'page'], 'children' => []],
                        ['id' => '404', 'component' => 'kit-account-login-rescue-404', 'settings' => ['role' => '404'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-handled-wordpress',
                'title'   => 'Handled WordPress Design System',
                'excerpt' => 'Editorial managed WordPress design with product-health hero, plain-language outcomes, plans, FAQ, and closing action.',
                'spec'    => [
                    'version'  => '3.0',
                    'name'     => 'Handled WordPress Design System',
                    'viewport' => 'responsive',
                    'template_role' => 'page',
                    'template_usage' => 'managed-wordpress-service',
                    'screenshot' => 'theme-pack-handled-wordpress.webp',
                    'assets'   => [
                        'images' => ['theme-pack-handled-wordpress.webp'],
                        'fonts'  => ['Montserrat', 'Inter'],
                        'icons'  => ['managed-hosting', 'site-health', 'backup-restore', 'support-ticket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'two-column-product-health-hero', 'settings' => ['headline' => 'WordPress handled. Business moving.'], 'children' => []],
                        ['id' => 'outcomes', 'component' => 'three-outcome-band', 'settings' => ['items' => 'secure|fast|supported'], 'children' => []],
                        ['id' => 'plans', 'component' => 'plain-language-plan-path', 'settings' => ['tiers' => 3], 'children' => []],
                        ['id' => 'faq', 'component' => 'managed-service-faq', 'settings' => ['open_first' => true], 'children' => []],
                        ['id' => 'close', 'component' => 'dark-closing-action-band', 'settings' => ['button' => 'Compare plans'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-catalog-command',
                'title'   => 'Catalog Command Commerce Design',
                'excerpt' => 'High-volume commerce layout for filters, variations, subscriptions, comparisons, stock states, and checkout routing.',
                'spec'    => [
                    'version'  => '3.0',
                    'name'     => 'Catalog Command Commerce Design',
                    'viewport' => 'responsive',
                    'template_role' => 'page',
                    'template_usage' => 'native-commerce-catalog',
                    'screenshot' => 'theme-pack-catalog-command.webp',
                    'assets'   => [
                        'images' => ['theme-pack-catalog-command.webp'],
                        'fonts'  => ['Inter'],
                        'icons'  => ['commerce-cart', 'variant-matrix', 'subscription-cycle', 'processor-router'],
                    ],
                    'sections' => [
                        ['id' => 'intro', 'component' => 'catalog-command-intro', 'settings' => ['headline' => 'Find the right product without the hunt.'], 'children' => []],
                        ['id' => 'catalog', 'component' => 'filterable-product-command-grid', 'settings' => ['filters' => true, 'compare' => true, 'quick_view' => true], 'children' => []],
                        ['id' => 'commerce-features', 'component' => 'commerce-capability-rail', 'settings' => ['items' => 'variations|recurring|routing|scale'], 'children' => []],
                        ['id' => 'checkout', 'component' => 'checkout-and-support-split', 'settings' => ['support' => true], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-proof-studio',
                'title'   => 'Proof Studio Portfolio Design',
                'excerpt' => 'Screenshot-led agency portfolio with editorial project proof, process, testimonial, and project inquiry.',
                'spec'    => [
                    'version'  => '3.0',
                    'name'     => 'Proof Studio Portfolio Design',
                    'viewport' => 'responsive',
                    'template_role' => 'page',
                    'template_usage' => 'agency-portfolio',
                    'screenshot' => 'theme-pack-proof-studio.webp',
                    'assets'   => [
                        'images' => ['theme-pack-proof-studio.webp'],
                        'fonts'  => ['Montserrat', 'Inter'],
                        'icons'  => ['website-snapshot-gallery', 'design-handoff', 'responsive-qa', 'launch-rocket'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'proof-led-snapshot-hero', 'settings' => ['headline' => 'Websites built from the proof you bring.'], 'children' => []],
                        ['id' => 'projects', 'component' => 'editorial-project-index', 'settings' => ['rows' => 4], 'children' => []],
                        ['id' => 'process', 'component' => 'three-step-build-process', 'settings' => ['steps' => 'handoff|build|launch'], 'children' => []],
                        ['id' => 'quote', 'component' => 'large-testimonial-proof', 'settings' => ['media' => true], 'children' => []],
                        ['id' => 'inquiry', 'component' => 'project-inquiry-band', 'settings' => ['button' => 'Start a project'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-local-service-command',
                'title'   => 'Local Service Command Design',
                'excerpt' => 'Quote-first local service page with emergency routing, service proof, reviews, process, and area coverage.',
                'spec'    => [
                    'version'  => '3.0',
                    'name'     => 'Local Service Command Design',
                    'viewport' => 'responsive',
                    'template_role' => 'page',
                    'template_usage' => 'local-service-conversion',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Oswald', 'Inter'],
                        'icons'  => ['local-service', 'quote-request', 'review-stars', 'service-area-map'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'dark-quote-first-hero', 'settings' => ['headline' => 'Local service without the runaround.'], 'children' => []],
                        ['id' => 'services', 'component' => 'repair-replace-maintain-rail', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'proof', 'component' => 'reviews-and-service-area-split', 'settings' => ['map' => true], 'children' => []],
                        ['id' => 'close', 'component' => 'estimate-action-band', 'settings' => ['button' => 'Request an estimate'], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-visual-documentation-hub',
                'title'   => 'Visual Documentation Hub Design',
                'excerpt' => 'Screenshot-first help center with search, guided setup paths, common fixes, and support escalation.',
                'spec'    => [
                    'version'  => '3.0',
                    'name'     => 'Visual Documentation Hub Design',
                    'viewport' => 'responsive',
                    'template_role' => 'page',
                    'template_usage' => 'visual-documentation-hub',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Montserrat', 'Inter'],
                        'icons'  => ['tutorial-screenshot', 'documentation-hub', 'screenshot-step', 'support-escalation'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'docs-search-hero', 'settings' => ['headline' => 'Show the screen. Explain the next click.'], 'children' => []],
                        ['id' => 'paths', 'component' => 'setup-builder-launch-paths', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'tutorial', 'component' => 'screenshot-and-checklist-split', 'settings' => ['ordered' => true], 'children' => []],
                        ['id' => 'faq', 'component' => 'common-fix-faq', 'settings' => ['support' => true], 'children' => []],
                    ],
                ],
            ],
            [
                'key'     => 'starter-design-plugin-product-launch',
                'title'   => 'Plugin Product Launch Design',
                'excerpt' => 'Product-led plugin page with screenshots, plain-language outcomes, compatibility, FAQ, and download path.',
                'spec'    => [
                    'version'  => '3.0',
                    'name'     => 'Plugin Product Launch Design',
                    'viewport' => 'responsive',
                    'template_role' => 'page',
                    'template_usage' => 'plugin-product-launch',
                    'assets'   => [
                        'images' => [],
                        'fonts'  => ['Montserrat', 'Inter'],
                        'icons'  => ['builder-blocks', 'template-pack', 'update-readiness', 'digital-download'],
                    ],
                    'sections' => [
                        ['id' => 'hero', 'component' => 'plugin-screenshot-hero', 'settings' => ['headline' => 'Build the site. Keep the stack understandable.'], 'children' => []],
                        ['id' => 'outcomes', 'component' => 'template-module-launch-outcomes', 'settings' => ['columns' => 3], 'children' => []],
                        ['id' => 'compatibility', 'component' => 'compatibility-and-faq-split', 'settings' => ['current_wordpress' => true], 'children' => []],
                        ['id' => 'download', 'component' => 'download-action-band', 'settings' => ['button' => 'Download latest'], 'children' => []],
                    ],
                ],
            ],
        ];

        foreach ($templates as $template) {
            $key = (string) ($template['key'] ?? '');
            if ($key === '') {
                continue;
            }

            // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Template seeding checks existing Help4 seed-key markers before inserting.
            $existing = get_posts(
                [
                    'post_type'      => 'h4_template',
                    'post_status'    => 'any',
                    'posts_per_page' => 1,
                    'meta_key'       => '_h4_template_seed_key',
                    'meta_value'     => $key,
                    'fields'         => 'ids',
                ]
            );
            // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
            if (is_array($existing) && ! empty($existing[0])) {
                continue;
            }

            $postId = wp_insert_post(
                [
                    'post_type'    => 'h4_template',
                    'post_status'  => 'publish',
                    'post_title'   => (string) ($template['title'] ?? 'Starter Template'),
                    'post_excerpt' => (string) ($template['excerpt'] ?? ''),
                ],
                true
            );
            if (is_wp_error($postId) || ! $postId) {
                continue;
            }

            update_post_meta((int) $postId, '_h4_template_seed_key', $key);
            update_post_meta(
                (int) $postId,
                '_h4_template_spec',
                wp_json_encode($template['spec'] ?? [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
            );
        }

            update_option('h4bs_template_seed_version', $version);
        } finally {
            delete_option($lockKey);
        }
    }

    private function starterTemplateSeedCount(): int
    {
        // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Bulk seed-key lookup is scoped to Help4 template maintenance.
        $items = get_posts(
            [
                'post_type'      => 'h4_template',
                'post_status'    => ['publish', 'draft'],
                'posts_per_page' => -1,
                'fields'         => 'ids',
                'meta_query'     => [
                    [
                        'key'     => '_h4_template_seed_key',
                        'compare' => 'EXISTS',
                    ],
                    [
                        'key'     => '_h4_template_seed_key',
                        'value'   => self::HIDDEN_STARTER_SEED_KEYS,
                        'compare' => 'NOT IN',
                    ],
                ],
            ]
        );
        // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_query

        return is_array($items) ? count($items) : 0;
    }

    /**
     * @param mixed $raw
     * @return array<string, mixed>|null
     */
    private function normalizeSpec($raw): ?array
    {
        if (is_string($raw)) {
            $decoded = json_decode($raw, true);
            if (! is_array($decoded)) {
                return null;
            }
            $raw = $decoded;
        }

        if (! is_array($raw)) {
            return null;
        }

        $raw['version']  = sanitize_text_field((string) ($raw['version'] ?? '1.0'));
        $raw['name']     = sanitize_text_field((string) ($raw['name'] ?? 'Template'));
        $raw['viewport'] = sanitize_text_field((string) ($raw['viewport'] ?? '8k-ready'));

        if (! isset($raw['assets']) || ! is_array($raw['assets'])) {
            $raw['assets'] = [];
        }
        if (! isset($raw['sections']) || ! is_array($raw['sections'])) {
            $raw['sections'] = [];
        }

        return $raw;
    }
}
