/* ================================
   AJAX SEARCH SUGGESTIONS STYLES
   ================================ */

/* Search Suggestions Container */
.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--site-color-bg);
    border: 2px solid var(--site-color-border);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    max-height: 400px;
    overflow-y: auto;
    margin-top: 4px;
    font-family: var(--font-primary);
}

.search-suggestions--mobile {
    position: relative;
    margin-top: 8px;
    max-height: 300px;
    width: 100%;
    box-sizing: border-box;
    /* Prevent layout shifts */
    contain: layout style;
}

/* Search Suggestions Content */
.search-suggestions__content {
    padding: 0;
}

/* Search Sections */
.search-section {
    border-bottom: 1px solid var(--site-color-border);
}

.search-section:last-child {
    border-bottom: none;
}

.search-section__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--site-color-surface);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--site-color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--site-color-border);
}

.search-section__header i {
    font-size: 0.7rem;
    opacity: 0.7;
}

.search-section__items {
    padding: 0;
}

/* Search Items */
.search-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--site-color-text-primary);
    border-bottom: 1px solid var(--site-color-border);
    transition: all 0.2s ease;
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background: var(--site-color-surface);
    color: var(--site-color-text-strong);
    text-decoration: none;
}

/* Product Items */
.search-item--product .search-item__image {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--site-color-surface);
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-item--product .search-item__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.search-item__placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--site-color-text-muted);
    font-size: 0.9rem;
}

.search-item__content {
    flex: 1;
    min-width: 0;
}

.search-item__title {
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-item__price {
    font-size: 0.8rem;
    color: var(--site-color-accent);
    font-weight: 600;
}

.search-item__type {
    font-size: 0.75rem;
    color: var(--site-color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Category and Brand Items */
.search-item--category .search-item__icon,
.search-item--brand .search-item__icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--site-color-accent);
    color: var(--site-color-text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.search-item--brand .search-item__icon {
    background: var(--site-color-text-strong);
}

/* Highlight Text */
.search-item mark {
    background: var(--site-color-accent);
    color: var(--site-color-text-inverse);
    padding: 0.1em 0.2em;
    border-radius: 3px;
    font-weight: 600;
}

/* Loading State */
.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem;
    color: var(--site-color-text-muted);
    font-size: 0.9rem;
}

.search-loading i {
    color: var(--site-color-accent);
}

/* No Results */
.search-no-results {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem;
    color: var(--site-color-text-muted);
    font-size: 0.9rem;
    text-align: center;
}

.search-no-results i {
    opacity: 0.5;
}

/* Error State */
.search-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem;
    color: #dc3545;
    font-size: 0.9rem;
    text-align: center;
}

/* Footer with "View all results" */
.search-footer {
    border-top: 2px solid var(--site-color-border);
    background: var(--site-color-surface);
}

.search-view-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--site-color-accent);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.search-view-all:hover {
    background: var(--site-color-accent);
    color: var(--site-color-text-inverse);
    text-decoration: none;
}

.search-view-all i {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.search-view-all:hover i {
    transform: translateX(2px);
}

/* ================================
   RESPONSIVE DESIGN
   ================================ */

/* Mobile Adjustments */
@media (max-width: 768px) {
    .search-suggestions {
        border-radius: 6px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
        width: 100%;
        max-width: none;
        left: 0;
        right: 0;
    }
    
    .search-suggestions--mobile {
        position: static;
        margin-top: 8px;
        max-height: 300px;
        width: 100%;
        border-radius: 8px;
        z-index: 50;
    }
    
    .search-item {
        padding: 0.6rem 0.75rem;
        gap: 0.6rem;
        min-height: 48px; /* Touch-friendly minimum */
    }
    
    .search-item--product .search-item__image {
        width: 36px;
        height: 36px;
        border-radius: 4px;
    }
    
    .search-item__title {
        font-size: 0.85rem;
        line-height: 1.2;
        /* Allow multiline on mobile */
        white-space: normal;
        overflow: visible;
        text-overflow: initial;
    }
    
    .search-item__price {
        font-size: 0.75rem;
    }
    
    .search-section__header {
        padding: 0.6rem 0.75rem;
        font-size: 0.75rem;
    }
    
    .search-view-all {
        padding: 0.6rem 0.75rem;
        font-size: 0.8rem;
        min-height: 44px;
    }
    
    /* Ensure mobile drawer search container has proper positioning */
    .drawer-search {
        position: relative;
        overflow: visible;
        z-index: 60;
    }
    
    .drawer-search__form {
        position: relative;
        z-index: 61;
    }
    
    .drawer-search__input {
        width: 100%;
        box-sizing: border-box;
    }
}

/* Small mobile screens */
@media (max-width: 480px) {
    .search-suggestions--mobile {
        max-height: 280px;
        margin-top: 6px;
    }
    
    .search-item {
        padding: 0.5rem 0.6rem;
        gap: 0.5rem;
        min-height: 44px;
    }
    
    .search-item--product .search-item__image {
        width: 32px;
        height: 32px;
        border-radius: 4px;
    }
    
    .search-item--category .search-item__icon,
    .search-item--brand .search-item__icon {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
        border-radius: 4px;
    }
    
    .search-item__title {
        font-size: 0.8rem;
        line-height: 1.2;
    }
    
    .search-item__price {
        font-size: 0.7rem;
    }
    
    .search-section__header {
        padding: 0.5rem 0.6rem;
        font-size: 0.7rem;
    }
    
    .search-view-all {
        padding: 0.5rem 0.6rem;
        font-size: 0.75rem;
        min-height: 40px;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .search-suggestions--mobile {
        max-height: 260px;
        margin-top: 4px;
    }
    
    .search-item {
        padding: 0.4rem 0.5rem;
        gap: 0.4rem;
        min-height: 40px;
    }
    
    .search-item--product .search-item__image {
        width: 28px;
        height: 28px;
    }
    
    .search-item--category .search-item__icon,
    .search-item--brand .search-item__icon {
        width: 24px;
        height: 24px;
        font-size: 0.6rem;
    }
    
    .search-item__title {
        font-size: 0.75rem;
        line-height: 1.1;
    }
    
    .search-item__price {
        font-size: 0.65rem;
    }
}

/* ================================
   DESKTOP SEARCH SPECIFIC
   ================================ */

/* Ensure desktop search suggestions appear above other content */
.navbar-search__form {
    position: relative;
}

.navbar-search {
    position: relative;
    z-index: 100;
}

#desktop-search-suggestions {
    min-width: 400px;
}

/* ================================
   MOBILE DRAWER SEARCH FIXES
   ================================ */

/* Fix drawer search container to prevent overflow issues */
.site-drawer__panel .drawer-search {
    position: relative;
    overflow: visible !important;
    margin-bottom: 1rem;
}

/* Ensure mobile search suggestions don't get clipped */
.site-drawer__panel {
    overflow-x: hidden;
    overflow-y: auto;
}

/* Mobile search suggestions specific positioning */
#mobile-search-suggestions {
    position: relative !important;
    width: 100%;
    max-width: 100%;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Prevent horizontal scroll on small screens */
@media (max-width: 480px) {
    .search-item__content {
        min-width: 0;
        flex: 1;
        overflow: hidden;
    }
    
    .search-item__title {
        word-break: break-word;
        hyphens: auto;
    }
    
    .search-suggestions--mobile {
        margin-left: 0;
        margin-right: 0;
        border-left: 1px solid var(--site-color-border);
        border-right: 1px solid var(--site-color-border);
        border-radius: 8px;
        /* Ensure it doesn't exceed viewport */
        max-width: calc(100vw - 20px);
        /* Prevent content from breaking out */
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* Fix for very narrow screens */
    .drawer-search {
        padding-left: 0;
        padding-right: 0;
    }
}

/* ================================
   CRITICAL MOBILE FIXES
   ================================ */

/* Ensure mobile search container doesn't cause layout shifts */
.search-suggestions--mobile[hidden] {
    display: none !important;
}

.search-suggestions--mobile:not([hidden]) {
    display: block;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
        overflow: hidden;
    }
    to {
        opacity: 1;
        max-height: 400px;
        overflow: visible;
    }
}

/* Prevent mobile keyboard viewport issues */
@media (max-width: 768px) and (max-height: 600px) {
    .search-suggestions--mobile {
        max-height: 200px;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 1000;
    }
}

/* Fix for mobile browsers with viewport units issues */
@supports (height: 100dvh) {
    @media (max-width: 768px) and (max-height: 600px) {
        .search-suggestions--mobile {
            max-height: min(200px, 30dvh);
        }
    }
}

/* ================================
   DARK MODE SUPPORT (if needed)
   ================================ */

@media (prefers-color-scheme: dark) {
    .search-suggestions {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }
    
    .search-item mark {
        background: var(--site-color-accent);
        color: var(--site-color-bg);
    }
}

/* ================================
   ACCESSIBILITY IMPROVEMENTS
   ================================ */

/* Focus states */
.search-item:focus {
    outline: 2px solid var(--site-color-accent);
    outline-offset: -2px;
    background: var(--site-color-surface);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .search-item,
    .search-view-all,
    .search-view-all i {
        transition: none;
    }
    
    .search-loading i {
        animation: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .search-suggestions {
        border-width: 3px;
    }
    
    .search-item mark {
        outline: 2px solid currentColor;
    }
}

/* ================================
   SCROLLBAR STYLING
   ================================ */

.search-suggestions {
    scrollbar-width: thin;
    scrollbar-color: var(--site-color-border) transparent;
}

.search-suggestions::-webkit-scrollbar {
    width: 6px;
}

.search-suggestions::-webkit-scrollbar-track {
    background: transparent;
}

.search-suggestions::-webkit-scrollbar-thumb {
    background-color: var(--site-color-border);
    border-radius: 3px;
}

.search-suggestions::-webkit-scrollbar-thumb:hover {
    background-color: var(--site-color-text-muted);
}