/* WC Dynamic Search - Styles */

:root {
    --wcds-primary: #7c3aed;
    --wcds-primary-hover: #6d28d9;
    --wcds-bg: #ffffff;
    --wcds-border: #e5e7eb;
    --wcds-text: #1f2937;
    --wcds-text-light: #6b7280;
    --wcds-success: #10b981;
    --wcds-warning: #f59e0b;
    --wcds-error: #ef4444;
    --wcds-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.15);
    --wcds-radius: 12px;
    --wcds-transition: 0.2s ease;
}

/* Container */
.wcds-search-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    box-sizing: border-box;
}

.wcds-search-container *,
.wcds-search-container *::before,
.wcds-search-container *::after {
    box-sizing: border-box;
}

/* Form */
.wcds-search-form {
    display: flex;
    gap: 8px;
    align-items: stretch;
    width: 100%;
}

/* Input Wrapper */
.wcds-input-wrapper {
    position: relative;
    flex: 1;
    width: 100%;
    min-width: 0;
}

/* Input */
.wcds-search-input {
    width: 100% !important;
    min-width: 100%;
    padding: 14px 45px 14px 48px !important;
    font-size: 16px !important;
    line-height: 1.5;
    color: var(--wcds-text);
    background: var(--wcds-bg) !important;
    border: 2px solid var(--wcds-border) !important;
    border-radius: var(--wcds-radius) !important;
    outline: none;
    transition: border-color var(--wcds-transition), box-shadow var(--wcds-transition);
    box-sizing: border-box !important;
    margin: 0 !important;
    height: auto !important;
    max-width: none !important;
}

.wcds-search-input:focus {
    border-color: var(--wcds-primary);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.1);
}

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

/* Search Icon */
.wcds-search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--wcds-text-light);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Spinner */
.wcds-spinner {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--wcds-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.wcds-spinner svg {
    animation: wcds-spin 1s linear infinite;
}

@keyframes wcds-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Clear Button */
.wcds-clear-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    padding: 4px;
    background: transparent;
    border: none;
    color: var(--wcds-text-light);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--wcds-transition), background var(--wcds-transition);
}

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

/* Search Button */
.wcds-search-button {
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: var(--wcds-primary);
    border: none;
    border-radius: var(--wcds-radius);
    cursor: pointer;
    transition: background var(--wcds-transition), transform var(--wcds-transition);
    white-space: nowrap;
}

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

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

/* Results Container */
.wcds-results-container {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--wcds-bg);
    border: 1px solid var(--wcds-border);
    border-radius: var(--wcds-radius);
    box-shadow: var(--wcds-shadow);
    max-height: 70vh;
    overflow-y: auto;
    z-index: 9999;
}

.wcds-results-inner {
    padding: 8px;
}

/* Results Header */
.wcds-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--wcds-border);
    font-size: 13px;
    color: var(--wcds-text-light);
}

.wcds-results-count {
    font-weight: 500;
}

/* Product Item */
.wcds-product-item {
    display: flex;
    gap: 16px;
    padding: 12px;
    border-radius: 8px;
    transition: background var(--wcds-transition);
    text-decoration: none;
    color: inherit;
}

.wcds-product-item:hover {
    background: #f9fafb;
}

.wcds-product-link {
    display: flex;
    gap: 16px;
    text-decoration: none;
    color: inherit;
    flex: 1;
}

/* Product Image */
.wcds-product-image {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    background: #f3f4f6;
}

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

/* Product Info */
.wcds-product-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.wcds-product-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--wcds-text);
    margin: 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.wcds-product-sku {
    color: var(--wcds-text-light);
}

.wcds-product-price {
    font-weight: 600;
    color: var(--wcds-primary);
}

.wcds-product-price del {
    color: var(--wcds-text-light);
    font-weight: 400;
}

.wcds-product-price ins {
    text-decoration: none;
}

/* Stock Status */
.wcds-stock-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.wcds-stock-badge.in-stock {
    background: rgba(16, 185, 129, 0.1);
    color: var(--wcds-success);
}

.wcds-stock-badge.out-of-stock {
    background: rgba(239, 68, 68, 0.1);
    color: var(--wcds-error);
}

.wcds-stock-badge.on-backorder {
    background: rgba(245, 158, 11, 0.1);
    color: var(--wcds-warning);
}

/* Variable Product Badge */
.wcds-variable-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(124, 58, 237, 0.1);
    color: var(--wcds-primary);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--wcds-transition);
    border: none;
    margin-left: auto;
}

.wcds-variable-badge:hover {
    background: rgba(124, 58, 237, 0.2);
}

.wcds-variable-badge svg {
    transition: transform var(--wcds-transition);
}

.wcds-variable-badge.expanded svg {
    transform: rotate(180deg);
}

/* Variations Container */
.wcds-variations-container {
    margin-top: 8px;
    margin-left: 80px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
}

.wcds-variations-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--wcds-text-light);
    font-size: 14px;
    gap: 8px;
}

.wcds-variations-loading svg {
    animation: wcds-spin 1s linear infinite;
}

/* Variation Item - Now a link */
a.wcds-variation-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    border-radius: 6px;
    transition: background var(--wcds-transition);
    align-items: center;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

a.wcds-variation-item:hover {
    background: #fff;
}

a.wcds-variation-item + a.wcds-variation-item {
    border-top: 1px solid var(--wcds-border);
}

/* Matched SKU highlight */
.wcds-matched-sku {
    background: rgba(124, 58, 237, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}

/* Go button for variations */
.wcds-go-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--wcds-primary);
    color: #fff;
    border-radius: 50%;
    transition: transform var(--wcds-transition), background var(--wcds-transition);
}

a.wcds-variation-item:hover .wcds-go-btn {
    background: var(--wcds-primary-hover);
    transform: translateX(2px);
}

.wcds-stock-indicator {
    font-size: 12px;
    color: var(--wcds-text-light);
}

.wcds-stock-indicator.out {
    color: var(--wcds-error);
}

.wcds-variation-image {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}

.wcds-variation-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wcds-variation-info {
    flex: 1;
    min-width: 0;
}

.wcds-variation-attributes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
}

.wcds-attribute-tag {
    display: inline-flex;
    padding: 2px 8px;
    background: #fff;
    border: 1px solid var(--wcds-border);
    border-radius: 4px;
    font-size: 12px;
    color: var(--wcds-text);
}

.wcds-attribute-tag .attr-name {
    color: var(--wcds-text-light);
    margin-right: 4px;
}

.wcds-variation-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 13px;
}

.wcds-variation-sku {
    color: var(--wcds-text-light);
}

.wcds-variation-price {
    font-weight: 600;
    color: var(--wcds-primary);
}

.wcds-variation-actions {
    margin-left: auto;
    flex-shrink: 0;
}

/* Variations Pagination */
.wcds-variations-pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--wcds-border);
}

.wcds-var-page-btn {
    padding: 6px 12px;
    background: #fff;
    border: 1px solid var(--wcds-border);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all var(--wcds-transition);
}

.wcds-var-page-btn:hover:not(:disabled) {
    border-color: var(--wcds-primary);
    color: var(--wcds-primary);
}

.wcds-var-page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* No Results */
.wcds-no-results {
    padding: 40px 20px;
    text-align: center;
    color: var(--wcds-text-light);
}

.wcds-no-results-icon {
    margin-bottom: 12px;
    color: var(--wcds-border);
}

.wcds-no-results h4 {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--wcds-text);
}

.wcds-no-results p {
    margin: 0;
    font-size: 14px;
}

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

.wcds-view-all:hover {
    background: rgba(124, 58, 237, 0.05);
}

/* Pagination */
.wcds-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--wcds-border);
}

.wcds-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    background: #fff;
    border: 1px solid var(--wcds-border);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--wcds-text);
    cursor: pointer;
    transition: all var(--wcds-transition);
}

.wcds-page-btn:hover:not(:disabled):not(.active) {
    border-color: var(--wcds-primary);
    color: var(--wcds-primary);
}

.wcds-page-btn.active {
    background: var(--wcds-primary);
    border-color: var(--wcds-primary);
    color: #fff;
}

.wcds-page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Highlight matched text */
.wcds-highlight {
    background: rgba(124, 58, 237, 0.15);
    padding: 0 2px;
    border-radius: 2px;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .wcds-search-container {
        max-width: 100%;
    }
    
    .wcds-search-input {
        padding: 12px 40px 12px 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .wcds-results-container {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 70vh;
        border-radius: var(--wcds-radius) var(--wcds-radius) 0 0;
    }
    
    .wcds-product-item {
        gap: 12px;
        padding: 10px;
    }
    
    .wcds-product-image {
        width: 56px;
        height: 56px;
    }
    
    .wcds-product-name {
        font-size: 14px;
    }
    
    .wcds-variations-container {
        margin-left: 0;
        margin-top: 12px;
    }
    
    .wcds-variation-item {
        flex-wrap: wrap;
    }
    
    .wcds-variation-actions {
        margin-left: auto;
    }
}

/* Scrollbar styling */
.wcds-results-container::-webkit-scrollbar {
    width: 8px;
}

.wcds-results-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.wcds-results-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.wcds-results-container::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Animation */
@keyframes wcds-fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wcds-results-container {
    animation: wcds-fadeIn 0.2s ease;
}

.wcds-product-item {
    animation: wcds-fadeIn 0.2s ease;
    animation-fill-mode: both;
}

.wcds-product-item:nth-child(1) { animation-delay: 0.02s; }
.wcds-product-item:nth-child(2) { animation-delay: 0.04s; }
.wcds-product-item:nth-child(3) { animation-delay: 0.06s; }
.wcds-product-item:nth-child(4) { animation-delay: 0.08s; }
.wcds-product-item:nth-child(5) { animation-delay: 0.10s; }
