/**
 * WooCommerce AJAX Product Search - Styles
 *
 * @package WC_Ajax_Product_Search
 */

/* ============================================
   CSS Variables for easy customization
   ============================================ */
:root {
    --wcaps-primary-color: #01be64;
    --wcaps-primary-hover: #01be64;
    --wcaps-text-color: #1f2937;
    --wcaps-text-light: #6b7280;
    --wcaps-border-color: #e5e7eb;
    --wcaps-bg-color: #ffffff;
    --wcaps-bg-hover: #f9fafb;
    --wcaps-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --wcaps-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --wcaps-radius: 8px;
    --wcaps-radius-lg: 12px;
    --wcaps-transition: 0.2s ease;
    --wcaps-sale-color: #dc2626;
    --wcaps-stock-in: #059669;
    --wcaps-stock-out: #dc2626;
}

/* ============================================
   Search Wrapper
   ============================================ */
.wcaps-search-wrapper {
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    box-sizing: border-box;
}

.wcaps-search-wrapper *,
.wcaps-search-wrapper *::before,
.wcaps-search-wrapper *::after {
    box-sizing: inherit;
}

/* ============================================
   Search Container
   ============================================ */
.wcaps-search-container {
    position: relative;
    width: 100%;
}

.wcaps-search-form {
    display: flex;
    align-items: stretch;
    gap: 8px;
    width: 100%;
}

/* ============================================
   Input Wrapper
   ============================================ */
.wcaps-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.wcaps-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--wcaps-text-light);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.wcaps-search-input {
    width: 100%;
    height: 48px;
    padding: 12px 80px 12px 44px;
    border: 2px solid var(--wcaps-border-color);
    border-radius: var(--wcaps-radius);
    background: var(--wcaps-bg-color);
    color: var(--wcaps-text-color);
    font-size: 16px;
    transition: border-color var(--wcaps-transition), box-shadow var(--wcaps-transition);
    outline: none;
}

.wcaps-search-input:focus {
    border-color: var(--wcaps-primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.wcaps-search-input::placeholder {
    color: var(--wcaps-text-light);
}

/* ============================================
   Clear Button
   ============================================ */
.wcaps-clear-btn {
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--wcaps-text-light);
    font-size: 20px;
    font-weight: 300;
    border-radius: 50%;
    transition: background-color var(--wcaps-transition), color var(--wcaps-transition);
}

.wcaps-clear-btn:hover {
    background-color: var(--wcaps-border-color);
    color: var(--wcaps-text-color);
}

.wcaps-search-wrapper.has-value .wcaps-clear-btn {
    display: flex;
}

/* ============================================
   Loading Spinner
   ============================================ */
.wcaps-loading-spinner {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    display: none;
}

.wcaps-search-wrapper.is-loading .wcaps-loading-spinner {
    display: block;
}

.wcaps-search-wrapper.is-loading .wcaps-loading-spinner::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid var(--wcaps-border-color);
    border-top-color: var(--wcaps-primary-color);
    border-radius: 50%;
    animation: wcaps-spin 0.8s linear infinite;
}

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

/* ============================================
   Search Button
   ============================================ */
.wcaps-search-button {
    height: 48px;
    padding: 0 24px;
    background: var(--wcaps-primary-color);
    color: #ffffff;
    border: none;
    border-radius: var(--wcaps-radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--wcaps-transition), transform var(--wcaps-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

.wcaps-search-button:hover {
    background: var(--wcaps-primary-hover);
}

.wcaps-search-button:active {
    transform: scale(0.98);
}

.wcaps-button-icon {
    display: none;
}

/* ============================================
   Results Wrapper
   ============================================ */
.wcaps-results-wrapper {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--wcaps-bg-color);
    border-radius: var(--wcaps-radius-lg);
    box-shadow: var(--wcaps-shadow-lg);
    border: 1px solid var(--wcaps-border-color);
    max-height: 480px;
    overflow: hidden;
    display: none;
    z-index: 9999;
}

.wcaps-search-wrapper.has-results .wcaps-results-wrapper {
    display: block;
}

.wcaps-results-container {
    max-height: 480px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Custom scrollbar */
.wcaps-results-container::-webkit-scrollbar {
    width: 6px;
}

.wcaps-results-container::-webkit-scrollbar-track {
    background: transparent;
}

.wcaps-results-container::-webkit-scrollbar-thumb {
    background: var(--wcaps-border-color);
    border-radius: 3px;
}

.wcaps-results-container::-webkit-scrollbar-thumb:hover {
    background: var(--wcaps-text-light);
}

/* ============================================
   Results List
   ============================================ */
.wcaps-results-list {
    list-style: none;
    margin: 0;
    padding: 8px;
}

.wcaps-result-item {
    margin: 0;
    padding: 0;
}

.wcaps-result-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    text-decoration: none;
    color: var(--wcaps-text-color);
    border-radius: var(--wcaps-radius);
    transition: background-color var(--wcaps-transition);
}

.wcaps-result-link:hover,
.wcaps-result-link:focus {
    background-color: var(--wcaps-bg-hover);
    outline: none;
}

/* ============================================
   Product Image
   ============================================ */
.wcaps-product-image {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: var(--wcaps-radius);
    overflow: hidden;
    background: var(--wcaps-bg-hover);
    position: relative;
}

.wcaps-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wcaps-sale-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--wcaps-sale-color);
    color: #ffffff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

/* ============================================
   Product Info
   ============================================ */
.wcaps-product-info {
    flex: 1;
    min-width: 0;
}

.wcaps-product-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--wcaps-text-color);
    margin: 0 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wcaps-product-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.wcaps-product-category {
    color: var(--wcaps-text-light);
}

.wcaps-product-price {
    font-weight: 600;
    color: var(--wcaps-text-color);
}

.wcaps-product-price del {
    color: var(--wcaps-text-light);
    font-weight: 400;
    margin-right: 4px;
}

.wcaps-product-price ins {
    text-decoration: none;
    color: var(--wcaps-sale-color);
}

.wcaps-stock-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.wcaps-stock-status.in-stock {
    background: rgba(5, 150, 105, 0.1);
    color: var(--wcaps-stock-in);
}

.wcaps-stock-status.out-of-stock {
    background: rgba(220, 38, 38, 0.1);
    color: var(--wcaps-stock-out);
}

/* ============================================
   No Results
   ============================================ */
.wcaps-no-results {
    padding: 32px 16px;
    text-align: center;
    color: var(--wcaps-text-light);
}

.wcaps-no-results-icon {
    margin-bottom: 12px;
    opacity: 0.5;
}

.wcaps-no-results-text {
    font-size: 14px;
    margin: 0;
}

/* ============================================
   View All Results Link
   ============================================ */
.wcaps-view-all {
    display: block;
    padding: 14px 16px;
    text-align: center;
    text-decoration: none;
    color: var(--wcaps-primary-color);
    font-weight: 500;
    border-top: 1px solid var(--wcaps-border-color);
    transition: background-color var(--wcaps-transition);
}

.wcaps-view-all:hover {
    background-color: var(--wcaps-bg-hover);
}

.wcaps-view-all-count {
    font-weight: 400;
    color: var(--wcaps-text-light);
}

/* ============================================
   Mobile Trigger Button
   ============================================ */
.wcaps-mobile-trigger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: 2px solid var(--wcaps-border-color);
    border-radius: var(--wcaps-radius);
    color: var(--wcaps-text-color);
    cursor: pointer;
    transition: border-color var(--wcaps-transition), background-color var(--wcaps-transition);
}

.wcaps-mobile-trigger:hover {
    border-color: var(--wcaps-primary-color);
    background-color: var(--wcaps-bg-hover);
}

.wcaps-close-mobile {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--wcaps-text-color);
    cursor: pointer;
    flex-shrink: 0;
}

.wcaps-mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ============================================
   Style Variations
   ============================================ */

/* Minimal Style */
.wcaps-style-minimal .wcaps-search-input {
    border: none;
    border-bottom: 2px solid var(--wcaps-border-color);
    border-radius: 0;
    padding-left: 36px;
}

.wcaps-style-minimal .wcaps-search-input:focus {
    border-color: var(--wcaps-primary-color);
    box-shadow: none;
}

.wcaps-style-minimal .wcaps-search-icon {
    left: 4px;
}

.wcaps-style-minimal .wcaps-search-button {
    border-radius: 0;
}

/* Rounded Style */
.wcaps-style-rounded .wcaps-search-input {
    border-radius: 24px;
    padding-left: 48px;
}

.wcaps-style-rounded .wcaps-search-icon {
    left: 16px;
}

.wcaps-style-rounded .wcaps-search-button {
    border-radius: 24px;
}

.wcaps-style-rounded .wcaps-results-wrapper {
    border-radius: 16px;
}

/* Fullwidth Style */
.wcaps-style-fullwidth {
    max-width: 100%;
}

.wcaps-style-fullwidth .wcaps-search-form {
    flex-direction: column;
}

.wcaps-style-fullwidth .wcaps-search-button {
    width: 100%;
    margin-top: 8px;
}

/* ============================================
   Responsive Styles
   ============================================ */
@media screen and (max-width: 768px) {
    /* Show mobile trigger, hide desktop search */
    .wcaps-mobile-trigger {
        display: flex;
    }
    
    .wcaps-search-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--wcaps-bg-color);
        z-index: 9999;
        padding: 16px;
        display: none;
        flex-direction: column;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .wcaps-search-wrapper.mobile-open .wcaps-search-container {
        display: flex;
        transform: translateY(0);
    }
    
    .wcaps-search-wrapper.mobile-open .wcaps-mobile-overlay {
        display: block;
        opacity: 1;
    }
    
    .wcaps-search-form {
        flex-shrink: 0;
    }
    
    .wcaps-close-mobile {
        display: flex;
    }
    
    .wcaps-search-button .wcaps-button-text {
        display: none;
    }
    
    .wcaps-search-button .wcaps-button-icon {
        display: flex;
    }
    
    .wcaps-search-button {
        padding: 0 12px;
    }
    
    .wcaps-results-wrapper {
        position: relative;
        top: 16px;
        flex: 1;
        max-height: none;
        border: none;
        box-shadow: none;
        display: none;
    }
    
    .wcaps-search-wrapper.mobile-open.has-results .wcaps-results-wrapper {
        display: block;
    }
    
    .wcaps-results-container {
        max-height: calc(100vh - 160px);
    }
    
    .wcaps-product-image {
        width: 56px;
        height: 56px;
    }
    
    .wcaps-result-link {
        padding: 10px;
    }
}

@media screen and (max-width: 480px) {
    .wcaps-product-image {
        width: 48px;
        height: 48px;
    }
    
    .wcaps-product-title {
        font-size: 13px;
    }
    
    .wcaps-product-meta {
        font-size: 11px;
    }
}

/* ============================================
   Keyboard Navigation Focus States
   ============================================ */
.wcaps-result-link:focus-visible {
    outline: 2px solid var(--wcaps-primary-color);
    outline-offset: -2px;
}

.wcaps-search-input:focus-visible {
    outline: none;
}

/* ============================================
   Animation for Results
   ============================================ */
.wcaps-results-wrapper {
    animation: wcaps-fadeIn 0.2s ease;
}

@keyframes wcaps-fadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .wcaps-search-wrapper {
        display: none;
    }
}
