/* 
   EXTRA FIXES & UI STABILIZATION
   This file contains overrides for mobile UI and visibility safety nets.
*/

/* =============================================
   1. NUCLEAR VISIBILITY SAFETY NET
   Uses pure CSS animation to force-reveal all content after 2s.
   This works even if JavaScript completely fails.
   ============================================= */
@keyframes force-visible {
    to {
        opacity: 1;
        transform: none;
        filter: none;
        visibility: visible;
    }
}

.reveal,
.reveal-up,
.reveal-left,
.reveal-right,
.animate-on-scroll,
.stagger-children > * {
    animation: force-visible 0s 2.5s forwards !important;
}

/* JS-based safety: if body gets page-loaded, show immediately */
body.page-loaded .reveal,
body.page-loaded .reveal-up,
body.page-loaded .reveal-left,
body.page-loaded .reveal-right,
body.page-loaded .animate-on-scroll,
body.page-loaded .stagger-children > * {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    visibility: visible !important;
    animation: none !important;
}

/* When IntersectionObserver fires (adds .visible or .active), 
   cancel the fallback animation and show immediately */
.reveal.visible, .reveal.active,
.reveal-up.visible, .reveal-up.active,
.reveal-left.visible, .reveal-left.active,
.reveal-right.visible, .reveal-right.active,
.animate-on-scroll.visible, .animate-on-scroll.active {
    animation: none !important;
}

/* =============================================
   2. PRELOADER SAFETY - Force hide after 3s via CSS
   ============================================= */
@keyframes preloader-force-hide {
    to {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }
}

.page-preloader {
    animation: preloader-force-hide 0.5s 3s forwards !important;
}

.page-preloader.hide {
    animation: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* =============================================
   3. Mobile UI Specifics
   ============================================= */
@media (max-width: 1023px) {
    /* Hide only the sticky single-product bars on mobile if needed, but KEEP product card buttons */
    .btn-add-to-cart-industrial, 
    .sticky-buy-bar,
    .quick-add-btn {
        display: none !important;
    }

    /* Ensure 2 columns for product grid */
    .featured-grid,
    .lg-grid-3.md-grid-2,
    #products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }

    /* Optimize product cards for 2-column mobile */
    .product-card {
        padding: 0.5rem !important;
    }
    
    .p-title {
        font-size: 0.85rem !important;
        line-height: 1.2 !important;
        margin-bottom: 0.25rem !important;
    }

    .p-price-box {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
    }

    /* Make buttons fit in 2 columns on mobile */
    .p-card-actions {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.25rem !important;
        flex-wrap: wrap !important;
    }

    .btn-card-add, .btn-card-buy {
        display: flex !important;
        padding: 0.35rem 0.5rem !important;
        font-size: 0.7rem !important;
        flex: 1 !important;
        min-width: 0 !important;
        justify-content: center !important;
        align-items: center !important;
    }
    
    .btn-card-add span, .btn-card-buy span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Mobile Header Cleanup for Logged-in Users */
    .nav-actions {
        flex-wrap: nowrap !important;
        gap: 0.35rem !important;
    }
    
    .btn-admin-action {
        padding: 0.45rem !important;
        min-width: 36px;
        min-height: 36px;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }
    
    .login-btn {
        padding: 0.45rem !important;
        min-width: 36px;
        min-height: 36px;
    }
    
    .login-btn span {
        display: none !important;
    }

    /* Mobile Submenu Visibility */
    .mobile-submenu {
        padding-left: 1.5rem;
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        margin-top: 0.5rem;
        margin-bottom: 0.75rem;
        border-left: 2px solid var(--orange);
    }
    
    .mobile-submenu a {
        font-size: 0.9rem !important;
        color: rgba(255, 255, 255, 0.8) !important;
        padding: 0.4rem 0 !important;
        display: block !important;
    }
}

/* =============================================
   4. Cookie Popup Styling
   ============================================= */
.cookie-popup {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    right: 2rem;
    max-width: 450px;
    background: #0a0c10;
    border: 1px solid rgba(245, 117, 57, 0.4);
    border-radius: 12px;
    padding: 1.5rem;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease !important;
}

.cookie-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.cookie-title {
    font-family: var(--font-display);
    font-weight: 700;
    color: #fff;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.cookie-title::before {
    content: "";
    width: 10px;
    height: 10px;
    background: var(--orange);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--orange);
}

.cookie-text {
    color: #94a3b8;
    font-size: 0.85rem;
    line-height: 1.5;
}

.cookie-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-cookie {
    padding: 0.6rem 1.25rem;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease !important;
}

.btn-cookie.accept {
    background: var(--orange);
    color: #fff;
    border: none;
}

.btn-cookie.decline {
    background: transparent;
    color: #94a3b8;
    border: 1px solid rgba(255,255,255,0.1);
}

@media (max-width: 640px) {
    .cookie-popup {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
        max-width: none;
    }
}

/* =============================================
   5. Desktop Grid Settings (Requested by User)
   ============================================= */
@media (min-width: 1024px) {
    #products-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .related-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* =============================================
   6. NUCLEAR GRID UTILITY SYSTEM (CALIBRATED)
   Ensures horizontal grid integrity site-wide.
   ============================================= */
html body .grid, 
html body .site-footer .grid,
html body .footer-main .grid {
    display: grid !important;
}

/* Force horizontal columns for the specific classes used in footers */
html body .lg-grid-4 { 
    grid-template-columns: repeat(4, 1fr) !important; 
    display: grid !important;
}
html body .lg-grid-3 { 
    grid-template-columns: repeat(3, 1fr) !important; 
    display: grid !important;
}

/* Specific Footer Override for standard desktop sizes 1024px+ */
@media (min-width: 1024px) {
    .site-footer .grid.lg-grid-4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* Tablet / Desktop fallback (768px+) */
@media (min-width: 768px) {
    html body .md-grid-2 { 
        grid-template-columns: repeat(2, 1fr) !important; 
        display: grid !important;
    }
}

/* Mobile: Only stack below 768px */
@media (max-width: 767px) {
    html body .grid:not(.no-stack-mobile) { 
        grid-template-columns: 1fr !important; 
    }
}
