/*  AI Mode v3 – matches SearXNG native style  */

/* ===== toggle: native SearXNG style ===== */
.ai-toggle-wrap {
    display: flex;
    justify-content: center;
    margin-top: .75rem;
}

.ai-toggle {
    display: inline-flex;
    background: var(--color-base-background-mobile, #f3f4f6);
    border: 1px solid var(--color-result-border, #ddd);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}

.ai-toggle__btn {
    all: unset;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 22px;
    border-radius: 6px;
    font-family: sans-serif;
    font-size: .85rem;
    font-weight: 500;
    color: var(--color-base-font, #444);
    opacity: .5;
    transition: all .2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.ai-toggle__btn:hover {
    opacity: .75;
    background: rgba(0, 0, 0, .04);
}

.ai-toggle__btn--active {
    opacity: 1;
    background: var(--color-btn-background, #3050ff);
    color: var(--color-btn-font, #fff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.ai-toggle__btn--active:hover {
    opacity: 1;
    background: var(--color-btn-background, #3050ff);
}

/* ===== AI results container (hidden by default, shown inline) ===== */
#ai-results-wrap {
    display: none;
    max-width: 800px;
    margin: 1.5rem auto 3rem;
    padding: 0 1rem;
}

/* ===== when AI mode is active ===== */

/* show the AI results area */
body.ai-on #ai-results-wrap { display: block; }

/* hide the big SearXNG title on the index page */
body.ai-on .index .title { display: none !important; }

/* hide classic search results, sidebar, pagination, footer
   NOTE: do NOT hide #main_results – it also contains the search form,
   toggle pill and AI results area on the results page. */
body.ai-on #results,
body.ai-on .result,
body.ai-on #sidebar,
body.ai-on #pagination,
body.ai-on .search_filters,
body.ai-on footer {
    display: none !important;
}

/* on index page: remove the vertical centering so search sits at top */
body.ai-on.index_endpoint main {
    display: block !important;
}
body.ai-on .index {
    margin-top: 2rem !important;
    padding-top: 0 !important;
}

/* ===== card ===== */
.ai-card {
    background: var(--color-result-background, #fff);
    border: 1px solid var(--color-result-border, #ddd);
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
}
.ai-card--error {
    border-color: #c44;
    color: #c44;
}
.ai-card__query {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: .35rem;
    color: var(--color-base-font, #222);
}
.ai-card__meta {
    font-size: .78rem;
    color: var(--color-result-publishdate-font, #888);
    margin-bottom: 1rem;
}
.ai-card__body {
    line-height: 1.7;
    font-size: .95rem;
    color: var(--color-base-font, #333);
}
.ai-card__body h1,
.ai-card__body h2,
.ai-card__body h3 {
    margin: 1rem 0 .4rem;
    color: var(--color-base-font, #222);
    font-weight: 600;
}
.ai-card__body h1 { font-size: 1.25rem; }
.ai-card__body h2 { font-size: 1.1rem; }
.ai-card__body h3 { font-size: 1rem; }
.ai-card__body code {
    background: var(--color-doc-code-background, #f0f0f0);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: .88em;
}
.ai-card__body pre {
    background: var(--color-doc-code-background, #f5f5f5);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    border: 1px solid var(--color-result-border, #ddd);
}
.ai-card__body pre code { background: transparent; padding: 0; }
.ai-card__body a {
    color: var(--color-result-link-font, #36c);
    text-decoration: none;
}
.ai-card__body a:hover { text-decoration: underline; }
.ai-card__body strong { font-weight: 600; }
.ai-ref { font-size: .75em; color: var(--color-result-link-font, #36c); }

/* ===== sources ===== */
.ai-sources {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-result-border, #ddd);
}
.ai-sources__title {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    font-weight: 600;
    color: var(--color-result-publishdate-font, #888);
    margin-bottom: .5rem;
}
.ai-sources__list { display: flex; flex-wrap: wrap; gap: .4rem; }
.ai-source {
    display: inline-block;
    padding: 3px 10px;
    background: var(--color-result-background, #fff);
    border: 1px solid var(--color-result-border, #ddd);
    border-radius: 999px;
    font-size: .8rem;
    color: var(--color-url-font, #666);
    text-decoration: none;
    transition: .15s;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-source:hover {
    background: var(--color-btn-background, #3050ff);
    color: var(--color-btn-font, #fff);
    border-color: var(--color-btn-background, #3050ff);
}

/* ===== loading dots ===== */
.ai-loading {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--color-result-publishdate-font, #888);
    font-style: italic;
    padding: .5rem 0;
}
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots i {
    width: 6px;
    height: 6px;
    background: var(--color-btn-background, #3050ff);
    border-radius: 50%;
    animation: ai-bounce 1.4s infinite ease-in-out both;
}
.ai-dots i:nth-child(1) { animation-delay: -.32s; }
.ai-dots i:nth-child(2) { animation-delay: -.16s; }
@keyframes ai-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40%           { transform: scale(1); }
}

/* ===== cache badge ===== */
.ai-cache-badge {
    display: inline-block;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #16a34a;
    color: #fff;
    vertical-align: middle;
    margin-left: .5rem;
    animation: ai-cache-pop .3s ease;
}
@keyframes ai-cache-pop {
    0%   { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1);   opacity: 1; }
}

/* ===== responsive ===== */
@media (max-width: 768px) {
    #ai-results-wrap { padding: 0 .5rem; margin-top: 1rem; }
    .ai-card { padding: 1rem; }
    .ai-card__query { font-size: 1rem; }
    .ai-toggle__btn { padding: 5px 14px; font-size: .8rem; }
}
