/**
 * MxChat AI Search — front-end AI Overview.
 *
 * OVERLAY MODE (default .mxchat-search-overview) is deliberately UNSTYLED:
 * it renders as plain text that inherits the theme's font, size, and colors,
 * so it blends into any site's search results page (Maxwell direction,
 * 2026-07-15: "less is more — just the clean text"). No card, no background,
 * no shadow, no pills. Neutral hairlines only, drawn with a transparent
 * gray that works on light AND dark themes without prefers-color-scheme
 * guessing (an OS-level dark preference must NOT dark-card a light site).
 *
 * REPLACE MODE (.mxchat-search-overview--replace, inside .mxchat-search-page)
 * keeps the styled card treatment — there we own the whole layout.
 */

.mxchat-search-overview {
    margin: 28px 0 32px;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    box-sizing: border-box;
}
.mxchat-search-overview *,
.mxchat-search-overview *::before,
.mxchat-search-overview *::after {
    box-sizing: border-box;
}

/* Overlay: no chrome. A single neutral hairline below separates the
   overview from the theme's results. */
.mxchat-search-overview__inner {
    padding: 0 0 20px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.25);
}

.mxchat-search-overview__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.mxchat-search-overview__badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: inherit;
    opacity: 0.8;
}
.mxchat-search-spark {
    color: #7873f5;
    flex: 0 0 auto;
}
.mxchat-search-overview.is-loading .mxchat-search-spark {
    animation: mxchat-search-spin 1.4s ease-in-out infinite;
}
@keyframes mxchat-search-spin {
    0%, 100% { transform: rotate(0) scale(1); opacity: 0.85; }
    50% { transform: rotate(18deg) scale(1.08); opacity: 1; }
}

/* Body text: fully inherited from the theme. */
.mxchat-search-overview__body p {
    margin: 0 0 10px;
}
.mxchat-search-overview__body p:last-child {
    margin-bottom: 0;
}
.mxchat-search-overview__body ul {
    margin: 4px 0 10px;
    padding-left: 20px;
}
.mxchat-search-overview__body li {
    margin: 0 0 6px;
}
.mxchat-search-overview__loading {
    font-size: 0.9em;
    opacity: 0.6;
    margin: 8px 0 0;
}

/* Loading skeleton shimmer — neutral gray, theme-agnostic. */
.mxchat-search-overview__skeleton {
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.mxchat-search-overview__skeleton span {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, rgba(128,128,128,0.12) 25%, rgba(128,128,128,0.22) 37%, rgba(128,128,128,0.12) 63%);
    background-size: 400% 100%;
    animation: mxchat-search-shimmer 1.3s ease infinite;
}
.mxchat-search-overview__skeleton span:nth-child(1) { width: 92%; }
.mxchat-search-overview__skeleton span:nth-child(2) { width: 100%; }
.mxchat-search-overview__skeleton span:nth-child(3) { width: 68%; }
@keyframes mxchat-search-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}
/* Once answered, hide the skeleton. */
.mxchat-search-overview:not(.is-loading) .mxchat-search-overview__skeleton,
.mxchat-search-overview:not(.is-loading) .mxchat-search-overview__loading {
    display: none;
}

/* Sources: plain text links that pick up the theme's own link styling. */
.mxchat-search-overview__sources {
    margin-top: 14px;
}
.mxchat-search-overview__sources-title {
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.6;
    margin: 0 0 6px;
}
.mxchat-search-overview__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
}
.mxchat-search-chip {
    display: inline;
    font-size: 0.9em;
    line-height: 1.5;
    color: inherit;
}
/* Overlay: no thumbnails, no pills — the link text is the whole affordance. */
.mxchat-search-overview__chips .mxchat-search-chip__thumb {
    display: none;
}
.mxchat-search-chip__title {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Collapse animation when there's no answer / an error. */
.mxchat-search-overview.is-collapsing {
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

/* =====================================================================
 * Replace-mode card treatment.
 *
 * Inside the full AI results page the overview IS a designed surface, so
 * the card chrome lives here, scoped under the --replace modifier that
 * search-overview.js adds in replace mode.
 * ===================================================================== */

.mxchat-search-overview--replace {
    --mxs-accent: #7873f5;
    --mxs-radius: 14px;
    --mxs-bg: #ffffff;
    --mxs-fg: #1f2328;
    --mxs-muted: #57606a;
    --mxs-border: rgba(120, 115, 245, 0.22);
    --mxs-chip-bg: #f6f7fb;
    --mxs-chip-border: rgba(0, 0, 0, 0.08);
    --mxs-shadow: 0 6px 24px rgba(31, 35, 40, 0.08);
}
.mxchat-search-overview--replace .mxchat-search-overview__inner {
    position: relative;
    background: var(--mxs-bg);
    color: var(--mxs-fg);
    border: 1px solid var(--mxs-border);
    border-bottom: 1px solid var(--mxs-border);
    border-radius: var(--mxs-radius);
    box-shadow: var(--mxs-shadow);
    padding: 20px 22px;
    overflow: hidden;
}
/* Subtle accent hairline at the top edge. */
.mxchat-search-overview--replace .mxchat-search-overview__inner::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: linear-gradient(90deg, var(--mxs-accent), #b3a8ff 55%, transparent);
}
.mxchat-search-overview--replace .mxchat-search-overview__head {
    margin-bottom: 10px;
}
.mxchat-search-overview--replace .mxchat-search-overview__badge {
    font-size: 13px;
    color: var(--mxs-accent);
    opacity: 1;
}
.mxchat-search-overview--replace .mxchat-search-overview__body {
    font-size: 15.5px;
    line-height: 1.62;
    color: var(--mxs-fg);
}
.mxchat-search-overview--replace .mxchat-search-overview__loading {
    color: var(--mxs-muted);
    font-size: 14px;
    opacity: 1;
}
.mxchat-search-overview--replace .mxchat-search-overview__sources {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.07);
}
.mxchat-search-overview--replace .mxchat-search-overview__sources-title {
    color: var(--mxs-muted);
    opacity: 1;
    margin-bottom: 10px;
}
.mxchat-search-overview--replace .mxchat-search-overview__chips {
    gap: 10px;
}
.mxchat-search-overview--replace .mxchat-search-chip {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    max-width: 260px;
    padding: 7px 12px 7px 8px;
    background: var(--mxs-chip-bg);
    border: 1px solid var(--mxs-chip-border);
    border-radius: 999px;
    color: var(--mxs-fg);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.3;
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.mxchat-search-overview--replace .mxchat-search-chip:hover {
    border-color: var(--mxs-accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(120, 115, 245, 0.18);
}
.mxchat-search-overview--replace .mxchat-search-overview__chips .mxchat-search-chip__thumb {
    display: inline-block;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 auto;
    background: rgba(120, 115, 245, 0.12);
}
.mxchat-search-overview--replace .mxchat-search-overview__chips .mxchat-search-chip__thumb--placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--mxs-accent);
    font-size: 13px;
}
.mxchat-search-overview--replace .mxchat-search-chip__title {
    white-space: nowrap;
}

/* Dark-mode adaptation — REPLACE MODE ONLY (the overlay inherits the theme
   and must never re-color itself off the OS preference). */
@media (prefers-color-scheme: dark) {
    .mxchat-search-overview--replace {
        --mxs-bg: #1c1d22;
        --mxs-fg: #e8e9ec;
        --mxs-muted: #a4abb4;
        --mxs-border: rgba(146, 141, 255, 0.30);
        --mxs-chip-bg: #26272e;
        --mxs-chip-border: rgba(255, 255, 255, 0.10);
        --mxs-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    }
    .mxchat-search-overview--replace .mxchat-search-overview__sources { border-top-color: rgba(255, 255, 255, 0.10); }
}

/* Responsive. */
@media (max-width: 600px) {
    .mxchat-search-overview--replace .mxchat-search-overview__inner { padding: 16px 16px; }
    .mxchat-search-overview--replace .mxchat-search-overview__body { font-size: 15px; }
    .mxchat-search-overview--replace .mxchat-search-chip { max-width: 100%; }
}

/* =====================================================================
 * Mode 2 — Full AI results page (replace)
 *
 * A Google-style two-column layout: AI answer on the left, a rail of
 * matched-article cards on the right. Inherits the site font; light/dark
 * aware; stacks on mobile. Everything is scoped under .mxchat-search-page
 * so it never leaks into theme styles.
 * ===================================================================== */

/* Utility: hide the theme's suppressed results (restored on failure / Show all). */
.mxchat-search-hidden { display: none !important; }

.mxchat-search-page {
    --mxs-accent: #7873f5;
    --mxs-fg: #1f2328;
    --mxs-muted: #57606a;
    --mxs-card-bg: #ffffff;
    --mxs-card-border: rgba(0, 0, 0, 0.08);
    --mxs-card-shadow: 0 2px 10px rgba(31, 35, 40, 0.06);
    --mxs-card-hover-shadow: 0 8px 22px rgba(120, 115, 245, 0.16);

    display: grid;
    grid-template-columns: minmax(0, 62fr) minmax(0, 38fr);
    gap: 28px;
    align-items: start;
    margin: 0 0 28px;
    font-family: inherit;
    box-sizing: border-box;
}
.mxchat-search-page *,
.mxchat-search-page *::before,
.mxchat-search-page *::after { box-sizing: border-box; }

.mxchat-search-page--no-rail { grid-template-columns: minmax(0, 1fr); }

.mxchat-search-page__main { min-width: 0; }

/* The answer card sits flush in its column (no bottom margin, fills width). */
.mxchat-search-overview--replace { margin: 0; }

/* ---- Right rail ---- */
.mxchat-search-page__rail {
    min-width: 0;
    position: sticky;
    top: 24px;
}
.mxchat-search-page__rail-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--mxs-muted);
    margin: 0 0 12px;
    padding-left: 2px;
}
.mxchat-search-page__cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mxchat-search-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px;
    background: var(--mxs-card-bg);
    border: 1px solid var(--mxs-card-border);
    border-radius: 12px;
    box-shadow: var(--mxs-card-shadow);
    color: var(--mxs-fg);
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.mxchat-search-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--mxs-card-hover-shadow);
    border-color: rgba(120, 115, 245, 0.35);
}
.mxchat-search-card__thumb {
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(120, 115, 245, 0.10);
    display: flex;
    align-items: center;
    justify-content: center;
}
.mxchat-search-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.mxchat-search-card__thumb--placeholder { color: var(--mxs-accent); opacity: 0.7; }
.mxchat-search-card__body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mxchat-search-card__title {
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--mxs-fg);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.mxchat-search-card:hover .mxchat-search-card__title { color: var(--mxs-accent); }
.mxchat-search-card__meta {
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--mxs-muted);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.mxchat-search-card__date { font-weight: 600; opacity: 0.9; }
.mxchat-search-card__excerpt {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mxchat-search-showall {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-top: 14px;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--mxs-accent);
    border-radius: 999px;
    color: var(--mxs-accent);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.mxchat-search-showall:hover {
    background: var(--mxs-accent);
    color: #fff;
}

/* ---- Dark-mode adaptation ---- */
@media (prefers-color-scheme: dark) {
    .mxchat-search-page {
        --mxs-fg: #e8e9ec;
        --mxs-muted: #a4abb4;
        --mxs-card-bg: #1c1d22;
        --mxs-card-border: rgba(255, 255, 255, 0.10);
        --mxs-card-shadow: 0 2px 10px rgba(0, 0, 0, 0.30);
        --mxs-card-hover-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
    }
}

/* ---- Responsive: stack (summary first, cards after) ---- */
@media (max-width: 860px) {
    .mxchat-search-page {
        grid-template-columns: minmax(0, 1fr);
        gap: 22px;
    }
    .mxchat-search-page__rail { position: static; top: auto; }
    .mxchat-search-page__cards {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 12px;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }
    .mxchat-search-card {
        flex: 0 0 78%;
        max-width: 320px;
    }
    .mxchat-search-showall { margin-top: 16px; }
}
@media (max-width: 480px) {
    .mxchat-search-card { flex-basis: 86%; }
}
