/* Evovio Smart Search Styles */

.evovio-smart-search-wrapper {
    position: relative;
    display: inline-block;
    margin: 0 0.75rem;
}

.evovio-smart-search {
    position: relative;
    width: 100%;
    /* Wider desktop default; customizable via CSS var */
    max-width: var(--evovio-search-max-width, 640px);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.evovio-search-toggle {
    display: none; /* desktop hidden */
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    gap: 0.25rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: inherit;
    cursor: pointer;
}

.evovio-search-toggle:focus-visible {
    outline: 2px solid var(--wp--preset--color--primary, #006d57);
    outline-offset: 2px;
}

.evovio-search-panel {
    display: block;
}

.evovio-search-close { display: none; }

.evovio-search-form {
    position: relative;
}

.evovio-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid #d0d0d0;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.evovio-search-input-wrapper:focus-within {
    border-color: var(--wp--preset--color--primary, #006d57);
    box-shadow: 0 0 0 3px rgba(0, 109, 87, 0.1);
}

.evovio-search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    color: #333;
    appearance: none;
    -webkit-appearance: none;
}

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

.evovio-search-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.evovio-search-submit:hover {
    color: var(--wp--preset--color--primary, #006d57);
    background: rgba(0, 109, 87, 0.05);
}

/* Unified action button (search/clear toggle) */
.evovio-search-action {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.evovio-search-action:hover {
    color: var(--wp--preset--color--primary, #006d57);
    background: rgba(0, 109, 87, 0.05);
}

.evovio-search-action .icon-close { display: none; }
.evovio-search-action.is-clear .icon-search { display: none; }
.evovio-search-action.is-clear .icon-close { display: inline; }

.evovio-search-spinner {
    display: none; /* default hidden; shown via .is-loading */
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    color: var(--wp--preset--color--primary, #006d57);
}

/* Show spinner and hide submit during loading */
.evovio-search-input-wrapper.is-loading .evovio-search-spinner {
    display: flex;
}
.evovio-search-input-wrapper.is-loading .evovio-search-submit,
.evovio-search-input-wrapper.is-loading .evovio-search-action {
    display: none;
}

.evovio-search-spinner .spinner {
    stroke-dasharray: 62.83185307179586;
    stroke-dashoffset: 62.83185307179586;
    animation: spinner-rotation 1.4s linear infinite;
}

@keyframes spinner-rotation {
    0% {
        stroke-dashoffset: 62.83185307179586;
        transform: rotate(0deg);
    }
    50% {
        stroke-dashoffset: 15.707963267948966;
        transform: rotate(45deg);
    }
    100% {
        stroke-dashoffset: 62.83185307179586;
        transform: rotate(360deg);
    }
}

/* Results Container */
.evovio-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: #ffffff;
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    max-height: 480px;
    overflow-y: auto;
    z-index: 9999;
    color: #333;
}

.evovio-search-section {
    padding: 0;
}

.evovio-search-section:not(:last-child) {
    border-bottom: none;
}

.evovio-search-section-title {
    padding: 1rem 1.25rem 0.75rem;
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #666;
    letter-spacing: 0.08em;
    background: #f8f8f8;
    border-bottom: 1px solid #e0e0e0;
}

.evovio-search-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.evovio-search-item {
    margin: 0;
}

.evovio-search-item a {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.25rem;
    text-decoration: none;
    color: #333;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid #f0f0f0;
}

.evovio-search-item:hover a,
.evovio-search-item.selected a {
    background-color: #fafafa;
}

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

.evovio-search-item-image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    margin-right: 1rem;
    overflow: hidden;
    border-radius: 8px;
    background: #f5f5f5;
}

.evovio-search-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.evovio-search-item-content {
    flex: 1;
    min-width: 0;
}

.evovio-search-item-title {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.4;
    color: #333;
}

.evovio-search-item-title mark {
    background-color: rgba(255, 235, 59, 0.3);
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 600;
}

.evovio-search-item-price {
    margin-bottom: 0.25rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--wp--preset--color--primary, #006d57);
}

.evovio-search-item-price del {
    color: #999;
    font-weight: 400;
    font-size: 0.875rem;
    margin-right: 0.5rem;
}

.evovio-search-item-sku {
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    color: #999;
    font-family: monospace;
}

.evovio-search-item-excerpt {
    font-size: 0.875rem;
    line-height: 1.5;
    color: #555;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.evovio-search-item-excerpt mark {
    background-color: rgba(255, 235, 59, 0.3);
    padding: 0 2px;
    border-radius: 2px;
}

/* Footer */
.evovio-search-footer {
    padding: 1rem 1.25rem;
    background-color: #f8f8f8;
    border-top: 1px solid #e5e5e5;
    text-align: center;
    border-radius: 0 0 8px 8px;
}

.evovio-search-view-all {
    font-size: 0.875rem;
    color: var(--wp--preset--color--primary, #006d57);
    text-decoration: none;
    font-weight: 600;
    transition: opacity 0.2s ease;
}

.evovio-search-view-all:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Messages */
.evovio-search-no-results,
.evovio-search-error {
    padding: 3rem 1.5rem;
    text-align: center;
    color: #555;
    font-size: 0.9375rem;
}

.evovio-search-error {
    color: #d32f2f;
}

/* Scrollbar Styling */
.evovio-search-results::-webkit-scrollbar {
    width: 6px;
}

.evovio-search-results::-webkit-scrollbar-track {
    background: #f8f8f8;
    border-radius: 6px;
}

.evovio-search-results::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 6px;
}

.evovio-search-results::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* Product-specific styling */
.evovio-search-product .evovio-search-item-content {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .evovio-smart-search-wrapper { margin: 0 0.25rem; }

    /* Show only the icon; open panel overlays when toggled */
    .evovio-search-toggle { display: inline-flex; }
    .evovio-search-panel { display: none; }
    .evovio-smart-search.is-open .evovio-search-panel {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding: 0.5rem;
        background: #fff;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
        z-index: 10000;
        border-bottom: 1px solid #eaeaea;
    }

    .evovio-search-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
        background: transparent;
        border: none;
        color: #666;
        cursor: pointer;
    }

    .evovio-search-results {
        top: calc(100% + 8px);
        left: 0;
        right: 0;
        max-height: 70vh;
        border-radius: 12px;
        border: 1px solid #e5e5e5;
    }

    .evovio-search-item-image {
        width: 50px;
        height: 50px;
    }
    
    .evovio-search-footer {
        position: sticky;
        bottom: 0;
        background: #fff;
        border-top: 1px solid #e0e0e0;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
    }
}

/* Mobile menu integration: render inline inside WP nav overlay */
@media (max-width: 782px) {
    .wp-block-navigation__responsive-container .evovio-smart-search-wrapper { 
        margin: 0.5rem 0 1rem; 
        display: block; 
        width: 100%;
    }
    .wp-block-navigation__responsive-container .evovio-smart-search {
        max-width: none;
        width: 100%;
    }
    .wp-block-navigation__responsive-container .evovio-search-toggle { 
        display: none !important; 
    }
    .wp-block-navigation__responsive-container .evovio-search-panel {
        display: block !important;
        position: static !important;
        padding: 0;
        background: transparent;
        box-shadow: none;
        border: 0;
        z-index: auto;
    }
    .wp-block-navigation__responsive-container .evovio-search-input-wrapper {
        border: 1px solid rgba(255,255,255,0.35);
        background: #ffffff;
        border-radius: 10px;
    }
    .wp-block-navigation__responsive-container .evovio-search-results {
        position: static;
        top: auto; left: auto; right: auto;
        margin-top: 8px;
        max-height: 50vh;
        border: 1px solid #e5e5e5;
        border-radius: 10px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    }
    .wp-block-navigation__responsive-container .evovio-search-footer {
        position: static;
        box-shadow: none;
    }
}

/* Accessibility */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Hide native clear buttons on search inputs across browsers */
.evovio-search-input::-webkit-search-decoration,
.evovio-search-input::-webkit-search-cancel-button,
.evovio-search-input::-webkit-search-results-button,
.evovio-search-input::-webkit-search-results-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}
.evovio-search-input::-ms-clear,
.evovio-search-input::-ms-reveal {
    display: none;
    width: 0;
    height: 0;
}

/* Focus styles for keyboard navigation */
.evovio-search-item.selected a {
    background-color: #f0f7f5;
    outline: 2px solid var(--wp--preset--color--primary, #006d57);
    outline-offset: -2px;
}

/* Animation for results appearance */
.evovio-search-results {
    animation: slideDown 0.2s ease-out;
}

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

/* Force light mode within plugin scope regardless of OS/theme */
.evovio-smart-search,
.evovio-smart-search .evovio-search-input-wrapper,
.evovio-smart-search .evovio-search-input,
.evovio-smart-search .evovio-search-results,
.evovio-smart-search .evovio-search-section-title,
.evovio-smart-search .evovio-search-item a,
.evovio-smart-search .evovio-search-footer {
    background: #ffffff !important;
    color: #333333 !important;
    border-color: #e5e5e5 !important;
    border-radius: 8px;
}

.evovio-smart-search .evovio-search-item:hover a,
.evovio-smart-search .evovio-search-item.selected a {
    background-color: #f0f7f5 !important;
}

.evovio-smart-search .evovio-search-item-title { color: #333333 !important; }
.evovio-smart-search .evovio-search-item-excerpt { color: #555555 !important; }

/* Tablet width tuning */
@media (min-width: 769px) and (max-width: 1024px) {
    .evovio-smart-search {
        max-width: 420px;
    }
}
/* Suggestions */
.evovio-search-suggestions .evovio-search-item-title { font-weight: 500; }
.evovio-search-item-meta {
    margin-top: 2px;
    font-size: 0.75rem;
    color: #888;
}
