/**
 * TanDoanh Search Styles v6.0.2 - White Theme với Border Radius
 * Theo style cũ: nền trắng, border radius 10px, clean design
 */

/* Search Input Field - White theme with border radius */
.header-search-form .search-field,
.header-search-form input[type="search"],
.header-search-form input[name="s"],
.header-search-form .header-search input,
.header-search-form .header-search .search-field,
.header-search-form form.searchform input[type="search"],
.header-search-form .searchform input.search-field,
.header-search-form #searchform input,
.header-search-form .nav-search input {
    border-radius: 10px !important;
    border: 1px solid #e0e0e0 !important;
    background: #ffffff !important;
    color: #333333 !important;
    padding: 8px 15px !important;
    font-size: 14px !important;
    transition: border-color 0.1s ease !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
}

.search-field:focus,
input[type="search"]:focus,
input[name="s"]:focus,
.header-search input:focus,
form.searchform input[type="search"]:focus,
.searchform input.search-field:focus,
#searchform input:focus,
.nav-search input:focus {
    border-color: #446084 !important;
    box-shadow: 0 0 0 2px rgba(68, 96, 132, 0.1) !important;
    outline: none !important;
}

/* Search Form Container */
.searchform,
.header-search-form,
[data-live-search] {
    position: relative;
}

/* Search Results Container - White Theme */
.td-search-results,
.searchform .td-search-results,
.header-search-form .td-search-results,
[data-live-search] .td-search-results {
    position: absolute !important;
    top: calc(100% + 5px) !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 999999 !important;
    background: #ffffff !important;
    color: #333333 !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 10px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    max-height: 500px !important;
    overflow-y: auto !important;
    display: none;
    margin: 0 !important;
    padding: 0 !important;
    /* Instant show - no animation for ultra-fast response */
}

.header-search-form .tandoanh-badge {
    display: none;
}

/* Loading State - White theme */
.td-search-loading,
.td-search-no-results,
.td-search-error {
    padding: 15px 20px !important;
    text-align: center !important;
    color: #666666 !important;
    font-size: 14px !important;
    background: #ffffff !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    border: none !important;
    margin: 0 !important;
    min-height: 50px !important;
}

/* Loading Spinner */
.td-search-loading::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #446084;
    border-radius: 50%;
    animation: tdSearchSpin 0.6s linear infinite;
}

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

/* Search Items List */
.td-search-items {
    max-height: 400px;
    overflow-y: auto;
}

/* Custom Scrollbar - Webkit (Chrome, Safari, Edge) */
.td-search-results::-webkit-scrollbar,
.td-search-items::-webkit-scrollbar {
    width: 6px;
}

.td-search-results::-webkit-scrollbar-track,
.td-search-items::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.td-search-results::-webkit-scrollbar-thumb,
.td-search-items::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

.td-search-results::-webkit-scrollbar-thumb:hover,
.td-search-items::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Custom Scrollbar - Firefox */
.td-search-results,
.td-search-items {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* Individual Search Item - White theme style */
.td-search-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.1s ease;
    text-decoration: none;
    color: #333 !important;
    background-color: #ffffff !important;
}

.td-search-item:hover {
    background-color: #f9f9f9;
}

.td-search-item:last-child {
    border-bottom: none;
}

/* Search Item Link - Full coverage, no underline */
.td-item-link {
    display: flex;
    align-items: center;
    width: 100%;
    text-decoration: none !important;
    color: inherit !important;
}

.td-item-link:hover,
.td-item-link:focus,
.td-item-link:active {
    text-decoration: none !important;
    color: inherit !important;
}

/* Product Image - Clean white style */
.td-item-image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    margin-right: 15px;
    border-radius: 4px;
    overflow: hidden;
    background: #ffffff;
}

.td-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.td-search-item:hover .td-item-image img {
    transform: scale(1.05);
}

/* Product Content */
.td-item-content {
    flex: 1;
    min-width: 0; /* Prevents flex item from overflowing */
}

.td-item-title {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 5px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
}

.td-item-price {
    font-size: 14px;
    font-weight: 600;
    color: #000000;
}

/* WooCommerce price styling - dùng HTML structure <del><span>...ổ</span></del> <ins><span>...</span></ins> */
.td-item-price del {
    text-decoration: line-through;
    color: #999;
    font-weight: normal;
}

.td-item-price ins {
    text-decoration: none;
    color: #dd3333;
    font-weight: 700;
}

.td-item-sku {
    font-size: 12px;
    color: #999;
    margin-bottom: 3px;
}

/* No Results State */
.td-search-no-results {
    padding: 15px 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

.td-search-no-results::before {
    content: "🔍";
    display: block;
    font-size: 24px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* Error State */
.td-search-error {
    padding: 15px 20px;
    text-align: center;
    color: #d32f2f;
    font-size: 14px;
    background: #ffffff;
}

/* View All Results Link */
.td-search-more {
    padding: 12px 15px;
    border-top: 1px solid #f0f0f0;
    background: #ffffff;
}

.td-search-more a {
    display: block;
    text-align: center;
    color: #446084;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    transition: color 0.2s ease;
}

.td-search-more a:hover {
    color: #2c3e50;
}

/* Tablet Responsive */
@media (max-width: 1024px) and (min-width: 769px) {
    .td-search-results {
        max-height: 450px;
    }
    
    .td-search-item {
        padding: 14px 16px;
    }
}

/* High DPI Screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .td-item-image img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Search Active State */
body.td-search-active {
    overflow: hidden;
}

/* Performance Optimizations */
.td-search-results * {
    box-sizing: border-box;
}

/* Prevent text selection on items */
.td-search-item {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Smooth scrolling for search results */
.td-search-items {
    scroll-behavior: smooth;
}

/* Focus states for accessibility */
.td-search-item:focus {
    outline: 2px solid #2563eb;
    outline-offset: -2px;
    background-color: #f8f9fa;
}

/* =================================================================
   KEYWORD HIGHLIGHT STYLES - Bôi đậm từ khóa tìm kiếm
   ================================================================= */

/* Highlighted keyword trong search results */
.td-search-highlight {
    background-color: #fff3cd !important; /* Màu vàng nhạt */
    color: #333333 !important; /* Text đen để nổi bật */
    font-weight: 700 !important; /* Đậm */
    padding: 1px 2px !important; /* Padding nhỏ */
    border-radius: 2px !important; /* Bo góc nhẹ */
    border: 1px solid #ffeaa7 !important; /* Border vàng nhạt */
    display: inline !important; /* Giữ inline với text */
    line-height: inherit !important; /* Giữ line-height */
}

/* Highlight trong title */
.td-item-title .td-search-highlight {
    background-color: #fff3cd !important;
    color: #2c3e50 !important; /* Màu đậm hơn cho title */
    font-weight: 700 !important;
}

/* Highlight trong SKU */
.td-item-sku .td-search-highlight {
    background-color: #fff3cd !important;
    color: #495057 !important;
    font-weight: 600 !important;
}

/* Highlight hiệu ứng hover - nhẹ nhàng hơn khi hover item */
.td-search-item:hover .td-search-highlight {
    background-color: #ffecb3 !important; /* Vàng đậm hơn khi hover */
    border-color: #ffc107 !important;
}

/* Đảm bảo highlight không bị lỗi layout */
.td-search-highlight {
    white-space: nowrap !important; /* Không xuống dòng giữa từ */
    word-break: keep-all !important; /* Giữ nguyên từ */
}

/* Mobile responsive cho highlight */
@media (max-width: 768px) {
    .td-search-highlight {
        padding: 0px 1px !important; /* Padding nhỏ hơn trên mobile */
        font-size: inherit !important; /* Giữ font size gốc */
    }
}

/* Đảm bảo theme trắng với selector mạnh nhất - ghi đè Flatsome dark theme */
.livesearch-form .td-search-results .td-search-item,
.livesearch-form .td-search-results .td-search-items .td-search-item,
body .td-search-results .td-search-item,
body .td-search-results .td-search-items .td-search-item,
html body .td-search-results .td-search-item {
    background-color: #ffffff !important;
    color: #333333 !important;
}

.livesearch-form .td-search-results .td-search-item:hover,
.livesearch-form .td-search-results .td-search-items .td-search-item:hover,
body .td-search-results .td-search-item:hover,
body .td-search-results .td-search-items .td-search-item:hover,
html body .td-search-results .td-search-item:hover {
    background-color: #f9f9f9 !important;
    color: #333333 !important;
}

/* Đảm bảo td-search-items container cũng có nền trắng */
.livesearch-form .td-search-results .td-search-items,
body .td-search-results .td-search-items,
html body .td-search-results .td-search-items {
    background-color: #ffffff !important;
}

/* =================================================================
   Mobile Responsive - Sửa lại với class đúng
   ================================================================= */
@media (max-width: 768px) {
    /* Search Results Container - Giảm chiều cao trên mobile */
    .td-search-results {
        max-height: 300px !important;
        border-radius: 8px !important;
    }
    
    /* Search Items Container */
    .td-search-items {
        max-height: 250px !important;
    }
    
    /* Search Item - Compact hơn trên mobile */
    .td-search-item {
        padding: 10px 12px !important;
    }
    
    /* Product Image - Nhỏ hơn trên mobile */
    .td-item-image {
        width: 50px !important;
        height: 50px !important;
        margin-right: 12px !important;
        border-radius: 6px !important;
    }
    
    /* Product Title - Font nhỏ hơn */
    .td-item-title {
        font-size: 13px !important;
        line-height: 1.3 !important;
        margin-bottom: 3px !important;
    }
    
    /* Product SKU */
    .td-item-sku {
        font-size: 11px !important;
        margin-bottom: 2px !important;
    }
    
    /* Product Price */
    .td-item-price {
        font-size: 12px !important;
    }
    
    /* Search Field - Tăng font size cho mobile */
    .search-field,
    input[type="search"],
    input[name="s"] {
        font-size: 16px !important;
        padding: 12px 15px !important;
    }
    
    /* Loading & No Results - Compact hơn */
    .td-search-loading,
    .td-search-no-results,
    .td-search-error {
        padding: 12px 15px !important;
        font-size: 13px !important;
    }
    
    /* View All Results Link */
    .td-search-more {
        padding: 10px 12px !important;
    }
    
    .td-search-more a {
        font-size: 12px !important;
    }
}

/* =================================================================
   MOBILE SEARCH MODAL FIX - Dính lên trên, trong suốt đẹp mắt
   SỬA LẠI VỚI CLASS ĐÚNG VÀ SEARCH RESULTS MỚI
   ================================================================= */
@media screen and (max-width: 849px) {
    /* Off-canvas wrapper - Dính lên trên KHI ĐÃ MỞ */
    .mfp-wrap.off-canvas.mfp-ready {
        align-items: flex-start !important;
        padding-top: 0 !important;
    }
    
    /* MFP Container - Dính trên */
    .mfp-wrap.off-canvas.mfp-ready .mfp-container {
        padding-top: 0 !important;
        padding-right: 10px !important;
        padding-left: 10px !important;
        margin-top: 0 !important;
    }
    
    /* Search Lightbox Content - Trong suốt, chiều cao tự động */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox {
        position: relative !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        min-height: auto !important;
        max-height: none !important;
    }
    
    /* Search Form Wrapper - Phần trên, trong suốt tối */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .searchform {
        position: relative !important;
        padding: 20px 10px 10px !important;
        background: rgba(0, 0, 0, 0.40) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border-radius: 20px !important;
        margin-bottom: 15px !important;
    }
    
    /* Search Input - Trắng, nổi bật */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .search-field,
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox input[type="search"] {
        background: #ffffff !important;
        border: none !important;
        border-radius: 25px !important;
        padding: 12px 50px 12px 20px !important;
        font-size: 16px !important;
        color: #333333 !important;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
    }
    
    /* Search Submit Button */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .search-submit,
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox button[type="submit"] {
        border-radius: 0 25px 25px 0 !important;
        background: #0066cc !important;
        border: none !important;
        padding: 3px 16px !important;
    }
    
    /* Search Results Container - SỬA ĐỂ DÙNG CLASS MỚI */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-search-results {
        position: relative !important;
        overflow-y: auto !important;
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border-radius: 15px !important;
        border: none !important;
        max-height: calc(100vh - 200px) !important;
        margin: 0 6px !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
    }
    
    /* Search Items trong modal */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-search-items {
        max-height: calc(100vh - 250px) !important;
    }
    
    /* Search Item trong modal */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-search-item {
        padding: 12px 15px !important;
        background: rgba(255, 255, 255, 0.9) !important;
    }
    
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-search-item:hover {
        background: rgba(249, 249, 249, 0.95) !important;
    }
    
    /* Product Image trong modal */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-item-image {
        width: 50px !important;
        height: 50px !important;
        margin-right: 12px !important;
        border-radius: 8px !important;
    }
    
    /* Product Title trong modal */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-item-title {
        font-size: 14px !important;
        color: #333333 !important;
        font-weight: 500 !important;
        text-align: left !important;
    }
    
    /* Product Price trong modal */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-item-price,
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox span.woocommerce-Price-amount.amount {
        font-size: 14px !important;
        color: #000000 !important;
        text-align: left !important;
    }

    .mfp-wrap.off-canvas.mfp-ready #search-lightbox ins span.woocommerce-Price-amount.amount {
        color: #ff0000 !important;
    }
    
    /* Loading, No Results, Error states trong modal */
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-search-loading,
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-search-no-results,
    .mfp-wrap.off-canvas.mfp-ready #search-lightbox .td-search-error {
        background: rgba(255, 255, 255, 0.9) !important;
        color: #666666 !important;
        padding: 20px !important;
        margin: 0 !important;
    }
    
    /* Close Button - Trắng, nổi bật, không đè lên search */
    .mfp-wrap.off-canvas.mfp-ready .mfp-close {
        position: absolute !important;
        top: 15px !important;
        right: 20px !important;
        width: 44px !important;
        height: 44px !important;
        opacity: 1 !important;
        background: rgba(255, 255, 255, 0.2) !important;
        border-radius: 50% !important;
        z-index: 10 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .mfp-wrap.off-canvas.mfp-ready .mfp-close:before {
        font-size: 24px !important;
        color: #ffffff !important;
        line-height: 1 !important;
    }
    
    .mfp-wrap.off-canvas.mfp-ready .mfp-close svg {
        width: 20px !important;
        height: 20px !important;
        stroke: #ffffff !important;
        stroke-width: 3 !important;
    }
}

/* Search Input Placeholder Styles */
.header-search-form .search-field::placeholder,
.header-search-form input[type="search"]::placeholder,
.header-search-form input[name="s"]::placeholder,
.header-search-form .header-search input::placeholder,
.header-search-form .header-search .search-field::placeholder,
.header-search-form form.searchform input[type="search"]::placeholder,
.header-search-form .searchform input.search-field::placeholder,
.header-search-form #searchform input::placeholder,
.header-search-form .nav-search input::placeholder,
.search-field::placeholder,
input[type="search"]::placeholder,
input[name="s"]::placeholder {
    color: #999999 !important;
    opacity: 1 !important;
    font-style: italic !important;
}

/* Firefox placeholder */
.header-search-form .search-field::-moz-placeholder,
.header-search-form input[type="search"]::-moz-placeholder,
.header-search-form input[name="s"]::-moz-placeholder,
.search-field::-moz-placeholder,
input[type="search"]::-moz-placeholder,
input[name="s"]::-moz-placeholder {
    color: #999999 !important;
    opacity: 1 !important;
    font-style: italic !important;
}

/* Chrome/Safari placeholder */
.header-search-form .search-field::-webkit-input-placeholder,
.header-search-form input[type="search"]::-webkit-input-placeholder,
.header-search-form input[name="s"]::-webkit-input-placeholder,
.search-field::-webkit-input-placeholder,
input[type="search"]::-webkit-input-placeholder,
input[name="s"]::-webkit-input-placeholder {
    color: #999999 !important;
    opacity: 1 !important;
    font-style: italic !important;
}