<!-- === COMPACT MULTI-LINE CATEGORY QUICK FILTERS START === -->
<style>
    .quick-filters-container {
        display: flex;
        flex-wrap: wrap;           /* Allows wrapping to 2 or 3 lines */
        justify-content: center;   /* Center aligns the buttons */
        gap: 6px;                  /* Small gap between buttons */
        margin-bottom: 15px;
    }
    .quick-filter-btn {
        background-color: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 50px;       /* Pill shape */
        padding: 5px 10px;         /* Smaller padding for compact look */
        font-size: 12px;           /* Smaller text size */
        font-weight: 500;
        color: #475569;
        display: flex;
        align-items: center;
        gap: 4px;                  /* Less gap between icon and text */
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 1px 2px rgba(0,0,0,0.02);
        white-space: nowrap;       
    }
    .quick-filter-btn:hover {
        border-color: #cbd5e1;
        background-color: #f8fafc;
    }
    .quick-filter-btn.active-filter {
        border-color: #3b82f6;
        color: #1d4ed8;
        background-color: #eff6ff;
    }
    .quick-filter-btn i {
        font-size: 14px;           /* Slightly smaller icons */
    }
</style>

<div class="quick-filters-container">
    <button type="button" class="quick-filter-btn active-filter" onclick="filterCategoryPanel('All', this)">
        <i class="bi bi-grid-fill" style="color: #64748b;"></i> All
    </button>
    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Instagram', this)">
        <i class="fab fa-instagram" style="color: #E1306C;"></i> Instagram
    </button>
    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('YouTube', this)">
        <i class="fab fa-youtube" style="color: #FF0000;"></i> YouTube
    </button>
    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('TikTok', this)">
        <i class="fab fa-tiktok" style="color: #000000;"></i> TikTok
    </button>
    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Facebook', this)">
        <i class="fab fa-facebook" style="color: #1877F2;"></i> Facebook
    </button>
    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Telegram', this)">
        <i class="fab fa-telegram" style="color: #0088cc;"></i> Telegram
    </button>
    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Twitter', this)">
        <i class="fab fa-twitter" style="color: #1DA1F2;"></i> Twitter
    </button>
    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Whatsapp', this)">
        <i class="fab fa-whatsapp" style="color: #25D366;"></i> WhatsApp
    </button>
</div>

<script>
document.addEventListener("DOMContentLoaded", function() {
    if(typeof jQuery !== 'undefined') {
        // Page load hote hi saari original categories memory me save
        window.allCategoryOptions = jQuery('#neworder_category').html();
    }
});

function filterCategoryPanel(platform, btnElement) {
    if(typeof jQuery === 'undefined') return;

    jQuery('.quick-filter-btn').removeClass('active-filter');
    jQuery(btnElement).addClass('active-filter');

    let catSelect = jQuery('#neworder_category');
    
    // Filter karne se pehle saari original categories wapas laana
    if(window.allCategoryOptions) {
        catSelect.html(window.allCategoryOptions);
    }

    // Har platform ke multiple naam (FB, IG, YT)
    const keywords = {
        'Instagram': ['instagram', 'ig', 'insta'],
        'YouTube':   ['youtube', 'yt', 'views'],
        'TikTok':    ['tiktok', 'tik tok'],
        'Facebook':  ['facebook', 'fb'],
        'Telegram':  ['telegram', 'tg'],
        'Twitter':   ['twitter', 'x'],
        'Whatsapp':  ['whatsapp', 'wa']
    };

    if (platform !== 'All') {
        let searchWords = keywords[platform] || [platform.toLowerCase()];
        
        catSelect.find('option').each(function() {
            let text = jQuery(this).text().toLowerCase();
            let isMatch = false;
            
            for(let i=0; i<searchWords.length; i++) {
                if (text.includes(searchWords[i].toLowerCase())) {
                    isMatch = true;
                    break;
                }
            }
            
            if (!isMatch) {
                jQuery(this).remove(); // Jo match nahi hua usko hata diya
            }
        });
    }

    // Pehli category automatically select
    catSelect.prop('selectedIndex', 0);
    catSelect.trigger('change'); 
    
    if (typeof jQuery.fn.selectpicker !== 'undefined') {
        catSelect.selectpicker('refresh');
    }
    if (typeof jQuery.fn.select2 !== 'undefined') {
        catSelect.trigger('change.select2');
    }
    
    let customContainer = jQuery('#select-category-container');
    if(customContainer.length) {
        catSelect.trigger('input');
    }
}
</script>
<!-- === COMPACT MULTI-LINE CATEGORY QUICK FILTERS END === -->