/**
 * 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;
    justify-content: space-between;
    background: #fff;
    gap: 10px;
    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;
}

/* ============================================================
   Display modes — inline / toggle / modal
   The collapse breakpoint is admin-configurable, so visibility is
   driven by a `.sb-collapsed` class that JS toggles via matchMedia
   (reading data-collapse-bp) rather than a hardcoded media query.
   ============================================================ */

/* The icon trigger — used for toggle/modal modes and collapsed inline.
   Self-contained so it renders even without the theme's .cm-icon-btn. */
.searchability-toggle {
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    border-radius: 50%;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.1s ease;
}

.searchability-toggle:hover {
    background: rgba(15, 23, 42, 0.06);
}

.searchability-toggle:active {
    transform: scale(0.94);
}

/* Default state (inline mode, expanded): show the form, hide the trigger.
   !important defeats theme button styles (e.g. Crafter's Market's .cm-icon-btn,
   which the trigger carries) that would otherwise re-show the magnifier. */
.searchability-container .searchability-toggle {
    display: none !important;
}

.searchability-container > .searchability-form {
    display: block;
}

/* Trigger-driven behaviour applies ONLY when JS is active (.searchability-js on <html>).
   Without JS, every mode falls back to the plain inline form and the icon stays hidden,
   so search is never a dead magnifier. */

/* Reveal the icon trigger for collapsed-inline / toggle / modal modes.
   (0,4,0)+!important beats both the base hide and any non-important theme rule. */
.searchability-js .searchability-container.sb-collapsed .searchability-toggle,
.searchability-js .searchability-container.searchability-mode-toggle .searchability-toggle,
.searchability-js .searchability-container.searchability-mode-modal .searchability-toggle {
    display: flex !important;
}

/* Trigger-only states shrink-wrap to the icon (so a header icon isn't 700px wide). */
.searchability-js .searchability-container.sb-collapsed,
.searchability-js .searchability-container.searchability-mode-toggle,
.searchability-js .searchability-container.searchability-mode-modal {
    position: relative;
    width: auto;
    max-width: none;
}

.searchability-js .searchability-container.sb-collapsed > .searchability-form,
.searchability-js .searchability-container.searchability-mode-toggle > .searchability-form {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    inset-inline-end: 0; /* right in LTR, left in RTL */
    z-index: 9999;
    width: min(440px, calc(100vw - 28px));
    padding: 14px;
    box-sizing: border-box;
    background: #fff;
    border: 1px solid #ececef;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(16, 24, 40, 0.16);
}

.searchability-js .searchability-container.sb-collapsed.is-expanded > .searchability-form,
.searchability-js .searchability-container.searchability-mode-toggle.is-expanded > .searchability-form {
    display: block;
    animation: searchability-panel-in 0.16s ease;
}

.searchability-container.is-expanded > .searchability-toggle {
    color: #05386B;
    background: rgba(5, 56, 107, 0.08);
}

/* Suggestions flow inside the floating panel (no second border / offset). */
.searchability-js .searchability-container.sb-collapsed > .searchability-form .searchability-suggestions,
.searchability-js .searchability-container.searchability-mode-toggle > .searchability-form .searchability-suggestions {
    position: static;
    margin-top: 12px;
    border: 0;
    border-top: 1px solid #ececef;
    border-radius: 0;
    box-shadow: none;
}

@keyframes searchability-panel-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Modal (overlay) search — Marie Curie style.
   Visibility is class-driven (.is-open) and gated behind .searchability-js, so
   without JS the dialog degrades to a plain inline search card (no dead trigger).
   ============================================================ */

/* No-JS / base: backdrop + close button only make sense as an overlay — hide them
   so the panel renders as an inline form card. */
.searchability-modal-backdrop,
.searchability-modal-close {
    display: none;
}

/* JS active: keep the dialog hidden until opened. */
.searchability-js .searchability-modal {
    display: none;
}

.searchability-js .searchability-modal.is-open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 100000;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(16px, 8vh, 96px) 16px 16px;
}

.searchability-js .searchability-modal.is-open .searchability-modal-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: searchability-fade-in 0.2s ease;
}

.searchability-js .searchability-modal.is-open .searchability-modal-close {
    display: inline-flex;
}

.searchability-modal-panel {
    position: relative;
    width: min(640px, 100%);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 30px 70px rgba(2, 6, 23, 0.35);
    padding: 20px;
}

.searchability-js .searchability-modal.is-open .searchability-modal-panel {
    animation: searchability-modal-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.searchability-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.searchability-modal-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #0f172a;
}

.searchability-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: #f1f5f9;
    color: #475569;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.1s ease;
}

.searchability-modal-close:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.searchability-modal-close:active {
    transform: scale(0.94);
}

/* Inside the modal the form + suggestions flow naturally. */
.searchability-modal .searchability-form {
    width: 100%;
}

.searchability-modal .searchability-suggestions {
    position: static;
    margin-top: 14px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}

.searchability-modal .searchability-suggestions-list {
    max-height: min(60vh, var(--searchability-search-max-height, 60vh));
}

body.searchability-modal-open {
    overflow: hidden;
}

@keyframes searchability-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes searchability-modal-in {
    from { opacity: 0; transform: translateY(-12px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   Keyboard focus — visible rings for accessibility
   ============================================================ */
.searchability-toggle:focus-visible,
.searchability-modal-close:focus-visible,
.searchability-submit:focus-visible,
.searchability-clear:focus-visible,
.searchability-image-btn:focus-visible {
    outline: 2px solid #05386B;
    outline-offset: 2px;
}

.searchability-suggestion-item a:focus-visible {
    outline: 2px solid #05386B;
    outline-offset: -2px;
}

/* ============================================================
   Small-screen refinements
   ============================================================ */
@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;
    }

    /* Collapsed/toggle panel goes full-bleed so it never overflows a phone. */
    .searchability-js .searchability-container.sb-collapsed > .searchability-form,
    .searchability-js .searchability-container.searchability-mode-toggle > .searchability-form {
        width: calc(100vw - 24px);
    }

    .searchability-js .searchability-modal.is-open {
        padding: 12px;
        align-items: stretch;
    }

    .searchability-modal-panel {
        border-radius: 16px;
    }

    .searchability-ai-style-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .searchability-modal-backdrop,
    .searchability-modal-panel,
    .searchability-container.is-expanded > .searchability-form {
        animation: none;
    }
}

/* 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;
}

/* Zero-result recovery notice */
.searchability-recovery-notice {
    margin: 0 0 20px;
    padding: 12px 16px;
    border-radius: 8px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #374151;
    font-size: 15px;
    line-height: 1.5;
}

.searchability-recovery-notice a {
    color: #4f46e5;
    font-weight: 600;
}