/* ============================================
   SEARCH RESULTS PAGE - OVERRIDE STYLES
   ============================================ */

/* Target the search results page specifically */
.search-page #search-form,
.buscar-page #search-form,
.results-page #search-form {
    display: flex !important;
    justify-content: center !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* More specific selector for results page */
.search-box #search-form:not(.hero-search-form) .input-group {
    max-width: 500px !important;
    width: 100% !important;
    margin: 0 auto !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    border: 1px solid #dee2e6 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-wrap: nowrap !important;
}

/* Specific selector for results page input */
.search-box #search-input:not(.hero-search-input) {
    height: 48px !important;
    border-radius: 0 !important;
    border: none !important;
    background: white !important;
    color: #333 !important;
    font-size: 1rem !important;
    padding: 10px 15px !important;
    border-right: 1px solid #dee2e6 !important;
    flex: 1 1 auto !important; /* Takes available space */
    min-width: 0 !important; /* Allows shrinking */
    backdrop-filter: none !important;
}

/* Reset placeholder for results page */
.search-box #search-input:not(.hero-search-input)::placeholder {
    color: #6c757d !important;
    opacity: 0.9;
    letter-spacing: normal !important;
}

/* Specific selector for results page button */
.search-box .btn.search-btn:not(.hero-search-btn) {
    height: 48px !important;
    border-radius: 0 !important;
    padding: 0 25px !important;
    background: #CC0000 !important;
    border: none !important;
    font-size: 1rem !important;
    min-width: auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background-color 0.3s ease !important;
    flex-shrink: 0 !important; /* Prevents button from shrinking */
    white-space: nowrap !important;
    width: auto !important; /* Auto width based on content */
}

/* Reset icon styles for results page */
.search-box .btn.search-btn:not(.hero-search-btn) i {
    font-size: 1rem !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: normal !important;
}

/* Hover state for results page button */
.search-box .btn.search-btn:not(.hero-search-btn):hover {
    background: #c82333 !important;
    transform: none !important;
    box-shadow: none !important;
    border: none !important;
}

/* Focus state for results page input */
.search-box #search-input:not(.hero-search-input):focus {
    background: white !important;
    border-color: #86b7fe !important;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
    outline: 0 !important;
    color: #333 !important;
    z-index: 3 !important;
}

/* Results page suggestions */
.search-box #search-suggestions:not(.hero-suggestions) {
    position: absolute !important;
    top: 100% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 500px !important;
    max-width: 90vw !important;
    background: white !important;
    border: 1px solid #dee2e6 !important;
    border-radius: 4px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    z-index: 1000 !important;
    max-height: 300px !important;
    overflow-y: auto !important;
    margin-top: 5px !important;
}

/* ============================================
   SIMPLE NUCLEAR OPTION: Override everything
   ============================================ */
/* Add this if nothing else works */
.search-box:not(.hero-search-box) .input-group {
    border: 1px solid #dee2e6 !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    max-width: 500px !important;
    margin: 0 auto !important;
    overflow: hidden !important;
    display: flex !important;
    
    border-color: var(--primary-red-color);
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);    
}

.search-box:not(.hero-search-box) #search-input {
    height: 48px !important;
    border: none !important;
    border-right: 1px solid #dee2e6 !important;
    background: white !important;
    color: #333 !important;
    border-radius: 0 !important;
    font-size: 1rem !important;
    padding: 10px 15px !important;
    flex: 1 1 70% !important; /* Takes 70% of space, can grow/shrink */
    min-width: 200px !important; /* Minimum width */
}

.search-box:not(.hero-search-box) .btn.search-btn {
    height: 48px !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 20px !important; /* Reduced from 25px */
    background: #CC0000 !important;
    font-size: 1rem !important;
    flex: 0 0 auto !important; /* Doesn't grow or shrink */
    width: auto !important;
    min-width: 90px !important; /* Fixed minimum width */
    max-width: 120px !important; /* Maximum width */
}

/* ============================================
   SEARCH ISOLATION FROM MEGA MENU - CRITICAL FIXES
   ============================================ */

/* When search suggestions are visible, mega menu should be hidden */
#search-suggestions.dropdown-menu.show ~ .mega-menu,
#search-suggestions.dropdown-menu.show ~ .mega-menu-overlay,
body:has(#search-suggestions.dropdown-menu.show) .mega-menu,
body:has(#search-suggestions.dropdown-menu.show) .mega-menu-overlay {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    z-index: 1 !important;
}

/* Search suggestions should be above everything - INCLUDING MEGA MENU */
#search-suggestions.dropdown-menu.show {
    z-index: 9999 !important;
    position: absolute !important;
}

/* Search inputs should close mega menu when focused */
.search-input:focus,
.hero-search-input:focus,
.search-isolated-input:focus {
    z-index: 1001 !important;
}

/* Emergency override for navbar - search should win */
#mainNavbar #search-suggestions {
    z-index: 9999 !important;
}

/* Make sure search doesn't trigger mega menu */
.search-form *,
#hero-search-form *,
.search-container *,
.hero-input-group * {
    pointer-events: auto !important;
}

/* When search is active, lower mega menu z-index */
.search-active .mega-menu,
.search-active .mega-menu-overlay {
    z-index: 1 !important;
}

/* Prevent mega menu from capturing search events */
.search-form,
#hero-search-form,
.search-container,
.hero-input-group,
.search-isolated-container {
    isolation: isolate;
    position: relative;
}

/* ============================================
   GENERAL SEARCH STYLES
   ============================================ */

/* Search Suggestions */
#search-suggestions {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    z-index: 9999 !important; /* CRITICAL: Higher than mega menu (1090) */
    max-height: 400px;
    overflow-y: auto;
}

#search-suggestions .dropdown-item {
    transition: background-color 0.2s;
    border-bottom: 1px solid #f8f9fa;
}

#search-suggestions .dropdown-item:hover {
    background-color: #f8f9fa;
}

#search-suggestions .dropdown-item:last-child {
    border-bottom: none;
}

#search-suggestions .dropdown-divider {
    margin: 0.25rem 0;
}

/* Highlight search terms in results */
.search-highlight {
    background-color: #fff3cd;
    padding: 0.1em 0.2em;
    border-radius: 0.2em;
}

/* Search result cards in search page */
.search-result-card {
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid #dee2e6;
}

.search-result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.search-result-card .card-title a {
    color: #212529;
}

.search-result-card .card-title a:hover {
    color: #CC0000;
    text-decoration: underline;
}

/* Loading indicator for search */
.search-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #CC0000;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   RESPONSIVE STYLES - FIXED FOR MOBILE
   ============================================ */

/* Tablet and mobile */
@media (max-width: 768px) {
    .search-box:not(.hero-search-box) .input-group {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    .search-box:not(.hero-search-box) #search-input {
        height: 50px !important;
        font-size: 1rem !important;
        padding: 12px 15px !important;
        min-height: 50px !important;
        flex: 1 1 75% !important; /* Input gets 75% of space on mobile */
        min-width: 180px !important;
    }
    
    .search-box:not(.hero-search-box) .btn.search-btn {
        height: 50px !important;
        padding: 0 15px !important; /* Reduced padding */
        font-size: 0.9rem !important;
        flex: 0 0 auto !important;
        min-width: 80px !important;
        max-width: 100px !important;
    }
    
    /* Hide button text, show only icon on mobile */
    .search-box:not(.hero-search-box) .btn.search-btn .btn-text,
    .search-box:not(.hero-search-box) .btn.search-btn span:not(.fa-search) {
        display: none !important;
    }
    
    .search-box:not(.hero-search-box) .btn.search-btn i {
        margin-right: 0 !important;
        font-size: 1.1rem !important;
    }
    
    /* Search suggestions responsive - ensure they stay above mega menu */
    #search-suggestions {
        max-height: 300px;
        font-size: 1rem !important;
        z-index: 9999 !important; /* Keep high on mobile */
    }
}

/* Small phones */
@media (max-width: 576px) {
    .search-box:not(.hero-search-box) #search-input {
        height: 52px !important;
        font-size: 1.05rem !important;
        padding: 14px 12px !important;
        min-height: 52px !important;
        flex: 1 1 80% !important; /* Input gets 80% of space */
        min-width: 150px !important;
    }
    
    .search-box:not(.hero-search-box) .btn.search-btn {
        height: 52px !important;
        padding: 0 12px !important; /* Even less padding */
        font-size: 0.85rem !important;
        min-width: 70px !important;
        max-width: 80px !important;
    }
    
    .search-box:not(.hero-search-box) .btn.search-btn i {
        font-size: 1.1rem !important;
        margin: 0 !important;
    }
    
    /* Mobile search isolation - ensure it works on small screens */
    .search-container,
    .hero-input-group {
        z-index: 1000 !important;
    }
}

/* Extra small devices */
@media (max-width: 400px) {
    .search-box:not(.hero-search-box) #search-input {
        height: 54px !important;
        font-size: 1rem !important;
        padding: 15px 10px !important;
        flex: 1 1 85% !important; /* Input gets 85% of space */
        min-width: 120px !important;
    }
    
    .search-box:not(.hero-search-box) .btn.search-btn {
        height: 54px !important;
        padding: 0 8px !important; /* Minimal padding */
        min-width: 60px !important;
        max-width: 70px !important;
    }
    
    /* Larger icon for better visibility */
    .search-box:not(.hero-search-box) .btn.search-btn i {
        font-size: 1.3rem !important;
        margin: 0 !important;
    }
}

/* Mobile responsive for search results cards */
@media (max-width: 767.98px) {
    .search-result-card .float-md-start {
        float: left !important;
        margin-right: 15px !important;
        margin-bottom: 10px !important;
    }
    
    .search-result-card .overflow-hidden {
        overflow: visible !important;
    }
    
    .search-result-card .img-thumbnail {
        max-width: 100px;
        height: 100px;
    }
}

/* Remove duplicate/conflicting mobile styles */
@media (max-width: 768px) {
    /* Remove these conflicting styles */
    .search-input {
        font-size: 1rem !important;
    }
}

@media (max-width: 576px) {
    /* Remove these conflicting styles */
    .search-form .input-group {
        flex-wrap: nowrap;
    }
    
    .search-form .form-control {
        font-size: 0.9rem;
        padding: 0.375rem 0.75rem;
    }
    
    .search-form .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.9rem;
    }
}

/* ===========================
   ISOLATED SEARCH STYLES - UPDATED
   =========================== */

/* Container that isolates search from navbar */
.search-isolated-container {
    position: relative;
    z-index: 1000;
    isolation: isolate;
    pointer-events: auto;
}

/* Ensure search doesn't affect navbar */
.search-isolated-container * {
    box-sizing: border-box;
}

/* Search input - isolated from mega menu */
.search-isolated-input {
    position: relative;
    z-index: 1001 !important;
    pointer-events: auto !important;
}

/* Search results - isolated from mega menu */
.search-results-isolated {
    position: absolute !important;
    z-index: 9999 !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    background: white !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    border-radius: 8px !important;
    margin-top: 10px !important;
    border: 1px solid var(--border-color) !important;
    pointer-events: auto !important;
}

/* Add this to prevent mega menu from capturing events */
.search-results-isolated * {
    pointer-events: auto !important;
}

/* When search is active, ensure mega menu is below */
.search-active .mega-menu,
.search-active .desktop-mega-menu,
.search-active .mega-menu-overlay {
    z-index: 1 !important;
    opacity: 0.5 !important;
}

/* When mega menu is active, ensure search is below */
.nav-item.dropdown.active .search-isolated-container {
    z-index: 900 !important;
}

/* ===========================
   FINAL EMERGENCY FIXES
   =========================== */

/* Force search to be above mega menu at all times */
.search-input,
.hero-search-input,
.search-form,
#hero-search-form,
.search-container,
.hero-input-group {
    position: relative;
    z-index: 1000 !important;
}

/* When typing in search, ensure mega menu stays hidden */
.search-input:focus ~ .mega-menu,
.search-input:focus ~ .mega-menu-overlay,
.hero-search-input:focus ~ .mega-menu,
.hero-search-input:focus ~ .mega-menu-overlay {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Ensure search suggestions block mega menu clicks */
#search-suggestions.dropdown-menu.show {
    pointer-events: auto !important;
}

/* Prevent any search element from triggering mega menu */
[class*="search"]:not(.mega-menu):not(.desktop-mega-menu):not(.mobile-mega-menu) {
    pointer-events: auto !important;
}

/* ── Hero search suggestion items ─────────────────────────── */
#search-suggestions .sugg-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .9rem;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none;
    color: inherit;
    transition: background .15s;
}
#search-suggestions .sugg-item:hover {
    background: #fdf4f4;
}
.sugg-thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 7px;
    flex-shrink: 0;
    border: 1px solid #eee;
}
.sugg-thumb-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    color: #aaa;
    font-size: .95rem;
}
.sugg-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.sugg-name {
    font-size: .9rem;
    font-weight: 600;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sugg-cat {
    font-size: .75rem;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* View-all footer row */
#search-suggestions .sugg-viewall {
    display: block;
    text-align: center;
    padding: .55rem;
    font-size: .85rem;
    font-weight: 700;
    color: #CC0000;
    text-decoration: none;
    border-top: 1px solid #eee;
}
#search-suggestions .sugg-viewall:hover { background: #fff5f5; }
