/*
 * Amasty Xsearch Enhanced Styles - High Specificity Version
 * Using high-specificity selectors instead of !important for better maintainability
 * Integrates Amasty search with glpbio theme
 */

/* =================================
   CSS VARIABLES
   ================================= */
:root {
    --amsearch-color-primary: #007bff;
    --amsearch-color-primary-hover: #0056b3;
    --amsearch-color-border: #ddd;
    --amsearch-color-background: #fff;
    --amsearch-color-text: #333;
    --amsearch-color-placeholder: #666;
}

/* =================================
   SEARCH WRAPPER & FORM STYLES
   ================================= */
body .glpbio-search-enhanced.amsearch-wrapper-block.header-search-wrapper {
    position: relative;
    width: 100%;
}

body .glpbio-search-enhanced .amsearch-form-block.mini-search {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--amsearch-color-background);
    border: 1px solid var(--amsearch-color-border);
    border-radius: 4px;
    padding: 0;
    margin: 0;
    height: 38px;
    min-height: 38px;
}

/* =================================
   INPUT & BUTTON STYLES
   ================================= */
body .glpbio-search-enhanced .amsearch-input-wrapper {
    display: flex;
    align-items: center;
    flex-grow: 1;
    position: relative;
}

body .glpbio-search-enhanced .amsearch-input-wrapper .tslabel {
    position: absolute;
    left: -9999px;
    visibility: hidden;
}

body .glpbio-search-enhanced .amsearch-input {
    border: none;
    outline: none;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.3;
    background: transparent;
    flex-grow: 1;
    width: auto;
    min-width: 380px;
    color: var(--amsearch-color-text);
    height: 36px;
}

body .glpbio-search-enhanced .amsearch-input:focus {
    box-shadow: none;
    border: none;
}

body .glpbio-search-enhanced .amsearch-input::placeholder {
    color: var(--amsearch-color-placeholder);
}

/* Clear button */
body .glpbio-search-enhanced .amsearch-button.-close {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    position: absolute;
    right: 100px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    height: 28px;
    width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

body .glpbio-search-enhanced .amsearch-button.-close:before {
    content: "×";
    font-size: 18px;
    color: #666;
}

/* Search button */
body .glpbio-search-enhanced .amsearch-button.-loupe {
    background: var(--amsearch-color-primary);
    border: none;
    padding: 6px 16px;
    cursor: pointer;
    border-radius: 0 3px 3px 0;
    transition: all 0.3s ease;
    height: 38px;
    min-width: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

body .glpbio-search-enhanced .amsearch-button.-loupe:hover {
    background: var(--amsearch-color-primary-hover);
    transform: none;
}

body .glpbio-search-enhanced .amsearch-button.-loupe.-disabled {
    background: #6c757d;
    cursor: not-allowed;
    opacity: 0.8;
}

body .glpbio-search-enhanced .amsearch-button.-loupe span span {
    color: #fff;
    font-weight: 500;
    font-size: 14px;
    display: inline-block;
}

/* Loading spinner for search button */
body .glpbio-search-enhanced .amsearch-button.-loupe.loading {
    background: var(--amsearch-color-primary);
    cursor: wait;
}

body .glpbio-search-enhanced .amsearch-button.-loupe.loading span span {
    opacity: 0;
}

body .glpbio-search-enhanced .amsearch-button.-loupe.loading:before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid #ffffff;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1;
}

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

/* =================================
   覆盖全局按钮样式
   ================================= */
body .glpbio-search-enhanced .amsearch-button span {
    background: none;
}

/* =================================
   SEARCH RESULTS CONTAINER
   ================================= */
body .glpbio-search-enhanced .amsearch-result-section,
body .header-search-wrapper.glpbio-search-enhanced .amsearch-result-section,
body .amsearch-wrapper-block.glpbio-search-enhanced .amsearch-result-section,
body section.amsearch-result-section {
    position: absolute;
    top: 100%;
    left: -10%;
    right: auto;
    width: 120%;
    background: var(--amsearch-color-background);
    border: 1px solid var(--amsearch-color-border);
    border-top: none;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    z-index: 9999;
    max-height: 450px;
    min-height: auto;
    height: auto;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    float: none;
    clear: none;
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
    flex: none;
    grid-column: unset;
    grid-row: unset;
    margin-top: -1px;
    contain: none;
}

/* Visibility states */
body .glpbio-search-enhanced .amsearch-result-section[style*="display: none"] {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

/* 当搜索结果容器为空或没有内容时隐藏边框 */
body .glpbio-search-enhanced .amsearch-result-section:empty {
    display: none !important;
    border: none !important;
    box-shadow: none !important;
    height: 0 !important;
    min-height: 0 !important;
}

/* 当搜索结果容器没有可见子元素时隐藏边框 */
body .glpbio-search-enhanced .amsearch-result-section:not(:has(.amsearch-items-section:not(:empty), .amsearch-products-section:not(:empty))) {
    display: none !important;
    border: none !important;
    box-shadow: none !important;
    height: 0 !important;
    min-height: 0 !important;
}

body .glpbio-search-enhanced .amsearch-result-section[style*="display: block"],
body .glpbio-search-enhanced .amsearch-result-section:not([style*="display: none"]),
body .glpbio-search-enhanced .amsearch-result-section[data-bind*="visible"] {
    display: block;
    visibility: visible;
    height: auto;
    min-height: auto;
    max-height: 450px;
    overflow-y: auto;
    contain: none;
}

/* Override KnockoutJS inline styles */
body .glpbio-search-enhanced .amsearch-result-section[data-bind*="visible"][style] {
    position: absolute;
    top: 100%;
    z-index: 9999;
    height: auto;
    min-height: auto;
    max-height: 450px;
    contain: none;
}

/* =================================
   CONTAINER POSITIONING CONTEXT
   ================================= */
body .header-search-wrapper.glpbio-search-enhanced,
body .amsearch-wrapper-block.glpbio-search-enhanced {
    position: relative;
    overflow: visible;
    height: auto;
    min-height: 0;
    isolation: isolate;
    z-index: 1000;
}

body .glpbio-search-enhanced .amsearch-form-block {
    position: relative;
    isolation: isolate;
    overflow: visible;
    z-index: 1001;
    background: var(--amsearch-color-background);
    height: auto;
    min-height: auto;
}

/* =================================
   RESULT CONTENT STYLING
   ================================= */
body .glpbio-search-enhanced .amsearch-result-section .amsearch-items-section,
body .glpbio-search-enhanced .amsearch-result-section .amsearch-products-section {
    max-height: 420px;
    min-height: 50px;
    height: auto;
    overflow-y: auto;
    padding: 0;
    background: var(--amsearch-color-background);
}

/* Force minimum height when results are visible and have content */
body .glpbio-search-enhanced .amsearch-result-section:not([style*="display: none"]):has(.amsearch-items-section:not(:empty), .amsearch-products-section:not(:empty)) {
    min-height: 50px;
    height: auto;
}

/* 确保没有内容时完全隐藏 */
body .glpbio-search-enhanced .amsearch-result-section:not([style*="display: none"]):not(:has(.amsearch-items-section:not(:empty), .amsearch-products-section:not(:empty))) {
    display: none !important;
    border: none !important;
    box-shadow: none !important;
    height: 0 !important;
    min-height: 0 !important;
}

/* Ensure content areas have proper height */
body .glpbio-search-enhanced .amsearch-result-section[data-bind*="visible"] .amsearch-items-section,
body .glpbio-search-enhanced .amsearch-result-section[data-bind*="visible"] .amsearch-products-section {
    min-height: 30px;
    height: auto;
}

/* =================================
   CATEGORY SECTION STYLING
   ================================= */
body .glpbio-search-enhanced .amsearch-items-section {
    border-bottom: 1px solid #e5e5e5;
    margin-bottom: 0;
    background: #fafafa;
}

body .glpbio-search-enhanced .amsearch-item-container {
    border-bottom: 1px solid #e5e5e5;
}

body .glpbio-search-enhanced .amsearch-item-container:last-child {
    border-bottom: none;
}

body .glpbio-search-enhanced .amsearch-block-header {
    background: #f8f9fa;
    padding: 12px 16px;
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    color: #495057;
    border-bottom: 1px solid #e9ecef;
    position: relative;
}

body .glpbio-search-enhanced .amsearch-block-header .amsearch-title {
    color: #495057;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

body .glpbio-search-enhanced .amsearch-tab-items {
    list-style: none;
    padding: 0;
    margin: 0;
    background: #fff;
}

body .glpbio-search-enhanced .amsearch-tab-items .amsearch-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
}

body .glpbio-search-enhanced .amsearch-tab-items .amsearch-item:hover {
    background: #f8f9fa;
}

body .glpbio-search-enhanced .amsearch-tab-items .amsearch-item:last-child {
    border-bottom: none;
}

body .glpbio-search-enhanced .amsearch-tab-items .amsearch-link {
    color: var(--amsearch-color-primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    display: block;
    margin-bottom: 4px;
}

body .glpbio-search-enhanced .amsearch-tab-items .amsearch-link:hover {
    color: var(--amsearch-color-primary-hover);
    text-decoration: underline;
}

body .glpbio-search-enhanced .amsearch-tab-items .amsearch-description {
    color: #6c757d;
    font-size: 12px;
    line-height: 1.4;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* =================================
   PRODUCTS SECTION STYLING
   ================================= */
body .glpbio-search-enhanced .amsearch-products-section {
    padding: 0;
    background: #fff;
}

body .glpbio-search-enhanced .amsearch-products-section .amsearch-block-header {
    background: #f8f9fa;
    padding: 12px 16px;
    margin: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e9ecef;
}

body .glpbio-search-enhanced .amsearch-products-section .amsearch-title {
    color: #495057;
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

body .glpbio-search-enhanced .amsearch-products-section .amsearch-count {
    background: var(--amsearch-color-primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 8px;
}

body .glpbio-search-enhanced .amsearch-products-section .amsearch-link.-view-all {
    color: var(--amsearch-color-primary);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

body .glpbio-search-enhanced .amsearch-products-section .amsearch-link.-view-all:hover {
    color: var(--amsearch-color-primary-hover);
    text-decoration: underline;
}

body .glpbio-search-enhanced .amsearch-products-section .amsearch-link.-view-all .amsearch-count {
    background: #6c757d;
    margin-left: 4px;
}

body .glpbio-search-enhanced .amsearch-product-list {
    list-style: none;
    padding: 16px;
    margin: 0;
    display: grid;
    gap: 16px;
}

/* Grid layout for products */
body .glpbio-search-enhanced .amsearch-products-section.-grid .amsearch-product-list {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

/* List layout for products */
body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-product-list {
    grid-template-columns: 1fr;
    gap: 12px;
}

/* Product item styling */
body .glpbio-search-enhanced .amsearch-product-list .amsearch-item {
    border: 1px solid #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    transition: all 0.3s ease;
    cursor: pointer;
}

body .glpbio-search-enhanced .amsearch-product-list .amsearch-item:hover {
    border-color: var(--amsearch-color-primary);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
    transform: translateY(-2px);
}

/* Product image */
body .glpbio-search-enhanced .amsearch-item .amsearch-image {
    display: block;
    position: relative;
    overflow: hidden;
    background: #f8f9fa;
}

body .glpbio-search-enhanced .amsearch-product-image-container {
    position: relative;
    width: 100%;
    padding-bottom: 100%;
    overflow: hidden;
}

body .glpbio-search-enhanced .amsearch-product-image-container .product-image-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding-bottom: 0;
}

body .glpbio-search-enhanced .amsearch-product-image-container .product-image-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

body .glpbio-search-enhanced .amsearch-item:hover .product-image-photo {
    transform: scale(1.05);
}

/* Product details */
body .glpbio-search-enhanced .amsearch-description {
    padding: 12px;
}

body .glpbio-search-enhanced .amsearch-description .product-item-link {
    color: #212529;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.4;
    display: block;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

body .glpbio-search-enhanced .amsearch-description .product-item-link:hover {
    color: var(--amsearch-color-primary);
}

body .glpbio-search-enhanced .amsearch-highlight {
    background: #fff3cd;
    color: #856404;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
}

body .glpbio-search-enhanced .product-item-description {
    color: #6c757d;
    font-size: 12px;
    line-height: 1.4;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Price styling */
body .glpbio-search-enhanced .amsearch-wrapper-inner {
    margin-top: auto;
}

body .glpbio-search-enhanced .price-box {
    margin: 0;
}

body .glpbio-search-enhanced .minimal-price {
    margin: 0;
    font-size: 14px;
}

body .glpbio-search-enhanced .price-label {
    color: #6c757d;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 2px;
}

body .glpbio-search-enhanced .price-wrapper .price {
    color: var(--amsearch-color-primary);
    font-weight: 700;
    font-size: 16px;
}

/* List view specific styling */
body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-item {
    display: flex;
    align-items: center;
    padding: 12px;
}

body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-image {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    margin-right: 12px;
    border-radius: 6px;
    overflow: hidden;
}

body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-product-image-container {
    width: 80px;
    height: 80px;
    padding-bottom: 0;
}

body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-description {
    flex-grow: 1;
    padding: 0;
}

body .glpbio-search-enhanced .amsearch-products-section.-list .product-item-link {
    font-size: 14px;
    margin-bottom: 4px;
}

body .glpbio-search-enhanced .amsearch-products-section.-list .product-item-description {
    margin-bottom: 8px;
    -webkit-line-clamp: 1;
}

body .glpbio-search-enhanced .amsearch-products-section.-list .price-wrapper .price {
    font-size: 14px;
}

/* =================================
   INTERACTION STATES
   ================================= */
body .glpbio-search-enhanced .amsearch-form-block.-opened {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body .glpbio-search-enhanced .amsearch-input-wrapper.-dynamic-width {
    transition: width 0.3s ease;
}

/* =================================
   OVERRIDE DYNAMIC INLINE STYLES
   ================================= */
body .glpbio-search-enhanced .amsearch-product-image-container[class*="amsearch-product-image-container-"] {
    width: 100%;
}

body .glpbio-search-enhanced .amsearch-product-image-container[class*="amsearch-product-image-container-"] .product-image-wrapper {
    padding-bottom: 100%;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* =================================
   RESPONSIVE DESIGN
   ================================= */
@media (max-width: 768px) {
    body .glpbio-search-enhanced .amsearch-input {
        min-width: 200px;
        font-size: 16px;
    }
    
    body .glpbio-search-enhanced .amsearch-button.-loupe {
        padding: 6px 12px;
        height: 38px;
    }
    
    body .glpbio-search-enhanced .amsearch-button.-loupe span span {
        font-size: 12px;
    }
    
    body .glpbio-search-enhanced .amsearch-result-section {
        max-height: 350px;
        left: -5%;
        width: 110%;
    }
    
    body .glpbio-search-enhanced .amsearch-products-section.-grid .amsearch-product-list {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 12px;
    }
    
    body .glpbio-search-enhanced .amsearch-product-list {
        padding: 12px;
    }
    
    body .glpbio-search-enhanced .amsearch-block-header {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    body .glpbio-search-enhanced .amsearch-tab-items .amsearch-item {
        padding: 10px 12px;
    }
    
    body .glpbio-search-enhanced .amsearch-form-block.mini-search {
        height: 36px;
        min-height: 36px;
    }
    
    body .glpbio-search-enhanced .amsearch-input {
        height: 34px;
    }
    
    body .glpbio-search-enhanced .amsearch-button.-loupe {
        height: 36px;
    }
}

@media (max-width: 480px) {
    body .glpbio-search-enhanced .amsearch-input {
        min-width: 150px;
    }
    
    body .glpbio-search-enhanced .amsearch-button.-loupe span span {
        display: none;
    }
    
    body .glpbio-search-enhanced .amsearch-button.-loupe:after {
        content: "🔍";
        font-size: 14px;
    }
    
    body .glpbio-search-enhanced .amsearch-result-section {
        max-height: 300px;
        left: 0;
        width: 100%;
    }
    
    body .glpbio-search-enhanced .amsearch-products-section.-grid .amsearch-product-list {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    
    body .glpbio-search-enhanced .amsearch-result-section .amsearch-items-section,
    body .glpbio-search-enhanced .amsearch-result-section .amsearch-products-section {
        max-height: 250px;
    }
    
    body .glpbio-search-enhanced .amsearch-product-list {
        padding: 8px;
    }
    
    body .glpbio-search-enhanced .amsearch-description {
        padding: 8px;
    }
    
    body .glpbio-search-enhanced .amsearch-description .product-item-link {
        font-size: 13px;
    }
    
    body .glpbio-search-enhanced .price-wrapper .price {
        font-size: 14px;
    }
    
    body .glpbio-search-enhanced .amsearch-block-header {
        padding: 8px 10px;
        font-size: 12px;
    }
    
    body .glpbio-search-enhanced .amsearch-tab-items .amsearch-item {
        padding: 8px 10px;
    }
    
    body .glpbio-search-enhanced .amsearch-tab-items .amsearch-link {
        font-size: 13px;
    }
    
    body .glpbio-search-enhanced .amsearch-tab-items .amsearch-description {
        font-size: 11px;
    }
    
    /* Simplified list view for mobile */
    body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-image {
        width: 60px;
        height: 60px;
        margin-right: 8px;
    }
    
    body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-product-image-container {
        width: 60px;
        height: 60px;
    }
    
    body .glpbio-search-enhanced .amsearch-products-section.-list .amsearch-item {
        padding: 8px;
    }
    
    body .glpbio-search-enhanced .amsearch-form-block.mini-search {
        height: 34px;
        min-height: 34px;
    }
    
    body .glpbio-search-enhanced .amsearch-input {
        height: 32px;
        padding: 4px 8px;
    }
    
    body .glpbio-search-enhanced .amsearch-button.-loupe {
        height: 34px;
        min-width: 40px;
        padding: 4px 8px;
    }
}

/* =================================
   ANIMATION & TRANSITIONS
   ================================= */
body .glpbio-search-enhanced .amsearch-result-section {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body .glpbio-search-enhanced .amsearch-item {
    transition: all 0.2s ease;
}

body .glpbio-search-enhanced .amsearch-link {
    transition: color 0.2s ease;
}

/* =================================
   ACCESSIBILITY
   ================================= */
body .glpbio-search-enhanced .amsearch-link:focus {
    outline: 2px solid var(--amsearch-color-primary);
    outline-offset: 2px;
}

body .glpbio-search-enhanced .amsearch-item:focus-within {
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* =================================
   SPECIAL COMPONENTS
   ================================= */
body .glpbio-search-enhanced .amsearch-button.-full-close {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #fff;
    border: 1px solid var(--amsearch-color-border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    z-index: 1001;
}

body .glpbio-search-enhanced .amsearch-button.-full-close:before {
    content: "×";
    font-size: 24px;
    color: #333;
}

body .glpbio-search-enhanced .focusable-trap {
    position: fixed;
    top: -1px;
    left: -1px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* =================================
   COMPATIBILITY & CLEANUP
   ================================= */
body .glpbio-search-enhanced #search_autocomplete.search-autocomplete {
    display: none;
}

body .glpbio-search-enhanced .amsearch-input-wrapper[data-bind*="loader"] {
    position: relative;
}

/* =================================
   PRINT STYLES
   ================================= */
@media print {
    body .glpbio-search-enhanced .amsearch-result-section {
        display: none;
    }
}