/**
 * Enhanced Search Styles
 * - Lịch sử tìm kiếm
 * - Autocomplete dropdown
 * - Mobile responsive
 */

/* Dropdown Container - appended to body */
.enhanced-search-dropdown {
    position: fixed !important;
    background: #fff !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15) !important;
    z-index: 99999 !important;
    display: none !important;
    max-height: 60vh !important;
    overflow-y: auto !important;
    min-width: 300px !important;
}

.enhanced-search-dropdown.active {
    display: block !important;
}

/* Search History Section */
.search-history-section {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
}

.search-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.search-history-title {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.search-history-clear {
    font-size: 12px;
    color: #999;
    cursor: pointer;
    transition: color 0.2s;
    background: none;
    border: none;
    padding: 0;
}

.search-history-clear:hover {
    color: #e74c3c;
}

.search-history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.search-history-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f5f5f5;
    border-radius: 20px;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    transition: all 0.2s;
}

.search-history-item:hover {
    background: #e8e8e8;
}

.search-history-item .history-icon {
    width: 14px;
    height: 14px;
    opacity: 0.5;
}

/* Search Suggestions Section (cấu hình trong admin) */
.search-suggestions-section {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
}

.search-suggestions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.search-suggestions-title {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.search-suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.search-suggestion-item {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    transition: all 0.2s;
}

.search-suggestion-item:hover {
    background: #f0f7ff;
    border-color: #0070ae;
    color: #0070ae;
}


/* Autocomplete Results */
.search-results-section {
    padding: 8px 0;
}

.search-results-header {
    padding: 8px 16px;
    font-size: 12px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Product Item */
.search-product-item {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 10px 16px !important;
    cursor: pointer !important;
    transition: background 0.15s !important;
    text-decoration: none !important;
    color: inherit !important;
}

.search-product-item:hover {
    background: #f8f8f8 !important;
}

.search-product-image {
    width: 50px !important;
    height: 50px !important;
    min-width: 50px !important;
    border-radius: 6px !important;
    object-fit: cover !important;
    background: #f5f5f5 !important;
}

.search-product-info {
    flex: 1;
    min-width: 0;
}

.search-product-name {
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #333 !important;
    margin: 0 0 4px 0 !important;
    line-height: 1.3 !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-product-price {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #e74c3c !important;
}

.search-product-price del {
    font-size: 12px !important;
    color: #999 !important;
    font-weight: 400 !important;
    margin-right: 6px !important;
}

.search-product-price ins {
    text-decoration: none !important;
}

/* View All Link */
.search-view-all {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    padding: 14px 16px !important;
    background: #f8f8f8 !important;
    color: #2563eb !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    text-decoration: none !important;
    transition: background 0.2s !important;
    border-top: 1px solid #eee !important;
}

.search-view-all:hover {
    background: #f0f0f0 !important;
    color: #1d4ed8 !important;
}

.search-view-all svg {
    width: 16px;
    height: 16px;
}

/* Loading State */
.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #999;
    font-size: 14px;
}

.search-loading::before {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid #e0e0e0;
    border-top-color: #2563eb;
    border-radius: 50%;
    margin-right: 10px;
    animation: enhanced-search-spin 0.8s linear infinite;
}

@keyframes enhanced-search-spin {
    to { transform: rotate(360deg); }
}

/* No Results */
.search-no-results {
    padding: 24px 16px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

.search-no-results-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* Body scroll lock */
body.enhanced-search-open {
    overflow: hidden !important;
}

/* Overlay - chỉ che content, không che header */
.enhanced-search-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.enhanced-search-overlay.active {
    display: block;
}

/* No special fix needed - dropdown is appended to body */

/* ========================================
   MOBILE FULLSCREEN SEARCH
   ======================================== */

@media (max-width: 991px) {
    /* Mobile fullscreen container - hidden by default */
    .enhanced-search-mobile-fullscreen {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        border: none !important;
        z-index: 999999 !important;
        display: none !important;
        flex-direction: column !important;
        background: #fff !important;
    }

    /* Show only when active */
    .enhanced-search-mobile-fullscreen.active {
        display: flex !important;
    }

    /* Mobile search header with back button and input */
    .mobile-search-header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        background: #0070AE;
        border-bottom: none;
        position: sticky;
        top: 0;
        z-index: 10;
        flex-shrink: 0;
    }

    .mobile-search-back {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        min-width: 40px;
        background: none;
        border: none;
        cursor: pointer;
        color: #fff;
        padding: 0;
        border-radius: 50%;
        transition: background 0.2s;
    }

    .mobile-search-back:hover,
    .mobile-search-back:active {
        background: rgba(255, 255, 255, 0.15);
    }

    .mobile-search-back svg {
        width: 24px;
        height: 24px;
    }

    .mobile-search-input-wrapper {
        flex: 1;
        position: relative;
    }

    .mobile-search-input {
        width: 100%;
        height: 44px;
        padding: 0 16px;
        border: 1px solid #e0e0e0;
        border-radius: 22px;
        font-size: 16px;
        background: #f8f8f8;
        outline: none;
        -webkit-appearance: none;
    }

    .mobile-search-input:focus {
        border-color: #2563eb;
        background: #fff;
    }

    .mobile-search-input::placeholder {
        color: #999;
    }

    /* Mobile search content area */
    .mobile-search-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Hide original dropdown on mobile when fullscreen is active */
    body.mobile-search-active .enhanced-search-dropdown:not(.enhanced-search-mobile-fullscreen) {
        display: none !important;
    }

    /* Hide overlay on mobile fullscreen mode */
    body.mobile-search-active .enhanced-search-overlay {
        display: none !important;
    }

    /* Adjust sections for mobile fullscreen */
    .enhanced-search-mobile-fullscreen .search-history-section {
        padding: 16px;
        border-bottom: none;
    }

    .enhanced-search-mobile-fullscreen .search-history-list {
        gap: 10px;
    }

    .enhanced-search-mobile-fullscreen .search-history-item {
        padding: 10px 16px;
        font-size: 14px;
        background: #f5f5f5;
    }

    .enhanced-search-mobile-fullscreen .search-suggestions-section {
        padding: 16px;
        border-bottom: none;
    }

    .enhanced-search-mobile-fullscreen .search-suggestions-list {
        gap: 10px;
    }

    .enhanced-search-mobile-fullscreen .search-suggestion-item {
        padding: 10px 16px;
        font-size: 14px;
    }

    .enhanced-search-mobile-fullscreen .search-results-section {
        padding: 0;
    }

    .enhanced-search-mobile-fullscreen .search-results-header {
        padding: 12px 16px;
        background: #f8f8f8;
        font-weight: 600;
    }

    .enhanced-search-mobile-fullscreen .search-product-item {
        padding: 14px 16px !important;
        border-bottom: 1px solid #f0f0f0;
    }

    .enhanced-search-mobile-fullscreen .search-product-image {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
    }

    .enhanced-search-mobile-fullscreen .search-product-name {
        font-size: 15px !important;
    }

    .enhanced-search-mobile-fullscreen .search-product-price {
        font-size: 15px !important;
        margin-top: 4px;
    }

    .enhanced-search-mobile-fullscreen .search-view-all {
        margin: 16px;
        border-radius: 8px;
        background: #2563eb !important;
        color: #fff !important;
        border: none !important;
    }

    .enhanced-search-mobile-fullscreen .search-view-all:hover,
    .enhanced-search-mobile-fullscreen .search-view-all:active {
        background: #1d4ed8 !important;
    }

    .enhanced-search-mobile-fullscreen .search-loading {
        padding: 40px 20px;
    }

    .enhanced-search-mobile-fullscreen .search-no-results {
        padding: 60px 20px;
    }

    /* Body state when mobile search is active */
    body.mobile-search-active {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
    }
}

/* Desktop styles remain unchanged */
@media (min-width: 992px) {
    .mobile-search-header {
        display: none !important;
    }
}

/* Overlay hiện trên cả desktop và mobile */
