/**
 * TWOWIN Smart Search — Styles
 * v1.0.0
 */

:root {
    --ts-bg: #f4f5f7;
    --ts-card: #ffffff;
    --ts-text: #172b4d;
    --ts-text2: #6b778c;
    --ts-border: #dfe1e6;
    --ts-brand: #4caf50;
    --ts-brand-light: rgba(76, 175, 80, 0.1);
    --ts-radius: 12px;
}

/* Hide native Webasyst search results */
.search-res,
.search__history,
.search__history_active {
    display: none !important;
}

/* ========== DESKTOP ========== */
@media (min-width: 769px) {
    .ts-overlay {
        position: absolute;
        top: 100%;
        left: -80px;
        right: -80px;
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s ease;
        margin-top: 2px;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    }
    .ts-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    .ts-container {
        background: var(--ts-card);
        border-radius: var(--ts-radius);
        box-shadow: 0 8px 32px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05);
        border: 1px solid var(--ts-border);
        overflow: hidden;
    }

    .ts-header,
    .ts-input-wrap {
        display: none;
    }

    .ts-body {
        display: grid;
        grid-template-columns: 1fr 1.6fr;
        gap: 0;
        max-height: 500px;
    }

    .ts-suggestions {
        padding: 14px;
        border-right: 1px solid var(--ts-border);
        overflow-y: auto;
        max-height: 500px;
    }

    .ts-results {
        padding: 14px;
        overflow-y: auto;
        max-height: 500px;
    }

    .ts-section-label {
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--ts-text2);
        padding: 6px 12px;
        margin-bottom: 4px;
    }

    .ts-suggestion-item {
        padding: 10px 12px;
        border-radius: 6px;
        cursor: pointer;
        transition: background 0.15s;
        font-size: 14px;
        line-height: 1.4;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 2px;
    }
    .ts-suggestion-item:hover {
        background: var(--ts-bg);
    }

    .ts-history-remove {
        width: 22px;
        height: 22px;
        border: none;
        border-radius: 50%;
        background: transparent;
        color: var(--ts-text2);
        font-size: 16px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.15s;
        padding: 0;
    }
    .ts-history-remove:hover {
        background: #ff4757;
        color: #fff;
    }

    /* Products grid */
    .ts-results-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 14px;
    }

    .ts-product {
        border: 1px solid var(--ts-border);
        border-radius: 8px;
        padding: 12px;
        text-decoration: none;
        color: inherit;
        display: block;
        transition: all 0.15s;
        background: #fff;
    }
    .ts-product:hover {
        box-shadow: 0 4px 16px rgba(9,30,66,0.13);
        transform: translateY(-2px);
        border-color: var(--ts-brand);
    }

    .ts-product-img {
        height: 96px;
        border-radius: 6px;
        margin-bottom: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #f8f9fa;
        overflow: hidden;
    }
    .ts-product-img img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .ts-product-name {
        font-size: 13px;
        line-height: 1.4;
        margin-bottom: 6px;
        color: var(--ts-text);
        font-weight: 500;
        word-wrap: break-word;
    }

    .ts-stock {
        display: inline-block;
        font-size: 11px;
        padding: 2px 6px;
        border-radius: 4px;
        margin-bottom: 6px;
    }
    .ts-in-stock {
        background: var(--ts-brand-light);
        color: var(--ts-brand);
    }
    .ts-no-stock {
        background: #fff3e0;
        color: #e65100;
    }

    .ts-product-price {
        font-size: 15px;
        font-weight: 600;
        color: var(--ts-brand);
        text-align: center;
        padding: 5px 8px;
        background: var(--ts-brand-light);
        border-radius: 6px;
    }

    .ts-empty,
    .ts-loading {
        padding: 24px 12px;
        text-align: center;
        color: var(--ts-text2);
        font-size: 14px;
    }
    .ts-empty-icon {
        font-size: 24px;
        display: block;
        margin-bottom: 6px;
        opacity: 0.7;
    }
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
    .ts-overlay {
        position: fixed;
        inset: 0;
        background: rgba(9,30,66,0.5);
        z-index: 10000;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    }
    .ts-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    .ts-container {
        width: 100%;
        height: 100%;
        background: var(--ts-bg);
        display: flex;
        flex-direction: column;
        transform: translateY(-20px);
        transition: transform 0.25s ease;
    }
    .ts-overlay.show .ts-container {
        transform: translateY(0);
    }

    .ts-header {
        padding: 10px 14px;
        background: var(--ts-card);
        border-bottom: 1px solid var(--ts-border);
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
    }
    .ts-title {
        font-size: 17px;
        font-weight: 600;
        color: var(--ts-text);
    }
    .ts-close {
        width: 32px;
        height: 32px;
        border: none;
        border-radius: 50%;
        background: transparent;
        font-size: 22px;
        color: var(--ts-text2);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .ts-input-wrap {
        padding: 8px 14px 12px;
        background: var(--ts-card);
        border-bottom: 1px solid var(--ts-border);
        flex-shrink: 0;
    }
    .ts-input {
        width: 100%;
        padding: 12px 14px;
        border: 1px solid var(--ts-border);
        border-radius: 10px;
        font-size: 16px;
        outline: none;
        color: var(--ts-text);
        box-sizing: border-box;
        transition: border-color 0.2s, box-shadow 0.2s;
    }
    .ts-input:focus {
        border-color: var(--ts-brand);
        box-shadow: 0 0 0 3px var(--ts-brand-light);
    }

    .ts-body {
        flex: 1;
        overflow-y: auto;
        padding: 8px;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .ts-suggestions {
        background: var(--ts-card);
        border-radius: 8px;
        padding: 6px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    }

    .ts-results {
        background: var(--ts-card);
        border-radius: 8px;
        padding: 6px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    }

    .ts-section-label {
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--ts-text2);
        padding: 8px 10px 4px;
    }

    .ts-suggestion-item {
        padding: 10px 12px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 15px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        transition: background 0.15s;
    }
    .ts-suggestion-item:hover,
    .ts-suggestion-item:active {
        background: var(--ts-bg);
    }

    .ts-history-remove {
        width: 24px;
        height: 24px;
        border: none;
        border-radius: 50%;
        background: var(--ts-bg);
        color: var(--ts-text2);
        font-size: 16px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }
    .ts-history-remove:hover {
        background: #ff4757;
        color: #fff;
    }

    /* Products — 1 per row on mobile */
    .ts-results-grid {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .ts-product {
        border: 1px solid var(--ts-border);
        border-radius: 8px;
        padding: 10px;
        text-decoration: none;
        color: inherit;
        display: flex;
        align-items: center;
        gap: 12px;
        transition: all 0.15s;
        background: #fff;
    }
    .ts-product:hover,
    .ts-product:active {
        border-color: var(--ts-brand);
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }

    .ts-product-img {
        width: 72px;
        height: 72px;
        border-radius: 6px;
        background: #f8f9fa;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        flex-shrink: 0;
    }
    .ts-product-img img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .ts-product-info {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .ts-product-name {
        font-size: 14px;
        line-height: 1.3;
        margin-bottom: 4px;
        color: var(--ts-text);
        font-weight: 500;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .ts-stock {
        display: inline-block;
        font-size: 11px;
        padding: 2px 6px;
        border-radius: 4px;
        margin-bottom: 4px;
        width: fit-content;
    }
    .ts-in-stock {
        background: var(--ts-brand-light);
        color: var(--ts-brand);
    }
    .ts-no-stock {
        background: #fff3e0;
        color: #e65100;
    }

    .ts-product-price {
        font-size: 14px;
        font-weight: 600;
        color: var(--ts-brand);
        padding: 3px 8px;
        background: var(--ts-brand-light);
        border-radius: 4px;
        width: fit-content;
    }

    .ts-empty,
    .ts-loading {
        padding: 20px 12px;
        text-align: center;
        color: var(--ts-text2);
        font-size: 14px;
    }
    .ts-empty-icon {
        font-size: 22px;
        display: block;
        margin-bottom: 6px;
        opacity: 0.7;
    }
}
