﻿<?php
/**
 * Theme functions and definitions
 *
 * @package HelloElementor
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

define( 'HELLO_ELEMENTOR_VERSION', '3.4.9' );
define( 'EHP_THEME_SLUG', 'hello-elementor' );

define( 'HELLO_THEME_PATH', get_template_directory() );
define( 'HELLO_THEME_URL', get_template_directory_uri() );
define( 'HELLO_THEME_ASSETS_PATH', HELLO_THEME_PATH . '/assets/' );
define( 'HELLO_THEME_ASSETS_URL', HELLO_THEME_URL . '/assets/' );
define( 'HELLO_THEME_SCRIPTS_PATH', HELLO_THEME_ASSETS_PATH . 'js/' );
define( 'HELLO_THEME_SCRIPTS_URL', HELLO_THEME_ASSETS_URL . 'js/' );
define( 'HELLO_THEME_STYLE_PATH', HELLO_THEME_ASSETS_PATH . 'css/' );
define( 'HELLO_THEME_STYLE_URL', HELLO_THEME_ASSETS_URL . 'css/' );
define( 'HELLO_THEME_IMAGES_PATH', HELLO_THEME_ASSETS_PATH . 'images/' );
define( 'HELLO_THEME_IMAGES_URL', HELLO_THEME_ASSETS_URL . 'images/' );

if ( ! isset( $content_width ) ) {
	$content_width = 800; // Pixels.
}

if ( ! function_exists( 'hello_elementor_setup' ) ) {
	/**
	 * Set up theme support.
	 *
	 * @return void
	 */
	function hello_elementor_setup() {
		if ( is_admin() ) {
			hello_maybe_update_theme_version_in_db();
		}

		if ( apply_filters( 'hello_elementor_register_menus', true ) ) {
			register_nav_menus( [ 'menu-1' => esc_html__( 'Header', 'hello-elementor' ) ] );
			register_nav_menus( [ 'menu-2' => esc_html__( 'Footer', 'hello-elementor' ) ] );
		}

		if ( apply_filters( 'hello_elementor_post_type_support', true ) ) {
			add_post_type_support( 'page', 'excerpt' );
		}

		if ( apply_filters( 'hello_elementor_add_theme_support', true ) ) {
			add_theme_support( 'post-thumbnails' );
			add_theme_support( 'automatic-feed-links' );
			add_theme_support( 'title-tag' );
			add_theme_support(
				'html5',
				[
					'search-form',
					'comment-form',
					'comment-list',
					'gallery',
					'caption',
					'script',
					'style',
					'navigation-widgets',
				]
			);
			add_theme_support(
				'custom-logo',
				[
					'height'      => 100,
					'width'       => 350,
					'flex-height' => true,
					'flex-width'  => true,
				]
			);
			add_theme_support( 'align-wide' );
			add_theme_support( 'responsive-embeds' );

			/*
			 * Editor Styles
			 */
			add_theme_support( 'editor-styles' );
			add_editor_style( 'assets/css/editor-styles.css' );

			/*
			 * WooCommerce.
			 */
			if ( apply_filters( 'hello_elementor_add_woocommerce_support', true ) ) {
				// WooCommerce in general.
				add_theme_support( 'woocommerce' );
				// Enabling WooCommerce product gallery features (are off by default since WC 3.0.0).
				// zoom.
				add_theme_support( 'wc-product-gallery-zoom' );
				// lightbox.
				add_theme_support( 'wc-product-gallery-lightbox' );
				// swipe.
				add_theme_support( 'wc-product-gallery-slider' );
			}
		}
	}
}
add_action( 'after_setup_theme', 'hello_elementor_setup' );


/**
 * 加载 Google Fonts - Inter + Noto Sans SC
 */
function mika_load_google_fonts() {
    wp_enqueue_style('mika-google-fonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;700&display=swap', array(), null);
}
add_action('wp_enqueue_scripts', 'mika_load_google_fonts', 5);

function hello_maybe_update_theme_version_in_db() {
	$theme_version_option_name = 'hello_theme_version';
	// The theme version saved in the database.
	$hello_theme_db_version = get_option( $theme_version_option_name );

	// If the 'hello_theme_version' option does not exist in the DB, or the version needs to be updated, do the update.
	if ( ! $hello_theme_db_version || version_compare( $hello_theme_db_version, HELLO_ELEMENTOR_VERSION, '<' ) ) {
		update_option( $theme_version_option_name, HELLO_ELEMENTOR_VERSION );
	}
}

if ( ! function_exists( 'hello_elementor_display_header_footer' ) ) {
	/**
	 * Check whether to display header footer.
	 *
	 * @return bool
	 */
	function hello_elementor_display_header_footer() {
		$hello_elementor_header_footer = true;

		return apply_filters( 'hello_elementor_header_footer', $hello_elementor_header_footer );
	}
}

if ( ! function_exists( 'hello_elementor_scripts_styles' ) ) {
	/**
	 * Theme Scripts & Styles.
	 *
	 * @return void
	 */
	function hello_elementor_scripts_styles() {
		if ( apply_filters( 'hello_elementor_enqueue_style', true ) ) {
			wp_enqueue_style(
				'hello-elementor',
				HELLO_THEME_STYLE_URL . 'reset.css',
				[],
				HELLO_ELEMENTOR_VERSION
			);
		}

		if ( apply_filters( 'hello_elementor_enqueue_theme_style', true ) ) {
			wp_enqueue_style(
				'hello-elementor-theme-style',
				HELLO_THEME_STYLE_URL . 'theme.css',
				[],
				HELLO_ELEMENTOR_VERSION
			);
		}

		if ( hello_elementor_display_header_footer() ) {
			wp_enqueue_style(
				'hello-elementor-header-footer',
				HELLO_THEME_STYLE_URL . 'header-footer.css',
				[],
				HELLO_ELEMENTOR_VERSION
			);
		}
	}
}
add_action( 'wp_enqueue_scripts', 'hello_elementor_scripts_styles' );

if ( ! function_exists( 'hello_elementor_register_elementor_locations' ) ) {
	/**
	 * Register Elementor Locations.
	 *
	 * @param ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager $elementor_theme_manager theme manager.
	 *
	 * @return void
	 */
	function hello_elementor_register_elementor_locations( $elementor_theme_manager ) {
		if ( apply_filters( 'hello_elementor_register_elementor_locations', true ) ) {
			$elementor_theme_manager->register_all_core_location();
		}
	}
}
add_action( 'elementor/theme/register_locations', 'hello_elementor_register_elementor_locations' );

if ( ! function_exists( 'hello_elementor_content_width' ) ) {
	/**
	 * Set default content width.
	 *
	 * @return void
	 */
	function hello_elementor_content_width() {
		$GLOBALS['content_width'] = apply_filters( 'hello_elementor_content_width', 800 );
	}
}
add_action( 'after_setup_theme', 'hello_elementor_content_width', 0 );

if ( ! function_exists( 'hello_elementor_add_description_meta_tag' ) ) {
	/**
	 * Add description meta tag with excerpt text.
	 *
	 * @return void
	 */
	function hello_elementor_add_description_meta_tag() {
		if ( ! apply_filters( 'hello_elementor_description_meta_tag', true ) ) {
			return;
		}

		if ( ! is_singular() ) {
			return;
		}

		$post = get_queried_object();
		if ( empty( $post->post_excerpt ) ) {
			return;
		}

		echo '<meta name="description" content="' . esc_attr( wp_strip_all_tags( $post->post_excerpt ) ) . '">' . "\n";
	}
}
add_action( 'wp_head', 'hello_elementor_add_description_meta_tag' );

// Settings page
require get_template_directory() . '/includes/settings-functions.php';

// Header & footer styling option, inside Elementor
require get_template_directory() . '/includes/elementor-functions.php';

if ( ! function_exists( 'hello_elementor_customizer' ) ) {
	// Customizer controls
	function hello_elementor_customizer() {
		if ( ! is_customize_preview() ) {
			return;
		}

		if ( ! hello_elementor_display_header_footer() ) {
			return;
		}

		require get_template_directory() . '/includes/customizer-functions.php';
	}
}
add_action( 'init', 'hello_elementor_customizer' );

if ( ! function_exists( 'hello_elementor_check_hide_title' ) ) {
	/**
	 * Check whether to display the page title.
	 *
	 * @param bool $val default value.
	 *
	 * @return bool
	 */
	function hello_elementor_check_hide_title( $val ) {
		if ( defined( 'ELEMENTOR_VERSION' ) ) {
			$current_doc = Elementor\Plugin::instance()->documents->get( get_the_ID() );
			if ( $current_doc && 'yes' === $current_doc->get_settings( 'hide_title' ) ) {
				$val = false;
			}
		}
		return $val;
	}
}
add_filter( 'hello_elementor_page_title', 'hello_elementor_check_hide_title' );

/**
 * BC:
 * In v2.7.0 the theme removed the `hello_elementor_body_open()` from `header.php` replacing it with `wp_body_open()`.
 * The following code prevents fatal errors in child themes that still use this function.
 */
if ( ! function_exists( 'hello_elementor_body_open' ) ) {
	function hello_elementor_body_open() {
		wp_body_open();
	}
}

require HELLO_THEME_PATH . '/theme.php';

HelloTheme\Theme::instance();

/* 语言切换器已移至MU-Plugin */

/**
 * 语言切换器：嵌入菜单栏（完美版）
 * 功能：1. 检测当前语言 2. 追加到菜单末尾 3. 下拉选项 4. 深蓝色主题
 */
function mika_lang_switcher_in_menu($items, $args) {
    // 只在主菜单（menu-1）添加
    if (isset($args->theme_location) && $args->theme_location === "menu-1") {
        
        // 检测当前语言（通过 URL slug 判断，最可靠）
        $current_lang = "zh";  // 默认中文
        $request_uri = $_SERVER["REQUEST_URI"];
        // 英文 slug 都带 -en 后缀
        if (strpos($request_uri, "-en/") !== false) {
            $current_lang = "en";
        }
        // 根目录：如果默认首页是英文（ID=21），则根目录是英文
        $home_url = home_url();
        $home_path = parse_url($home_url, PHP_URL_PATH);
        if ($request_uri === $home_path || $request_uri === $home_path . "/") {
            // 检查默认首页是否是英文
            $front_page_id = get_option("page_on_front");
            if ($front_page_id == 21) {  // ID=21 是英文首页
                $current_lang = "en";
            }
        }
        
        // 输出语言切换器HTML（含下拉选项）
        $lang_html = "<li class=\"menu-item lang-switcher-item\">";
        $lang_html .= "<a href=\"#\" class=\"lang-toggle-trigger\" style=\"color: #374151 !important; font-weight: 400 !important; padding: 0 !important; line-height: 1 !important; vertical-align: baseline !important; border: none !important; border-radius: 0 !important; transition: color 0.3s ease !important; text-decoration: none !important; background: transparent !important;\">";
        
        if ($current_lang === "en") {
            $lang_html .= "<span class=\"lang-text\">EN</span><span class=\"lang-arrow\"></span>";
            $lang_html .= "</a>";
            $lang_html .= "<ul class=\"lang-dropdown\" style=\"display: none !important; position: absolute; top: 100%; right: 0; width: auto; min-width: 120px; background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; margin-top: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); list-style: none; overflow: hidden; padding: 0;\">";
            $lang_html .= "<li><a href=\"" . home_url("/home/") . "\" style=\"display: block; padding: 8px 12px; color: #4b5563; background: transparent; text-decoration: none; font-size: 14px; text-align: center; white-space: nowrap; transition: background 0.2s ease;\">中文</a></li>";
            $lang_html .= "</ul>";
        } else {
            $lang_html .= "中文<span class=\"lang-arrow\"></span>";
            $lang_html .= "</a>";
            $lang_html .= "<ul class=\"lang-dropdown\" style=\"display: none !important; position: absolute; top: 100%; right: 0; width: auto; min-width: 120px; background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; margin-top: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); list-style: none; overflow: hidden; padding: 0;\">";
            $lang_html .= "<li><a href=\"" . home_url("/") . "\" style=\"display: block; padding: 8px 12px; color: #4b5563; background: transparent; text-decoration: none; font-size: 14px; text-align: center; white-space: nowrap; transition: background 0.2s ease;\">EN (English)</a></li>";
            $lang_html .= "</ul>";
        }
        
        $lang_html .= "</li>";
        
        $items .= $lang_html;
    }
    
    return $items;
}

add_filter('wp_nav_menu_items', 'mika_lang_switcher_in_menu', 10, 2);

/**
 * 语言切换器 JavaScript（下拉功能）
 */
function mika_lang_switcher_js() {
    ?>
    <style>
    /* 强制隐藏下拉菜单 */
    .lang-dropdown {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    /* 只有JS明确设置display:block时才显示 */
    .lang-dropdown[style*="display: block"] {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
        overflow: visible !important;
    }
    </style>
        <script>
    document.addEventListener('DOMContentLoaded', function() {
        var all = document.querySelectorAll('.lang-dropdown');
        // 初始化隐藏
        all.forEach(function(d) {
            d.style.display = 'none';
            d.style.visibility = 'hidden';
            d.style.opacity = '0';
        });

        document.querySelectorAll('.lang-toggle-trigger').forEach(function(t) {
            t.addEventListener('click', function(e) {
                e.preventDefault();
                e.stopPropagation();
                var dd = this.nextElementSibling;
                if (!dd || !dd.classList.contains('lang-dropdown')) return;
                
                if (dd.style.display === 'block') {
                    dd.style.display = 'none';
                    dd.style.visibility = 'hidden';
                    dd.style.opacity = '0';
                } else {
                    dd.style.display = 'block';
                    dd.style.visibility = 'visible';
                    dd.style.opacity = '1';
                }
            });
        });

        document.addEventListener('click', function(e) {
            if (!e.target.closest('.lang-switcher-item')) {
                all.forEach(function(d) {
                    d.style.display = 'none';
                    d.style.visibility = 'hidden';
                    d.style.opacity = '0';
                });
            }
        });
    });
    </script>
    <?php
}
add_action('wp_footer', 'mika_lang_switcher_js', 100);

/**
 * 语言切换器CSS（悬停效果）
 */
function mika_lang_switcher_style() {
    ?>
    <style>
    
    /* EN/CN 文字 - 与菜单项同 baseline */

/* 最终对齐修复：菜单容器 flex 居中 */
.site-navigation .menu {
    display: flex !important;
    align-items: center !important;
    height: 100% !important;
}
.site-navigation .menu > li {
    display: flex !important;
    align-items: center !important;
    height: 100% !important;
}
.site-navigation .menu > li > a {
    display: flex !important;
    align-items: center !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    line-height: 1 !important;
}
/* 语言切换器项也用 flex 居中 */
.lang-switcher-item {
    display: flex !important;
    align-items: center !important;
    height: 100% !important;
    margin-left: auto !important;
}
.lang-toggle-trigger {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    line-height: 1 !important;
    height: auto !important;
}
/* 去掉 lang-arrow 的 inline-block，改用 flex 居中 */
.lang-toggle-trigger 

    .lang-text {
        display: inline !important;
        vertical-align: baseline !important;
    }
    
    /* 三角箭头 - 小字号 + 顶部对齐 */
    .lang-arrow {
        display: inline-block !important;
        vertical-align: middle !important;
        width: 0 !important;
        height: 0 !important;
        margin-left: 6px !important;
        padding: 0 !important;
        border-left: 4px solid transparent !important;
        border-right: 4px solid transparent !important;
        border-top: 5px solid #374151 !important;
        opacity: 0.6 !important;
        line-height: 0 !important;
        font-size: 0 !important;
    }
    
    /* 悬停时箭头微旋转 */
    .lang-switcher-item:hover .lang-arrow {
        transform: rotate(180deg) translateY(0) !important;
    }
    .lang-switcher-item {
        position: relative !important;
        margin-left: 20px !important;
        padding-left: 20px !important;
        border-left: 1px solid #e0e0e0 !important;
    }
    
    .lang-toggle-trigger:hover {
        color: #e82127 !important;
        text-decoration: underline !important;
        text-decoration-color: #e82127 !important;
        text-underline-offset: 4px !important;
    }
    
    .lang-dropdown li a:hover {
        background: #fff7ed !important;
        color: #e82127 !important;
    }
    

/* === 方案C：现代黑橙系（参考色卡 mika-schemeC-reference.html）=== */
/* 全局字体 */
body, p, li, a, span, div, .elementor-widget-container { font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important; }
h1, h2, h3, h4, h5, h6, .entry-title, .elementor-heading-title { font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important; font-weight: 700 !important; letter-spacing: -0.02em !important; }

/* 导航栏：白色背景 */
#site-header .site-branding { flex-shrink: 0 !important; }
#site-header .site-navigation { flex: 1 !important; display: flex !important; justify-content: center !important; }
#site-header .site-navigation .menu { display: flex !important; justify-content: center !important; width: 100% !important; }
#site-header .header-inner { background: #ffffff !important; box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important; padding: 12px 40px !important; width: 100% !important; max-width: 100% !important; display: flex !important; align-items: center !important; }
#site-header .site-title a { color: #e82127 !important; font-weight: 700 !important; letter-spacing: 1px !important; }
#site-header .site-description { color: rgba(0,0,0,0.4) !important; font-size: 13px !important; }
#site-header .menu > li > a { color: #1a1a1a !important; font-weight: 500 !important; font-size: 15px !important; padding: 8px 16px !important; transition: background 0.2s, color 0.2s !important; }
#site-header .menu > li > a:hover { color: #e82127 !important; opacity: 1 !important; }
#site-header .menu > li.current-menu-item > a { color: #e82127 !important; font-weight: 700 !important; }

/* 标题：纯黑 */
.entry-title, .elementor-heading-title, .mika-card h3, .mika-card h4, .widget-title { color: #0f0f0f !important; } h1, h2, h3, h4, h5, h6 { color: inherit; }

/* 正文：深灰 */
p, li, .elementor-widget-container p, .entry-content p { color: #333333 !important; line-height: 1.8 !important; }

/* 按钮：橙底 */
.elementor-button, button, input[type='submit'], .wp-block-button__link {
  background: #e82127 !important;
  color: #ffffff !important;
  border: none !important;
  border-radius: 30px!important;
  padding: 14px 32px !important;
  font-weight: 600 !important;
  font-size: 15px !important;
  transition: background 0.2s, color 0.2s !important;
  cursor: pointer !important;
}
.elementor-button:hover, button:hover, input[type='submit']:hover {
  background: #c11a1f !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 12px rgba(255,107,53,0.3) !important;
}

/* 描边按钮（二級按钮） */
.elementor-button-outline, .wp-block-button.is-style-outline .wp-block-button__link {
  background: transparent !important;
  color: #e82127 !important;
  border: 2px solid #e82127 !important;
}
.elementor-button-outline:hover, .wp-block-button.is-style-outline .wp-block-button__link:hover {
  background: #e82127 !important;
  color: #ffffff !important;
}

/* 页脚：纯黑 */
.site-footer, footer { background: #0f0f0f !important; color: rgba(255,255,255,0.8) !important; padding: 80px 40px !important; }
.site-footer a, footer a { color: #e82127 !important; }
.site-footer a:hover, footer a:hover { color: #ffffff !important; }
.site-footer h3, footer h3 { color: #ffffff !important; }
.site-footer .widget-title, footer .widget-title { color: #ffffff !important; font-size: 16px !important; font-weight: 600 !important; letter-spacing: 1px !important; }

/* CTA区域 */
.mika-cta-section, .elementor-cta, .wp-block-cover.has-background-dim {
  background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 100%) !important;
}

/* 分割线：橙色 */
hr, .elementor-divider, .wp-block-separator { border-color: #e82127 !important; }

/* 页脚表单元素 */
footer input, footer textarea { background: rgba(255,255,255,0.1) !important; color: #fff !important; border: 1px solid rgba(255,255,255,0.2) !important; border-radius: 6px !important; padding: 12px !important; }
footer input::placeholder, footer textarea::placeholder { color: rgba(255,255,255,0.5) !important; }
footer input:focus, footer textarea:focus { border-color: #e82127 !important; outline: none !important; }

/* 语言切换器：在黑色导航上适配 */
.lang-toggle-trigger { color: rgba(255,255,255,0.85) !important; font-weight: 500 !important; }
.lang-toggle-trigger:hover { color: #e82127 !important; }
.lang-dropdown { background: #ffffff !important; border: 1px solid #e5e7eb !important; border-radius: 8px !important; box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important; }

/* 卡片：更多留白 */
.mika-card, .elementor-widget-wrap, .elementor-element { transition: background 0.2s, color 0.2s !important; }
.mika-card:hover { transform: translateY(-4px) !important; box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important; }

/* 强调文字：橙色 */
.highlight, .mika-highlight, .accent-text { color: #e82127 !important; }


/* === 特斯拉风格字体优化 === */
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.02em; }
p, li { line-height: 1.6; }


    /* === 特斯拉风格排版（P0优化）=== */
    /* h1 - 56px, 极粗 */
    h1, .elementor-widget-heading h1 a,
    h1.elementor-heading-title {
        font-size: 56px !important;
        font-weight: 700 !important;
        letter-spacing: -0.02em !important;
        line-height: 1.1 !important;
        margin-bottom: 20px !important;
    }

    /* h2 - 40px */
    h2, .elementor-widget-heading h2 a,
    h2.elementor-heading-title {
        font-size: 40px !important;
        font-weight: 600 !important;
        letter-spacing: -0.01em !important;
        line-height: 1.2 !important;
        margin-bottom: 16px !important;
        color: #1a1a1a !important;
    }

    /* h3 - 28px */
    h3, .elementor-widget-heading h3 a,
    h3.elementor-heading-title {
        font-size: 28px !important;
        font-weight: 600 !important;
        line-height: 1.3 !important;
        margin-bottom: 12px !important;
        color: #1a1a1a !important;
    }

    /* 正文 - 16px */
    body, p, .elementor-widget-text-editor,
    .elementor-text-editor {
        font-size: 16px !important;
        line-height: 1.6 !important;
        color: #333333 !important;
    }

    /* 辅助文字 - 14px */
    .text-sm, .elementor-widget-text-editor p.small {
        font-size: 14px !important;
        color: #666666 !important;
    }

    /* === 特斯拉风格间距（P0优化）=== */
    /* Section 间距 - 100px */
    .elementor-section,
    .elementor-top-section {
        padding-top: 100px !important;
        padding-bottom: 100px !important;
    }

    /* 首个 section（Hero）可以更大 */
    .elementor-section:first-child {
        padding-top: 0 !important;
        padding-bottom: 120px !important;
    }

    /* Container 宽度限制 - 1200px */
    .elementor-section .elementor-container {
        max-width: 1200px !important;
        margin: 0 auto !important;
        padding-left: 40px !important;
        padding-right: 40px !important;
    }

    /* 移动端减少 padding */
    @media (max-width: 768px) {
        .elementor-section {
            padding-top: 60px !important;
            padding-bottom: 60px !important;
        }
        .elementor-container {
            padding-left: 20px !important;
            padding-right: 20px !important;
        }
        h1, .elementor-widget-heading h1 a,
        h1.elementor-heading-title {
            font-size: 36px !important;
        }
        h2, .elementor-widget-heading h2 a,
        h2.elementor-heading-title {
            font-size: 28px !important;
        }
    }

    /* === 特斯拉风格按钮（P1优化）=== */
    /* 主按钮 - 红底白字，圆角 30px 药丸形 */
    .elementor-button,
    .elementor-widget-button .elementor-button,
    button, input[type="submit"],
    .btn,
    .demo-btn {
        background-color: #e82127 !important;
        color: #ffffff !important;
        border: none !important;
        border-radius: 30px !important;
        padding: 14px 36px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        letter-spacing: 0.02em !important;
        text-transform: none !important;
        transition: all 0.3s ease !important;
        text-decoration: none !important;
        display: inline-block !important;
        cursor: pointer !important;
        box-shadow: none !important;
    }

    .elementor-button:hover,
    .elementor-widget-button .elementor-button:hover,
    button:hover, input[type="submit"]:hover,
    .btn:hover,
    .demo-btn:hover {
        background-color: #c11a1f !important;
        color: #ffffff !important;
        transform: translateY(-2px) !important;
        box-shadow: 0 4px 12px rgba(232, 33, 39, 0.3) !important;
        text-decoration: none !important;
    }

    /* 次要按钮 - 透明底红框红字 */
    .elementor-button.elementor-size-sm,
    .btn-outline {
        background-color: transparent !important;
        color: #e82127 !important;
        border: 2px solid #e82127 !important;
        border-radius: 30px !important;
    }
    .elementor-button.elementor-size-sm:hover,
    .btn-outline:hover {
        background-color: #e82127 !important;
        color: #ffffff !important;
    }

    /* === 特斯拉风格卡片（P1优化）=== */
    .mika-card,
    .elementor-column .elementor-widget-wrap {
        background: #f9f9f9 !important;
        border-radius: 10px !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important;
        transition: all 0.3s ease !important;
        overflow: hidden !important;
        padding: 40px !important;
    }

    .mika-card:hover,
    .elementor-column .elementor-widget-wrap:hover {
        transform: translateY(-4px) !important;
        box-shadow: 0 8px 24px rgba(0,0,0,0.12) !important;
    }

    /* === 特斯拉风格表单（P1优化）=== */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        border: 1px solid #e5e5e5 !important;
        border-radius: 8px !important;
        padding: 12px 16px !important;
        font-size: 16px !important;
        transition: border-color 0.3s ease !important;
        width: 100% !important;
        background: #ffffff !important;
        color: #222222 !important;
    }

    input:focus, textarea:focus, select:focus {
        border-color: #e82127 !important;
        box-shadow: 0 0 0 2px rgba(232, 33, 39, 0.15) !important;
        outline: none !important;
    }

    /* 表单标签 */
    label {
        font-size: 13px !important;
        font-weight: 500 !important;
        color: #222222 !important;
        margin-bottom: 4px !important;
        display: block !important;
    }

    /* === 特斯拉风格导航栏优化 === */
    /* 当前菜单项 - 红色 + 下划线 */
    .site-header .menu > li.current-menu-item > a {
        color: #e82127 !important;
        font-weight: 600 !important;
        position: relative !important;
    }
    .site-header .menu > li.current-menu-item > a::after {
        content: "";
        position: absolute;
        bottom: -4px;
        left: 0;
        right: 0;
        height: 2px;
        background: #e82127;
        border-radius: 1px;
    }

    /* 菜单项 hover - 红色 */
    .site-header .menu > li > a:hover {
        color: #e82127 !important;
        opacity: 1 !important;
    }

    /* === 深色背景区域文字颜色 === */
    .elementor-section[class*="dark"],
    .elementor-section[style*="background: #0f0f0f"],
    .elementor-section[style*="background:#0f0f0f"],
    .elementor-section[style*="background: #1a1a1a"],
    .elementor-section[style*="background:#1a1a1a"] {
        color: #ffffff !important;
    }
    .elementor-section[class*="dark"] h1,
    .elementor-section[class*="dark"] h2,
    .elementor-section[class*="dark"] h3,
    .elementor-section[style*="background: #0f0f0f"] h1,
    .elementor-section[style*="background: #0f0f0f"] h2,
    .elementor-section[style*="background: #0f0f0f"] h3 {
        color: #ffffff !important;
    }
    .elementor-section[class*="dark"] p,
    .elementor-section[style*="background: #0f0f0f"] p {
        color: #aaaaaa !important;
    }

    </style>
    <?php
}
add_action('wp_head', 'mika_lang_switcher_style', 999);;



// AOS 滚动动效库
function mika_aos_scripts() {
    wp_enqueue_style( 'aos-css', 'https://unpkg.com/aos@2.3.1/dist/aos.css', array(), '2.3.1' );
    wp_enqueue_script( 'aos-js', 'https://unpkg.com/aos@2.3.1/dist/aos.js', array('jquery'), '2.3.1', true );
}
add_action( 'wp_enqueue_scripts', 'mika_aos_scripts' );

// AOS 初始化
function mika_aos_init() {
    if ( ! is_admin() ) {
        echo '<script>
        document.addEventListener("DOMContentLoaded", function() {
            if (typeof AOS !== "undefined") {
                AOS.init({
                    duration: 800,
                    easing: "ease-out-cubic",
                    once: true,
                    offset: 80,
                    delay: 100
                });
            }
        });
        </script>';
    }
}
add_action( 'wp_head', 'mika_aos_init', 997 );

// AOS CSS 增强
function mika_aos_style() {
    echo '<style>
    /* AOS 基础增强 */
    [data-aos] {
        pointer-events: auto !important;
    }
    
    /* 滚动动效：fade-up */
    [data-aos="fade-up"] {
        transform: translate3d(0, 30px, 0) !important;
        opacity: 0 !important;
        transition-property: transform, opacity !important;
    }
    [data-aos="fade-up"].aos-animate {
        transform: translate3d(0, 0, 0) !important;
        opacity: 1 !important;
    }
    
    /* 滚动动效：fade-down */
    [data-aos="fade-down"] {
        transform: translate3d(0, -30px, 0) !important;
        opacity: 0 !important;
        transition-property: transform, opacity !important;
    }
    [data-aos="fade-down"].aos-animate {
        transform: translate3d(0, 0, 0) !important;
        opacity: 1 !important;
    }
    
    /* 滚动动效：zoom-in */
    [data-aos="zoom-in"] {
        transform: scale(0.9) !important;
        opacity: 0 !important;
        transition-property: transform, opacity !important;
    }
    [data-aos="zoom-in"].aos-animate {
        transform: scale(1) !important;
        opacity: 1 !important;
    }
    
    /* 滚动动效：fade-left/right */
    [data-aos="fade-left"] {
        transform: translate3d(-40px, 0, 0) !important;
        opacity: 0 !important;
    }
    [data-aos="fade-left"].aos-animate {
        transform: translate3d(0, 0, 0) !important;
        opacity: 1 !important;
    }
    
    [data-aos="fade-right"] {
        transform: translate3d(40px, 0, 0) !important;
        opacity: 0 !important;
    }
    [data-aos="fade-right"].aos-animate {
        transform: translate3d(0, 0, 0) !important;
        opacity: 1 !important;
    }
    
    /* 各 section 默认 padding（与 P0 一致） */
    .elementor-section-wrap,
    .elementor-top-section {
        padding-top: 100px !important;
        padding-bottom: 100px !important;
    }
    

    /* === P1 优化：CTA 区域增强 === */
    /* 深色 CTA 背景 */
    .mika-cta-dark,
    .elementor-section.mika-cta-section {
        background: #0f0f0f !important;
        padding: 80px 0 !important;
    }
    .mika-cta-dark h2,
    .mika-cta-dark h3 {
        color: #ffffff !important;
    }
    .mika-cta-dark p {
        color: #aaaaaa !important;
        font-size: 18px !important;
        line-height: 1.6 !important;
    }
    
    /* CTA 按钮组 */
    .mika-cta-buttons {
        display: flex !important;
        gap: 16px !important;
        margin-top: 32px !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
    
    /* CTA 次要按钮（描边） */
    .mika-cta-buttons .btn-outline {
        background: transparent !important;
        color: #e82127 !important;
        border: 2px solid #e82127 !important;
        border-radius: 30px !important;
        padding: 14px 36px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        text-decoration: none !important;
        transition: all 0.3s ease !important;
    }
    .mika-cta-buttons .btn-outline:hover {
        background: #e82127 !important;
        color: #ffffff !important;
    }

    /* === P1 优化：产品卡片网格 === */
    .mika-products-grid,
    .elementor-widget-wrap.mika-products {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 24px !important;
    }
    
    .mika-product-card {
        background: #f9f9f9 !important;
        border-radius: 10px !important;
        overflow: hidden !important;
        transition: all 0.3s ease !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important;
    }
    .mika-product-card:hover {
        transform: translateY(-6px) !important;
        box-shadow: 0 12px 32px rgba(0,0,0,0.12) !important;
    }
    .mika-product-card img {
        width: 100% !important;
        height: 200px !important;
        object-fit: cover !important;
    }
    .mika-product-info {
        padding: 20px !important;
    }
    .mika-product-info h3 {
        font-size: 18px !important;
        font-weight: 600 !important;
        margin-bottom: 8px !important;
        color: #1a1a1a !important;
    }
    .mika-product-info p {
        font-size: 14px !important;
        color: #666666 !important;
        line-height: 1.5 !important;
    }
    
    @media (max-width: 900px) {
        .mika-products-grid { grid-template-columns: repeat(2, 1fr) !important; }
    }
    @media (max-width: 560px) {
        .mika-products-grid { grid-template-columns: 1fr !important; }
    }

    /* === P1 优化：统计数据区域 === */
    .mika-stats-row {
        display: flex !important;
        justify-content: center !important;
        gap: 60px !important;
        flex-wrap: wrap !important;
        text-align: center !important;
    }
    .mika-stat-item {
        flex: 0 0 auto !important;
        padding: 0 30px !important;
    }
    .mika-stat-number {
        font-size: 48px !important;
        font-weight: 700 !important;
        color: #e82127 !important;
        letter-spacing: -0.02em !important;
        line-height: 1 !important;
    }
    .mika-stat-label {
        font-size: 14px !important;
        color: #6e6e6e !important;
        margin-top: 8px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.05em !important;
    }
    
    @media (max-width: 560px) {
        .mika-stats-row { gap: 30px !important; }
        .mika-stat-number { font-size: 36px !important; }
    }

    /* === P1 优化：滚动动效应用 === */
    /* Hero 标题 */
    .elementor-section:first-child h1,
    .mika-hero-title {
        opacity: 0 !important;
        transform: translateY(30px) !important;
        animation: mika-hero-in 0.8s ease-out 0.2s forwards !important;
    }
    
    @keyframes mika-hero-in {
        to {
            opacity: 1 !important;
            transform: translateY(0) !important;
        }
    }
    
    /* Hero 副标题 */
    .elementor-section:first-child h2,
    .mika-hero-subtitle {
        opacity: 0 !important;
        transform: translateY(20px) !important;
        animation: mika-hero-in 0.8s ease-out 0.4s forwards !important;
    }
    
    /* Hero 按钮 */
    .elementor-section:first-child .elementor-button-wrapper,
    .mika-hero-btn {
        opacity: 0 !important;
        transform: translateY(20px) !important;
        animation: mika-hero-in 0.8s ease-out 0.6s forwards !important;
    }
    
    /* Card 悬停红色上边框 */
    .mika-card:hover,
    .elementor-column:hover .elementor-widget-wrap {
        border-top: 3px solid #e82127 !important;
    }

    /* === P1 优化：页脚增强 === */
    .site-footer {
        background: #0f0f0f !important;
        color: #888888 !important;
        padding: 40px 0 !important;
        text-align: center !important;
    }
    .site-footer p,
    .site-footer a {
        color: #888888 !important;
        font-size: 14px !important;
    }
    .site-footer a:hover {
        color: #e82127 !important;
    }


    

    /* === 修复: 排除 WordPress admin bar 按钮（之前被全局样式误改） === */
    #wpadminbar button,
    #wpadminbar input[type="submit"],
    #wpadminbar .ab-item,
    #wpadminbar .ab-icon,
    #wpadminbar .ab-icon:before,
    #wpadminbar .ab-label {
        background-color: transparent !important;
        background: none !important;
        color: #ddd !important;
        border: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        font-size: inherit !important;
        font-weight: normal !important;
        text-transform: none !important;
        letter-spacing: normal !important;
        box-shadow: none !important;
        transform: none !important;
        transition: none !important;
        text-decoration: none !important;
        cursor: pointer !important;
        display: inline-block !important;
    }
    #wpadminbar button:hover,
    #wpadminbar .ab-item:hover {
        background: rgba(255,255,255,0.1) !important;
        color: #e82127 !important;
    }
    #wpadminbar .quicklinks .ab-sub-wrapper {
        background: #23282d !important;
    }
    #wpadminbar .ab-top-menu > li > .ab-item:focus {
        background: transparent !important;
    }

    

    /* === 增强修复: 重置 WordPress admin bar 所有样式 === */
    #wpadminbar,
    #wpadminbar .ab-top-menu,
    #wpadminbar .ab-top-secondary,
    #wpadminbar .ab-sub-wrapper,
    #wpadminbar .ab-submenu,
    #wpadminbar .ab-item,
    #wpadminbar .ab-icon,
    #wpadminbar .ab-icon::before,
    #wpadminbar .ab-label,
    #wpadminbar .ab-empty-item,
    #wpadminbar button,
    #wpadminbar input,
    #wpadminbar select,
    #wpadminbar textarea,
    #wpadminbar form,
    #wpadminbar fieldset,
    #wpadminbar .adminbar-input,
    #wpadminbar .adminbar-button {
        background: transparent !important;
        background-color: transparent !important;
        background-image: none !important;
        color: #ddd !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        text-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 13px !important;
        font-weight: 400 !important;
        line-height: 1.4 !important;
        letter-spacing: normal !important;
        text-transform: none !important;
        transition: none !important;
        transform: none !important;
        text-decoration: none !important;
        cursor: default !important;
        width: auto !important;
        height: auto !important;
        max-width: none !important;
        max-height: none !important;
        min-width: 0 !important;
        min-height: 0 !important;
        outline: none !important;
    }
    #wpadminbar .ab-icon::before {
        color: #a7aaad !important;
    }
    #wpadminbar .ab-top-menu > li > .ab-item:focus,
    #wpadminbar .ab-top-menu > li:hover > .ab-item,
    #wpadminbar .ab-top-menu > li > .ab-item {
        background: transparent !important;
        color: #ddd !important;
    }
    #wpadminbar .ab-top-menu > li:hover > .ab-item {
        color: #e82127 !important;
    }
    #wpadminbar .ab-submenu .ab-item:hover {
        background: #e82127 !important;
        color: #fff !important;
    }
    #wpadminbar #adminbarsearch {
        background: transparent !important;
        height: 28px !important;
        padding: 0 2px !important;
    }
    #wpadminbar .adminbar-input {
        background: #32373c !important;
        color: #fff !important;
        border: 1px solid #555 !important;
        border-radius: 3px !important;
        height: 28px !important;
        padding: 0 4px !important;
        font-size: 13px !important;
        width: 100px !important;
    }
    #wpadminbar .adminbar-button {
        display: none !important;
    }

    

    /* === 最终修复: 彻底解决 admin bar Search 按钮问题 === */
    /* 方案: 直接隐藏整个 admin bar search 区域 */
    #wpadminbar #wp-admin-bar-search,
    #wpadminbar .admin-bar-search,
    #wpadminbar .ab-top-secondary,
    #wpadminbar .ab-icon-search,
    #wpadminbar .ab-search,
    #wpadminbar .ab-empty-item {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        height: 0 !important;
        width: 0 !important;
        overflow: hidden !important;
    }
    /* 隐藏 admin bar 中的所有 input submit（防止样式污染）*/
    #wpadminbar input[type="submit"],
    #wpadminbar button[type="submit"] {
        display: none !important;
    }
    /* 如果某种情况下 search 仍显示，强制重置 */
    #wpadminbar .adminbar-button,
    #wpadminbar .adminbar-input,
    #wpadminbar input.adminbar-button {
        display: none !important;
        background: transparent !important;
        background-color: transparent !important;
        color: transparent !important;
        border: 0 !important;
        width: 0 !important;
        height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* 暴力解决: 排除 admin bar 内的所有元素不被全局按钮样式影响 */
    #wpadminbar input,
    #wpadminbar button,
    #wpadminbar a {
        background: transparent !important;
        background-color: transparent !important;
        color: inherit !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        font-size: inherit !important;
        font-weight: normal !important;
        text-transform: none !important;
        letter-spacing: normal !important;
        transition: none !important;
        transform: none !important;
        text-decoration: none !important;
    }
    
    /* 排除 admin bar */
    #wpadminbar input[type="submit"]:not(.mika-exclude) {
        background: transparent !important;
    }
    

    /* === P2-3: 移动端优化 === */
    /* 触摸目标增大 (44x44px iOS HIG) */
    @media (max-width: 768px) {
        /* 字体大小 */
        h1, h1.elementor-heading-title { font-size: 36px !important; line-height: 1.15 !important; }
        h2, h2.elementor-heading-title { font-size: 28px !important; line-height: 1.2 !important; }
        h3, h3.elementor-heading-title { font-size: 20px !important; }
        p, body { font-size: 15px !important; line-height: 1.7 !important; }
        
        /* Hero 区域 */
        .elementor-top-section:first-of-type,
        [style*="height:100vh"] {
            min-height: 500px !important;
            height: auto !important;
            padding: 80px 20px 60px !important;
        }
        
        /* Section 内边距 */
        .elementor-section,
        .elementor-top-section {
            padding: 60px 20px !important;
        }
        [style*="padding:140px"] {
            padding: 60px 20px !important;
        }
        [style*="padding:60px 40px"] {
            padding: 30px 20px !important;
        }
        
        /* 网格：单列 */
        [style*="grid-template-columns:repeat(4"],
        [style*="grid-template-columns: repeat(4"],
        [style*="grid-template-columns:repeat(2"],
        [style*="grid-template-columns: repeat(2"],
        [style*="grid-template-columns:repeat(auto-fit"] {
            grid-template-columns: 1fr !important;
            gap: 24px !important;
        }
        [style*="grid-template-columns:repeat(auto-fit,minmax(260px"] {
            grid-template-columns: 1fr !important;
        }
        
        /* 数字：缩小 */
        [style*="font-size:96px"] {
            font-size: 56px !important;
            letter-spacing: -2px !important;
        }
        
        /* 按钮：触摸目标 */
        a[style*="padding:20px 50px"],
        a[style*="padding: 20px 50px"] {
            padding: 16px 32px !important;
            font-size: 15px !important;
            width: 100% !important;
            max-width: 320px !important;
            box-sizing: border-box !important;
        }
        
        /* 导航：移动端 */
        .site-header .header-inner {
            padding: 10px 16px !important;
        }
        .site-header .site-title a {
            font-size: 18px !important;
        }
        .site-header .site-description {
            font-size: 11px !important;
        }
        .site-header .menu > li > a {
            padding: 12px 10px !important;
            font-size: 14px !important;
            min-height: 44px !important;
            display: flex !important;
            align-items: center !important;
        }
        
        /* Hero 文字：避免过宽 */
        h1[style*="font-size:88px"] {
            font-size: 36px !important;
            letter-spacing: -1px !important;
        }
        p[style*="font-size:22px"] {
            font-size: 16px !important;
        }
        
        /* 产品卡片 */
        [style*="border-radius:16px"] img {
            height: 180px !important;
        }
        [style*="padding:30px"][style*="border-radius"] {
            padding: 20px !important;
        }
        
        /* 数据统计 */
        [style*="font-size:18px"][style*="margin-top:12px"] {
            font-size: 14px !important;
        }
        
        /* 客户评价 */
        [style*="width:80px"][style*="height:80px"] {
            width: 56px !important;
            height: 56px !important;
            font-size: 22px !important;
        }
        [style*="padding:40px"][style*="border-radius:16px"] {
            padding: 24px !important;
        }
    }
    
    /* 中等屏幕：平板 */
    @media (min-width: 769px) and (max-width: 1024px) {
        [style*="grid-template-columns:repeat(4"] {
            grid-template-columns: repeat(2, 1fr) !important;
        }
        h1, h1.elementor-heading-title { font-size: 48px !important; }
        h2, h2.elementor-heading-title { font-size: 36px !important; }
    }
    

    
    /* === 产品轮播 Swiper === */
    .mika-product-swiper {
        width: 100%;
        max-width: 1100px !important;
        margin: 40px auto 0;
        padding: 20px 0 8px !important;
        position: relative;
        overflow: hidden !important;
        height: 480px !important; /* 固定高度：图片260 + 文字区约160 + 留白60 */
    }
    .mika-product-swiper .swiper-slide {
        display: flex !important;
        justify-content: center;
        align-items: flex-start !important;
        width: 360px !important;
        height: auto !important;
        transition: all 0.4s ease !important;
    }
    .mika-product-swiper .swiper-slide > a {
        width: 360px !important;
        display: block !important;
    }
    /* 产品卡片：和产品中心一致 */
    .mika-product-swiper .swiper-slide img {
        height: 260px !important;
        object-fit: cover !important;
    }
    .mika-product-swiper .swiper-slide > a > div:last-child {
        padding: 24px !important;
    }
    .mika-product-swiper .swiper-slide > a > div:last-child > div:first-child {
        font-size: 24px !important;
        margin-bottom: 4px !important;
    }
    .mika-product-swiper .swiper-slide > a > div:last-child > div:last-child {
        font-size: 16px !important;
        line-height: 1.4 !important;
    }
    /* === 产品卡片：class 化样式（HTML 中只用 class） === */
    .mika-product-card {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        background: #fff !important;
        border-radius: 24px !important;
        overflow: hidden !important;
        width: 100% !important;
        max-width: 360px !important;
        text-decoration: none !important;
        color: inherit !important;
        box-shadow: 0 8px 32px rgba(0,0,0,0.12) !important;
        transition: all 0.4s ease !important;
    }
    .mika-product-card:hover {
        transform: translateY(-6px) scale(1.02) !important;
        box-shadow: 0 16px 48px rgba(0,0,0,0.18) !important;
    }
    .mika-product-img {
        width: 100% !important;
        height: 260px !important;
        object-fit: cover !important;
        display: block !important;
        flex-shrink: 0 !important;
    }
    .mika-product-text {
        padding: 24px !important;
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
    }
    .mika-product-title {
        font-size: 24px !important;
        font-weight: 700 !important;
        color: #111 !important;
        margin-bottom: 4px !important;
    }
    .mika-product-desc {
        font-size: 16px !important;
        color: #666 !important;
        line-height: 1.4 !important;
    }
    /* === 页面 section 通用样式（用于 HTML class 化） === */
    .mika-section-light {
        padding: 140px 30px;
        background: #fff;
    }
    .mika-section-gray {
        padding: 100px 30px;
        background: #f5f5f7;
    }
    .mika-section-dark {
        padding: 140px 30px;
        background: #111;
        text-align: center;
        margin-top: 80px;
    }
    .mika-section-footer {
        background: #000;
        padding: 60px 40px;
        text-align: center;
        font-size: 14px;
        color: rgba(255,255,255,0.5);
    }
    /* 导航按钮：更明显 */
    .mika-product-swiper .swiper-button-next,
    .mika-product-swiper .swiper-button-prev {
        color: #e82127 !important;
        width: 56px !important;
        height: 56px !important;
        background: #fff !important;
        border-radius: 50% !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.25) !important;
        transition: all 0.3s ease !important;
        z-index: 9999 !important;
        position: absolute !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        cursor: pointer !important;
        pointer-events: auto !important;
    }
    .mika-product-swiper .swiper-button-next {
        right: 20px !important;
    }
    .mika-product-swiper .swiper-button-prev {
        left: 20px !important;
    }
    .mika-product-swiper .swiper-button-next:after,
    .mika-product-swiper .swiper-button-prev:after {
        font-size: 20px !important;
        font-weight: 900 !important;
    }
    .mika-product-swiper .swiper-button-next:hover,
    .mika-product-swiper .swiper-button-prev:hover {
        background: #e82127 !important;
        color: #fff !important;
        box-shadow: 0 6px 20px rgba(232,33,39,0.4) !important;
    }
    .mika-product-swiper .swiper-pagination-bullet {
        background: rgba(232,33,39,0.3) !important;
        opacity: 1 !important;
        width: 8px !important;
        height: 8px !important;
        transition: all 0.3s ease !important;
    }
    .mika-product-swiper .swiper-pagination {
        position: absolute;
        bottom: 0 !important;
        left: 0;
        right: 0;
        text-align: center;
    }
    
    .mika-product-swiper .swiper-pagination-bullet-active {
        background: #e82127 !important;
        width: 24px !important;
        border-radius: 4px !important;
    }
    @media (max-width: 768px) {
        .m
    /* 响应式 */
    /* 响应式断点 */
    @media (max-width: 576px) {
        .mika-product-swiper .swiper-slide {
            width: 280px !important;
        }
        .mika-product-swiper .swiper-slide > a {
            width: 280px !important;
        }
    }
    
    @media (min-width: 577px) and (max-width: 992px) {
        .mika-product-swiper .swiper-slide {
            width: 320px !important;
        }
        .mika-product-swiper .swiper-slide > a {
            width: 320px !important;
        }
    }
    
    @media (max-width: 768px) {
        .mika-product-swiper {
            max-width: 100% !important;
            padding: 10px 0 50px !important;
        }
        .mika-product-swiper .swiper-slide {
            width: 300px !important;
        }
        .mika-product-swiper .swiper-slide > a {
            width: 300px !important;
        }
        .mika-product-swiper .swiper-slide img {
            height: 220px !important;
        }
        .mika-product-swiper .swiper-button-next {
            right: 10px !important;
        }
        .mika-product-swiper .swiper-button-prev {
            left: 10px !important;
        }
        .mika-product-swiper .swiper-button-next,
        .mika-product-swiper .swiper-button-prev {
            width: 44px !important;
            height: 44px !important;
        }
    }
    @media (max-width: 480px) {
        .mika-product-swiper .swiper-slide {
            width: 260px !important;
        }
        .mika-product-swiper .swiper-slide > a {
            width: 260px !important;
        }
        .mika-product-swiper .swiper-slide img {
            height: 180px !important;
        }
    }ika-product-swiper {
            padding: 0 40px;
        }
        .mika-product-swiper .swiper-button-next,
        .mika-product-swiper .swiper-button-prev {
            width: 36px !important;
            height: 36px !important;
        }
    }
    </style>';
}
add_action( 'wp_head', 'mika_aos_style', 998 );



function mika_product_swiper_init() {
    ?>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css">
    <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
    <script>
    document.addEventListener("DOMContentLoaded", function() {
        if (document.querySelector(".mika-product-swiper")) {
            var swiper = new Swiper(".mika-product-swiper", {
                effect: "coverflow",
                grabCursor: true,
                centeredSlides: true,
                slidesPerView: 3,
                loop: true,
                autoplay: {
                    delay: 4000,
                    disableOnInteraction: false,
                    pauseOnMouseEnter: true,
                },
                speed: 600,
                coverflowEffect: {
                    rotate: 0,
                    stretch: -50,
                    depth: 250,
                    modifier: 2,
                    slideShadows: false,
                },
                pagination: {
                    el: ".swiper-pagination",
                    clickable: true,
                },
                navigation: {
                    nextEl: ".swiper-button-next",
                    prevEl: ".swiper-button-prev",
                },
                observer: true,
                observeSlideChildren: true,
                observeParents: true,
                on: {
                    resize: function() {
                        swiper.update();
                    },
                },
            });
        }
    });
    </script>
    <?php
}
add_action("wp_footer", "mika_product_swiper_init", 20);

// 对包含 swiper 的页面禁用 wpautop（防止破坏卡片结构）
function mika_disable_autop_for_swiper($content) {
    if (strpos($content, 'mika-product-swiper') !== false) {
        remove_filter('the_content', 'wpautop');
        remove_filter('the_content', 'wptexturize');
    }
    return $content;
}
add_filter('the_content', 'mika_disable_autop_for_swiper', 1);

// 允许 inline style 使用 background-image（解决 Hero 区域背景图被 wp_kses 过滤掉的问题）
function mika_allow_background_image($styles) {
    $styles[] = 'background-image';
    return $styles;
}
add_filter('safe_style_css', 'mika_allow_background_image');

// Hero 背景图（通过 class 方式避免 wp_kses 过滤 background-image 的 url()）
// 已禁用 - CSS 已移至 header.php
/*
function mika_hero_background_css() {
    $url = home_url() . '/wp-content/uploads/2026/06/hero-24.jpg';
    echo '<style>
        .mika-hero {
            background-image: url("' . $url . '") !important;
            background-size: cover !important;
            background-position: center !important;
        }
    </style>';
}
add_action('wp_head', 'mika_hero_background_css');
*/
