/**
 * WSBI Visual Search Styles
 * Clean, minimal design without rounded corners
 *
 * @package WSBI
 */

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

/* CSS Variables */
:root {
    --wsbi-primary: #000000;
    --wsbi-primary-hover: #333333;
    --wsbi-accent: #0066ff;
    --wsbi-bg: #ffffff;
    --wsbi-bg-secondary: #fafafa;
    --wsbi-text: #111111;
    --wsbi-text-secondary: #666666;
    --wsbi-border: #e0e0e0;
    --wsbi-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

/* Trigger Button - Icon only */
.wsbi-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    color: var(--wsbi-text);
    border: 1px solid var(--wsbi-border);
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.wsbi-trigger-icon {
    width: 20px;
    height: 20px;
}

/* 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.6);
}

.wsbi-modal-container {
    position: relative;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--wsbi-bg);
    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: 16px;
    font-weight: 600;
    color: var(--wsbi-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

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

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

/* Search Form Grid Layout */
.wsbi-search-form {
    display: grid;
    gap: 16px;
}

/* Upload Area */
.wsbi-upload-area {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    padding: 32px 20px;
    background: var(--wsbi-bg-secondary);
    border: 1px dashed var(--wsbi-border);
    cursor: pointer;
    transition: all 0.15s ease;
}

.wsbi-upload-area:hover,
.wsbi-upload-area.wsbi-drag-over {
    border-color: var(--wsbi-text);
    background: var(--wsbi-bg);
}

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

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

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

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

/* Preview */
.wsbi-preview {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    padding: 16px;
    background: var(--wsbi-bg-secondary);
}

.wsbi-preview img {
    max-width: 100%;
    max-height: 280px;
    object-fit: contain;
}

.wsbi-preview-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--wsbi-text);
    border: none;
    color: white;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.wsbi-preview-remove:hover {
    opacity: 0.8;
}

/* Text Input */
.wsbi-text-input-wrapper {
    width: 100%;
}

.wsbi-text-input {
    width: 100%;
    padding: 14px 16px;
    font-size: 14px;
    color: var(--wsbi-text);
    background: var(--wsbi-bg);
    border: 1px solid var(--wsbi-border);
    transition: border-color 0.15s ease;
    box-sizing: border-box;
}

.wsbi-text-input::placeholder {
    color: var(--wsbi-text-secondary);
}

.wsbi-text-input:focus {
    outline: none;
    border-color: var(--wsbi-text);
}

/* Search Button */
.wsbi-search-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 8px;
    padding: 16px 24px;
    background: var(--wsbi-primary);
    color: white;
    border: none;
    font-size: 14px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.15s ease;
    box-sizing: border-box;
}

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

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

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

.wsbi-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid var(--wsbi-border);
    border-top-color: var(--wsbi-text);
    animation: wsbi-spin 0.8s linear infinite;
}

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

.wsbi-loading p {
    margin: 12px 0 0;
    font-size: 13px;
    color: var(--wsbi-text-secondary);
}

/* Error State */
.wsbi-error {
    padding: 14px;
    background: #fff0f0;
    border: 1px solid #ffcccc;
    color: #cc0000;
    font-size: 13px;
    text-align: center;
}

/* Results */
.wsbi-results {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--wsbi-border);
}

.wsbi-results-title {
    margin: 0 0 16px;
    font-size: 11px;
    font-weight: 600;
    color: var(--wsbi-text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

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

/* Product Card */
.wsbi-product-card {
    display: grid;
    grid-template-rows: auto 1fr;
    background: var(--wsbi-bg);
    border: 1px solid var(--wsbi-border);
    overflow: hidden;
    transition: border-color 0.15s ease;
}

.wsbi-product-card:hover {
    border-color: var(--wsbi-text);
}

.wsbi-product-link {
    display: grid;
    grid-template-rows: auto 1fr;
    text-decoration: none;
    color: inherit;
    height: 100%;
}

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

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

.wsbi-similarity-badge {
    position: absolute;
    top: 0;
    right: 0;
    padding: 4px 8px;
    background: var(--wsbi-text);
    color: white;
    font-size: 10px;
    font-weight: 600;
}

.wsbi-product-info {
    display: grid;
    grid-template-rows: 1fr auto;
    gap: 8px;
    padding: 12px;
    align-content: space-between;
}

.wsbi-product-name {
    margin: 0;
    font-size: 12px;
    font-weight: 400;
    color: var(--wsbi-text);
    line-height: 1.5;
    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-text);
}

.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: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--wsbi-text);
    cursor: pointer;
    transition: background 0.15s ease;
}

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

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

/* 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.5);
    pointer-events: none;
    display: none;
}

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

.wsbi-crop-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    background: var(--wsbi-text);
    color: white;
    border: none;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.wsbi-crop-btn:hover {
    opacity: 0.85;
}

.wsbi-crop-btn-success {
    background: #22c55e;
}

.wsbi-crop-btn-danger {
    background: #ef4444;
}

.wsbi-crop-btn-detect {
    background: #0066ff;
}

/* 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 #0066ff;
    background: rgba(0, 102, 255, 0.1);
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.15s ease;
}

.wsbi-detect-box:hover {
    border-color: #0052cc;
    background: rgba(0, 102, 255, 0.2);
}

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

.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: 2px;
}

.wsbi-detect-label {
    position: absolute;
    top: -22px;
    left: 0;
    padding: 2px 6px;
    background: var(--wsbi-text);
    color: white;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
}

.wsbi-detect-box-suggested .wsbi-detect-label {
    background: #22c55e;
}

.wsbi-detect-box-selected .wsbi-detect-label {
    background: #f59e0b;
}

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

.wsbi-detect-info span {
    display: inline-block;
    padding: 4px 10px;
    background: var(--wsbi-text);
    color: white;
    font-size: 11px;
}

/* Spin animation */
.wsbi-spin {
    animation: wsbi-spin 0.8s linear infinite;
}

/* Scanning Overlay (AliExpress style) */
.wsbi-scan-overlay {
    position: absolute;
    inset: 0;
    display: none;
    z-index: 25;
    pointer-events: none;
}

.wsbi-scan-overlay.wsbi-scan-active {
    display: block;
}

.wsbi-scan-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, #0066ff, transparent);
    box-shadow: 0 0 8px #0066ff, 0 0 16px #0066ff;
    animation: wsbi-scan-line 2s ease-in-out infinite;
}

@keyframes wsbi-scan-line {
    0%, 100% {
        top: 0;
        opacity: 1;
    }
    50% {
        top: calc(100% - 2px);
        opacity: 1;
    }
}

.wsbi-scan-corners {
    position: absolute;
    inset: 8px;
}

.wsbi-scan-corner {
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: #0066ff;
    border-style: solid;
    border-width: 0;
}

.wsbi-scan-corner-tl {
    top: 0;
    left: 0;
    border-top-width: 2px;
    border-left-width: 2px;
}

.wsbi-scan-corner-tr {
    top: 0;
    right: 0;
    border-top-width: 2px;
    border-right-width: 2px;
}

.wsbi-scan-corner-bl {
    bottom: 0;
    left: 0;
    border-bottom-width: 2px;
    border-left-width: 2px;
}

.wsbi-scan-corner-br {
    bottom: 0;
    right: 0;
    border-bottom-width: 2px;
    border-right-width: 2px;
}

.wsbi-scan-status {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
}

.wsbi-scan-text {
    display: inline-block;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* Powered By */
.wsbi-powered-by {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--wsbi-border);
    text-align: center;
}

.wsbi-powered-by a {
    font-size: 10px;
    color: var(--wsbi-text-secondary);
    text-decoration: none;
    letter-spacing: 0.3px;
    transition: color 0.15s ease;
}

.wsbi-powered-by a:hover {
    color: var(--wsbi-text);
}

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

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

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

    .wsbi-search-form {
        gap: 12px;
    }

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

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

    .wsbi-product-name {
        font-size: 11px;
    }

    .wsbi-product-price {
        font-size: 12px;
    }
}
