(function($) {
    "use strict";

    // Changed some elements with new animation
    var slowFadeIn = 'animated fadeIn';
    $('body').addClass('perfex_office_theme_initiated');
    $('.screen-options-area').addClass(slowFadeIn);
    $('#mobile-collapse').addClass(slowFadeIn);

    $('.quick-links').prependTo('#header nav .navbar-nav');

    $('.quick-links').css('display', 'block');

    // Move header logo into sidebar for a more cohesive layout (Perfex 3.4.x)
    (function moveHeaderLogoToSidebar() {
        // Only on desktop/tablet widths; keep header logo on mobile where sidebar is hidden.
        if (window.matchMedia && !window.matchMedia('(min-width: 768px)').matches) return;

        var $logo = $('#header #logo');
        var $menu = $('#menu');

        if ($logo.length === 0 || $menu.length === 0) return;
        if ($('#office-sidebar-logo').length > 0) return;

        var $sidebarLogo = $logo.clone(true, true);
        $sidebarLogo.attr('id', 'office-sidebar-logo');
        // Remove Tailwind utility classes to avoid layout surprises; we style via theme CSS.
        $sidebarLogo.removeAttr('class');

        $menu.prepend($sidebarLogo);
        $('body').addClass('office_logo_in_sidebar');
    })();

    // Theme customizer header background (use CSS variables instead of hardcoded colors)
    (function styleCustomizerHeader() {
        var primaryDark = getComputedStyle(document.documentElement)
            .getPropertyValue('--color-primary-dark')
            .trim() || '#3b82f6';

        $('li:has(a.close-customizer)').css({
            'background': primaryDark,
            'height': '62px'
        });
    })();

    // Add butons wave effects
    if (window.Waves) {
        Waves.init();
        Waves.attach('.btn', ['waves-effect', 'waves-light', 'waves-ripple']);
    }

    // Change chart default font color (guard for Chart.js v2/v3+ and missing charts on some pages)
    if (window.Chart && Chart.defaults) {
        var textColor = getComputedStyle(document.documentElement)
            .getPropertyValue('--text-primary')
            .trim() || '#111827';

        // Chart.js v2
        if (Chart.defaults.global) {
            Chart.defaults.global.defaultFontColor = textColor;
        }
        // Chart.js v3+
        if ('color' in Chart.defaults) {
            Chart.defaults.color = textColor;
        }
    }
    // Ini nanobar
    if (window.Nanobar) {
        var options = {
            target: document.getElementsByTagName("BODY")[0]
        };

        var nanobar = new Nanobar(options);
        if (document.readyState == 'loading') {
            nanobar.go(30);
            nanobar.go(76);
            nanobar.go(100);
        }
    }


})(jQuery);