﻿/*
 * SafiHome AI search (loaded only when appSettings AiSearchEnabled = 1).
 * Header: a compact "Search or ask AI" trigger instead of an always-open input.
 * Click, "/" or Ctrl+K opens a full-width search panel with the assistant.
 * With AiSearchEnabled = 0 this file is not loaded and the old design is unchanged.
 */
:root {
    /* SafiHome palette only: charcoal, greys and white (from site.css). */
    --ai-ink: #1c1c1c;
    --ai-charcoal: #333333;
    --ai-muted: #535353;
    --ai-faint: #8a8a8a;
    --ai-line: #e6e6e6;
    --ai-soft: #f3f3f3;
    --ai-sheet: #ffffff;
    --ai-gradient: linear-gradient(110deg, #1c1c1c, #333333 35%, #8a8a8a 50%, #333333 65%, #1c1c1c);
    --ai-ring: linear-gradient(110deg, #ffffff, #8a8a8a 50%, #ffffff);
    --ai-bold: var(--font-assistant-bold, inherit);
    --ai-radius: 18px;
    --ai-ease: cubic-bezier(.2, .8, .2, 1);
}

/* ---------- Header: hide the old open inputs, show the trigger ---------- */
.main_menu_search.ai-enabled {
    width: auto;
}

    .main_menu_search.ai-enabled > .textfield,
    .main_menu_search.ai-enabled > .search_autoComplete_container,
    .main_menu_burger_search_container.ai-enabled {
        display: none !important;
    }

.ai-trigger {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    padding: 0 8px 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .28);
    background: rgba(255, 255, 255, .06);
    color: #fff;
    font: inherit;
    font-size: 14px;
    letter-spacing: .01em;
    cursor: pointer;
    position: relative;
    isolation: isolate;
    transition: border-color .25s ease, background-color .25s ease, transform .25s var(--ai-ease);
}

    /* Gradient ring that lights up on hover/focus */
    .ai-trigger::before {
        content: '';
        position: absolute;
        inset: -1px;
        border-radius: inherit;
        padding: 1px;
        background: var(--ai-ring);
        -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
        -webkit-mask-composite: xor;
        mask-composite: exclude;
        opacity: 0;
        transition: opacity .25s ease;
        z-index: -1;
    }

    .ai-trigger:hover,
    .ai-trigger:focus-visible {
        border-color: transparent;
        background: rgba(255, 255, 255, .12);
        outline: none;
    }

        .ai-trigger:hover::before,
        .ai-trigger:focus-visible::before {
            opacity: 1;
        }

    .ai-trigger:active {
        transform: scale(.98);
    }

.ai-spark {
    flex: 0 0 auto;
    fill: currentColor;
}

.ai-trigger .ai-spark {
    color: #ffffff;
    animation: ai-twinkle 3.2s ease-in-out infinite;
}

.ai-trigger-kbd {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, .25);
    font: 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: rgba(255, 255, 255, .75);
    background: transparent;
    box-shadow: none;
}

.ai-trigger-mobile {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    margin-left: auto;
    position: relative;
    z-index: 2;
}

    .ai-trigger-mobile .ai-spark {
        width: 20px;
        height: 20px;
    }

@media (min-width: 1210px) {
    .ai-trigger-mobile {
        display: none;
    }
}

/* ---------- Panel ---------- */
.ai-panel[hidden] {
    display: none !important;
}

.ai-panel {
    position: fixed;
    inset: 0;
    z-index: 2000;
    color: var(--ai-ink);
    font-family: var(--font-assistant-regular, system-ui), system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.ai-panel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(28, 28, 28, .45);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    backdrop-filter: blur(8px) saturate(120%);
    opacity: 0;
    transition: opacity .3s ease;
}

.ai-panel-sheet {
    position: relative;
    background: var(--ai-sheet);
    border-radius: 0 0 var(--ai-radius) var(--ai-radius);
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .35);
    max-height: min(88vh, 760px);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateY(-16px);
    opacity: 0;
    transition: transform .35s var(--ai-ease), opacity .25s ease;
}

.ai-panel.is-open .ai-panel-backdrop {
    opacity: 1;
}

.ai-panel.is-open .ai-panel-sheet {
    transform: none;
    opacity: 1;
}

.ai-panel-inner {
    max-width: 920px;
    margin: 0 auto;
    padding: 22px 24px 28px;
}

.ai-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.ai-panel-bar {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ai-panel-icon {
    display: grid;
    place-items: center;
    flex: 0 0 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--ai-gradient);
    color: #fff;
    box-shadow: 0 8px 22px -10px rgba(0, 0, 0, .55);
}

    .ai-panel-icon .ai-spark {
        width: 20px;
        height: 20px;
    }

.ai-panel-field {
    flex: 1 1 auto;
    min-width: 0;
}

    /* The site's own search textbox is moved here, so the old server-side search keeps working. */
    .ai-panel-field input {
        width: 100%;
        height: 52px;
        border: 0 !important;
        background: transparent !important;
        background-image: none !important;
        padding: 0 !important;
        color: var(--ai-ink) !important;
        font-size: 24px;
        font-family: inherit;
        letter-spacing: -.01em;
        outline: none;
        box-shadow: none !important;
        unicode-bidi: plaintext;
    }

        .ai-panel-field input::placeholder {
            color: var(--ai-faint);
            font-size: 24px;
        }

.ai-badge {
    flex: 0 0 auto;
    font-size: 12px;
    font-family: var(--ai-bold);
    font-weight: 700;
    letter-spacing: .08em;
    padding: 4px 10px;
    border-radius: 999px;
    color: #fff;
    background: var(--ai-charcoal);
}

.ai-panel-close {
    flex: 0 0 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--ai-soft);
    color: var(--ai-ink);
    cursor: pointer;
    transition: background-color .2s ease;
}

    .ai-panel-close svg {
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        fill: none;
    }

    .ai-panel-close:hover,
    .ai-panel-close:focus-visible {
        background: var(--ai-line);
        outline: none;
    }

/* Gradient line under the input; it flows while the assistant is thinking. */
.ai-panel-glow {
    height: 2px;
    margin: 14px 0 18px;
    border-radius: 2px;
    background: var(--ai-line);
    position: relative;
    overflow: hidden;
}

    .ai-panel-glow::after {
        content: '';
        position: absolute;
        inset: 0;
        background: var(--ai-gradient);
        background-size: 200% 100%;
        transform: scaleX(0);
        transform-origin: left;
        transition: transform .45s var(--ai-ease);
    }

.ai-panel.has-focus .ai-panel-glow::after {
    transform: scaleX(1);
}

.ai-panel.is-thinking .ai-panel-glow::after {
    transform: scaleX(1);
    animation: ai-flow 1.1s linear infinite;
}

/* ---------- Panel body ---------- */
.ai-panel-body {
    font-size: 15px;
    line-height: 1.45;
}

.ai-intro {
    color: var(--ai-muted);
    margin: 0 0 12px;
}

.ai-heading {
    font-family: var(--ai-bold);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ai-muted);
    margin: 0 0 10px;
}

.ai-section + .ai-section {
    margin-top: 22px;
}

.ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ai-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--ai-line);
    background: #fff;
    color: var(--ai-ink);
    font: inherit;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s var(--ai-ease);
    unicode-bidi: plaintext;
}

    .ai-chip:hover,
    .ai-chip:focus-visible {
        border-color: #cfcfcf;
        box-shadow: 0 6px 18px -10px rgba(0, 0, 0, .35);
        transform: translateY(-1px);
        color: var(--ai-ink);
        text-decoration: none;
        outline: none;
    }

.ai-chip-prompt::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ai-charcoal);
}

.ai-products {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
}

    .ai-products > li {
        display: flex;
        min-width: 0;
    }

.ai-product {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 14px;
    border: 1px solid var(--ai-line);
    color: var(--ai-ink);
    text-decoration: none;
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s var(--ai-ease);
}

    .ai-product:hover,
    .ai-product:focus-visible {
        border-color: #cfcfcf;
        box-shadow: 0 10px 26px -14px rgba(0, 0, 0, .35);
        transform: translateY(-2px);
        color: var(--ai-ink);
        text-decoration: none;
        outline: none;
    }

    .ai-product img {
        flex: 0 0 56px;
        width: 56px;
        height: 56px;
        object-fit: contain;
        border-radius: 10px;
        background: var(--ai-soft);
    }

.ai-product-title {
    font-size: 14px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* "Ask SafiHome AI" call to action above the instant suggestions */
.ai-ask {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    margin: 0 0 22px;
    padding: 14px 16px;
    border: 0;
    border-radius: 16px;
    background: var(--ai-ink);
    color: #fff;
    font: inherit;
    text-align: start;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    box-shadow: 0 14px 30px -18px rgba(0, 0, 0, .6);
    transition: transform .2s var(--ai-ease), box-shadow .2s ease;
    animation: ai-rise .3s var(--ai-ease);
}

    /* A soft silver light that sweeps across now and then */
    .ai-ask::after {
        content: '';
        position: absolute;
        inset: 0;
        background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .14) 50%, transparent 70%);
        transform: translateX(-100%);
        animation: ai-sweep 3.6s ease-in-out 0.4s infinite;
        z-index: -1;
    }

    .ai-ask:hover,
    .ai-ask:focus-visible {
        transform: translateY(-1px);
        box-shadow: 0 18px 34px -16px rgba(0, 0, 0, .65);
        outline: none;
    }

    .ai-ask:focus-visible {
        box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ai-ink);
    }

.ai-ask-icon {
    flex: 0 0 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--ai-gradient);
    background-size: 200% 100%;
    border: 1px solid rgba(255, 255, 255, .18);
    color: #fff;
}

    .ai-ask-icon .ai-spark {
        width: 18px;
        height: 18px;
        animation: ai-twinkle 3.2s ease-in-out infinite;
    }

.ai-ask-text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-ask-label {
    font-family: var(--ai-bold);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: .01em;
}

.ai-ask-about {
    font-size: 14px;
    color: rgba(255, 255, 255, .7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-ask-query {
    color: #fff;
    unicode-bidi: plaintext;
}

.ai-ask-kbd {
    flex: 0 0 auto;
    font: 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .3);
    background: rgba(255, 255, 255, .08);
    color: #fff;
    box-shadow: none;
}

@keyframes ai-sweep {
    0%, 55% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Assistant answer */
.ai-reply {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 18px;
    animation: ai-rise .35s var(--ai-ease);
}

.ai-reply-avatar {
    flex: 0 0 32px;
    height: 32px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--ai-gradient);
    color: #fff;
}

    .ai-reply-avatar .ai-spark {
        width: 16px;
        height: 16px;
    }

.ai-reply-bubble {
    background: var(--ai-soft);
    border-radius: 4px 16px 16px 16px;
    padding: 12px 16px;
    unicode-bidi: plaintext;
}

    .ai-reply-bubble[dir="rtl"] {
        border-radius: 16px 4px 16px 16px;
    }

    .ai-reply-bubble p {
        margin: 0;
    }

.ai-reply-name {
    font-family: var(--ai-bold);
    font-size: 12px;
    font-weight: 700;
    color: var(--ai-muted);
    margin-bottom: 2px;
}

.ai-reply-question {
    margin-top: 6px !important;
    font-family: var(--ai-bold);
    font-weight: 700;
}

.ai-reply + .ai-chips {
    margin: -6px 0 18px 44px;
}

.ai-all {
    font-family: var(--ai-bold);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--ai-ink);
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

    .ai-all:hover,
    .ai-all:focus-visible {
        color: #fff;
        text-decoration: none;
        opacity: .9;
        outline: none;
    }

.ai-hint {
    margin-top: 18px;
    font-size: 13px;
    color: var(--ai-muted);
}

    .ai-hint kbd {
        font: 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        padding: 2px 6px;
        border-radius: 5px;
        border: 1px solid var(--ai-line);
        background: #fff;
        color: var(--ai-ink);
        box-shadow: none;
    }

.ai-note {
    color: var(--ai-muted);
}

/* Thinking state: shimmering text and placeholders */
.ai-thinking {
    display: inline-block;
    font-family: var(--ai-bold);
    font-weight: 700;
    background: var(--ai-gradient);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: ai-flow 1.4s linear infinite;
    margin-bottom: 16px;
}

.ai-skeleton {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
}

    .ai-skeleton span {
        height: 78px;
        border-radius: 14px;
        background: linear-gradient(90deg, var(--ai-soft) 25%, #e8e8e8 50%, var(--ai-soft) 75%);
        background-size: 200% 100%;
        animation: ai-flow 1.2s linear infinite;
    }

html.ai-panel-lock,
html.ai-panel-lock body {
    overflow: hidden;
}

@media (max-width: 640px) {
    .ai-panel-sheet {
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
    }

    .ai-panel-inner {
        padding: 14px 16px 24px;
    }

    .ai-panel-bar {
        gap: 10px;
    }

    .ai-panel-icon {
        flex-basis: 34px;
        height: 34px;
    }

    .ai-badge {
        display: none;
    }

    .ai-panel-field input,
    .ai-panel-field input::placeholder {
        font-size: 18px;
    }

    .ai-products,
    .ai-skeleton {
        grid-template-columns: 1fr;
    }

    .ai-reply + .ai-chips {
        margin-left: 0;
    }
}

@keyframes ai-flow {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

@keyframes ai-twinkle {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .65; transform: scale(.88); }
}

@keyframes ai-rise {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-trigger, .ai-trigger::before, .ai-panel-backdrop, .ai-panel-sheet,
    .ai-chip, .ai-product, .ai-panel-glow::after, .ai-panel-close, .ai-ask {
        transition: none;
    }

    .ai-trigger .ai-spark, .ai-thinking, .ai-skeleton span, .ai-reply,
    .ai-ask, .ai-ask::after, .ai-ask-icon .ai-spark,
    .ai-panel.is-thinking .ai-panel-glow::after {
        animation: none;
    }
}

@media (max-width: 640px) {
    .ai-ask-kbd {
        display: none;
    }
}
