/**
 * Searchability Frontend Styles.
 */

/* Container */
.searchability-container {
    position: relative;
    width: 100%;
    width: var(--searchability-search-width, 100%);
    max-width: var(--searchability-search-max-width, 700px);
}

/* Form */
.searchability-form {
    position: relative;
    width: 100%;
}

/* Input wrapper */
.searchability-input-wrapper {
    display: flex;
    align-items: center;
    background: #fff;
    gap: 4px;
    border: 1.5px solid #e3e3e6;
    border-radius: 999px;
    padding: 3px 4px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
    box-sizing: border-box;
}

.searchability-input-wrapper:hover {
    border-color: #d2d2d6;
}

.searchability-input-wrapper:focus-within {
    border-color: #05386B;
    box-shadow: 0 0 0 4px rgba(5, 56, 107, 0.12);
}

/* Input field */
.searchability-input[type="text"] {
    flex: 1;
    border: none;
    padding: 12px 8px 12px 20px;
    font-size: 16px;
    line-height: 1.4;
    color: #1d2127;
    border-radius: 999px;
    background: transparent;
    outline: none;
    min-width: 0;
}

.searchability-input[type="text"]:focus {
    box-shadow: none;
}

.searchability-input::placeholder {
    color: #9aa0aa;
    transition: opacity 0.3s ease-in-out;
}

.searchability-input.placeholder-fade::placeholder {
    opacity: 0;
}

/* Clear button */
.searchability-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #666;
    padding: 0;
    margin-right: 4px;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s;
}

.searchability-clear:hover {
    background: #f0f0f0;
    color: #333;
}

/* Submit button */
.searchability-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: none;
    background: #05386B;
    cursor: pointer;
    color: #fff;
    padding: 0;
    margin: 0;
    flex: none;
    border-radius: 50%;
    transition: background-color 0.18s ease, transform 0.1s ease;
}

.searchability-submit:hover {
    background: #06294e;
}

.searchability-submit:active {
    transform: scale(0.94);
}

/* Suggestions dropdown */
.searchability-suggestions {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ececef;
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.12);
    z-index: 9999;
    overflow: hidden;
}

.searchability-suggestions-list {
    list-style: none;
    margin: 0;
    padding: 8px 0;
    max-height: var(--searchability-search-max-height, none);
    overflow-y: auto;
}

/* Suggestion item */
.searchability-suggestion-item {
    margin: 0;
    padding: 0;
}

.searchability-suggestion-item a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: #333;
    text-decoration: none;
    transition: background-color 0.15s;
    gap: 12px;
}

.searchability-suggestion-item a:hover,
.searchability-suggestion-item.is-selected a {
    background: #f3f6fa;
}

/* Suggestion icon */
.searchability-suggestion-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
}

.searchability-suggestion-icon.icon-store {
    background: linear-gradient(135deg, #f79090, #F76C6C);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 50%;
}

.searchability-suggestion-icon.icon-search {
    color: #666;
}

.searchability-suggestion-icon.icon-category {
    color: #666;
}

/* Suggestion text */
.searchability-suggestion-text {
    flex: 1;
    font-size: 15px;
    line-height: 1.4;
}

.searchability-suggestion-text strong {
    font-weight: 600;
}

/* Result row: thumbnail + price (live dropdown) */
.searchability-suggestion-thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f3f5;
    color: #9aa0aa;
}

.searchability-suggestion-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.searchability-suggestion-price {
    margin-left: auto;
    padding-left: 12px;
    font-weight: 600;
    font-size: 14px;
    color: #05386B;
    white-space: nowrap;
}

/* Vendor badge */
.searchability-vendor-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.searchability-vendor-badge::before {
    content: 'Shop';
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    background: #f56400;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

/* Loading state */
.searchability-loading .searchability-submit {
    pointer-events: none;
}

.searchability-loading .searchability-submit::after {
    content: '';
    display: block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: searchability-spin 0.6s linear infinite;
}

.searchability-loading .searchability-submit svg {
    display: none;
}

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

/* No results */
.searchability-no-results {
    padding: 16px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .searchability-input[type="text"] {
        padding: 12px 16px;
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    .searchability-submit {
        width: 40px;
        height: 40px;
    }

    .searchability-suggestion-item a {
        padding: 10px 14px;
    }

    /* Mobile collapsed state - only show toggle button */
    .searchability-container {
        position: static;
    }

    .searchability-toggle {
        /* Inheriting from .cm-icon-btn */
        display: flex;
        opacity: 1;
        visibility: visible;
    }

    /* Hide the full form, show toggle instead */
    .searchability-form {
        display: none;
        position: absolute;
        top: 59px;
        left: 0;
        right: 0;
        z-index: 9999;
        padding: 12px 16px;
        box-sizing: border-box;
        background: #fff;
        box-shadow: 0 15px 30px rgb(0 0 0 / .15);
    }

    .searchability-container.is-expanded .searchability-form {
        display: block;
    }

    .searchability-container.is-expanded .searchability-toggle {
        color: #05386B;
    }

    /* Suggestions inside fixed form */
    .searchability-container.is-expanded .searchability-suggestions {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        max-height: 70vh;
        overflow-y: auto;
    }

    /* Mobile full-width form wrapper */
    .searchability-container.is-expanded .searchability-input-wrapper {
        width: 100%;
    }

    /* Header integration - remove sizing constraints */
    .header-search-wrap .searchability-container {
        width: auto;
        max-width: none;
    }

    .searchability-ai-style-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* Desktop - hide the standalone toggle magnifier, show the inline form.
   Extra-specific selector so theme button styles (e.g. .cm-icon-btn) can't re-show it. */
@media (min-width: 481px) {
    .searchability-container .searchability-toggle,
    .searchability-container button.searchability-toggle.cm-icon-btn {
        display: none !important;
    }

    .searchability-container .searchability-form {
        display: block !important;
    }
}

/* Image Search Button (camera icon in search bar) */
.searchability-image-btn {
    display: flex;
    align-items: center;
    font-family: var(--wp--preset--font-family--system-sans-serif);
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #999;
    padding: 0;
    margin-right: 2px;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s;
}

.searchability-image-btn:hover {
    background: #f0f0f0;
    color: #f56400;
}

/* Style Match Button Wrapper */
.searchability-style-match-wrapper {
    position: absolute;
    z-index: 10;
    margin: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.searchability-pos-top-left {
    top: 0;
    left: 0;
}

.searchability-pos-top-right {
    top: 0;
    right: 0;
}

.searchability-pos-bottom-left {
    bottom: 0;
    left: 0;
}

.searchability-pos-bottom-right {
    bottom: 0;
    right: 0;
}

.searchability-ai-style-match-btn {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 30px;
    padding: 0;
    width: 38px;
    height: 38px;
    overflow: hidden;
    color: #333;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-weight: 500;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
}

.searchability-ai-style-match-btn:hover {
    width: auto;
    padding-right: 15px;
    background: #fff;
    color: #9333ea;
}

.searchability-style-match-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    color: #9333ea;
    transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.searchability-ai-style-match-btn:hover .searchability-style-match-icon {
    transform: rotate(15deg) scale(1.1);
}

.searchability-style-match-icon svg {
    display: block;
}

.searchability-style-match-label {
    white-space: nowrap;
    font-weight: 500;
    font-family: Montserrat, sans-serif;
    opacity: 0;
    transform: translateX(-15px) scale(.5);
    transition: all 0.2s cubic-bezier(0.23, 1, 0.32, 1);
    font-size: 13px;
}

.searchability-ai-style-match-btn:hover .searchability-style-match-label {
    opacity: 1;
    transform: translateX(0) scale(1);
}

/* Ensure product card is relative */
.products .product,
.woocommerce-loop-product-link {
    position: relative;
    display: block;
}

/* Style Match Modal */
.searchability-ai-style-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.searchability-ai-style-modal.is-active {
    display: flex;
}

.searchability-ai-style-modal-content {
    background: #fff;
    width: 95vw;
    max-width: 800px;
    max-height: 85vh;
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.searchability-ai-style-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.searchability-ai-style-modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #333;
}

.searchability-ai-style-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 5px;
    line-height: 1;
}

.searchability-ai-style-modal-close:hover {
    color: #333;
}

.searchability-ai-style-modal-body {
    padding: 24px;
    overflow-y: auto;
}

.searchability-ai-style-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 30px;
    align-items: start;
    width: 100%;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .searchability-ai-style-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 20px;
    }
}

@media (max-width: 480px) {}

.searchability-ai-style-item {
    text-align: left;
    text-decoration: none;
    color: #333;
    transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
    display: flex;
    flex-direction: column;
}

.searchability-ai-style-item:hover {
    transform: translateY(-8px);
}

.searchability-ai-style-item:hover img {
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
}

.searchability-ai-style-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.searchability-ai-style-item .title {
    font-size: 15px;
    line-height: 1.5;
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #333;
}

.searchability-ai-style-item .price {
    font-size: 13px;
    color: #9333ea;
    font-weight: 700;
}

.searchability-ai-style-modal-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 50px;
    color: #666;
}

.searchability-ai-style-modal-loader .spin {
    font-size: 32px;
    width: 32px;
    height: 32px;
    margin-bottom: 15px;
    animation: searchability-spin 1s linear infinite;
    color: #9333ea;
}