/**
 * Woo Smart Search - Frontend Styles
 *
 * Modern, responsive autocomplete search styling
 */

/* CSS Variables */
:root {
    --wss-primary-color: #2563eb;
    --wss-secondary-color: #64748b;
    --wss-background-color: #ffffff;
    --wss-text-color: #1e293b;
    --wss-highlight-color: #fef08a;
    --wss-border-radius: 8px;
    --wss-overlay-color: rgba(0, 0, 0, 0.5);
    --wss-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --wss-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --wss-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --wss-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --wss-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Search Wrapper */
.wss-search-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    z-index: 9999;
}

.wss-search-wrapper * {
    box-sizing: border-box;
}

/* =============================================
   HEADER / INLINE LAYOUT MODE
   Use class "wss-inline" or "wss-header" on wrapper
   ============================================= */
.wss-search-wrapper.wss-inline,
.wss-search-wrapper.wss-header {
    width: auto;
    max-width: none;
    margin: 0;
    flex: 1 1 auto;
    min-width: 200px;
    max-width: 450px;
}

/* Compact mode for tight spaces */
.wss-search-wrapper.wss-compact {
    max-width: 350px;
}

.wss-search-wrapper.wss-compact .wss-search-input {
    padding: 10px 12px 10px 40px;
    font-size: 14px;
}

.wss-search-wrapper.wss-compact .wss-search-icon {
    left: 12px;
    width: 18px;
    height: 18px;
}

.wss-search-wrapper.wss-compact .wss-voice-btn,
.wss-search-wrapper.wss-compact .wss-clear-btn {
    width: 32px;
    height: 32px;
    margin-right: 4px;
}

.wss-search-wrapper.wss-compact .wss-mic-icon,
.wss-search-wrapper.wss-compact .wss-clear-btn svg {
    width: 16px;
    height: 16px;
}

/* Full width mode */
.wss-search-wrapper.wss-full-width {
    max-width: 100%;
}

/* Fixed width options */
.wss-search-wrapper.wss-w-200 { max-width: 200px; }
.wss-search-wrapper.wss-w-250 { max-width: 250px; }
.wss-search-wrapper.wss-w-300 { max-width: 300px; }
.wss-search-wrapper.wss-w-350 { max-width: 350px; }
.wss-search-wrapper.wss-w-400 { max-width: 400px; }
.wss-search-wrapper.wss-w-450 { max-width: 450px; }
.wss-search-wrapper.wss-w-500 { max-width: 500px; }

/* =============================================
   ELEMENTOR COMPATIBILITY
   ============================================= */
.elementor-widget-shortcode .wss-search-wrapper,
.elementor-widget-html .wss-search-wrapper,
.elementor-widget-text-editor .wss-search-wrapper,
.elementor-element .wss-search-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 0;
}

/* Elementor Section/Container with flex */
.elementor-section .wss-search-wrapper,
.elementor-container .wss-search-wrapper,
.e-con .wss-search-wrapper,
.e-con-inner .wss-search-wrapper {
    flex: 1 1 auto;
    min-width: 180px;
    max-width: 100%;
    width: auto;
    margin: 0;
}

/* When in Elementor column - respect column width */
.elementor-column .wss-search-wrapper,
.elementor-widget .wss-search-wrapper {
    max-width: 100%;
    margin: 0;
}

/* Elementor Nav Menu integration */
.elementor-nav-menu .wss-search-wrapper,
.elementor-menu-toggle + .wss-search-wrapper {
    flex: 0 1 350px;
    min-width: 150px;
    margin: 0 15px;
}

/* =============================================
   COMMON THEME HEADER COMPATIBILITY
   ============================================= */
/* Generic header containers */
header .wss-search-wrapper,
.site-header .wss-search-wrapper,
.header-wrapper .wss-search-wrapper,
#masthead .wss-search-wrapper,
.main-header .wss-search-wrapper,
nav .wss-search-wrapper,
.navbar .wss-search-wrapper {
    flex: 1 1 auto;
    max-width: 400px;
    min-width: 180px;
    margin: 0;
    width: auto;
}

/* Ensure it doesn't break flex layouts */
.wss-search-wrapper:only-child {
    margin: 0 auto;
}

/* When inside a flex container, don't center */
[style*="display: flex"] > .wss-search-wrapper,
[style*="display:flex"] > .wss-search-wrapper,
.d-flex > .wss-search-wrapper,
.flex > .wss-search-wrapper {
    margin: 0;
}

/* =============================================
   RESULTS DROPDOWN POSITIONING FOR HEADERS
   ============================================= */
/* When in header, dropdown should have minimum width */
.wss-search-wrapper.wss-header .wss-results-wrapper,
.wss-search-wrapper.wss-inline .wss-results-wrapper,
.wss-search-wrapper.wss-compact .wss-results-wrapper,
header .wss-search-wrapper .wss-results-wrapper,
.site-header .wss-search-wrapper .wss-results-wrapper,
nav .wss-search-wrapper .wss-results-wrapper {
    min-width: 350px;
    width: max-content;
    max-width: min(500px, 90vw);
    right: auto;
}

/* On smaller screens, center the dropdown */
@media (max-width: 768px) {
    .wss-search-wrapper.wss-header .wss-results-wrapper,
    .wss-search-wrapper.wss-inline .wss-results-wrapper,
    header .wss-search-wrapper .wss-results-wrapper {
        position: fixed;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: calc(100vw - 20px);
        max-width: 450px;
        min-width: auto;
    }
}

/* =============================================
   ADDITIONAL PAGE BUILDER COMPATIBILITY
   ============================================= */
/* Divi Builder */
.et_pb_module .wss-search-wrapper {
    max-width: 100%;
    margin: 0;
}

/* WPBakery */
.wpb_wrapper .wss-search-wrapper,
.vc_column-inner .wss-search-wrapper {
    max-width: 100%;
    margin: 0;
}

/* Beaver Builder */
.fl-module .wss-search-wrapper {
    max-width: 100%;
    margin: 0;
}

/* Oxygen Builder */
.oxy-element .wss-search-wrapper,
.ct-section .wss-search-wrapper {
    max-width: 100%;
    margin: 0;
}

/* Bricks Builder */
.brxe-shortcode .wss-search-wrapper,
.bricks-element .wss-search-wrapper {
    max-width: 100%;
    margin: 0;
}

/* GeneratePress */
.inside-navigation .wss-search-wrapper {
    flex: 0 1 300px;
    margin: 0 15px;
}

/* Astra Theme */
.ast-container .wss-search-wrapper,
.main-header-bar .wss-search-wrapper {
    flex: 0 1 350px;
    max-width: 350px;
    margin: 0;
}

/* OceanWP */
#site-header .wss-search-wrapper,
.oceanwp-mobile-menu-icon + .wss-search-wrapper {
    flex: 0 1 300px;
    margin: 0 15px;
}

/* Kadence Theme */
.kadence-header .wss-search-wrapper {
    flex: 0 1 350px;
    margin: 0;
}

/* Flatsome */
.header-wrapper .wss-search-wrapper,
.nav-wrapper .wss-search-wrapper {
    flex: 0 1 350px;
    margin: 0 15px;
}

/* =============================================
   ELEMENTOR WIDGET SPECIFIC STYLES
   ============================================= */
.wss-elementor-widget {
    margin: 0;
}

.elementor-widget-wss_search_form .wss-search-wrapper {
    margin: 0;
    width: 100%;
}

/* Reset conflicting Elementor styles */
.elementor-widget-wss_search_form .wss-search-input-wrapper {
    display: flex;
    align-items: center;
    border-style: solid;
    transition: all 0.2s ease;
}

.elementor-widget-wss_search_form .wss-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    width: 100%;
    min-width: 0;
}

.elementor-widget-wss_search_form .wss-search-icon {
    position: absolute;
    pointer-events: none;
    flex-shrink: 0;
}

.elementor-widget-wss_search_form .wss-voice-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-right: 4px;
}

.elementor-widget-wss_search_form .wss-voice-btn:hover {
    opacity: 0.7;
}

/* Ensure proper z-index for results in Elementor */
.elementor-widget-wss_search_form .wss-results-wrapper {
    z-index: 99999;
}

/* Fix for Elementor editor preview */
.elementor-editor-active .wss-search-wrapper .wss-search-input {
    pointer-events: none;
}

/* Search Form */
.wss-search-form {
    position: relative;
    width: 100%;
}

.wss-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--wss-background-color);
    border: 2px solid #e2e8f0;
    border-radius: var(--wss-border-radius);
    transition: var(--wss-transition);
    overflow: hidden;
}

.wss-search-input-wrapper:focus-within {
    border-color: var(--wss-primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.wss-search-icon {
    position: absolute;
    left: 16px;
    width: 20px;
    height: 20px;
    color: var(--wss-secondary-color);
    pointer-events: none;
    transition: var(--wss-transition);
}

.wss-search-input-wrapper:focus-within .wss-search-icon {
    color: var(--wss-primary-color);
}

.wss-search-input {
    flex: 1;
    width: 100%;
    padding: 14px 16px 14px 48px;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--wss-text-color);
    outline: none;
}

.wss-search-input::placeholder {
    color: var(--wss-secondary-color);
}

/* Clear Button */
.wss-clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-right: 8px;
    padding: 0;
    border: none;
    background: #f1f5f9;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--wss-transition);
}

.wss-clear-btn:hover {
    background: #e2e8f0;
}

.wss-clear-btn svg {
    width: 16px;
    height: 16px;
    color: var(--wss-secondary-color);
}

/* Voice Button */
.wss-voice-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-right: 8px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--wss-transition);
}

.wss-voice-btn:hover {
    background: #f1f5f9;
}

.wss-voice-btn.wss-listening {
    background: #fee2e2;
}

.wss-mic-icon {
    width: 20px;
    height: 20px;
    color: var(--wss-secondary-color);
    transition: var(--wss-transition);
}

.wss-voice-btn:hover .wss-mic-icon {
    color: var(--wss-primary-color);
}

.wss-voice-btn.wss-listening .wss-mic-icon {
    color: #ef4444;
}

.wss-voice-listening {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.wss-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    background: #ef4444;
    border-radius: 50%;
    animation: wss-pulse 1.5s ease-in-out infinite;
}

@keyframes wss-pulse {
    0%, 100% {
        transform: scale(0.8);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.5;
    }
}

/* Loading Spinner */
.wss-loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-right: 8px;
}

.wss-spinner {
    width: 24px;
    height: 24px;
    animation: wss-spin 1s linear infinite;
}

.wss-spinner circle {
    stroke: var(--wss-primary-color);
}

@keyframes wss-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Results Wrapper */
.wss-results-wrapper {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--wss-background-color);
    border-radius: var(--wss-border-radius);
    box-shadow: var(--wss-shadow-xl);
    max-height: 70vh;
    overflow: hidden;
    z-index: 10000;
    animation: wss-slideDown 0.2s ease-out;
}

@keyframes wss-slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wss-results-container {
    max-height: calc(70vh - 60px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Scrollbar Styling */
.wss-results-container::-webkit-scrollbar {
    width: 6px;
}

.wss-results-container::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.wss-results-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.wss-results-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Result Sections */
.wss-results-section {
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.wss-results-section:last-child {
    border-bottom: none;
}

.wss-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--wss-secondary-color);
}

/* Result Item */
.wss-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--wss-transition);
}

.wss-result-item:hover,
.wss-result-item.wss-focused {
    background: #f8fafc;
}

.wss-result-item:active {
    background: #f1f5f9;
}

/* Product Item */
.wss-product-item .wss-item-image {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    border-radius: 6px;
    overflow: hidden;
    background: #f1f5f9;
}

.wss-product-item .wss-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wss-item-content {
    flex: 1;
    min-width: 0;
}

.wss-item-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--wss-text-color);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wss-item-sku {
    font-size: 12px;
    color: var(--wss-secondary-color);
    margin-top: 2px;
}

.wss-sku-label {
    font-weight: 500;
}

.wss-item-description {
    font-size: 13px;
    color: var(--wss-secondary-color);
    line-height: 1.4;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wss-item-price {
    font-size: 14px;
    font-weight: 600;
    color: var(--wss-text-color);
    margin-top: 4px;
}

.wss-item-price del {
    color: var(--wss-secondary-color);
    font-weight: 400;
    font-size: 12px;
}

.wss-item-price ins {
    text-decoration: none;
    color: #16a34a;
}

.wss-item-categories {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.wss-category-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--wss-primary-color);
    background: rgba(37, 99, 235, 0.1);
    border-radius: 12px;
}

/* Item Details */
.wss-item-details {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}

.wss-stock-status {
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 12px;
}

.wss-stock-in {
    color: #16a34a;
    background: rgba(22, 163, 74, 0.1);
}

.wss-stock-out {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
}

.wss-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #eab308;
}

.wss-rating svg {
    width: 14px;
    height: 14px;
}

.wss-arrow {
    width: 16px;
    height: 16px;
    color: #cbd5e1;
    transition: var(--wss-transition);
}

.wss-result-item:hover .wss-arrow {
    color: var(--wss-primary-color);
    transform: translateX(3px);
}

/* Term Items (Categories, Tags, Brands) */
.wss-term-item .wss-term-icon,
.wss-post-item .wss-post-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: #f1f5f9;
    border-radius: 8px;
}

.wss-term-item .wss-term-icon svg,
.wss-post-item .wss-post-icon svg {
    width: 20px;
    height: 20px;
    color: var(--wss-secondary-color);
}

.wss-term-item .wss-item-count,
.wss-post-item .wss-type-label {
    font-size: 12px;
    color: var(--wss-secondary-color);
}

/* Highlight */
.wss-highlight,
mark.wss-highlight {
    background: var(--wss-highlight-color);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

/* No Results */
.wss-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.wss-no-results svg {
    width: 48px;
    height: 48px;
    color: #cbd5e1;
    margin-bottom: 12px;
}

.wss-no-results p {
    font-size: 14px;
    color: var(--wss-secondary-color);
    margin: 0;
}

/* View All */
.wss-view-all {
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    text-align: center;
}

.wss-search-wrapper .wss-view-all .wss-view-all-link,
.wss-search-wrapper .wss-view-all-link,
.wss-view-all-link,
.wss-results-wrapper .wss-view-all a.wss-view-all-link {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: var(--wss-primary-color) !important;
    text-decoration: none !important;
    transition: var(--wss-transition);
    /* Override theme/page builder link styles (Elementor, etc.) */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}

.wss-search-wrapper .wss-view-all .wss-view-all-link:hover,
.wss-search-wrapper .wss-view-all-link:hover,
.wss-view-all-link:hover,
.wss-results-wrapper .wss-view-all a.wss-view-all-link:hover {
    text-decoration: underline !important;
    color: var(--wss-primary-color) !important;
}

.wss-search-wrapper .wss-view-all .wss-view-all-link:focus,
.wss-search-wrapper .wss-view-all-link:focus,
.wss-view-all-link:focus,
.wss-results-wrapper .wss-view-all a.wss-view-all-link:focus {
    color: var(--wss-primary-color) !important;
    outline: none !important;
}

.wss-search-wrapper .wss-view-all .wss-view-all-link:visited,
.wss-search-wrapper .wss-view-all-link:visited,
.wss-view-all-link:visited,
.wss-results-wrapper .wss-view-all a.wss-view-all-link:visited {
    color: var(--wss-primary-color) !important;
}

.wss-view-all-link svg {
    width: 16px;
    height: 16px;
}

/* Overlay */
.wss-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--wss-overlay-color);
    z-index: 9998;
    animation: wss-fadeIn 0.2s ease-out;
}

@keyframes wss-fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .wss-search-wrapper {
        max-width: 100%;
    }

    .wss-results-wrapper {
        position: fixed;
        top: 70px;
        left: 10px;
        right: 10px;
        max-height: calc(100vh - 100px);
        border-radius: 12px;
    }

    .wss-product-item .wss-item-image {
        width: 48px;
        height: 48px;
    }

    .wss-item-title {
        font-size: 13px;
    }

    .wss-item-description {
        display: none;
    }

    .wss-item-details {
        display: none;
    }

    .wss-term-item .wss-term-icon,
    .wss-post-item .wss-post-icon {
        width: 36px;
        height: 36px;
    }
}

/* Accessibility */
.wss-result-item:focus {
    outline: 2px solid var(--wss-primary-color);
    outline-offset: -2px;
}

/* Animation for items */
.wss-result-item {
    animation: wss-itemFadeIn 0.15s ease-out;
    animation-fill-mode: both;
}

.wss-result-item:nth-child(1) { animation-delay: 0s; }
.wss-result-item:nth-child(2) { animation-delay: 0.02s; }
.wss-result-item:nth-child(3) { animation-delay: 0.04s; }
.wss-result-item:nth-child(4) { animation-delay: 0.06s; }
.wss-result-item:nth-child(5) { animation-delay: 0.08s; }
.wss-result-item:nth-child(6) { animation-delay: 0.1s; }
.wss-result-item:nth-child(7) { animation-delay: 0.12s; }
.wss-result-item:nth-child(8) { animation-delay: 0.14s; }
.wss-result-item:nth-child(9) { animation-delay: 0.16s; }
.wss-result-item:nth-child(10) { animation-delay: 0.18s; }

@keyframes wss-itemFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Print styles */
@media print {
    .wss-search-wrapper {
        display: none !important;
    }
}
