/**
 * WSBI Visual Search Styles
 *
 * @package WSBI
 */

/* Hidden elements */
[hidden] {
    display: none !important;
}

/* CSS Variables */
:root {
    --wsbi-primary: #7c3aed;
    --wsbi-primary-hover: #6d28d9;
    --wsbi-bg: #ffffff;
    --wsbi-bg-secondary: #f8fafc;
    --wsbi-text: #1e293b;
    --wsbi-text-secondary: #64748b;
    --wsbi-border: #e2e8f0;
    --wsbi-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
    --wsbi-radius: 12px;
    --wsbi-radius-sm: 8px;
}

/* Trigger Button */
.wsbi-trigger-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--wsbi-primary);
    color: white;
    border: none;
    border-radius: var(--wsbi-radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.wsbi-trigger-button:hover {
    background: var(--wsbi-primary-hover);
}

.wsbi-trigger-button svg {
    flex-shrink: 0;
}

/* Modal */
.wsbi-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.wsbi-modal[hidden] {
    display: none;
}

.wsbi-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.wsbi-modal-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--wsbi-bg);
    border-radius: var(--wsbi-radius);
    box-shadow: var(--wsbi-shadow);
}

.wsbi-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--wsbi-border);
}

.wsbi-modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--wsbi-text);
}

.wsbi-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--wsbi-radius-sm);
    color: var(--wsbi-text-secondary);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.wsbi-modal-close:hover {
    background: var(--wsbi-bg-secondary);
    color: var(--wsbi-text);
}

.wsbi-modal-body {
    padding: 24px;
}

/* Upload Area */
.wsbi-upload-area {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 40px 20px;
    background: var(--wsbi-bg-secondary);
    border: 2px dashed var(--wsbi-border);
    border-radius: var(--wsbi-radius);
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.wsbi-upload-area:hover,
.wsbi-upload-area.wsbi-drag-over {
    border-color: var(--wsbi-primary);
    background: rgba(124, 58, 237, 0.05);
}

.wsbi-upload-content {
    text-align: center;
}

.wsbi-upload-content svg {
    margin-bottom: 16px;
    color: var(--wsbi-text-secondary);
}

.wsbi-upload-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 500;
    color: var(--wsbi-text);
}

.wsbi-upload-subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--wsbi-text-secondary);
}

/* Preview */
.wsbi-preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 20px;
    background: var(--wsbi-bg-secondary);
    border-radius: var(--wsbi-radius);
}

.wsbi-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--wsbi-radius-sm);
    object-fit: contain;
}

.wsbi-preview-remove {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: background 0.2s ease;
}

.wsbi-preview-remove:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Text Input */
.wsbi-text-input-wrapper {
    margin-top: 16px;
}

.wsbi-text-input {
    width: 100%;
    padding: 14px 16px;
    font-size: 14px;
    border: 1px solid var(--wsbi-border);
    border-radius: var(--wsbi-radius-sm);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.wsbi-text-input:focus {
    outline: none;
    border-color: var(--wsbi-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

/* Search Button */
.wsbi-search-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 16px;
    padding: 14px 24px;
    background: var(--wsbi-primary);
    color: white;
    border: none;
    border-radius: var(--wsbi-radius-sm);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.wsbi-search-button:hover:not(:disabled) {
    background: var(--wsbi-primary-hover);
}

.wsbi-search-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Loading State */
.wsbi-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    text-align: center;
}

.wsbi-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--wsbi-border);
    border-top-color: var(--wsbi-primary);
    border-radius: 50%;
    animation: wsbi-spin 1s linear infinite;
}

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

.wsbi-loading p {
    margin: 16px 0 0;
    color: var(--wsbi-text-secondary);
}

/* Error State */
.wsbi-error {
    padding: 16px;
    background: #fef2f2;
    border-radius: var(--wsbi-radius-sm);
    color: #991b1b;
    text-align: center;
}

/* Results */
.wsbi-results {
    margin-top: 24px;
}

.wsbi-results-title {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--wsbi-text);
}

.wsbi-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}

/* Product Card */
.wsbi-product-card {
    background: var(--wsbi-bg);
    border: 1px solid var(--wsbi-border);
    border-radius: var(--wsbi-radius-sm);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.wsbi-product-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.wsbi-product-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.wsbi-product-image {
    position: relative;
    aspect-ratio: 1;
    background: var(--wsbi-bg-secondary);
}

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

.wsbi-similarity-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    background: var(--wsbi-primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
}

.wsbi-product-info {
    padding: 12px;
}

.wsbi-product-name {
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--wsbi-text);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wsbi-product-price {
    font-size: 14px;
    font-weight: 600;
    color: var(--wsbi-primary);
}

.wsbi-add-to-cart {
    display: block;
    width: 100%;
    padding: 10px;
    background: var(--wsbi-bg-secondary);
    border: none;
    border-top: 1px solid var(--wsbi-border);
    font-size: 13px;
    font-weight: 500;
    color: var(--wsbi-text);
    cursor: pointer;
    transition: background 0.2s ease;
}

.wsbi-add-to-cart:hover:not(:disabled) {
    background: var(--wsbi-border);
}

.wsbi-add-to-cart:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Crop UI */
.wsbi-crop-container {
    position: absolute;
    inset: 0;
    display: none;
    z-index: 5;
}

.wsbi-crop-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: crosshair;
    max-width: 100%;
    max-height: 100%;
}

.wsbi-crop-selection {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.3), inset 0 0 0 1px rgba(255,255,255,0.3);
    pointer-events: none;
    display: none;
}

.wsbi-crop-buttons {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 20;
}

.wsbi-crop-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
    backdrop-filter: blur(4px);
}

.wsbi-crop-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.wsbi-crop-btn-success {
    background: rgba(34, 197, 94, 0.9);
}

.wsbi-crop-btn-success:hover {
    background: rgba(22, 163, 74, 1);
}

.wsbi-crop-btn-danger {
    background: rgba(239, 68, 68, 0.9);
}

.wsbi-crop-btn-danger:hover {
    background: rgba(220, 38, 38, 1);
}

/* Auto-detect button */
.wsbi-crop-btn-detect {
    background: rgba(59, 130, 246, 0.9);
}

.wsbi-crop-btn-detect:hover {
    background: rgba(37, 99, 235, 1);
}

/* Detection Overlay */
.wsbi-detect-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    z-index: 15;
    pointer-events: none;
}

.wsbi-detect-boxes {
    position: relative;
    width: 100%;
    height: 100%;
}

.wsbi-detect-box {
    position: absolute;
    border: 2px solid #3b82f6;
    background: rgba(59, 130, 246, 0.1);
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.2s ease;
}

.wsbi-detect-box:hover {
    border-color: #2563eb;
    background: rgba(59, 130, 246, 0.2);
}

.wsbi-detect-box-suggested {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.15);
    border-width: 3px;
}

.wsbi-detect-box-suggested:hover {
    border-color: #16a34a;
    background: rgba(34, 197, 94, 0.25);
}

.wsbi-detect-box-selected {
    border-color: #f59e0b !important;
    background: rgba(245, 158, 11, 0.2) !important;
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

.wsbi-detect-label {
    position: absolute;
    top: -24px;
    left: 0;
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 11px;
    font-weight: 500;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
}

.wsbi-detect-box-suggested .wsbi-detect-label {
    background: rgba(34, 197, 94, 0.9);
}

.wsbi-detect-box-selected .wsbi-detect-label {
    background: rgba(245, 158, 11, 0.9);
}

.wsbi-detect-info {
    position: absolute;
    bottom: -30px;
    left: 0;
    right: 0;
    text-align: center;
    pointer-events: none;
}

.wsbi-detect-info span {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 12px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

/* Spin animation for detecting state */
.wsbi-spin {
    animation: wsbi-spin 1s linear infinite;
}

/* Responsive */
@media (max-width: 640px) {
    .wsbi-modal {
        padding: 0;
    }

    .wsbi-modal-container {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .wsbi-results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}
