/* Main Container */
.kuad-advanced-search-form {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    z-index: 99999 !important; /* Forced ultra-high z-index */
}

/* Wrapper (Mobile-First Pattern applied) */
.kuad-advanced-search-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    padding: 0.8rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    gap: 0.75rem;
    position: relative;
    overflow: auto;
    z-index: 99999 !important;
}

/* Input Styles */
.kuad-advanced-search-input-wrapper {
    display: flex;
    width: 100%;
    flex: 1;
    justify-content: left;
    align-items: center;
}

.kuad-advanced-search-input 
{
    width: 100%;
    flex: 1;
    border: none !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 1rem;
    color: #000;
    background: #fff;
    box-sizing: border-box;
    height: 42px;
    line-height: normal;
    margin: 0;
}

.kuad-advanced-search-dashicons-search 
{
    position: relative;
    left: 10px;
}

.kuad-advanced-search-dashicons-search:before {
    color: #64748b;
}

/* Select Dropdown */
.kuad-advanced-search-filter {
    width: 100%; /* Mobile first: full width */
    border: 1px solid #ccc;
    padding: 0.5rem;
    font-size: 1rem;
    color: #000;
    background: #fff;
    display: block;
    box-sizing: border-box;
    height: 42px; /* Match button height */
    margin: 0;
    /* border-radius is injected via PHP inline styles */
}

/* Hidden inputs fallback handling */
input[type="hidden"].kuad-advanced-search-filter {
    display: none !important;
}

/* Submit Button */
.kuad-advanced-search-submit {
    position: relative;
    width: 100%;
    max-width: 155px;
    height: 42px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

.kuad-advanced-search-submit-arrow-wrapper {
    position: relative;
    top: 2px;
}

.kuad-advanced-search-submit-arrow {
    width: 15px;
    height: 15px;
    color: #ffffff;
}

.kuad-advanced-search-submit.loading .dashicons,
.kuad-advanced-search-submit.loading .kuad-advanced-search-btn-text {
    display: none;
}

.kuad-advanced-search-submit.loading .kuad-advanced-search-spinner {
    display: block;
}

.kuad-advanced-search-btn-text {
    font-size: 1rem;
    font-weight: 500;
}

/* Loading Spinner */
.kuad-advanced-search-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid currentColor; /* inherits text color */
    border-radius: 50%;
    animation: kuad-spin 0.8s linear infinite;
    display: none;
}

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

/* Results Dropdown */
.kuad-advanced-search-results {
    /* Absolute Positioning to not push content down */
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    width: 100%;
    max-height: 450px;
    overflow-y: auto;
    display: none;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); /* Stronger shadow for depth */
    z-index: 999999 !important; /* Forced ultra-high z-index to stay on top */
}

/* Close Results Button Visible */
.kuad-advanced-search-close-results {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #000;
    border: none;
    font-size: 20px;
    color: #fff;
    cursor: pointer;
    border-radius: 6px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    line-height: 23px;
    transition: background-color 0.2s ease;
}

.kuad-advanced-search-close-results:hover {
    background: #ff4d4d;
}

/* Single Result Item */
.kuad-advanced-search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #eee;
    text-decoration: none;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    opacity: 0;
    animation: kuadFadeIn 0.3s ease-out forwards;
    position: relative;
    z-index: 1;
}

.kuad-advanced-search-result-item:hover {
    background: #f0f0f0;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.08);
}

/* Cascade Animation Delay */
.kuad-advanced-search-result-item:nth-child(1) { animation-delay: 0.05s; }
.kuad-advanced-search-result-item:nth-child(2) { animation-delay: 0.10s; }
.kuad-advanced-search-result-item:nth-child(3) { animation-delay: 0.15s; }
.kuad-advanced-search-result-item:nth-child(4) { animation-delay: 0.20s; }
.kuad-advanced-search-result-item:nth-child(5) { animation-delay: 0.25s; }
.kuad-advanced-search-result-item:nth-child(6) { animation-delay: 0.30s; }
.kuad-advanced-search-result-item:nth-child(7) { animation-delay: 0.35s; }
.kuad-advanced-search-result-item:nth-child(8) { animation-delay: 0.40s; }
.kuad-advanced-search-result-item:nth-child(9) { animation-delay: 0.45s; }
.kuad-advanced-search-result-item:nth-child(10) { animation-delay: 0.50s; }

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

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

.kuad-advanced-search-closing {
    animation: kuadFadeOut 0.2s ease-in forwards;
}

/* Product Thumbnail */
.kuad-advanced-search-product-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    background: #f0f0f0;
}

/* Product Info Block */
.kuad-advanced-search-product-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Product Title */
.kuad-advanced-search-product-title {
    font-size: 1rem;
    color: #000;
    font-weight: 600;
    line-height: 1.2;
}

/* Product Price */
.kuad-advanced-search-product-price {
    font-size: 0.95rem;
    color: #000;
}

/* Product Category */
.kuad-advanced-search-product-category {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: #333;
    gap: 0.4rem;
}

.kuad-advanced-search-product-category .dashicons {
    font-size: 14px;
    color: #333;
}

.kuad-advanced-search-category-text {
    font-style: italic;
    color: #333;
}

/* WooCommerce Price Inheritance Rules */
.kuad-advanced-search-product-info .woocommerce-Price-currencySymbol,
.kuad-advanced-search-product-info .woocommerce-Price-amount {
    color: #000;
    font-weight: 500;
}

/* Error and Empty State Messages */
.kuad-advanced-search-no-results,
.kuad-advanced-search-error {
    padding: 1rem;
    text-align: center;
    color: #666;
}

/* Search History Block */
.kuad-advanced-search-history {
    padding: 1rem;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    margin-top: 0.5rem;
    position: relative;
}

.kuad-advanced-search-history-label {
    font-size: 0.95rem;
    color: #333;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.kuad-advanced-search-history-item {
    display: inline-block;
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 0.4rem 0.8rem;
    margin: 0.25rem 0.35rem 0 0;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.kuad-advanced-search-history-item:hover {
    background: #000;
    color: #fff;
    border-color: #000;
}

/* Desktop and Tablet Enhancements (min-width: 768px) */
@media (min-width: 768px) {
    .kuad-advanced-search-wrapper {
        flex-direction: row;
        gap: 0.5rem;
    }
    
    .kuad-advanced-search-input {
        width: auto;
    }

    .kuad-advanced-search-filter {
        width: 140px;
    }

    .kuad-advanced-search-submit {
        width: auto;
        padding: 0 1rem; /* Better padding when text is dynamic */
        min-width: 42px; /* fallback just for icon */
    }
}