/*
 * Smart-search widget, styled for just-the-docs v0.10.x (light scheme).
 *
 * Self-contained: the theme's own search is disabled (search_enabled: false),
 * so this file carries ALL styles for the widget — bar, dropdown panel, AI
 * answer markdown, citation cards, popular chips, feedback row.
 *
 * Palette mapped to the theme:
 *   borders   #eeebee     text      #5c5962 / #44434d / #27262b
 *   muted     #959396     washes    #f5f6fa / #ebedf5 / #ecebed
 *   accent    #7253ed (theme link purple)
 * Breakpoint: 50rem (theme "md", where .main-header becomes flex).
 */

/* ---------- a11y helper (theme does not ship one) ----------------------- */

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ---------- header slot -------------------------------------------------- */

/* The theme hides .main-header below 50rem; re-enable it so the AI search
 * stays reachable on phones. aux-nav is empty on this site, so the header
 * is effectively just the search bar there. */
@media (max-width: 49.9375rem) {
    .side-bar + .main .main-header {
        display: block;
        background-color: #fff;
    }
}

.site-search-nav {
    position: relative;
    z-index: 5;
    flex: 1 1 auto;
    padding: 0.55rem 1rem;      /* mobile: bar in a block header */
}

@media (min-width: 50rem) {
    .site-search-nav {
        display: flex;
        align-items: center;    /* centers the bar in the 3.75rem header */
        max-width: 34rem;       /* ~540px, echoes the theme's 33.5rem */
        padding: 0 1rem;
    }
}

/* ---------- search bar --------------------------------------------------- */

.site-search-input-wrap {
    position: relative;
    width: 100%;
    height: 2.5rem;
}

.site-search-input {
    width: 100%;
    height: 100%;
    padding: 0 2.9rem 0 2.5rem;   /* room for magnifier + submit arrow */
    font-family: inherit;
    font-size: 0.875rem;
    color: #27262b;
    background-color: #ecebed;
    border: 1px solid transparent;
    border-radius: 8px;
    appearance: none;
    -webkit-appearance: none;
    transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.site-search-input::placeholder { color: #959396; }
.site-search-input:hover { background-color: #e5e3e7; }

.site-search-input:focus {
    outline: none;
    background-color: #fff;
    border-color: rgba(114, 83, 237, 0.55);
    box-shadow: 0 0 0 3px rgba(114, 83, 237, 0.14), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.site-search-icon {
    position: absolute;
    top: 0;
    left: 0.85rem;
    height: 100%;
    display: flex;
    align-items: center;
    color: #959396;
    pointer-events: none;
}

.site-search-input:focus + .site-search-icon { color: #7253ed; }

.site-search-submit {
    position: absolute;
    top: 50%;
    right: 0.3rem;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border: 0;
    border-radius: 999px;
    background-color: #7253ed;
    color: #fff;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.site-search-submit:hover:not(:disabled) { background-color: #5b3cd6; }
.site-search-submit svg { transition: transform 150ms ease; }
.site-search-submit:hover:not(:disabled) svg { transform: translateX(2px); }

.site-search-submit:focus-visible {
    outline: 2px solid #7253ed;
    outline-offset: 2px;
}

.site-search-submit:disabled {
    opacity: 0.55;
    cursor: default;
}

.site-search-submit[data-loading="true"] svg {
    animation: site-search-spin 0.9s linear infinite;
}

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

/* ---------- dropdown panel ----------------------------------------------- */

.site-search-panel {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0.5rem;
    right: 0.5rem;
    z-index: 60;                 /* above content; theme keeps everything at 0-2 */
    background-color: #fff;
    border: 1px solid #eeebee;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), 0 14px 40px rgba(0, 0, 0, 0.12);
    max-height: min(calc(100vh - 9rem), 40rem);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    animation: site-search-panel-in 140ms ease-out;
}

@media (min-width: 50rem) {
    .site-search-panel {
        top: calc(100% + 0.4rem);
        left: 1rem;              /* flush with the input's left edge */
        right: auto;
        /* Wider than the bar for comfortable answers, but never past the
         * viewport: 100vw minus sidebar (15.5-16.5rem) and margins. */
        width: min(44rem, calc(100vw - 19rem));
        max-height: min(calc(100vh - 5.5rem), 42rem);
    }
}

/* JS toggles visibility via the hidden attribute — make it authoritative. */
.site-search-panel[hidden],
.site-search-panel [hidden] { display: none !important; }

@keyframes site-search-panel-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- status + meta rows ------------------------------------------- */

.site-search-status {
    padding: 0.55rem 1rem;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: #959396;
    border-bottom: 1px solid #eeebee;
}
/* Status alone in the panel (idle / error states): no stray separator. */
.site-search-status:has(+ [hidden] + [hidden] + .site-search-results:empty) {
    border-bottom: 0;
}

.site-search-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    background-color: #f5f6fa;
    border-bottom: 1px solid #eeebee;
    font-size: 0.72rem;
    color: #959396;
}

.smart-search-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    background-color: #ecebed;
    color: #5c5962;
    font-variant-numeric: tabular-nums;
}

.smart-search-badge-hint {
    background-color: rgba(114, 83, 237, 0.1);
    color: #5636c7;
}

/* ---------- AI answer block ---------------------------------------------- */

.site-search-answer {
    position: relative;
    padding: 0.95rem 1.1rem 0.9rem 1.4rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #44434d;
    border-bottom: 1px solid #eeebee;
}

/* Purple accent stripe marking the generated answer. */
.site-search-answer::before {
    content: "";
    position: absolute;
    top: 1rem;
    bottom: 1rem;
    left: 0.6rem;
    width: 3px;
    border-radius: 999px;
    background-color: #7253ed;
    opacity: 0.55;
}

.site-search-answer p { margin: 0 0 0.6rem; }
.site-search-answer p:last-child { margin-bottom: 0; }
.site-search-answer strong { font-weight: 600; color: #27262b; }

.site-search-answer a { color: #7253ed; text-decoration: none; }
.site-search-answer a:hover { text-decoration: underline; }

/* Citation markers ([1][2]) injected as sup>a. */
.site-search-answer sup a {
    display: inline-block;
    padding: 0 0.28rem;
    margin: 0 0.05rem;
    background-color: rgba(114, 83, 237, 0.1);
    color: #5636c7;
    border-radius: 0.25rem;
    font-size: 0.72em;
    font-weight: 600;
    text-decoration: none;
}
.site-search-answer sup a:hover {
    background-color: rgba(114, 83, 237, 0.2);
    text-decoration: none;
}

/* Headings the LLM may emit — keep proportional to body text. */
.site-search-answer h1,
.site-search-answer h2,
.site-search-answer h3,
.site-search-answer h4,
.site-search-answer h5,
.site-search-answer h6 {
    margin: 0.9rem 0 0.4rem;
    font-weight: 600;
    line-height: 1.3;
    color: #27262b;
}
.site-search-answer h1 { font-size: 1.05rem; }
.site-search-answer h2 { font-size: 1rem; }
.site-search-answer h3 { font-size: 0.95rem; }
.site-search-answer h4,
.site-search-answer h5,
.site-search-answer h6 { font-size: 0.875rem; color: #5c5962; }
.site-search-answer h1:first-child,
.site-search-answer h2:first-child,
.site-search-answer h3:first-child { margin-top: 0; }

.site-search-answer ul,
.site-search-answer ol {
    margin: 0.25rem 0 0.7rem;
    padding-left: 1.25rem;
}
.site-search-answer ul { list-style: disc; }
.site-search-answer ol { list-style: decimal; }
.site-search-answer li { margin: 0.15rem 0; }
.site-search-answer li > p { margin: 0 0 0.25rem; }
.site-search-answer ul ul,
.site-search-answer ol ol,
.site-search-answer ul ol,
.site-search-answer ol ul { margin: 0.15rem 0; }

.site-search-answer blockquote {
    margin: 0.5rem 0 0.7rem;
    padding: 0.1rem 0 0.1rem 0.75rem;
    border-left: 3px solid #eeebee;
    color: #5c5962;
}
.site-search-answer blockquote p:last-child { margin-bottom: 0; }

.site-search-answer hr {
    border: 0;
    border-top: 1px solid #eeebee;
    margin: 0.8rem 0;
}

.site-search-answer table {
    border-collapse: collapse;
    margin: 0.5rem 0 0.7rem;
    font-size: 0.82rem;
    display: block;
    max-width: 100%;
    overflow-x: auto;
}
.site-search-answer th,
.site-search-answer td {
    border: 1px solid #eeebee;
    padding: 0.3rem 0.55rem;
    text-align: left;
}
.site-search-answer th {
    background-color: #f5f6fa;
    font-weight: 600;
    color: #27262b;
}

/* KaTeX display math can be wide — scroll it, don't clip. */
.site-search-answer .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.2rem 0;
}

/* ---------- code: inline + fenced smart-code blocks ---------------------- */

.site-search-answer code {
    padding: 0.1em 0.35em;
    font-family: "SFMono-Regular", menlo, consolas, monospace;
    font-size: 0.82em;
    color: #27262b;
    background-color: #f5f6fa;
    border: 1px solid #eeebee;
    border-radius: 4px;
}

.site-search-answer pre {
    margin: 0.7rem 0;
    padding: 0;
    background-color: #f5f6fa;
    border: 1px solid #eeebee;
    border-radius: 6px;
    overflow: hidden;
}

.smart-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 0.7rem;
    background-color: #ecebed;
    border-bottom: 1px solid #eeebee;
    font-family: "SFMono-Regular", menlo, consolas, monospace;
    font-size: 0.7rem;
    color: #5c5962;
}

.smart-code-lang {
    text-transform: lowercase;
    letter-spacing: 0.02em;
}

.smart-code-copy {
    padding: 0.15rem 0.45rem;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #5c5962;
    font-family: inherit;
    font-size: 0.7rem;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}
.smart-code-copy:hover {
    background-color: rgba(39, 38, 43, 0.08);
    color: #27262b;
}
.smart-code-copy[data-state="copied"] { color: #187339; }
.smart-code-copy[data-state="error"] { color: #b91c1c; }

.site-search-answer pre code {
    display: block;
    padding: 0.7rem 0.9rem;
    background: transparent;
    border: 0;
    font-size: 0.8rem;
    line-height: 1.5;
    color: #27262b;
    overflow-x: auto;
    white-space: pre;
}

/* Minimal highlight.js palette — calm mid-tones on the light background. */
.site-search-answer .hljs-comment,
.site-search-answer .hljs-quote { color: #959396; font-style: italic; }
.site-search-answer .hljs-keyword,
.site-search-answer .hljs-selector-tag,
.site-search-answer .hljs-subst,
.site-search-answer .hljs-built_in,
.site-search-answer .hljs-builtin-name { color: #5636c7; }
.site-search-answer .hljs-number,
.site-search-answer .hljs-literal,
.site-search-answer .hljs-variable,
.site-search-answer .hljs-template-variable,
.site-search-answer .hljs-tag .hljs-attr { color: #0e7490; }
.site-search-answer .hljs-string,
.site-search-answer .hljs-doctag,
.site-search-answer .hljs-regexp,
.site-search-answer .hljs-link { color: #187339; }
.site-search-answer .hljs-title,
.site-search-answer .hljs-section,
.site-search-answer .hljs-selector-id { color: #44434d; font-weight: 600; }
.site-search-answer .hljs-type,
.site-search-answer .hljs-class .hljs-title { color: #5c5962; }
.site-search-answer .hljs-tag,
.site-search-answer .hljs-name,
.site-search-answer .hljs-attribute { color: #0f766e; }
.site-search-answer .hljs-symbol,
.site-search-answer .hljs-bullet { color: #b45309; }
.site-search-answer .hljs-meta { color: #959396; }
.site-search-answer .hljs-deletion { background-color: #fef2f2; }
.site-search-answer .hljs-addition { background-color: #f0fdf4; }
.site-search-answer .hljs-emphasis { font-style: italic; }
.site-search-answer .hljs-strong { font-weight: 700; }

/* ---------- citation cards ----------------------------------------------- */

/* Anchor also carries Bootstrap-ish classes from the JS (list-group-item…)
 * that have no base styles here — everything is defined on this class. */
.smart-search-citation {
    display: block;
    padding: 0.7rem 1rem;
    color: #44434d;
    text-decoration: none;
    border-top: 1px solid #eeebee;
    transition: background-color 100ms ease;
}
.smart-search-citation:first-child { border-top: 0; }

.smart-search-citation:hover,
.smart-search-citation.active {
    background-color: #ebedf5;   /* theme's own search-result hover wash */
    color: #44434d;
    text-decoration: none;
}

.smart-search-citation:focus-visible {
    outline: 2px solid #7253ed;
    outline-offset: -2px;
    border-radius: 6px;
    background-color: #ebedf5;
}

.smart-search-citation-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.75rem;
    align-items: start;
}

.smart-search-citation-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    margin-top: 0.1rem;
    background-color: rgba(114, 83, 237, 0.1);
    color: #5636c7;
    border-radius: 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.smart-search-citation-body { min-width: 0; }

.smart-search-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.1rem;
    font-size: 0.7rem;
    color: #959396;
    text-transform: capitalize;
    overflow: hidden;
}
.smart-search-breadcrumb-sep { color: #d6d4da; }

.smart-search-citation-title {
    margin-bottom: 0.15rem;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
    color: #27262b;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.smart-search-citation-snippet {
    font-size: 0.8rem;
    line-height: 1.45;
    color: #5c5962;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.smart-search-citation-score {
    align-self: start;
    margin-top: 0.2rem;
    padding: 0.1rem 0.4rem;
    background-color: #f5f6fa;
    color: #959396;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ---------- popular queries (empty-input suggestions) -------------------- */

.smart-search-popular {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0.75rem 1rem 0.9rem;
}

.smart-search-popular-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid #eeebee;
    border-radius: 999px;
    background-color: #f5f6fa;
    color: #44434d;
    font-family: inherit;
    font-size: 0.8rem;
    line-height: 1.2;
    text-align: left;
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.smart-search-popular-chip:hover,
.smart-search-popular-chip:focus-visible {
    background-color: #ebedf5;
    border-color: rgba(114, 83, 237, 0.4);
    outline: 0;
}
.smart-search-popular-chip:active { transform: translateY(1px); }

.smart-search-popular-query {
    max-width: 22rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.smart-search-popular-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3rem;
    height: 1.2rem;
    padding: 0 0.35rem;
    background-color: rgba(114, 83, 237, 0.1);
    color: #5636c7;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ---------- feedback / expert referral / no-result ----------------------- */

.smart-search-feedback {
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid #eeebee;
    font-size: 0.8rem;
}

.smart-search-expert { margin-bottom: 0.4rem; color: #44434d; }

.smart-search-rate {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #959396;
}

.smart-search-thumb {
    padding: 0.1rem 0.5rem;
    background: none;
    border: 1px solid #eeebee;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 120ms ease;
}
.smart-search-thumb:hover:not(:disabled) { background-color: #ebedf5; }
.smart-search-thumb:focus-visible { outline: 2px solid #7253ed; outline-offset: 1px; }
.smart-search-thumb:disabled { opacity: 0.4; cursor: default; }

.smart-search-thanks { color: #187339; }

.smart-search-noresult {
    color: #5c5962;
    font-size: 0.85rem;
    line-height: 1.5;
}
.smart-search-noresult a { color: #7253ed; }
