(function () {
    'use strict';

    var icons = {
        home:'<path d="M3 11.5 12 4l9 7.5"/><path d="M5.5 10.5V20h13v-9.5M9.5 20v-6h5v6"/>',
        overview:'<rect x="3.5" y="3.5" width="7" height="7" rx="1.5"/><rect x="13.5" y="3.5" width="7" height="4" rx="1.5"/><rect x="3.5" y="13.5" width="7" height="7" rx="1.5"/><rect x="13.5" y="10.5" width="7" height="10" rx="1.5"/>',
        article:'<path d="M5 3.5h11l3 3V20.5H5z"/><path d="M15.5 3.5V7H19M8 10h8M8 13.5h8M8 17h5"/>',
        file:'<path d="M6 3.5h8l4 4V20H6z"/><path d="M14 3.5V8h4"/>',
        checklist:'<rect x="4" y="3" width="16" height="18" rx="2"/><path d="m7.5 9 1.5 1.5 2.5-3M13.5 9H17M7.5 15l1.5 1.5 2.5-3M13.5 15H17"/>',
        package:'<path d="m4 7 8-4 8 4-8 4z"/><path d="M4 7v10l8 4 8-4V7M12 11v10"/>',
        sitemap:'<rect x="9" y="3" width="6" height="4" rx="1"/><rect x="3" y="17" width="6" height="4" rx="1"/><rect x="15" y="17" width="6" height="4" rx="1"/><path d="M12 7v5M6 17v-5h12v5"/>',
        gallery:'<rect x="3.5" y="5" width="14" height="15" rx="2"/><path d="m5.5 17 3.5-4 3 3 2-2 3.5 3"/><path d="M7 5V3h13.5v14H18"/><circle cx="9" cy="10" r="1"/>',
        video:'<rect x="3.5" y="5" width="13" height="14" rx="2"/><path d="m16.5 10 4-2.5v9l-4-2.5z"/>',
        briefcase:'<rect x="3" y="7" width="18" height="13" rx="2"/><path d="M9 7V4h6v3M3 12h18M10 12v2h4v-2"/>',
        admin:'<circle cx="12" cy="8" r="3.5"/><path d="M5 20a7 7 0 0 1 14 0"/><path d="m17.5 5 .8.8 1.2-.2.3 1.2 1 .7-.6 1.1.3 1.2-1.1.5-.5 1.1-1.2-.2-.8.8"/>',
        key:'<circle cx="8" cy="15" r="4"/><path d="m11 12 8-8M16 7l2 2M14 9l2 2"/>',
        user:'<circle cx="12" cy="8" r="4"/><path d="M4.5 21a7.5 7.5 0 0 1 15 0"/>',
        userGroup:'<circle cx="9" cy="8" r="3"/><path d="M3.5 20v-2A4.5 4.5 0 0 1 8 13.5h2A4.5 4.5 0 0 1 14.5 18v2M16 5.5a3 3 0 0 1 0 5.5M16.5 14a4 4 0 0 1 4 4v2"/>',
        mail:'<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m4 7 8 6 8-6"/>',
        guestbook:'<path d="M4 4h16v13H9l-5 4z"/><path d="M8 8h8M8 12h5"/>',
        comment:'<path d="M5 5h14v11H9l-4 4z"/><path d="M9 9h6M9 12.5h4"/>',
        vote:'<rect x="4" y="5" width="16" height="16" rx="2"/><path d="m8 11 2 2 5-5M8 17h8M8 3h8"/>',
        pen:'<path d="M13.5 5.5 18.5 10.5M4 20l3.5-.8L19 7.7a2 2 0 0 0-2.8-2.8L4.8 16.5z"/>',
        media:'<rect x="3.5" y="4" width="17" height="16" rx="2"/><circle cx="9" cy="9" r="1.5"/><path d="m5 17 4.5-4 3.5 3 2.5-2 3.5 3"/>',
        slideshow:'<rect x="3" y="4" width="18" height="14" rx="2"/><path d="m10 8 5 3-5 3zM8 21h8M12 18v3"/>',
        link:'<path d="M9.5 14.5 14.5 9M7.5 17.5h-1a4 4 0 0 1 0-8h4M16.5 6.5h1a4 4 0 0 1 0 8h-4"/>',
        megaphone:'<path d="M4 10v4h4l9 4V6L8 10z"/><path d="m8 14 1.5 5h3M20 9v6"/>',
        palette:'<path d="M12 3a9 9 0 1 0 0 18h1.5a2 2 0 0 0 0-4H12a2 2 0 0 1 0-4h3a6 6 0 0 0 0-12z"/><circle cx="7.5" cy="10" r=".7"/><circle cx="9" cy="6.5" r=".7"/><circle cx="14" cy="6" r=".7"/>',
        panels:'<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 9h18M9 9v11"/>',
        lifeRing:'<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="3"/><path d="m5.6 5.6 4.3 4.3M14.1 14.1l4.3 4.3M18.4 5.6l-4.3 4.3M9.9 14.1l-4.3 4.3"/>',
        tags:'<path d="M3 5v6l9 9 8-8-9-9H5a2 2 0 0 0-2 2z"/><circle cx="7.5" cy="7.5" r="1"/>',
        bell:'<path d="M18 9a6 6 0 1 0-12 0c0 5-2 6.5-2 6.5h16S18 14 18 9M10 19h4"/>',
        tasks:'<path d="M9 5h11M9 12h11M9 19h11"/><path d="m3.5 5 1.2 1.2L7 3.8M3.5 12l1.2 1.2L7 10.8M3.5 19l1.2 1.2L7 17.8"/>',
        globe:'<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a15 15 0 0 1 0 18M12 3a15 15 0 0 0 0 18"/>',
        route:'<circle cx="6" cy="18" r="2"/><circle cx="18" cy="6" r="2"/><path d="M8 18h3a3 3 0 0 0 3-3V9a3 3 0 0 1 3-3"/>',
        activity:'<path d="M3 12h4l2.2-6 4.1 12 2.2-6H21"/>',
        target:'<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1"/><path d="m15.5 8.5 5-5M17 3.5h3.5V7"/>',
        shield:'<path d="M12 3 20 6v5c0 5-3.2 8.3-8 10-4.8-1.7-8-5-8-10V6z"/><path d="m8.5 12 2.2 2.2 4.8-5"/>',
        refresh:'<path d="M20 7v5h-5M4 17v-5h5"/><path d="M18.5 15a7 7 0 0 1-12 2L4 14M5.5 9a7 7 0 0 1 12-2L20 10"/>',
        code:'<path d="m8.5 8-4 4 4 4M15.5 8l4 4-4 4M13.5 5 10.5 19"/>',
        history:'<path d="M4 5v5h5"/><path d="M5.5 15a8 8 0 1 0 .5-7L4 10M12 7v5l3 2"/>',
        database:'<ellipse cx="12" cy="5.5" rx="8" ry="3"/><path d="M4 5.5v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6M4 11.5v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6"/>',
        storefront:'<path d="M4 9v11h16V9M3 9l2-5h14l2 5"/><path d="M3 9a3 3 0 0 0 5 2 3 3 0 0 0 4 0 3 3 0 0 0 4 0 3 3 0 0 0 5-2M9 20v-5h6v5"/>',
        receipt:'<path d="M6 3h12v18l-3-2-3 2-3-2-3 2z"/><path d="M9 8h6M9 12h6M9 16h4"/>',
        truck:'<path d="M3 6h11v11H3zM14 10h4l3 3v4h-7z"/><circle cx="7" cy="18" r="2"/><circle cx="18" cy="18" r="2"/>',
        refund:'<path d="M4 8V3M4 8h5"/><path d="M5.5 16a8 8 0 1 0 0-8L4 8M9 12h7M12 9l-3 3 3 3"/>',
        star:'<path d="m12 3 2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/>',
        wallet:'<path d="M4 6h14a2 2 0 0 1 2 2v11H4a2 2 0 0 1-2-2V6.5A2.5 2.5 0 0 1 4.5 4H17"/><path d="M14 11h6v4h-6a2 2 0 0 1 0-4z"/>',
        card:'<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 10h18M7 15h4"/>',
        sliders:'<path d="M4 6h5M13 6h7M4 12h10M18 12h2M4 18h2M10 18h10"/><circle cx="11" cy="6" r="2"/><circle cx="16" cy="12" r="2"/><circle cx="8" cy="18" r="2"/>',
        folder:'<path d="M3.5 6h6l2 2h9v11h-17z"/>',
        settings:'<circle cx="12" cy="12" r="3"/><path d="M12 3v3M12 18v3M3 12h3M18 12h3M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M18.4 5.6l-2.1 2.1M7.7 16.3l-2.1 2.1"/>',
        search:'<circle cx="10.5" cy="10.5" r="6.5"/><path d="m16 16 5 5"/>',
        upload:'<path d="M12 16V4M7.5 8.5 12 4l4.5 4.5M4 20h16"/>',
        download:'<path d="M12 3v12M7.5 10.5 12 15l4.5-4.5M4 20h16"/>',
        plus:'<path d="M12 5v14M5 12h14"/>',
        check:'<path d="m5 12 4 4L19 6"/>',
        edit:'<path d="M13.5 5.5 18.5 10.5M4 20l3.5-.8L19 7.7a2 2 0 0 0-2.8-2.8L4.8 16.5z"/>',
        trash:'<path d="M4 7h16M9 3h6l1 4H8zM6.5 7l1 14h9l1-14M10 11v6M14 11v6"/>',
        filter:'<path d="M4 5h16l-6 7v6l-4 2v-8z"/>',
        arrowLeft:'<path d="m10 5-7 7 7 7M3 12h18"/>',
        eye:'<path d="M2.5 12s3.5-6 9.5-6 9.5 6 9.5 6-3.5 6-9.5 6-9.5-6-9.5-6z"/><circle cx="12" cy="12" r="2.5"/>',
        chevronDown:'<path d="m6 9 6 6 6-6"/>',
        menu:'<path d="M4 6h16M4 12h16M4 18h16"/>',
        monitor:'<rect x="3" y="4" width="18" height="14" rx="2"/><path d="M8 21h8M12 18v3"/>',
        logOut:'<path d="M10 4H5v16h5M14 8l4 4-4 4M18 12H9"/>',
        close:'<path d="m6 6 12 12M18 6 6 18"/>',
        warning:'<path d="M12 3 2.5 20h19z"/><path d="M12 9v5M12 17.5h.01"/>',
        spinner:'<circle cx="12" cy="12" r="9" opacity=".25"/><path d="M12 3a9 9 0 0 1 9 9"/>'
    };

    var actIcons = {
        dashboard:'home',content:'overview',content_list:'overview',content_quality:'checklist',data_import:'upload',article:'article',product:'package',channel:'sitemap',page:'file',image:'gallery',download:'download',video:'video',recruit:'briefcase',
        admin_user:'admin',role:'key',member:'user',member_group:'userGroup',message:'mail',guestbook:'guestbook',comment:'comment',vote:'vote',contribute:'pen',
        media:'media',slide:'slideshow',link:'link',ads:'megaphone',template:'palette',builder:'panels',help_center:'lifeRing',tag_help:'tags',
        notification:'bell',task_center:'tasks',site:'globe',online_service:'message-circle',redirect:'route',system_status:'activity',seo_tools:'target',auth:'shield',version:'refresh',custom_var:'code',log:'history',database:'database',
        shop:'storefront',order:'receipt',shipping:'truck',refund:'refund',review:'star',recharge:'wallet',payment:'card',shop_config:'sliders',profile:'admin',upload:'upload',global_search:'search'
    };
    var groupIcons={content:'folder',shop:'storefront',user:'userGroup',interact:'comment',tools:'panels',system:'settings'};

    function svg(name,className){
        return '<svg class="'+className+'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">'+(icons[name]||icons.settings)+'</svg>';
    }
    function replaceHost(host,name,className){if(host)host.innerHTML=svg(name,className);}

    function enhanceNavigation(){
        document.querySelectorAll('.nav-link-root[data-act],.nav-sublink[data-act]').forEach(function(link){
            var name=actIcons[link.dataset.act]||'settings';
            var host=link.querySelector('.nav-icon')||link.querySelector('i,svg');
            if(host&&host.matches('.nav-icon'))replaceHost(host,name,'cms-nav-svg');else if(host)host.outerHTML=svg(name,'cms-nav-svg');
        });
        document.querySelectorAll('.nav-group-toggle[data-group]').forEach(function(button){replaceHost(button.querySelector('.nav-icon'),groupIcons[button.dataset.group]||'folder','cms-nav-svg');});
        document.querySelectorAll('.nav-arrow').forEach(function(host){replaceHost(host,'chevronDown','cms-arrow-svg');});
    }

    function enhancePageIcons(){
        var act=new URLSearchParams(window.location.search).get('act')||'dashboard';
        document.querySelectorAll('.page-header').forEach(function(header){
            var host=header.querySelector('.page-title')||header.querySelector('.header-title')||header.firstElementChild;if(!host)return;
            var icon=header.querySelector('.page-icon');if(!icon){icon=document.createElement('span');icon.className='page-icon cms-auto-page-icon';host.insertBefore(icon,host.firstChild);}
            icon.innerHTML=svg(actIcons[act]||'settings','cms-page-svg');
        });
    }

    var buttonRules=[
        [/^(?:\u65b0\u589e|\u6dfb\u52a0|\u521b\u5efa|\u65b0\u5efa|\u590d\u5236)/,'plus'],
        [/^(?:\u4fdd\u5b58|\u63d0\u4ea4|\u786e\u8ba4|\u53d1\u5e03|\u4e0a\u67b6|\u663e\u793a|\u542f\u7528|\u901a\u8fc7|\u5b8c\u6210)/,'check'],
        [/^(?:\u7f16\u8f91|\u4fee\u6539|\u8bbe\u7f6e|\u914d\u7f6e|\u8c03\u6574)/,'edit'],
        [/^(?:\u5220\u9664|\u56de\u6536|\u79fb\u9664|\u6e05\u7a7a|\u505c\u7528|\u7981\u7528)/,'trash'],
        [/^(?:\u641c\u7d22|\u7b5b\u9009|\u67e5\u8be2|\u68c0\u6d4b)/,'search'],
        [/^(?:\u5bfc\u5165|\u4e0a\u4f20)/,'upload'],[/^(?:\u5bfc\u51fa|\u4e0b\u8f7d)/,'download'],
        [/^(?:\u8fd4\u56de|\u53d6\u6d88|\u91cd\u7f6e)/,'arrowLeft'],[/^(?:\u9884\u89c8|\u67e5\u770b|\u8be6\u60c5)/,'eye'],
        [/^(?:\u5237\u65b0|\u6062\u590d|\u540c\u6b65)/,'refresh'],[/^(?:\u5ba1\u6838|\u5ba1\u9605|\u9a73\u56de)/,'check']
    ];
    var faIconMap={'fa-home':'home','fa-th-large':'overview','fa-file-text-o':'article','fa-file-o':'file','fa-check-square-o':'checklist','fa-table':'overview','fa-newspaper-o':'article','fa-cubes':'package','fa-sitemap':'sitemap','fa-picture-o':'media','fa-image':'gallery','fa-download':'download','fa-upload':'upload','fa-play-circle-o':'video','fa-briefcase':'briefcase','fa-users':'userGroup','fa-user-circle':'admin','fa-key':'key','fa-user':'user','fa-object-group':'userGroup','fa-envelope-o':'mail','fa-comments-o':'comment','fa-commenting-o':'guestbook','fa-comment-o':'comment','fa-pencil-square':'pen','fa-folder-open-o':'folder','fa-link':'link','fa-bullhorn':'megaphone','fa-paint-brush':'palette','fa-columns':'panels','fa-life-ring':'lifeRing','fa-tags':'tags','fa-cog':'settings','fa-cogs':'settings','fa-bell-o':'bell','fa-tasks':'tasks','fa-random':'route','fa-heartbeat':'activity','fa-search':'search','fa-shield':'shield','fa-refresh':'refresh','fa-code':'code','fa-history':'history','fa-database':'database','fa-shopping-bag':'storefront','fa-dashboard':'overview','fa-shopping-cart':'receipt','fa-truck':'truck','fa-undo':'refund','fa-star':'star','fa-rmb':'wallet','fa-credit-card':'card','fa-sliders':'sliders','fa-plus':'plus','fa-plus-circle':'plus','fa-check':'check','fa-edit':'edit','fa-pencil':'edit','fa-trash':'trash','fa-trash-o':'trash','fa-eye':'eye','fa-filter':'filter','fa-arrow-left':'arrowLeft','fa-desktop':'monitor','fa-sign-out':'logOut','fa-times':'close','fa-warning':'warning','fa-exclamation':'warning','fa-spinner':'spinner','fa-bars':'menu','fa-outdent':'menu','fa-indent':'menu','fa-angle-down':'chevronDown'};

    function iconFromLegacy(node){var classes=Array.prototype.slice.call(node.classList);for(var i=0;i<classes.length;i++){if(faIconMap[classes[i]])return faIconMap[classes[i]];}return null;}
    function enhanceButtons(){
        document.querySelectorAll('.btn').forEach(function(button){
            if(button.querySelector('.cms-button-svg'))return;
            var text=(button.textContent||'').replace(/\s+/g,'').trim(),name=null;
            for(var i=0;i<buttonRules.length;i++){if(buttonRules[i][0].test(text)){name=buttonRules[i][1];break;}}
            var legacy=button.querySelector('i.fa');if(!name&&legacy)name=iconFromLegacy(legacy);if(!name)return;
            if(legacy)legacy.remove();button.insertAdjacentHTML('afterbegin',svg(name,'cms-button-svg'+(name==='spinner'?' is-spinning':'')));
        });
    }

    function enhanceShell(){
        var rules=[['.topbar-chip-brand','megaphone'],['.global-search-trigger','search'],['.topbar-action-primary','panels'],['a[href*="act=notification"].topbar-action','bell'],['a[target="_blank"].topbar-action:not(.topbar-action-primary)','monitor'],['a[href*="act=auth"].topbar-action','shield'],['.topbar-user','chevronDown'],['.topbar-action-ghost','logOut'],['.profile-panel-close','close'],['.global-search-input-wrap','search'],['.shell-alert','warning']];
        rules.forEach(function(rule){document.querySelectorAll(rule[0]).forEach(function(element){var old=element.querySelector('i.fa,svg.cms-shell-svg');if(!old)return;old.outerHTML=svg(rule[1],'cms-shell-svg');});});
    }

    function enhanceLegacyIcons(){
        document.querySelectorAll('i.fa').forEach(function(node){if(node.closest('.edui-editor'))return;var name=iconFromLegacy(node);if(!name)return;node.outerHTML=svg(name,'cms-inline-svg'+(name==='spinner'?' is-spinning':''));});
    }

    function run(){enhanceNavigation();enhancePageIcons();enhanceButtons();enhanceShell();enhanceLegacyIcons();}
    window.CMSAdminIcons={svg:svg,run:run};
    if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',run);else run();
    var refreshTimer=null;new MutationObserver(function(mutations){var relevant=mutations.some(function(mutation){return Array.prototype.some.call(mutation.addedNodes,function(node){return node.nodeType===1&&(node.matches('.btn,.page-header,.nav-link,.topbar-action,i.fa')||node.querySelector('.btn,.page-header,.nav-link,.topbar-action,i.fa'));});});if(!relevant)return;clearTimeout(refreshTimer);refreshTimer=setTimeout(run,30);}).observe(document.documentElement,{childList:true,subtree:true});
})();
