<?php
/**
 * Customizer Class
 * 
 * Handles WordPress Customizer setup including panels, sections, controls, and options.
 * 
 * @package pawfect
 * @since 1.0.0
 */

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

/**
 * Main Customizer Class
 * 
 * This class manages the entire customizer functionality including:
 * - Loading customizer files and controls
 * - Setting up panels and sections
 * - Registering option classes
 * - Handling selective refresh partials
 * - Enqueuing customizer scripts and styles
 */
class Customizer
{
    /**
     * Constructor
     * 
     * Sets up all the WordPress hooks needed for the customizer to function.
     * 
     * @since 1.0.0
     */
    public function __construct()
    {
        // Load customizer with priority 20 to allow widgets to load first (widgets use priority 10)
        add_action('customize_register', [$this, 'setup_customizer'], 20);

        // Enqueue customizer control scripts and styles
        add_action('customize_controls_enqueue_scripts', [$this, 'enqueue_control_scripts']);

        // Enqueue customizer preview scripts
        add_action('customize_preview_init', [$this, 'enqueue_preview_scripts']);
    }

    /**
     * Setup Customizer
     * 
     * Loads all files and sets up panels/sections when customizer is ready
     * 
     * @param WP_Customize_Manager $wp_customize
     */
    public function setup_customizer($wp_customize)
    {
        // Load files first - now WordPress customizer classes are available
        $this->load_all_files();

        // Setup panels and sections FIRST - before option classes try to use them
        $this->setup_panels_and_sections($wp_customize);

        // THEN instantiate option classes - now sections exist for them to use
        // Load options with delay to allow widgets to load first
        add_action('customize_register', [$this, 'load_options_deferred'], 30);

        $this->setup_partials($wp_customize);
    }

    /**
     * Safe require method with error handling
     */
    private function safe_require($file)
    {
        if (file_exists($file)) {
            try {
                require_once $file;
            } catch (Exception $e) {
                // Silent error handling
            }
        }
    }

    /**
     * Load Customizer Files
     * 
     * Loads all necessary customizer files and registers option classes.
     * Called on 'after_setup_theme' hook to ensure proper loading order.
     * 
     * @since 1.0.0
     */
    public function load_customizer_files()
    {
        $this->load_all_files();
        // Option classes are automatically instantiated when included
        // No manual registration needed
    }

    /**
     * Load All Required Files
     * 
     * Loads customizer control classes and option classes in the correct order.
     * Base classes must be loaded before classes that extend them.
     * 
     * @since 1.0.0
     */
    private function load_all_files()
    {
        // Load base option class BEFORE specific option classes
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-base-option.php';

        // Load custom control classes - BASE CONTROL MUST BE FIRST
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-base-control.php';

        // Load all controls that extend base control
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-heading-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-toggle-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-slider-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-range-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-responsive-range-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-radio-image-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-radio-switch-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-layout-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-blog-sortable-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-frontpage-sortable-control.php';
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-category-control.php';
       // require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-upgrade-control.php';

        // Load repeater control class - using the correct filename
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-repeater-control.php';

        // Load custom palette control
        require_once PAWFECT_THEME_DIR . '/inc/customizer/controls/class-pawfect-customize-palette-control.php';

        // Load theme option classes
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-general.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-menu-bar.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-colors.php');
        // Typography file removed - using manual implementation in functions.php
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-footer.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-gradient.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-menu.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-popup.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-social-media.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-excerpt.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-page-header.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-templates.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-theme-colors.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-theme-typography.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-about.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-theme-layout.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-site-identity.php');

        // Load new theme option classes
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-topbar.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/theme/class-pawfect-options-blog-settings.php');

        // Load WooCommerce option classes
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/woocommerce/class-pawfect-options-shop-page.php');

        // Load frontpage option classes with safe loading
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-slider.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-press-mentions.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-testimonial.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-homepage-layout.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-blog.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-why-choose.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-portfolio.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-feature-highlight.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-mission.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-pet-shop.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-instagram.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-crafted.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-promo-timer.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-promo-banner.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-team.php');
        $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-funfact.php');

        if (class_exists('WooCommerce')) {
            $this->safe_require(PAWFECT_THEME_DIR . '/inc/customizer/options/frontpage/class-pawfect-options-woocommerce.php');
        }
    }

    /**
     * Load Options - Manual Instantiation
     *
     * Manually instantiate option classes that were working before
     */
    private function load_options()
    {
        global $wp_customize;

        // Theme options - manual instantiation
        if (class_exists('pawfect_Customize_General_Option')) {
            $general_option = new pawfect_Customize_General_Option();
            $general_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Menu_Bar_Option')) {
            $menu_bar_option = new pawfect_Customize_Menu_Bar_Option();
            $menu_bar_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Colors')) {
            $colors_option = new Pawfect_Options_Colors();
            $colors_option->pawfect_customizer_options($wp_customize);
        }

        // Disabled - conflicts with main typography controls
        // if (class_exists('pawfect_Customize_Theme_Typography_Option')) {
        //     $typography_option = new pawfect_Customize_Theme_Typography_Option();
        //     $typography_option->pawfect_customizer_options($wp_customize);
        // }

        if (class_exists('Pawfect_Options_Footer')) {
            $footer_option = new Pawfect_Options_Footer();
            $footer_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Gradient')) {
            $gradient_option = new Pawfect_Options_Gradient();
            $gradient_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Menu')) {
            $menu_option = new Pawfect_Options_Menu();
            $menu_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Excerpt')) {
            $excerpt_option = new Pawfect_Options_Excerpt();
            $excerpt_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Global_Badges')) {
            $global_badges_option = new Pawfect_Options_Global_Badges();
            $global_badges_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Page_Header_Option')) {
            $page_header_option = new pawfect_Customize_Page_Header_Option();
            $page_header_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Theme_Template_Option')) {
            $template_option = new pawfect_Customize_Theme_Template_Option();
            $template_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Theme_Colors')) {
            $theme_colors_option = new Pawfect_Options_Theme_Colors();
            $theme_colors_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Theme_Typography')) {
            $theme_typography_option = new Pawfect_Options_Theme_Typography();
            $theme_typography_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Theme_Layout')) {
            $theme_layout_option = new Pawfect_Options_Theme_Layout();
            $theme_layout_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_About_Option')) {
            $about_option = new pawfect_Customize_About_Option();
            $about_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Site_Identity_Option')) {
            $site_identity_option = new pawfect_Customize_Site_Identity_Option();
            $site_identity_option->pawfect_customizer_options($wp_customize);
        }

        // New theme options
        if (class_exists('Pawfect_Options_Topbar')) {
            $topbar_option = new Pawfect_Options_Topbar();
            $topbar_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Blog_Settings')) {
            $blog_settings_option = new Pawfect_Options_Blog_Settings();
            $blog_settings_option->pawfect_customizer_options($wp_customize);
        }

        // Frontpage options - manual instantiation
        if (class_exists('Pawfect_Options_Slider')) {
            $slider_option = new Pawfect_Options_Slider();
            $slider_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Popup')) {
            $popup_option = new Pawfect_Options_Popup();
            $popup_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Social_Media')) {
            $social_media_option = new Pawfect_Options_Social_Media();
            $social_media_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Press_Mentions')) {
            $press_mentions_option = new Pawfect_Options_Press_Mentions();
            $press_mentions_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Homepage_Layout')) {
            $layout_option = new Pawfect_Options_Homepage_Layout();
            $layout_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Blog')) {
            $blog_option = new Pawfect_Options_Blog();
            $blog_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Customize_Why_Choose_Option')) {
            $service_option = new Pawfect_Customize_Why_Choose_Option();
            $service_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Portfolio')) {
            $portfolio_option = new Pawfect_Options_Portfolio();
            $portfolio_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Testimonial')) {
            $testimonial_option = new Pawfect_Options_Testimonial();
            $testimonial_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Homepage_Feature_Highlight_Option')) {
            $feature_highlight_option = new pawfect_Customize_Homepage_Feature_Highlight_Option();
            $feature_highlight_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Mission')) {
            $mission_option = new Pawfect_Options_Mission();
            $mission_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Pet_Shop')) {
            $pet_shop_option = new Pawfect_Options_Pet_Shop();
            $pet_shop_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Team')) {
            $team_option = new Pawfect_Options_Team();
            $team_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Funfact')) {
            $funfact_option = new Pawfect_Options_Funfact();
            $funfact_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Crafted')) {
            $crafted_option = new Pawfect_Options_Crafted();
            $crafted_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Homepage_Promo_Timer_Option')) {
            $promo_timer_option = new pawfect_Customize_Homepage_Promo_Timer_Option();
            $promo_timer_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Homepage_Promo_Banner_Option')) {
            $promo_banner_option = new pawfect_Customize_Homepage_Promo_Banner_Option();
            $promo_banner_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_WooCommerce') && class_exists('WooCommerce')) {
            $woo_option = new Pawfect_Options_WooCommerce();
            $woo_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('Pawfect_Options_Shop_Page') && class_exists('WooCommerce')) {
            $shop_page_option = new Pawfect_Options_Shop_Page();
            $shop_page_option->pawfect_customizer_options($wp_customize);
        }

        if (class_exists('pawfect_Customize_Instagram_Gallery_Option')) {
            $instagram_option = new pawfect_Customize_Instagram_Gallery_Option();
            $instagram_option->pawfect_customizer_options($wp_customize);
        }
    }

    /**
     * Load Options Deferred
     *
     * Load options with lower priority to allow widgets to load first
     */
    public function load_options_deferred()
    {
        global $wp_customize;
        $this->load_options();
    }

    /**
     * Enqueue Customizer Control Scripts
     * 
     * Loads JavaScript and CSS files for the customizer controls panel.
     * These files handle the customizer interface functionality.
     * 
     * @since 1.0.0
     */
    public function enqueue_control_scripts()
    {
        $uri = get_template_directory_uri() . '/inc/customizer/assets/';

        // Enqueue customizer control styles
        wp_enqueue_style('pawfect-customize-customize-css', $uri . 'css/customize.css', [], PAWFECT_THEME_VERSION);
        wp_enqueue_style('pawfect-extend-customizer-css', $uri . 'css/extend-customizer.css', [], PAWFECT_THEME_VERSION);
        wp_enqueue_style('pawfect-admin-style-css', $uri . 'css/admin-style.css', [], PAWFECT_THEME_VERSION);
        wp_enqueue_style('pawfect-fontawesome-iconpicker-css', $uri . 'css/fontawesome-iconpicker.min.css', [], PAWFECT_THEME_VERSION);
        wp_enqueue_style('pawfect-controls-css', $uri . 'css/controls.css', [], PAWFECT_THEME_VERSION);
        wp_enqueue_style('pawfect-responsive-range-control-css', $uri . 'css/responsive-range-control.css', [], PAWFECT_THEME_VERSION);

        /**
         * Icon libraries bundled locally for WordPress.org compliance.
         */
        wp_enqueue_style('pawfect-font-awesome-customizer', get_template_directory_uri() . '/assets/vendor/font-awesome/css/all.min.css', [], '6.0.0-beta3');
        wp_enqueue_style('pawfect-phosphor-icons-customizer', get_template_directory_uri() . '/assets/vendor/phosphor-icons/style.css', [], '2.0.3');

        // Enqueue customizer control scripts
        wp_enqueue_script('pawfect-extend-customizer-js', $uri . 'js/extend-customizer.js', ['jquery'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-customizer-layout-js', $uri . 'js/customizer-layout.js', ['jquery', 'jquery-ui-sortable'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-customizer-repeater-js', $uri . 'js/customizer_repeater.js', ['jquery', 'jquery-ui-draggable', 'wp-color-picker'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-responsive-range-control-js', $uri . 'js/responsive-range-control.js', ['jquery', 'customize-controls'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-fontawesome-iconpicker-js', $uri . 'js/fontawesome-iconpicker.js', ['jquery'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-customizer-section-js', $uri . 'js/customizer-section.js', ['jquery'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-controls-js', $uri . 'js/controls.js', ['jquery', 'jquery-ui-slider', 'customize-controls'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-slider-limit-js', $uri . 'js/slider-limit.js', ['jquery', 'customize-controls'], PAWFECT_THEME_VERSION . '-v73-minimal-html-test', true);

        // Customizer presets logic
        wp_enqueue_script('pawfect-customizer-presets-js', $uri . 'js/customizer-presets.js', ['jquery', 'customize-controls'], PAWFECT_THEME_VERSION, true);
    }

    /**
     * Enqueue Customizer Preview Scripts
     * 
     * Loads JavaScript files for the customizer preview panel.
     * These files handle live preview functionality and selective refresh.
     * 
     * @since 1.0.0
     */
    public function enqueue_preview_scripts()
    {
        $uri = get_template_directory_uri() . '/inc/customizer/assets/';

        // Enqueue preview scripts
        wp_enqueue_script('pawfect-customizer-preview-js', $uri . 'js/customizer.js', ['customize-preview'], PAWFECT_THEME_VERSION, true);
        wp_enqueue_script('pawfect-site-title-customizer-js', $uri . 'js/site-title-customizer.js', ['customize-preview'], PAWFECT_THEME_VERSION, true);
    }

    /**
     * Setup Panels and Sections
     * 
     * Registers all customizer panels and sections.
     * Panels group related sections together in the customizer interface.
     * 
     * @since 1.0.0
     * @param WP_Customize_Manager $wp_customize WordPress Customizer Manager instance
     */
    public function setup_panels_and_sections($wp_customize)
    {
        // Register custom control types
        $wp_customize->register_control_type('Pawfect_Responsive_Range_Control');
        $wp_customize->register_control_type('pawfect_Customize_Heading_Control');
        $wp_customize->register_control_type('pawfect_Customize_Blog_Sortable_Control');
        $wp_customize->register_control_type('pawfect_Customize_Frontpage_Sortable_Control');

        /**
         * Panel: Frontpage Sections (Only if Matcha Extra plugin is active)
         */
        if (is_plugin_active('matcha-extra/matcha-extra.php')) {
            $wp_customize->add_panel('pawfect_frontpage_settings', array(
                'priority' => 10,
                'title' => esc_html__('Frontpage Sections', 'pawfect'),
                'capability' => 'edit_theme_options',
            ));
        }

        /**
         * Panel: Theme Options
         */
        $wp_customize->add_panel('pawfect_global_settings', array(
            'priority' => 11,
            'title' => esc_html__('Global Settings', 'pawfect'),
            'capability' => 'edit_theme_options',
        ));

        $wp_customize->add_panel('pawfect_header_settings', array(
            'priority' => 12,
            'title' => esc_html__('Header Builder', 'pawfect'),
            'capability' => 'edit_theme_options',
        ));
        
        $wp_customize->add_panel('pawfect_footer_settings', array(
            'priority' => 14,
            'title' => esc_html__('Footer Builder', 'pawfect'),
            'capability' => 'edit_theme_options',
        ));
        
        $wp_customize->add_panel('pawfect_blog_pages_settings', array(
            'priority' => 16,
            'title' => esc_html__('Blog & Pages', 'pawfect'),
            'capability' => 'edit_theme_options',
        ));

        /**
         * Panel: Colors & Styling
         */
        $wp_customize->add_panel('pawfect_colors_styling', array(
            'priority' => 20,
            'title' => esc_html__('Colors & Styling', 'pawfect'),
            'capability' => 'edit_theme_options',
        ));

        
        /**
         * Panel: Layout & Templates
         */
        $wp_customize->add_panel('pawfect_layout_templates', array(
            'priority' => 25,
            'title' => esc_html__('Layout & Templates', 'pawfect'),
            'capability' => 'edit_theme_options',
        ));


        /**
         * Panel: Typography
         */
        $wp_customize->add_panel('pawfect_typography', array(
            'priority' => 30,
            'title' => esc_html__('Typography', 'pawfect'),
            'capability' => 'edit_theme_options',
        ));

        // Frontpage sections (Only if Matcha Extra plugin is active)
        if (is_plugin_active('matcha-extra/matcha-extra.php')) {
            // Instructions section
            $wp_customize->add_section('pawfect_frontpage_instructions', array(
                'title' => esc_html__('💡 How to Enable Frontpage', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 5,
            ));

            // Frontpage sections
            $wp_customize->add_section('pawfect_main_theme_slider', array(
                'title' => esc_html__('Hero Slider', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 10,
            ));

            $wp_customize->add_section('pawfect_theme_press_mentions', array(
                'title' => esc_html__('Press Mentions', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 20,
            ));

            $wp_customize->add_section('pawfect_theme_feature_highlight', array(
                'title' => esc_html__('Feature Highlight', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 30,
            ));

            $wp_customize->add_section('pawfect_theme_portfolio', array(
                'title' => esc_html__('Shop by Category / Portfolio', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 40,
            ));

            $wp_customize->add_section('pawfect_theme_testimonial', array(
                'title' => esc_html__('Testimonial Settings', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 50,
            ));

            $wp_customize->add_section('pawfect_mission_section', array(
                'title' => esc_html__('Mission Section', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 60,
            ));

            $wp_customize->add_section('pawfect_theme_blog', array(
                'title' => esc_html__('Blog Settings', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 70,
            ));

            $wp_customize->add_section('pawfect_pet_shop_section', array(
                'title' => esc_html__('Shop By Pet', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 80,
            ));

            $wp_customize->add_section('pawfect_instagram_gallery_section', array(
                'title' => esc_html__('Instagram Gallery (Pro only)', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 90,
            ));

            $wp_customize->add_section('pawfect_promo_timer_section', array(
                'title' => esc_html__('Promo Timer (Pro only)', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 100,
            ));

            $wp_customize->add_section('pawfect_promo_banner_section', array(
                'title' => esc_html__('Promo Banner', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 105,
            ));

            $wp_customize->add_section('frontpage_layout', array(
                'title' => esc_html__('Front Page layout', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 106,
            ));

            // WooCommerce section (conditional)
            if (class_exists('WooCommerce')) {
                $wp_customize->add_section('pawfect_theme_woocommerce', array(
                    'title' => esc_html__('WooCommerce Settings', 'pawfect'),
                    'panel' => 'pawfect_frontpage_settings',
                    'priority' => 75,
                ));
            }

            // Service section
            $wp_customize->add_section('pawfect_theme_service', array(
                'title' => esc_html__('Service / why Choose Us Settings', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 45,
            ));

            // Crafted section
            $wp_customize->add_section('pawfect_crafted_section', array(
                'title' => esc_html__('Crafted With Care ', 'pawfect'),
                'panel' => 'pawfect_frontpage_settings',
                'priority' => 75,
            ));
        }




        // WooCommerce Shop Page section (only if WooCommerce is active)
        if (class_exists('WooCommerce')) {
            $wp_customize->add_section('pawfect_woocommerce_shop_page', array(
                'title'    => esc_html__('Shop Page Layout', 'pawfect'),
                'panel'    => 'woocommerce',
                'priority' => 10,
            ));
        }

        // Theme sections
        $wp_customize->add_section('pawfect_theme_general', array(
            'title' => esc_html__('Performance & Misc', 'pawfect'),
            'panel' => 'pawfect_global_settings',
            'priority' => 120,
        ));

        $wp_customize->add_section('pawfect_theme_menu_bar', array(
            'title' => esc_html__('Menu Bar Settings', 'pawfect'),
            'panel' => 'pawfect_header_settings',
            'priority' => 121,
        ));

        $wp_customize->add_section('pawfect_excerpt_general', array(
            'title' => esc_html__('Excerpt Settings', 'pawfect'),
            'panel' => 'pawfect_blog_pages_settings',
            'priority' => 122,
        ));

        $wp_customize->add_section('pawfect_global_badges_section', array(
            'title' => esc_html__('Global Badge Settings', 'pawfect'),
            'panel' => 'pawfect_global_settings',
            'priority' => 123,
        ));

        $wp_customize->add_section('pawfect_theme_contact_page', array(
            'title' => esc_html__('Contact Page Settings', 'pawfect'),
            'panel' => 'pawfect_blog_pages_settings',
            'priority' => 123,
        ));

        $wp_customize->add_section('pawfect_about_page_settings', array(
            'title' => esc_html__('About Page Settings', 'pawfect'),
            'panel' => 'pawfect_blog_pages_settings',
            'priority' => 124,
        ));

        // Top Bar Settings
        $wp_customize->add_section('pawfect_topbar_section', array(
            'title' => esc_html__('Top Bar', 'pawfect'),
            'panel' => 'pawfect_header_settings',
            'priority' => 125,
        ));

        // Page Header Settings
        $wp_customize->add_section('pawfect_page_header_section', array(
            'title' => esc_html__('Page Header', 'pawfect'),
            'panel' => 'pawfect_blog_pages_settings',
            'priority' => 126,
        ));

        // Blog Settings
        $wp_customize->add_section('pawfect_blog_section', array(
            'title' => esc_html__('Blog Settings', 'pawfect'),
            'panel' => 'pawfect_blog_pages_settings',
            'priority' => 127,
        ));

        // Page Templates Settings
        $wp_customize->add_section('pawfect_page_templates_section', array(
            'title' => esc_html__('Page Templates', 'pawfect'),
            'panel' => 'pawfect_layout_templates',
            'priority' => 30,
        ));

        // Color sections - moved to Colors & Styling panel
        $wp_customize->add_section('pawfect_theme_colors', array(
            'title' => esc_html__('Global Theme Colors', 'pawfect'),
            'panel' => 'pawfect_colors_styling',
            'priority' => 50,
        ));

        // Gradient colors section - moved to Colors & Styling panel
        $wp_customize->add_section('pawfect_theme_color_settings', array(
            'title' => esc_html__('Gradient Colors', 'pawfect'),
            'panel' => 'pawfect_colors_styling',
            'priority' => 60,
        ));

        // Typography sections - organized by category
        $wp_customize->add_section('pawfect_body_typography', array(
            'title' => esc_html__('Body Typography', 'pawfect'),
            'panel' => 'pawfect_typography',
            'priority' => 10,
        ));

        $wp_customize->add_section('pawfect_heading_typography', array(
            'title' => esc_html__('Heading Typography', 'pawfect'),
            'panel' => 'pawfect_typography',
            'priority' => 20,
        ));

        $wp_customize->add_section('pawfect_menu_typography', array(
            'title' => esc_html__('Menu Typography', 'pawfect'),
            'panel' => 'pawfect_typography',
            'priority' => 30,
        ));

        $wp_customize->add_section('pawfect_button_typography', array(
            'title' => esc_html__('Button Typography', 'pawfect'),
            'panel' => 'pawfect_typography',
            'priority' => 40,
        ));

        $wp_customize->add_section('pawfect_blog_typography', array(
            'title' => esc_html__('Blog Typography', 'pawfect'),
            'panel' => 'pawfect_typography',
            'priority' => 50,
        ));

        $wp_customize->add_section('pawfect_theme_layout', array(
            'title' => esc_html__('Layout & Spacing', 'pawfect'),
            'panel' => 'pawfect_layout_templates',
            'priority' => 10,
        ));

        // Footer sections - moved to Layout & Templates panel
        $wp_customize->add_section('pawfect_footer_widgets', array(
            'title' => esc_html__('Footer Widgets', 'pawfect'),
            'panel' => 'pawfect_footer_settings',
            'priority' => 15,
        ));

        $wp_customize->add_section('pawfect_footer_copyright', array(
            'title' => esc_html__('Footer Copyright', 'pawfect'),
            'panel' => 'pawfect_footer_settings',
            'priority' => 20,
        ));



        // Top Bar section
        $wp_customize->add_section('pawfect_topbar_section', array(
            'title' => esc_html__('Top Bar', 'pawfect'),
            'panel' => 'pawfect_header_settings',
            'priority' => 30,
        ));

        // Blog Settings section (removed duplicate - already registered above with priority 127)

        // All blog controls are now handled through the options system - no direct controls needed

    }
    /*
     * ========================================
     * SELECTIVE REFRESH PARTIALS
     * ========================================
     */

    /**
     * Setup Selective Refresh Partials
     * 
     * Configures selective refresh for various theme elements.
     * This allows live preview updates without full page refresh.
     * 
     * @since 1.0.0
     * @param WP_Customize_Manager $wp_customize WordPress Customizer Manager instance
     */
    public function setup_partials($wp_customize)
    {
        // Bail if selective refresh is not available
        if (!isset($wp_customize->selective_refresh)) {
            return;
        }

        /**
         * Site Identity Partials
         */

        // Site title
        $wp_customize->selective_refresh->add_partial('blogname', array(
            'selector' => '.header-titles-wrapper .site-title',
            'render_callback' => [$this, 'pawfect_customize_partial_blogname'],
        ));

        // Site tagline
        $wp_customize->selective_refresh->add_partial('blogdescription', array(
            'selector' => '.header-titles-wrapper .site-description',
            'render_callback' => [$this, 'pawfect_customize_partial_blogdescription'],
        ));

        /**
         * Homepage Section Partials
         */

        // Main slider content
        $wp_customize->selective_refresh->add_partial('pawfect_main_slider_content', array(
            'selector' => '.pawfect-hero-section',
            'render_callback' => [$this, 'pawfect_main_slider_content_render_callback'],
        ));

        // Press mentions section
        $wp_customize->selective_refresh->add_partial('pawfect_press_mentions_content', array(
            'selector' => '.pawfect-press-mentions-container',
            'render_callback' => [$this, 'pawfect_press_mentions_content_render_callback'],
        ));

        // Feature highlight section
        $wp_customize->selective_refresh->add_partial('pawfect_feature_highlight_collage', array(
            'selector' => '.pawfect-content-area',
            'render_callback' => [$this, 'pawfect_feature_highlight_collage_render_callback'],
        ));

        // Feature highlight title
        $wp_customize->selective_refresh->add_partial('pawfect_feature_highlight_title', array(
            'selector' => '.pawfect-feature-highlight h2',
            'render_callback' => [$this, 'pawfect_feature_highlight_title_render_callback'],
        ));

        // Feature highlight description
        $wp_customize->selective_refresh->add_partial('pawfect_feature_highlight_desc', array(
            'selector' => '.pawfect-feature-highlight .pawfect-text-base',
            'render_callback' => [$this, 'pawfect_feature_highlight_desc_render_callback'],
        ));

        // Feature highlight content area
        $wp_customize->selective_refresh->add_partial('pawfect_feature_highlight_content_area', array(
            'selector' => '.pawfect-content-area',
            'render_callback' => [$this, 'pawfect_feature_highlight_content_area_render_callback'],
        ));

        // Service/Why Choose Us content
        $wp_customize->selective_refresh->add_partial('pawfect_service_content', array(
            'selector' => '.pawfect-why-choose',
            'render_callback' => [$this, 'pawfect_service_content_render_callback'],
            'container_inclusive' => true,
            'fallback_refresh' => true,
        ));

        // Site logo - only when logo exists
        $wp_customize->selective_refresh->add_partial('custom_logo', array(
            'selector' => '.site-logo',
            'render_callback' => [$this, 'pawfect_site_logo_render_callback'],
        ));

        // Main navigation menu
        $wp_customize->selective_refresh->add_partial('primary_menu', array(
            'selector' => '.pawfect-primary-nav-menu',
            'render_callback' => [$this, 'pawfect_primary_menu_render_callback'],
        ));

        // Sticky menu logo
        $wp_customize->selective_refresh->add_partial('pawfect_sticky_bar_logo', array(
            'selector' => '.pawfect-sticky-scrolled-layout .pawfect-logo-link',
            'render_callback' => [$this, 'pawfect_sticky_logo_render_callback'],
        ));

        // Navigation menus
        $wp_customize->selective_refresh->add_partial('nav_menu_locations[primary]', array(
            'selector' => '.pawfect-primary-nav-menu',
            'render_callback' => [$this, 'pawfect_primary_menu_render_callback'],
        ));

        // Top bar
        $wp_customize->selective_refresh->add_partial('pawfect_topbar_enabled', array(
            'selector' => '.pawfect-topbar',
            'render_callback' => [$this, 'pawfect_topbar_render_callback'],
        ));

        // Top bar phone
        $wp_customize->selective_refresh->add_partial('pawfect_topbar_phone', array(
            'selector' => '.pawfect-topbar-left',
            'render_callback' => [$this, 'pawfect_topbar_left_render_callback'],
        ));

        // Top bar email
        $wp_customize->selective_refresh->add_partial('pawfect_topbar_email', array(
            'selector' => '.pawfect-topbar-left',
            'render_callback' => [$this, 'pawfect_topbar_left_render_callback'],
        ));

        // Site title
        $wp_customize->selective_refresh->add_partial('blogname', array(
            'selector' => '.header-titles-wrapper .site-title',
            'render_callback' => [$this, 'pawfect_customize_partial_blogname'],
        ));

        // Site description
        $wp_customize->selective_refresh->add_partial('blogdescription', array(
            'selector' => '.header-titles-wrapper .site-description',
            'render_callback' => [$this, 'pawfect_customize_partial_blogdescription'],
        ));

        // Section heading containers with specific names
        $wp_customize->selective_refresh->add_partial('pawfect_service_area_title', array(
            'selector' => '.pawfect-why-choose-heading',
            'render_callback' => [$this, 'pawfect_service_heading_render_callback'],
        ));

        $wp_customize->selective_refresh->add_partial('pawfect_testimonial_area_title', array(
            'selector' => '.pawfect-testimonial-heading',
            'render_callback' => [$this, 'pawfect_testimonial_heading_render_callback'],
        ));

        $wp_customize->selective_refresh->add_partial('pawfect_mission_area_title', array(
            'selector' => '.pawfect-mission-heading',
            'render_callback' => [$this, 'pawfect_mission_heading_render_callback'],
        ));

        // Blog section heading
        $wp_customize->selective_refresh->add_partial('pawfect_blog_area_title', array(
            'selector' => '.pawfect-blog-heading',
            'render_callback' => [$this, 'pawfect_blog_heading_render_callback'],
        ));

        // Crafted section heading
        $wp_customize->selective_refresh->add_partial('pawfect_crafted_title', array(
            'selector' => '.pawfect-crafted-heading',
            'render_callback' => [$this, 'pawfect_crafted_heading_render_callback'],
        ));

        // Shop by pet section heading
        $wp_customize->selective_refresh->add_partial('pawfect_pet_shop_title', array(
            'selector' => '.pawfect-shop-by-pet-heading',
            'render_callback' => [$this, 'pawfect_shop_by_pet_heading_render_callback'],
        ));

        // Category highlights section heading
        $wp_customize->selective_refresh->add_partial('pawfect_portfolio_heading', array(
            'selector' => '.pawfect-category-highlights-heading',
            'render_callback' => [$this, 'pawfect_category_highlights_heading_render_callback'],
        ));

        // Instagram section heading
        $wp_customize->selective_refresh->add_partial('pawfect_instagram_heading_text', array(
            'selector' => '.pawfect-instagram-heading',
            'render_callback' => [$this, 'pawfect_instagram_heading_render_callback'],
        ));

        // Promo timer section heading
        $wp_customize->selective_refresh->add_partial('pawfect_promo_timer_title', array(
            'selector' => '.pawfect-promo-timer-heading',
            'render_callback' => [$this, 'pawfect_promo_timer_heading_render_callback'],
        ));

        // Promo banner section heading
        $wp_customize->selective_refresh->add_partial('pawfect_promo_banner_title', array(
            'selector' => '.pawfect-promo-banner-heading',
            'render_callback' => [$this, 'pawfect_promo_banner_heading_render_callback'],
        ));

        // Footer features section
        $wp_customize->selective_refresh->add_partial('pawfect_footer_features', array(
            'selector' => '.pawfect-footer-features-heading',
            'render_callback' => [$this, 'pawfect_footer_features_render_callback'],
        ));

        // About section heading
        $wp_customize->selective_refresh->add_partial('pawfect_about_section_title', array(
            'selector' => '.pawfect-about-section-heading',
            'render_callback' => [$this, 'pawfect_about_section_heading_render_callback'],
        ));

        // Page header section
        $wp_customize->selective_refresh->add_partial('pawfect_page_header_title', array(
            'selector' => '.pawfect-page-title-heading',
            'render_callback' => [$this, 'pawfect_page_header_heading_render_callback'],
        ));

        // Page header container
        $wp_customize->selective_refresh->add_partial('pawfect_page_header_container', array(
            'selector' => '.pawfect-page-header-heading',
            'render_callback' => [$this, 'pawfect_page_header_container_render_callback'],
        ));

        // Shop toolbar
        $wp_customize->selective_refresh->add_partial('pawfect_shop_layout', array(
            'selector' => '.pawfect-shop-toolbar',
            'render_callback' => [$this, 'pawfect_shop_toolbar_render_callback'],
        ));

        // Top info area
        $wp_customize->selective_refresh->add_partial('pawfect_top_info_content', array(
            'selector' => '.top-contact-info .topinfo-selector',
            'render_callback' => [$this, 'pawfect_top_info_content_render_callback'],
        ));

        // Footer info area
        $wp_customize->selective_refresh->add_partial('pawfect_footer_info_content', array(
            'selector' => '.footer-contact-info .footerinfo-selector',
            'render_callback' => [$this, 'pawfect_footer_info_content_render_callback'],
        ));

        // Footer logo
        $wp_customize->selective_refresh->add_partial('pawfect_footer_logo_enabled', array(
            'selector' => '.pawfect-footer-logo-container',
            'render_callback' => [$this, 'pawfect_footer_logo_render_callback'],
            'container_inclusive' => true,
            'fallback_refresh' => false,
        ));

        $wp_customize->selective_refresh->add_partial('pawfect_footer_logo_size', array(
            'selector' => '.pawfect-footer-logo-container',
            'render_callback' => [$this, 'pawfect_footer_logo_render_callback'],
            'container_inclusive' => true,
            'fallback_refresh' => false,
        ));

        // Footer copyright text
        $wp_customize->selective_refresh->add_partial('pawfect_footer_copyright_text', array(
            'selector' => '.pawfect-footer-copyright',
            'render_callback' => [$this, 'pawfect_footer_copyright_text_render_callback'],
            'settings' => array('pawfect_footer_copyright_text'),
        ));

        // Portfolio section title
        $wp_customize->selective_refresh->add_partial('pawfect_project_area_title', array(
            'selector' => '.pawfect-portfolio-section .section-header .section-title',
            'render_callback' => [$this, 'customize_partial_pawfect_project_area_title'],
        ));

        // Portfolio section description
        $wp_customize->selective_refresh->add_partial('pawfect_project_area_des', array(
            'selector' => '.pawfect-portfolio-section .section-header p',
            'render_callback' => [$this, 'customize_partial_pawfect_project_area_des'],
        ));

        // Portfolio content area
        $wp_customize->selective_refresh->add_partial('pawfect_portfolio_content', array(
            'selector' => '.pawfect-portfolio-section .pawfect-portfolio-grid',
            'render_callback' => [$this, 'pawfect_portfolio_content_render_callback'],
        ));


        
        /**
         * Section Enable/Disable Partials for Front Page
         */

        // Hero Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_main_slider_enabled', array(
            'selector' => '.pawfect-slide-wrapper',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_hero_section_partial'],
            'fallback_refresh' => false,
        ));

        // Hero Slider Content (removed duplicate - using the one above with better selector)

        // Feature Highlight Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_feature_highlight_enabled', array(
            'selector' => '.pawfect-feature-highlight',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_feature_highlight_partial'],
            'fallback_refresh' => false,
        ));

        // Feature Highlight Title
        $wp_customize->selective_refresh->add_partial('pawfect_feature_highlight_title', array(
            'selector' => '.pawfect-feature-highlight .pawfect-section-title',
            'render_callback' => [$this, 'render_feature_highlight_title_partial'],
            'fallback_refresh' => false,
        ));

        // Feature Highlight Description
        $wp_customize->selective_refresh->add_partial('pawfect_feature_highlight_desc', array(
            'selector' => '.pawfect-feature-highlight .pawfect-section-description',
            'render_callback' => [$this, 'render_feature_highlight_desc_partial'],
            'fallback_refresh' => false,
        ));

        // Portfolio Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_portfolio_enabled', array(
            'selector' => '.pawfect-section-white, .pawfect-tailor-experience',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_portfolio_partial'],
            'fallback_refresh' => false,
        ));

        // CTA Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_cta_enabled', array(
            'selector' => '.pawfect-cta-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_cta_partial'],
            'fallback_refresh' => false,
        ));

        // Featured Collection Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_featured_collection_disabled', array(
            'selector' => '.pawfect-featured-collection',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_featured_collection_partial'],
            'fallback_refresh' => false,
        ));

        // Blog Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_blog_enabled', array(
            'selector' => '.pawfect-blog-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_blog_partial'],
            'fallback_refresh' => false,
        ));

        // Blog Layout Style (Grid/List)
        $wp_customize->selective_refresh->add_partial('pawfect_blog_layout_style', array(
            'selector' => '.pawfect-posts-container',
            'container_inclusive' => true,
            'render_callback' => function() {
                // Force full page refresh for layout changes
                return false;
            },
            'fallback_refresh' => true,
        ));



         // Blog Layout Style (Grid/List)
        $wp_customize->selective_refresh->add_partial('pawfect_blog_title_font_family', array(
            'selector' => '.pawfect-post-title',
            'container_inclusive' => true,
            'render_callback' => function() {
                // Force full page refresh for layout changes
                return false;
            },
            'fallback_refresh' => true,
        ));

        // Testimonial Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_testimonial_enabled', array(
            'selector' => '.pawfect-testimonial-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_testimonial_partial'],
            'fallback_refresh' => false,
        ));

        // WooCommerce Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_woocommerce_enabled', array(
            'selector' => '.pawfect-woocommerce-featured',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_woocommerce_partial'],
            'fallback_refresh' => false,
        ));

        // WooCommerce Section Title
        $wp_customize->selective_refresh->add_partial('pawfect_woocommerce_title', array(
            'selector' => '.pawfect-woocommerce-featured h2',
            'render_callback' => [$this, 'render_woocommerce_title_partial'],
            'fallback_refresh' => false,
        ));

        // WooCommerce Section Description
        $wp_customize->selective_refresh->add_partial('pawfect_woocommerce_area_des', array(
            'selector' => '.pawfect-woocommerce-featured .pawfect-text-base.pawfect-text-gray-600',
            'render_callback' => [$this, 'render_woocommerce_description_partial'],
            'fallback_refresh' => false,
        ));

        // Why Choose Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_service_area_enabled', array(
            'selector' => '.pawfect-why-choose-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_why_choose_partial'],
            'fallback_refresh' => false,
        ));

        /**
         * Page Header Partials
         */

        // Page Header Title
        $wp_customize->selective_refresh->add_partial('pawfect_page_header_title', array(
            'selector' => '.pawfect-page-title-heading',
            'render_callback' => [$this, 'pawfect_page_header_title_render_callback'],
            'fallback_refresh' => false,
        ));

        // Page Header Breadcrumbs
        $wp_customize->selective_refresh->add_partial('pawfect_page_header_breadcrumbs', array(
            'selector' => '.pawfect-breadcrumbs',
            'render_callback' => [$this, 'pawfect_page_header_breadcrumbs_render_callback'],
            'fallback_refresh' => false,
        ));

        // Mission Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_mission_enabled', array(
            'selector' => '.pawfect-mission-heading',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_mission_partial'],
            'fallback_refresh' => false,
        ));

        // Pet Shop Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_pet_shop_disabled', array(
            'selector' => '.pawfect-pet-shop-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_pet_shop_partial'],
            'fallback_refresh' => false,
        ));

        // Crafted Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_crafted_disabled', array(
            'selector' => '.pawfect-crafted-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_crafted_partial'],
            'fallback_refresh' => false,
        ));

        // Promotional Popup Selective Refresh
        // Since popup is in footer.php, we use fallback refresh for better compatibility
        $wp_customize->selective_refresh->add_partial('pawfect_popup_enable', array(
            'selector' => '#pawfect-promo-modal',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_popup_partial'],
            'fallback_refresh' => true,
        ));

        $wp_customize->selective_refresh->add_partial('pawfect_popup_title', array(
            'selector' => '#pawfect-promo-modal',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_popup_partial'],
            'fallback_refresh' => true,
        ));

        $wp_customize->selective_refresh->add_partial('pawfect_popup_subtitle', array(
            'selector' => '#pawfect-promo-modal',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_popup_partial'],
            'fallback_refresh' => true,
        ));

        $wp_customize->selective_refresh->add_partial('pawfect_popup_description', array(
            'selector' => '#pawfect-promo-modal',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_popup_partial'],
            'fallback_refresh' => true,
        ));

        $wp_customize->selective_refresh->add_partial('pawfect_popup_button_text', array(
            'selector' => '#pawfect-promo-modal',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_popup_partial'],
            'fallback_refresh' => true,
        ));

        // Promo Banner Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_promo_banner_disabled', array(
            'selector' => '.pawfect-promo-banner-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_promo_banner_partial'],
            'fallback_refresh' => false,
        ));

        // Instagram Section Enable/Disable
        $wp_customize->selective_refresh->add_partial('pawfect_instagram_disabled', array(
            'selector' => '.pawfect-instagram-section',
            'container_inclusive' => true,
            'render_callback' => [$this, 'render_instagram_partial'],
            'fallback_refresh' => false,
        ));
    }

    /*
     * ========================================
     * PARTIAL RENDER CALLBACKS
     * ========================================
     */

    /**
     * Site title partial render callback
     * 
     * @since 1.0.0
     * @return string Site title
     */
    public function pawfect_customize_partial_blogname()
    {
        return get_bloginfo('name');
    }

    /**
     * Site tagline partial render callback
     * 
     * @since 1.0.0
     * @return string Site description
     */
    public function pawfect_customize_partial_blogdescription()
    {
        return get_bloginfo('description');
    }

    /**
     * Client area description partial render callback
     * 
     * @since 1.0.0
     * @return string Client area description
     */
    public function customize_partial_pawfect_client_area_desc()
    {
        return get_theme_mod('pawfect_client_area_desc');
    }

    /**
     * WooCommerce area title partial render callback
     * 
     * @since 1.0.0
     * @return string WooCommerce area title
     */
    public function customize_partial_pawfect_woocommerce_area_title()
    {
        return get_theme_mod('pawfect_woocommerce_area_title');
    }

    /**
     * WooCommerce area description partial render callback
     * 
     * @since 1.0.0
     * @return string WooCommerce area description
     */
    public function customize_partial_pawfect_woocommerce_area_desc()
    {
        return get_theme_mod('pawfect_woocommerce_area_desc');
    }

    /**
     * WooCommerce content partial render callback
     * 
     * @since 1.0.0
     * @return string WooCommerce content
     */
    public function customize_partial_pawfect_woocommerce_content()
    {
        return get_theme_mod('pawfect_woocommerce_content');
    }

    /**
     * Footer copyright text partial render callback
     *
     * @since 1.0.0
     * @return string Footer copyright text
     */
    public function pawfect_footer_copyright_text_render_callback()
    {
        return get_theme_mod('pawfect_footer_copyright_text');
    }

    /**
     * Main slider content partial render callback
     *
     * @since 1.0.0
     * @return string Main slider content
     */
    public function pawfect_main_slider_content_render_callback()
    {
        ob_start();
        get_template_part('template-parts/front-page/hero-slider');
        return ob_get_clean();
    }

    /**
     * Press mentions content partial render callback
     *
     * @since 1.0.0
     * @return string Press mentions content
     */
    public function pawfect_press_mentions_content_render_callback()
    {
        ob_start();
        get_template_part('template-parts/front-page/press-mentions');
        return ob_get_clean();
    }

    /**
     * Feature highlight collage partial render callback
     *
     * @since 1.0.0
     * @return string Feature highlight content
     */
    public function pawfect_feature_highlight_collage_render_callback()
    {
        ob_start();
        get_template_part('template-parts/front-page/feature-highlight');
        return ob_get_clean();
    }

    /**
     * Top info content partial render callback
     *
     * @since 1.0.0
     * @return string Top info content
     */
    public function pawfect_top_info_content_render_callback()
    {
        $content = get_theme_mod('pawfect_top_info_content');
        if (is_string($content) && !empty($content)) {
            $decoded = json_decode($content);
            if (is_array($decoded)) {
                ob_start();
                foreach ($decoded as $item) {
                    if (!empty($item->title)) {
                        echo '<div class="topinfo-item">';
                        if (!empty($item->icon)) {
                            echo '<i class="' . esc_attr($item->icon) . '"></i>';
                        }
                        echo '<span>' . esc_html($item->title) . '</span>';
                        echo '</div>';
                    }
                }
                return ob_get_clean();
            }
        }
        return '';
    }

    /**
     * Footer info content partial render callback
     *
     * @since 1.0.0
     * @return string Footer info content
     */
    public function pawfect_footer_info_content_render_callback()
    {
        $content = get_theme_mod('pawfect_footer_info_content');
        if (is_string($content) && !empty($content)) {
            $decoded = json_decode($content);
            if (is_array($decoded)) {
                ob_start();
                foreach ($decoded as $item) {
                    if (!empty($item->title)) {
                        echo '<div class="footerinfo-item">';
                        if (!empty($item->icon)) {
                            echo '<i class="' . esc_attr($item->icon) . '"></i>';
                        }
                        echo '<span>' . esc_html($item->title) . '</span>';
                        echo '</div>';
                    }
                }
                return ob_get_clean();
            }
        }
        return '';
    }

    /**
     * Portfolio content partial render callback
     *
     * @since 1.0.0
     * @return string Portfolio content
     */
    public function pawfect_portfolio_content_render_callback()
    {
        $content = get_theme_mod('pawfect_portfolio_content');
        if (is_string($content) && !empty($content)) {
            $decoded = json_decode($content);
            if (is_array($decoded)) {
                ob_start();
                foreach ($decoded as $item) {
                    if (!empty($item->image_url)) {
                        echo '<div class="portfolio-item">';
                        echo '<img src="' . esc_url($item->image_url) . '" alt="' . esc_attr($item->title ?? '') . '">';
                        if (!empty($item->title)) {
                            echo '<h3>' . esc_html($item->title) . '</h3>';
                        }
                        if (!empty($item->description)) {
                            echo '<p>' . esc_html($item->description) . '</p>';
                        }
                        echo '</div>';
                    }
                }
                return ob_get_clean();
            }
        }
        return '';
    }

    /**
     * Portfolio area title partial render callback
     *
     * @since 1.0.0
     * @return string Portfolio area title
     */
    public function customize_partial_pawfect_project_area_title()
    {
        return get_theme_mod('pawfect_project_area_title');
    }

    /**
     * Portfolio area description partial render callback
     *
     * @since 1.0.0
     * @return string Portfolio area description
     */
    public function customize_partial_pawfect_project_area_des()
    {
        return get_theme_mod('pawfect_project_area_des');
    }

    /**
     * Selective Refresh Render Callbacks for Section Enable/Disable
     */

    public function render_hero_section_partial() {
        if (get_theme_mod('pawfect_main_slider_enabled', true)) {
            get_template_part('template-parts/front-page/hero-slider');
        }
    }

    public function render_feature_highlight_partial() {
        if (get_theme_mod('pawfect_feature_highlight_enabled', true)) {
            get_template_part('template-parts/front-page/feature-highlight');
        }
    }

    public function render_portfolio_partial() {
        if (get_theme_mod('pawfect_portfolio_enabled', true)) {
            get_template_part('template-parts/front-page/section-category-highlights');
        }
    }

    public function render_cta_partial() {
        if (get_theme_mod('pawfect_cta_enabled', true)) {
            get_template_part('template-parts/front-page/cta');
        }
    }

    public function render_featured_collection_partial() {
        if (get_theme_mod('pawfect_featured_collection_disabled', true)) {
            get_template_part('template-parts/front-page/featured-collection');
        }
    }

    public function render_blog_partial() {
        if (get_theme_mod('pawfect_blog_enabled', true)) {
            get_template_part('template-parts/front-page/index-blog');
        }
    }

    public function render_blog_content_partial() {
        // This renders the blog posts container for content ordering changes
        // For blog/archive pages, we need to render the posts loop
        if (have_posts()) {
            echo '<div class="pawfect-posts-container">';
            while (have_posts()) {
                the_post();
                get_template_part('template-parts/post/content');
            }
            echo '</div>';
        }
        return '';
    }

    public function render_testimonial_partial() {
        if (get_theme_mod('pawfect_testimonial_enabled', true)) {
            get_template_part('template-parts/front-page/index-testimonial');
        }
    }

    public function render_woocommerce_partial() {
        if (get_theme_mod('pawfect_woocommerce_enabled', true)) {
            get_template_part('template-parts/front-page/section-woocommerce-featured');
        }
    }

    public function render_woocommerce_title_partial() {
        return esc_html(get_theme_mod('pawfect_woocommerce_title', __('Featured Products', 'pawfect')));
    }

    public function render_woocommerce_description_partial() {
        return esc_html(get_theme_mod('pawfect_woocommerce_area_des', ''));
    }

    public function render_why_choose_partial() {
        if (get_theme_mod('pawfect_service_area_enabled', true)) {
            get_template_part('template-parts/front-page/why-choose');
        }
    }

    public function render_mission_partial() {
        if (get_theme_mod('pawfect_mission_disabled', true)) {
            get_template_part('template-parts/front-page/index-mission');
        }
    }

    public function render_pet_shop_partial() {
        if (get_theme_mod('pawfect_pet_shop_disabled', true)) {
            get_template_part('template-parts/front-page/index-shop-by-pet');
        }
    }

    public function render_crafted_partial() {
        if (get_theme_mod('pawfect_crafted_disabled', true)) {
            get_template_part('template-parts/front-page/index-crafted');
        }
    }

    public function render_promo_banner_partial() {
        if (get_theme_mod('pawfect_promo_banner_disabled', true)) {
            get_template_part('template-parts/front-page/index-promo-banner');
        }
    }

    public function render_instagram_partial() {
        if (get_theme_mod('pawfect_instagram_disabled', true)) {
            get_template_part('template-parts/front-page/index-instagram');
        }
    }

    /**
     * Individual Setting Render Callbacks
     */

    public function render_slider_content_partial() {
        // This would render the slider content based on the repeater data
        $slider_content = get_theme_mod('pawfect_main_slider_content', '');
        if (!empty($slider_content)) {
            // Render slider content here
            echo '<div class="pawfect-slider-content">';
            // Process and display slider items
            echo '</div>';
        }
    }

    public function render_feature_highlight_title_partial() {
        return get_theme_mod('pawfect_feature_highlight_title', esc_html__('Luxury Pet Essentials, Tailored for Style', 'pawfect'));
    }

    public function pawfect_feature_highlight_title_render_callback() {
        return get_theme_mod('pawfect_feature_highlight_title', __( 'Crafted with Love for Your Furry Friends', 'pawfect' ));
    }

    public function pawfect_feature_highlight_desc_render_callback() {
        return get_theme_mod('pawfect_feature_highlight_desc', __( 'Every product is carefully designed and tested to ensure the highest quality and safety for your beloved pets. From premium materials to innovative designs, we create products that both you and your pets will love.', 'pawfect' ));
    }

    public function pawfect_feature_highlight_content_area_render_callback() {
        ob_start();
        $title = get_theme_mod('pawfect_feature_highlight_title', __( 'Crafted with Love for Your Furry Friends', 'pawfect' ));
        $description = get_theme_mod('pawfect_feature_highlight_desc', __( 'Every product is carefully designed and tested to ensure the highest quality and safety for your beloved pets. From premium materials to innovative designs, we create products that both you and your pets will love.', 'pawfect' ));
        ?>
        <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-primary pawfect-text-sm pawfect-text-gray-500 pawfect-font-medium pawfect-mb-4">
            <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
            <span><?php echo esc_html__( 'PREMIUM QUALITY', 'pawfect' ); ?></span>
            <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
        </div>
        <h2 class="pawfect-text-3xl md:pawfect-text-4xl lg:pawfect-text-5xl pawfect-font-bold pawfect-mb-6 pawfect-leading-tight">
            <?php echo esc_html($title); ?>
        </h2>
        <p class="pawfect-text-base md:pawfect-text-lg pawfect-text-gray-600 pawfect-mb-8 pawfect-leading-relaxed">
            <?php echo esc_html($description); ?>
        </p>
        <?php
        return ob_get_clean();
    }

    public function pawfect_site_logo_render_callback() {
        $custom_logo_id = get_theme_mod('custom_logo');
        if (!$custom_logo_id) {
            return '';
        }

        $logo_data = wp_get_attachment_image_src($custom_logo_id, 'full');
        $main_logo = $logo_data ? $logo_data[0] : get_template_directory_uri() . '/assets/images/logo-white.webp';

        ob_start();
        ?>
        <div class="site-logo pawfect-mb-2">
            <a href="<?php echo esc_url(home_url('/')); ?>" class="pawfect-logo-link">
                <img src="<?php echo esc_url($main_logo); ?>" alt="<?php echo esc_attr(get_bloginfo('name')); ?>" class="pawfect-transition-all pawfect-duration-300" />
            </a>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_primary_menu_render_callback() {
        ob_start();
        if (has_nav_menu('primary')) {
            wp_nav_menu([
                'theme_location' => 'primary',
                'container' => false,
                'menu_class' => 'pawfect-flex pawfect-justify-center pawfect-items-center pawfect-text-[17px] pawfect-uppercase',
                'walker' => new Pawfect_Nav_Walker(),
                'fallback_cb' => false,
            ]);
        } else {
            echo '<div class="pawfect-no-menu-notice pawfect-text-center pawfect-py-4">';
            echo '<p class="pawfect-text-sm pawfect-text-gray-500">' . esc_html__( 'Please assign a menu to the Primary Menu location', 'pawfect' ) . '</p>';
            echo '</div>';
        }
        return ob_get_clean();
    }

    public function pawfect_topbar_render_callback() {
        if (!get_theme_mod('pawfect_topbar_enabled', true)) {
            return '';
        }
        ob_start();
        get_template_part('template-parts/topbar');
        return ob_get_clean();
    }

    public function pawfect_topbar_left_render_callback() {
        $phone = get_theme_mod( 'pawfect_topbar_phone', __( '+1 (555) 123-4567', 'pawfect' ) );
        $email = get_theme_mod('pawfect_topbar_email', 'example@example.com');

        ob_start();
        ?>
        <div class="pawfect-topbar-left pawfect-flex pawfect-flex-wrap pawfect-items-center pawfect-gap-4 md:pawfect-gap-6">
            <?php if ($phone): ?>
                <div class="pawfect-topbar-item pawfect-flex pawfect-items-center pawfect-gap-2">
                    <svg class="pawfect-w-4 pawfect-h-4 pawfect-opacity-80" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                    </svg>
                    <a href="tel:<?php echo esc_attr(str_replace(array(' ', '(', ')', '-'), '', $phone)); ?>" class="pawfect-text-current hover:pawfect-opacity-80 pawfect-transition-opacity">
                        <?php echo esc_html($phone); ?>
                    </a>
                </div>
            <?php endif; ?>

            <?php if ($email): ?>
                <div class="pawfect-topbar-item pawfect-flex pawfect-items-center pawfect-gap-2">
                    <svg class="pawfect-w-4 pawfect-h-4 pawfect-opacity-80" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 4.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                    </svg>
                    <a href="mailto:<?php echo esc_attr($email); ?>" class="pawfect-text-current hover:pawfect-opacity-80 pawfect-transition-opacity">
                        <?php echo esc_html($email); ?>
                    </a>
                </div>
            <?php endif; ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function render_feature_highlight_desc_partial() {
        return get_theme_mod('pawfect_feature_highlight_desc', esc_html__('Discover finely crafted collars, chic apparel, and elegant essentials designed to celebrate your pets personality with premium comfort and timeless style.', 'pawfect'));
    }

    public function pawfect_service_heading_render_callback() {
        $title = get_theme_mod('pawfect_service_area_title', __( 'Why Choose Pawfect?', 'pawfect' ));
        $desc = get_theme_mod('pawfect_service_area_des', __( 'We create thoughtful, high-quality essentials that keep tails wagging — and hearts full.', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-why-choose-heading pawfect-text-center pawfect-mb-16 lg:pawfect-mb-20">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-primary pawfect-text-sm pawfect-text-gray-500 pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'Why Choose Us', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
            </div>
            <h2 class="pawfect-text-3xl md:pawfect-text-4xl lg:pawfect-text-5xl pawfect-font-bold pawfect-leading-tight pawfect-mb-6">
                <?php echo esc_html($title); ?>
            </h2>
            <p class="pawfect-text-base pawfect-leading-relaxed pawfect-max-w-3xl pawfect-mx-auto">
                <?php echo esc_html($desc); ?>
            </p>
        </div>
        <?php
        return ob_get_clean();
    }

    /**
     * Service content partial render callback
     *
     * @since 1.0.0
     * @return string Service content HTML
     */
    public function pawfect_service_content_render_callback() {
        ob_start();
        get_template_part('template-parts/front-page/why-choose');
        return ob_get_clean();
    }

    public function pawfect_testimonial_heading_render_callback() {
        $title = get_theme_mod('pawfect_testimonial_area_title', __( 'Happy Customers', 'pawfect' ));
        $desc = get_theme_mod('pawfect_testimonial_area_desc', __( 'Real reviews from the Pawfect family.', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-testimonial-heading pawfect-flex pawfect-justify-between pawfect-items-end pawfect-mb-12">
            <div class="pawfect-text-left">
                <h2 class="pawfect-text-4xl md:pawfect-text-5xl pawfect-font-bold pawfect-text-[#1f2937] pawfect-mb-2">
                    <?php echo esc_html($title); ?>
                </h2>
                <?php if ($desc): ?>
                    <p class="pawfect-text-pawfect-text">
                        <?php echo esc_html($desc); ?>
                    </p>
                <?php endif; ?>
            </div>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_mission_heading_render_callback() {
        $title = get_theme_mod('pawfect_mission_area_title', __( 'Our Mission', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-mission-heading">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-white pawfect-text-sm pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-white pawfect-opacity-60"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'Our Mission', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-white pawfect-opacity-60"></div>
            </div>
            <h2 class="pawfect-text-4xl md:pawfect-text-5xl pawfect-font-bold pawfect-text-white pawfect-mb-6">
                <?php echo wp_kses_post($title); ?>
            </h2>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_blog_heading_render_callback() {
        $title = get_theme_mod('pawfect_blog_area_title', __( 'From Our Blog', 'pawfect' ));
        $desc = get_theme_mod('pawfect_blog_area_des', __( 'Tips, stories & ideas for every dog lover', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-blog-heading pawfect-text-center pawfect-mb-12 lg:pawfect-mb-16">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-primary pawfect-text-sm pawfect-text-gray-500 pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'Latest Stories', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
            </div>
            <h2 class="pawfect-text-4xl md:pawfect-text-5xl pawfect-font-bold pawfect-text-[#1f2937] pawfect-mb-2">
                <?php echo esc_html($title); ?>
            </h2>
            <?php if (!empty($desc)): ?>
                <p class="pawfect-text-pawfect-text">
                    <?php echo esc_html($desc); ?>
                </p>
            <?php endif; ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_crafted_heading_render_callback() {
        $title = get_theme_mod('pawfect_crafted_title', __( 'Crafted with Care', 'pawfect' ));
        $desc = get_theme_mod('pawfect_crafted_desc', __( 'We create products that make tails wag and whiskers wiggle...', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-crafted-heading pawfect-text-center lg:pawfect-text-left">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-primary pawfect-text-sm pawfect-text-gray-500 pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'Quality & Care', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
            </div>
            <h2 class="pawfect-text-4xl md:pawfect-text-5xl pawfect-font-bold pawfect-text-[#1f2937] pawfect-mb-2">
                <?php echo esc_html($title); ?>
            </h2>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_shop_by_pet_heading_render_callback() {
        $title = get_theme_mod('pawfect_pet_shop_title', __( 'Shop By Pets', 'pawfect' ));
        $desc = get_theme_mod('pawfect_pet_shop_desc', __( 'We create thoughtful, high-quality essentials that keep tails wagging — and hearts full.', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-shop-by-pet-heading pawfect-text-center pawfect-mb-12 lg:pawfect-mb-16">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-primary pawfect-text-sm pawfect-text-gray-500 pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'Pet Categories', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
            </div>
            <h2 class="pawfect-text-3xl md:pawfect-text-4xl lg:pawfect-text-5xl pawfect-font-bold pawfect-text-gray-900 pawfect-mb-4">
                <?php echo esc_html($title); ?>
            </h2>
            <?php if ($desc): ?>
                <p class="pawfect-text-base pawfect-text-gray-600 pawfect-max-w-2xl pawfect-mx-auto pawfect-leading-relaxed">
                    <?php echo esc_html($desc); ?>
                </p>
            <?php endif; ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_category_highlights_heading_render_callback() {
        $heading = get_theme_mod('pawfect_portfolio_heading', __( 'Tailor Your Pet Experience', 'pawfect' ));
        $description = get_theme_mod('pawfect_portfolio_description', __( 'Discover our curated collections designed specifically for your furry friends', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-category-highlights-heading pawfect-text-center pawfect-mb-12 lg:pawfect-mb-16">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-primary pawfect-text-sm pawfect-text-gray-500 pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'Shop by Category', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
            </div>
            <h2 class="pawfect-text-3xl md:pawfect-text-4xl lg:pawfect-text-5xl pawfect-font-bold pawfect-text-gray-900 pawfect-mb-4">
                <?php echo esc_html($heading); ?>
            </h2>
            <?php if ($description): ?>
                <p class="pawfect-text-base pawfect-text-gray-600 pawfect-max-w-2xl pawfect-mx-auto pawfect-leading-relaxed">
                    <?php echo esc_html($description); ?>
                </p>
            <?php endif; ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_instagram_heading_render_callback() {
        $heading = get_theme_mod('pawfect_instagram_heading_text', '@PAWS');
        $subtext = get_theme_mod('pawfect_instagram_subtext', __( 'FOLLOW US ON INSTAGRAM', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-instagram-heading pawfect-group pawfect-bg-white pawfect-bg-opacity-90 pawfect-backdrop-blur-lg pawfect-p-8 lg:pawfect-p-12 pawfect-rounded-2xl pawfect-text-center pawfect-shadow-2xl pawfect-border pawfect-border-white pawfect-border-opacity-50 ">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-bg-gradient-to-r pawfect-from-pink-500 pawfect-to-purple-600 pawfect-text-white pawfect-px-4 pawfect-py-2 pawfect-rounded-full pawfect-text-sm pawfect-font-bold pawfect-tracking-wider pawfect-uppercase pawfect-mb-6">
                <svg class="pawfect-w-4 pawfect-h-4" fill="currentColor" viewBox="0 0 24 24">
                    <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"/>
                </svg>
                <span><?php echo esc_html__( 'Instagram', 'pawfect' ); ?></span>
            </div>
            <h2 class="pawfect-text-4xl md:pawfect-text-5xl lg:pawfect-text-6xl pawfect-font-bold pawfect-text-[#1f2937] pawfect-mb-4 pawfect-leading-tight pawfect-tracking-tight pawfect-transition-all pawfect-duration-300 group-hover:pawfect-text-pawfect-primary">
                <?php echo esc_html($heading); ?>
            </h2>
            <p class="pawfect-text-lg pawfect-text-[#4b5563] pawfect-font-medium pawfect-tracking-wider pawfect-uppercase ">
                <?php echo esc_html($subtext); ?>
            </p>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_promo_timer_heading_render_callback() {
        $title = get_theme_mod('pawfect_promo_timer_title', __( "Don't Sleep On This Sale!", 'pawfect' ));
        $desc = get_theme_mod('pawfect_promo_timer_desc', __( 'Our semi-annual sale ends soon — grab your favorite picks before time runs out.', 'pawfect' ));
        $desc_color = get_theme_mod('pawfect_promo_timer_desc_color', '#F4A259');

        ob_start();
        ?>
        <div class="pawfect-promo-timer-heading pawfect-max-w-2xl pawfect-text-center lg:pawfect-text-left">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-white pawfect-text-sm pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-white pawfect-opacity-60"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'Limited Time', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-white pawfect-opacity-60"></div>
            </div>
            <?php if ($title): ?>
                <h2 class="pawfect-text-white pawfect-text-4xl md:pawfect-text-5xl lg:pawfect-text-6xl pawfect-font-bold pawfect-mb-6 pawfect-leading-tight pawfect-tracking-tight">
                    <?php echo esc_html($title); ?>
                </h2>
            <?php endif; ?>
            <?php if ($desc): ?>
                <p class="pawfect-text-lg md:pawfect-text-xl pawfect-mb-8 pawfect-leading-relaxed pawfect-font-light" style="color: <?php echo esc_attr($desc_color); ?>;">
                    <?php echo esc_html($desc); ?>
                </p>
            <?php endif; ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_promo_banner_heading_render_callback() {
        $title = get_theme_mod('pawfect_promo_banner_title', __( 'SAVE UP TO 50%', 'pawfect' ));
        $desc = get_theme_mod('pawfect_promo_banner_description', __( 'Can\'t wait to save? Shop our semi-annual sale now.', 'pawfect' ));
        $title_color = get_theme_mod('pawfect_promo_banner_title_color', '#ffffff');
        $subtitle_color = get_theme_mod('pawfect_promo_banner_subtitle_color', '#F4A259');

        ob_start();
        ?>
        <div class="pawfect-promo-banner-heading pawfect-relative pawfect-z-10 pawfect-py-12 pawfect-px-8 lg:pawfect-px-16">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-sm pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary pawfect-opacity-60"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider pawfect-text-primary"><?php echo esc_html__( 'Limited Offer', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary pawfect-opacity-60"></div>
            </div>
            <h2 class="pawfect-text-4xl md:pawfect-text-5xl pawfect-font-bold pawfect-mb-6" style="color: <?php echo esc_attr($title_color); ?>;">
                <?php echo esc_html($title); ?>
            </h2>
            <?php if (!empty($desc)): ?>
                <p class="pawfect-mb-8">
                    <?php echo esc_html($desc); ?>
                </p>
            <?php endif; ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_footer_features_render_callback() {
        ob_start();
        ?>
        <div class="pawfect-footer-features-heading pawfect-grid pawfect-grid-cols-1 md:pawfect-grid-cols-4 pawfect-gap-8 pawfect-mb-16 pawfect-text-center">
            <div class="pawfect-flex pawfect-flex-col pawfect-items-center pawfect-text-center">
                <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="#ffffff" viewBox="0 0 256 256"><path d="M251.71,118.52l-14-35A12,12,0,0,0,226.58,76H188V64a4,4,0,0,0-4-4H32A12,12,0,0,0,20,72V184a12,12,0,0,0,12,12H52.29a28,28,0,0,0,55.42,0h56.58a28,28,0,0,0,55.42,0H240a12,12,0,0,0,12-12V120A4,4,0,0,0,251.71,118.52ZM188,84h38.58a4,4,0,0,1,3.72,2.51L242.09,116H188ZM28,72a4,4,0,0,1,4-4H180v72H28ZM80,212a20,20,0,1,1,20-20A20,20,0,0,1,80,212Zm84.29-24H107.71a28,28,0,0,0-55.42,0H32a4,4,0,0,1-4-4V148H180v18.71A28.05,28.05,0,0,0,164.29,188ZM192,212a20,20,0,1,1,20-20A20,20,0,0,1,192,212Zm52-28a4,4,0,0,1-4,4H219.71A28,28,0,0,0,188,164.29V124h56Z"></path></svg>
                <h4 class="pawfect-font-semibold pawfect-text-xl pawfect-mb-2 pawfect-mt-2"><?php echo esc_html__( 'Fast Shipping', 'pawfect' ); ?></h4>
                <p class="pawfect-text-base pawfect-text-gray-400 pawfect-leading-relaxed"><?php echo esc_html__( 'Delivery within 24 hours, 2-day express available.', 'pawfect' ); ?></p>
            </div>
            <div class="pawfect-flex pawfect-flex-col pawfect-items-center pawfect-text-center">
                <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="#ffffff" viewBox="0 0 256 256"><path d="M221.76,69.66l-88-48.18a12,12,0,0,0-11.52,0l-88,48.18A12,12,0,0,0,28,80.18v95.64a12,12,0,0,0,6.24,10.52l88,48.18a11.95,11.95,0,0,0,11.52,0l88-48.18A12,12,0,0,0,228,175.82V80.18A12,12,0,0,0,221.76,69.66ZM126.08,28.5a3.94,3.94,0,0,1,3.84,0L216.67,76,178.5,96.89a4,4,0,0,0-.58-.4l-88-48.18Zm1.92,96L39.33,76,81.56,52.87l88.67,48.54Zm-89.92,54.8a4,4,0,0,1-2.08-3.5V83.29l88,48.16v94.91Zm179.84,0h0l-85.92,47V131.45l40-21.89V152a4,4,0,0,0,8,0V105.18l40-21.89v92.53A4,4,0,0,1,217.92,179.32Z"></path></svg>
                <h4 class="pawfect-font-semibold pawfect-text-xl pawfect-mb-2 pawfect-mt-2"><?php echo esc_html__( 'Free Returns', 'pawfect' ); ?></h4>
                <p class="pawfect-text-base pawfect-text-gray-400 pawfect-leading-relaxed"><?php echo esc_html__( '30-day free returns on all items.', 'pawfect' ); ?></p>
            </div>
            <div class="pawfect-flex pawfect-flex-col pawfect-items-center pawfect-text-center">
                <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="#ffffff" viewBox="0 0 256 256"><path d="M220,48V152a12,12,0,0,1-12,12H89.66l17.17,17.17a4,4,0,0,1-5.66,5.66l-24-24a4,4,0,0,1,0-5.66l24-24a4,4,0,0,1,5.66,5.66L89.66,156H208a4,4,0,0,0,4-4V48a4,4,0,0,0-4-4H96a4,4,0,0,0-4,4v8a4,4,0,0,1-8,0V48A12,12,0,0,1,96,36H208A12,12,0,0,1,220,48ZM168,196a4,4,0,0,0-4,4v8a4,4,0,0,1-4,4H48a4,4,0,0,1-4-4V104a4,4,0,0,1,4-4H166.34l-17.17,17.17a4,4,0,0,0,5.66,5.66l24-24a4,4,0,0,0,0-5.66l-24-24a4,4,0,0,0-5.66,5.66L166.34,92H48a12,12,0,0,0-12,12V208a12,12,0,0,0,12,12H160a12,12,0,0,0,12-12v-8A4,4,0,0,0,168,196Z"></path></svg>
                <h4 class="pawfect-font-semibold pawfect-text-xl pawfect-mb-2 pawfect-mt-2"><?php echo esc_html__( 'Easy Exchanges', 'pawfect' ); ?></h4>
                <p class="pawfect-text-base pawfect-text-gray-400 pawfect-leading-relaxed"><?php echo esc_html__( 'Exchange any item within 30 days.', 'pawfect' ); ?></p>
            </div>
            <div class="pawfect-flex pawfect-flex-col pawfect-items-center pawfect-text-center">
                <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="#ffffff" viewBox="0 0 256 256" class="pawfect-mb-3"><path d="M199.05,57.48A100.07,100.07,0,0,0,28,128v56a20,20,0,0,0,20,20H64a20,20,0,0,0,20-20V144a20,20,0,0,0-20-20H36.08A92,92,0,0,1,128,36h.7a91.75,91.75,0,0,1,91.22,88H192a20,20,0,0,0-20,20v40a20,20,0,0,0,20,20h28v4a28,28,0,0,1-28,28H136a4,4,0,0,0,0,8h56a36,36,0,0,0,36-36V128A99.44,99.44,0,0,0,199.05,57.48ZM64,132a12,12,0,0,1,12,12v40a12,12,0,0,1-12,12H48a12,12,0,0,1-12-12V132Zm116,52V144a12,12,0,0,1,12-12h28v64H192A12,12,0,0,1,180,184Z"></path></svg>
                <h4 class="pawfect-font-semibold pawfect-text-xl pawfect-mb-2 pawfect-mt-2"><?php echo esc_html__( 'World-Class Support', 'pawfect' ); ?></h4>
                <p class="pawfect-text-base pawfect-text-gray-400 pawfect-leading-relaxed"><?php echo esc_html__( 'Friendly help from real pet lovers.', 'pawfect' ); ?></p>
            </div>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_about_section_heading_render_callback() {
        $title = get_theme_mod('pawfect_about_section_title', __( 'Rooted in Love, Built for Paws', 'pawfect' ));
        $desc = get_theme_mod('pawfect_about_section_desc', __( 'We believe every pet deserves the finest care and comfort...', 'pawfect' ));

        ob_start();
        ?>
        <div class="pawfect-about-section-heading pawfect-text-left">
            <div class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-primary pawfect-text-sm pawfect-text-gray-500 pawfect-font-medium pawfect-mb-4">
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
                <span class="pawfect-uppercase pawfect-tracking-wider"><?php echo esc_html__( 'About Us', 'pawfect' ); ?></span>
                <div class="pawfect-w-6 pawfect-h-px pawfect-bg-primary"></div>
            </div>
            <h2 class="pawfect-text-3xl md:pawfect-text-4xl lg:pawfect-text-5xl pawfect-font-bold pawfect-text-gray-900 pawfect-mb-4">
                <?php echo esc_html($title); ?>
            </h2>
            <?php if ($desc): ?>
                <p class="pawfect-text-base pawfect-text-gray-600 pawfect-leading-relaxed pawfect-mb-6">
                    <?php echo esc_html($desc); ?>
                </p>
            <?php endif; ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_page_header_heading_render_callback() {
        ob_start();
        get_template_part('template-parts/page-header');
        return ob_get_clean();
    }

    public function pawfect_page_header_container_render_callback() {
        ob_start();
        ?>
        <div class="pawfect-page-header-heading pawfect-container pawfect-relative pawfect-text-center">
            <!-- This will be populated by the actual page header content -->
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_blog_sidebar_widgets_render_callback() {
        if (!is_active_sidebar('sidebar-1')) {
            return '';
        }

        ob_start();
        ?>
        <div class="pawfect-blog-sidebar-widgets">
            <?php dynamic_sidebar('sidebar-1'); ?>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_footer_widgets_render_callback() {
        $footer_widgets_enabled = get_theme_mod('pawfect_footer_widgets_enabled', false);
        if (!$footer_widgets_enabled) {
            return '';
        }

        ob_start();
        ?>
        <div class="pawfect-footer-widgets-heading pawfect-footer-widgets pawfect-mb-16">
            <div class="pawfect-grid pawfect-grid-cols-1 md:pawfect-grid-cols-2 lg:pawfect-grid-cols-4 pawfect-gap-8">
                <?php for ($i = 1; $i <= 4; $i++): ?>
                    <?php if (is_active_sidebar('footer-widget-' . $i)): ?>
                        <div class="pawfect-footer-widget-area">
                            <?php dynamic_sidebar('footer-widget-' . $i); ?>
                        </div>
                    <?php endif; ?>
                <?php endfor; ?>
            </div>
        </div>
        <?php
        return ob_get_clean();
    }

    /**
     * Footer logo partial render callback
     *
     * @since 1.0.0
     * @return string Footer logo HTML
     */
    public function pawfect_footer_logo_render_callback() {
        $footer_logo_enabled = get_theme_mod('pawfect_footer_logo_enabled', true);

        if (!$footer_logo_enabled) {
            return '';
        }

        ob_start();
        ?>
        <div class="pawfect-text-center pawfect-mb-8 pawfect-footer-logo-container"
             <?php echo pawfect_get_aos_attrs('fade-up', 600, 100); ?>>
            <?php
            // Get site logo or fallback to default
            $site_logo = get_theme_mod('custom_logo');
            if ($site_logo) {
                $logo_url = wp_get_attachment_image_url($site_logo, 'full');
                /* translators: %s: site name */
                $logo_alt = sprintf( __( '%s Logo', 'pawfect' ), get_bloginfo('name') );
            } else {
                // Fallback to theme default logo
                $logo_url = get_template_directory_uri() . '/assets/images/logo-white.webp';
                /* translators: %s: site name */
                $logo_alt = sprintf( __( '%s Logo', 'pawfect' ), get_bloginfo('name') );
            }
            ?>
            <img src="<?php echo esc_url($logo_url); ?>"
                 alt="<?php echo esc_attr($logo_alt); ?>"
                 class="pawfect-mx-auto pawfect-footer-logo">
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_shop_toolbar_render_callback() {
        // Check if WooCommerce functions exist before using them
        if (!class_exists('WooCommerce') || !function_exists('is_shop') || !function_exists('is_product_category') || !function_exists('is_product_tag')) {
            return '';
        }

        if (!is_shop() && !is_product_category() && !is_product_tag()) {
            return '';
        }

        // Get customizer settings
        $show_result_count = get_theme_mod('pawfect_shop_show_result_count', true);
        $show_sorting = get_theme_mod('pawfect_shop_show_sorting', true);
        $show_view_toggle = get_theme_mod('pawfect_shop_show_view_toggle', true);

        ob_start();
        ?>
        <div class="pawfect-shop-toolbar pawfect-bg-white pawfect-p-4 pawfect-rounded-lg pawfect-shadow-sm pawfect-mb-6 pawfect-border pawfect-border-gray-100">
            <div class="pawfect-flex pawfect-flex-col lg:pawfect-flex-row pawfect-justify-between lg:pawfect-items-center pawfect-gap-4">

                <!-- Left Side: Results Count & View Toggle -->
                <div class="pawfect-flex pawfect-flex-col sm:pawfect-flex-row pawfect-items-start pawfect-items-center pawfect-gap-4">
                    <?php if ($show_result_count): ?>
                    <!-- Results Count -->
                    <div class="pawfect-text-sm pawfect-text-gray-600">
                        <?php
                        global $wp_query;
                        $total = $wp_query->found_posts;
                        $per_page = get_option('posts_per_page');
                        $current = max(1, get_query_var('paged'));
                        $start = ($current - 1) * $per_page + 1;
                        $end = min($total, $current * $per_page);

                        if ($total <= $per_page) {
                            printf(esc_html__('Showing all %d results', 'pawfect'), $total);
                        } else {
                            printf(esc_html__('Showing %d-%d of %d results', 'pawfect'), $start, $end, $total);
                        }
                        ?>
                    </div>
                    <?php endif; ?>

                    <?php if ($show_view_toggle): ?>
                    <!-- View Toggle -->
                    <div class="pawfect-view-toggle pawfect-flex pawfect-items-center pawfect-gap-2 pawfect-bg-gray-50 pawfect-p-1 pawfect-rounded-md">
                        <button class="pawfect-view-btn pawfect-grid-view pawfect-p-2 pawfect-rounded pawfect-transition-colors pawfect-duration-200 pawfect-bg-white pawfect-text-pawfect-primary pawfect-shadow-sm" data-view="grid" data-columns="3" title="<?php esc_attr_e('3 Column Grid', 'pawfect'); ?>">
                            <svg class="pawfect-w-4 pawfect-h-4" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M5 3a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5zM5 11a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2v-2a2 2 0 00-2-2H5zM11 5a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V5zM11 13a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/>
                            </svg>
                        </button>
                        <button class="pawfect-view-btn pawfect-grid-view pawfect-p-2 pawfect-rounded pawfect-transition-colors pawfect-duration-200 pawfect-text-gray-500 hover:pawfect-text-pawfect-primary" data-view="grid" data-columns="2" title="<?php esc_attr_e('2 Column Grid', 'pawfect'); ?>">
                            <svg class="pawfect-w-4 pawfect-h-4" fill="currentColor" viewBox="0 0 20 20">
                                <path d="M5 3a2 2 0 00-2 2v10a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5zM13 3a2 2 0 00-2 2v10a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2h-2z"/>
                            </svg>
                        </button>
                        <button class="pawfect-view-btn pawfect-list-view pawfect-p-2 pawfect-rounded pawfect-transition-colors pawfect-duration-200 pawfect-text-gray-500 hover:pawfect-text-pawfect-primary" data-view="list" title="<?php esc_attr_e('List View', 'pawfect'); ?>">
                            <svg class="pawfect-w-4 pawfect-h-4" fill="currentColor" viewBox="0 0 20 20">
                                <path fill-rule="evenodd" d="M3 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm0 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm0 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm0 4a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z" clip-rule="evenodd"/>
                            </svg>
                        </button>
                    </div>
                    <?php endif; ?>
                </div>

                <?php if ($show_sorting): ?>
                <!-- Right Side: Sorting -->
                <div class="pawfect-flex pawfect-items-center pawfect-gap-3">
                    <label for="orderby" class="pawfect-text-sm pawfect-text-gray-600 pawfect-font-medium">
                        <?php esc_html_e('Sort by:', 'pawfect'); ?>
                    </label>
                    <?php woocommerce_catalog_ordering(); ?>
                </div>
                <?php endif; ?>

            </div>
        </div>
        <?php
        return ob_get_clean();
    }

    public function pawfect_shop_sidebar_widgets_render_callback() {
        // This function is deprecated - sidebar is now handled directly in archive-product.php
        // Return empty string to avoid conflicts
        return '';
    }

    public function pawfect_sticky_logo_render_callback() {
        $sticky_logo = get_theme_mod('pawfect_sticky_bar_logo', '');
        $custom_logo_id = get_theme_mod('custom_logo');

        if ($custom_logo_id) {
            $logo_data = wp_get_attachment_image_src($custom_logo_id, 'full');
            $main_logo = $logo_data ? $logo_data[0] : get_template_directory_uri() . '/assets/images/logo-white.webp';
        } else {
            $main_logo = get_template_directory_uri() . '/assets/images/logo-white.webp';
        }

        ob_start();
        ?>
        <a href="<?php echo esc_url(home_url('/')); ?>" class="pawfect-logo-link">
            <?php if (!empty($sticky_logo)): ?>
                <img src="<?php echo esc_url($sticky_logo); ?>" alt="<?php echo esc_attr( get_bloginfo('name') ); ?>" style="height: 40px; width: auto;" />
            <?php else: ?>
                <img src="<?php echo esc_url($main_logo); ?>" alt="<?php echo esc_attr( get_bloginfo('name') ); ?>" style="height: 40px; width: auto;" />
            <?php endif; ?>
        </a>
        <?php
        return ob_get_clean();
    }

    /**
     * Page Header Title partial render callback
     *
     * @since 1.0.0
     * @return string Page header title
     */
    public function pawfect_page_header_title_render_callback()
    {
        // Get page data similar to page-header.php
        $page_title = '';

        if (is_home()) {
            $page_title = get_theme_mod('pawfect_blog_area_title', __('Latest News', 'pawfect'));
        } elseif (is_single()) {
            $page_title = get_the_title();
        } elseif (is_page()) {
            $page_title = get_the_title();
        } elseif (is_category()) {
            $page_title = single_cat_title('', false);
        } elseif (is_tag()) {
            $page_title = single_tag_title('', false);
        } elseif (is_author()) {
            $page_title = get_the_author();
        } elseif (is_search()) {
            $page_title = sprintf(__('Search Results for: %s', 'pawfect'), get_search_query());
        } elseif (is_404()) {
            $page_title = __('Page Not Found', 'pawfect');
        } else {
            $page_title = get_the_title();
        }

        return esc_html($page_title);
    }

    /**
     * Page Header Breadcrumbs partial render callback
     *
     * @since 1.0.0
     * @return string Page header breadcrumbs
     */
    public function pawfect_page_header_breadcrumbs_render_callback()
    {
        $show_breadcrumbs = get_theme_mod('pawfect_page_header_breadcrumbs_enable', true);

        if (!$show_breadcrumbs || is_front_page()) {
            return '';
        }

        $breadcrumb_items = array();

        // Build breadcrumb items similar to page-header.php logic
        if (is_home()) {
            $breadcrumb_items[] = array('title' => __('Home', 'pawfect'), 'url' => home_url('/'));
            $breadcrumb_items[] = array('title' => get_theme_mod('pawfect_blog_area_title', __('Latest News', 'pawfect')), 'url' => '');
        } elseif (is_single()) {
            $breadcrumb_items[] = array('title' => __('Home', 'pawfect'), 'url' => home_url('/'));
            $breadcrumb_items[] = array('title' => get_the_title(), 'url' => '');
        } elseif (is_page()) {
            $breadcrumb_items[] = array('title' => __('Home', 'pawfect'), 'url' => home_url('/'));
            $breadcrumb_items[] = array('title' => get_the_title(), 'url' => '');
        }

        if (empty($breadcrumb_items)) {
            return '';
        }

        ob_start();
        ?>
        <nav class="pawfect-breadcrumbs pawfect-mb-8" aria-label="<?php esc_attr_e( 'Breadcrumb', 'pawfect' ); ?>">
            <ol class="pawfect-flex pawfect-items-center pawfect-justify-center pawfect-gap-2 pawfect-text-sm pawfect-opacity-80">
                <?php
                $total_items = count($breadcrumb_items);
                foreach ($breadcrumb_items as $index => $item):
                    $is_last = ($index === $total_items - 1);
                ?>
                    <li>
                        <?php if (!$is_last && !empty($item['url'])): ?>
                            <a href="<?php echo esc_url($item['url']); ?>" class="hover:pawfect-text-pawfect-primary pawfect-transition-colors">
                                <?php echo esc_html($item['title']); ?>
                            </a>
                        <?php else: ?>
                            <span class="pawfect-font-medium">
                                <?php echo esc_html($item['title']); ?>
                            </span>
                        <?php endif; ?>
                    </li>

                    <?php if (!$is_last): ?>
                        <li class="pawfect-opacity-50">
                            <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
                                <path d="M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z"/>
                            </svg>
                        </li>
                    <?php endif; ?>
                <?php endforeach; ?>
            </ol>
        </nav>
        <?php
        return ob_get_clean();
    }

    /**
     * Promotional Popup Render Callbacks
     */
    public function render_popup_partial() {
        if (get_theme_mod('pawfect_popup_enable', true)) {
            // Return empty string to trigger full refresh since popup is in footer
            return '';
        }
        return '';
    }

    public function render_popup_title_partial() {
        return esc_html(get_theme_mod('pawfect_popup_title', __('Get 10% Off', 'pawfect')));
    }

    public function render_popup_subtitle_partial() {
        return esc_html(get_theme_mod('pawfect_popup_subtitle', __('Be in the know', 'pawfect')));
    }

    public function render_popup_description_partial() {
        return esc_html(get_theme_mod('pawfect_popup_description', __('Sexy and sustainable goodies? Sign me up', 'pawfect')));
    }

    public function render_popup_button_partial() {
        return esc_html(get_theme_mod('pawfect_popup_button_text', __('GET 10% OFF', 'pawfect')));
    }

}

// Initialize the Customizer class
new Customizer();
