/* ICON FINAL CLEANUP - สุดท้ายแล้ว ไอคอนเดียวเท่านั้น! */
/* HIGHEST PRIORITY - Override everything */

/* ===== ULTIMATE DUPLICATE PREVENTION ===== */
/* Force single icon per element - NUCLEAR OPTION */
*:not(.rating):not(.stars):not([class*="star-rating"]) > [class*="fa-"] + [class*="fa-"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    left: -99999px !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    z-index: -999 !important;
}

/* ===== SPECIFIC CONTAINER CLEANUP ===== */
/* Mobile Navigation - ONLY ONE ICON */
.mobile-nav-item > i:not(:first-of-type),
.mobile-nav-item > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

.mobile-bottom-nav > * > i:not(:first-of-type),
.mobile-bottom-nav > * > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* Desktop Navigation - ONLY ONE ICON */
.nav-link > i:not(:first-of-type),
.nav-link > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

.desktop-header i:not(:first-of-type),
.desktop-header [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* Contact Section - ONLY ONE ICON */
.contact-item > i:not(:first-of-type),
.contact-item > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

.top-contact-bar > * > i:not(:first-of-type),
.top-contact-bar > * > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* Social Media - ONE ICON PER LINK */
.social-icons a > i:not(:first-of-type),
.social-icons a > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* Product Cards - ONLY ONE ICON PER TYPE */
.product-card > i:not(:first-of-type),
.product-card > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

.group > i:not(:first-of-type),
.group > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* ===== BUTTON AND LINK CLEANUP ===== */
/* Buttons - ONE ICON ONLY */
button > i:not(:first-of-type),
button > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

.btn > i:not(:first-of-type),
.btn > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* Links - ONE ICON ONLY */
a:not(.social-icons a) > i:not(:first-of-type),
a:not(.social-icons a) > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* ===== PSEUDO-ELEMENT CLEANUP ===== */
/* Prevent multiple pseudo-elements */
[class*="fa-"]::after,
.fas::after,
.far::after,
.fab::after {
    display: none !important;
    content: none !important;
}

/* Ensure only ::before shows */
[class*="fa-"]::before {
    display: inline-block !important;
    position: relative !important;
    z-index: 1 !important;
}

/* ===== CART BADGE SPECIFIC ===== */
/* Prevent multiple cart badges */
.cart-count:not(:first-of-type),
.mobile-cart-badge:not(:first-of-type),
.cart-badge:not(:first-of-type) {
    display: none !important;
}

/* ===== GRID AND FLEX SPECIFIC ===== */
/* Grid items - single icon */
.grid > * > i:not(:first-of-type),
.grid > * > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* Flex items - single icon */
.flex > * > i:not(:first-of-type),
.flex > * > [class*="fa-"]:not(:first-of-type) {
    display: none !important;
}

/* ===== RESPONSIVE SPECIFIC ===== */
@media (max-width: 768px) {
    /* Mobile - extra strict */
    .mobile-only > i:not(:first-of-type),
    .mobile-only > [class*="fa-"]:not(:first-of-type) {
        display: none !important;
    }
    
    /* Hide desktop duplicates completely on mobile */
    .desktop-only i,
    .desktop-only [class*="fa-"] {
        display: none !important;
    }
}

@media (min-width: 769px) {
    /* Desktop - extra strict */
    .desktop-only > i:not(:first-of-type),
    .desktop-only > [class*="fa-"]:not(:first-of-type) {
        display: none !important;
    }
    
    /* Hide mobile duplicates completely on desktop */
    .mobile-only i,
    .mobile-only [class*="fa-"] {
        display: none !important;
    }
}

/* ===== STAR RATING EXCEPTION ===== */
/* Allow up to 5 stars in rating containers */
.rating > .fa-star:nth-of-type(-n+5),
.stars > .fa-star:nth-of-type(-n+5),
[class*="star-rating"] > .fa-star:nth-of-type(-n+5),
.product-rating > .fa-star:nth-of-type(-n+5) {
    display: inline-block !important;
}

/* Hide excess stars (more than 5) */
.rating > .fa-star:nth-of-type(n+6),
.stars > .fa-star:nth-of-type(n+6),
[class*="star-rating"] > .fa-star:nth-of-type(n+6),
.product-rating > .fa-star:nth-of-type(n+6) {
    display: none !important;
}

/* ===== JAVASCRIPT GENERATED CLEANUP ===== */
/* Clean up dynamically added icons */
[data-duplicate-removed="true"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

.fa-loaded + .fa-loaded:not(.rating *):not(.stars *) {
    display: none !important;
}

/* ===== EMOJI FALLBACK CLEANUP ===== */
/* Prevent emoji + icon duplication */
.emoji-fallback + [class*="fa-"],
[class*="fa-"] + .emoji-fallback {
    display: none !important;
}

/* Hide emoji when FontAwesome is loaded */
.fa-loaded ~ .emoji-fallback,
.fa-loaded + .emoji-fallback {
    display: none !important;
}

/* ===== FORCE CLEAN STATE ===== */
/* Remove any conflicting styles */
[class*="fa-"] {
    text-decoration: none !important;
    background-image: none !important;
    list-style: none !important;
}

/* Ensure proper font family */
[class*="fa-"] {
    font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Brands', 'FontAwesome' !important;
}

/* ===== NUCLEAR OPTION - LAST RESORT ===== */
/* If all else fails, hide everything except first icon globally */
body [class*="fa-"]:not(.rating *):not(.stars *):not([class*="star-rating"] *) {
    counter-increment: icon-count;
}

body [class*="fa-"]:not(.rating *):not(.stars *):not([class*="star-rating"] *):not(:first-of-type) {
    display: none !important;
}

/* Reset counter for each container */
.mobile-nav-item,
.nav-link,
.contact-item,
.social-icons a,
.product-card,
.group,
button,
.btn {
    counter-reset: icon-count;
}

/* ===== DEBUG HELPER ===== */
.debug-icon-cleanup [class*="fa-"] {
    border: 1px solid blue !important;
    margin: 1px !important;
}

.debug-icon-cleanup [class*="fa-"]:not(:first-of-type) {
    border-color: red !important;
    background: rgba(255, 0, 0, 0.1) !important;
}

.debug-icon-cleanup [class*="fa-"]:not(:first-of-type)::before {
    content: "DUP" !important;
    color: red !important;
    font-size: 8px !important;
    position: absolute !important;
    top: -10px !important;
    left: 0 !important;
    background: white !important;
    padding: 1px !important;
}

/* ===== PERFORMANCE OPTIMIZATION ===== */
/* Use CSS containment for better performance */
[class*="fa-"] {
    contain: style layout !important;
}

/* ===== FINAL OVERRIDE ===== */
/* This is the last word - NO MORE DUPLICATES! */
* > [class*="fa-"] ~ [class*="fa-"]:not(.rating [class*="fa-"]):not(.stars [class*="fa-"]):not([class*="star-rating"] [class*="fa-"]) {
    display: none !important;
    position: absolute !important;
    left: -99999px !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    visibility: hidden !important;
    z-index: -999999 !important;
    pointer-events: none !important;
}

/* ===== IMPORTANT DECLARATIONS ===== */
/* Make sure these rules have highest specificity */
html body * > [class*="fa-"] + [class*="fa-"]:not(.rating *):not(.stars *):not([class*="star-rating"] *) {
    display: none !important;
}

/* ===== ACCESSIBILITY PRESERVATION ===== */
/* Ensure screen readers don't see duplicates */
[class*="fa-"][style*="display: none"],
[class*="fa-"][hidden],
[data-duplicate-removed="true"] {
    speak: none !important;
    aria-hidden: true !important;
}

/* Only first icon should be accessible */
[class*="fa-"]:first-of-type {
    speak: auto !important;
    aria-hidden: false !important;
}

