/* AI maslahatchi vidjeti — barcha klasslar wfai- prefiksli, sayt stillariga aralashmaydi */
#wfai-root {
    --wfai-brand: #006778;      /* saytning asosiy rangi */
    --wfai-brand-2: #003b54;
    --wfai-accent: #fdb924;     /* saytning oltin urg'u rangi */
    --wfai-glow: rgba(0, 103, 120, .38);
    --wfai-bg: #ffffff;
    --wfai-soft: #f1f5f9;
    --wfai-text: #0f172a;
    --wfai-muted: #64748b;
    --wfai-line: #e2e8f0;
    position: fixed; right: 20px; bottom: 20px; z-index: 9990;
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--wfai-text);
}
#wfai-root *, #wfai-root *::before, #wfai-root *::after { box-sizing: border-box; }

/* ---------- Ochish tugmasi: rangli ramka ichida robot + to'lqin effekti ---------- */
#wfai-root { --wfai-fab: 88px; }

.wfai-fab {
    position: relative; display: block; width: var(--wfai-fab); height: var(--wfai-fab);
    padding: 0; border: 0; background: none; cursor: pointer; border-radius: 50%;
    -webkit-tap-highlight-color: transparent;
}
/* Ramka: oq doira, sayt rangidagi hoshiya, robot ichida */
.wfai-frame {
    position: relative; z-index: 2; display: grid; place-items: end center;
    width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
    background: radial-gradient(circle at 50% 35%, #ffffff 0%, #eef7f8 70%, #d9ecef 100%);
    border: 4px solid var(--wfai-brand);
    box-shadow: 0 0 0 3px #fff, 0 12px 28px var(--wfai-glow);
    color: var(--wfai-brand);
    transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), box-shadow .25s;
}
.wfai-frame > svg:not(.tr-bot) { align-self: center; width: 40px; height: 40px; } /* zaxira ikonka */
.wfai-frame .tr-bot { width: 98%; height: 98%; flex: none; transform: translateY(-1%); }
.wfai-fab:hover .wfai-frame,
.wfai-fab:focus-visible .wfai-frame { transform: scale(1.07); box-shadow: 0 0 0 3px #fff, 0 16px 34px rgba(0, 103, 120, .5); }
.wfai-fab:active .wfai-frame { transform: scale(.96); }
.wfai-fab:focus-visible { outline: none; }

/* To'lqinlar: ramkadan tashqariga tarqaluvchi to'ldirilgan halqalar (har qanday fonda sezilsin) */
.wfai-wave {
    position: absolute; inset: 0; z-index: 1; border-radius: 50%; pointer-events: none;
    background: var(--wfai-glow); border: 2px solid var(--wfai-brand); opacity: 0;
    animation: wfai-wave 2.4s cubic-bezier(.2, .6, .35, 1) infinite;
}
/* O'rtadagi to'lqin oltin rangda — sayt urg'u rangi bilan almashinib turadi */
.wfai-wave + .wfai-wave { animation-delay: .8s; background: rgba(253, 185, 36, .35); border-color: var(--wfai-accent); }
.wfai-wave + .wfai-wave + .wfai-wave { animation-delay: 1.6s; background: var(--wfai-glow); border-color: var(--wfai-brand); }
@keyframes wfai-wave {
    0%   { transform: scale(1);    opacity: .95; }
    60%  { opacity: .35; }
    100% { transform: scale(1.6);  opacity: 0; }
}
/* Sichqoncha ustida to'lqin tezlashadi */
.wfai-fab:hover .wfai-wave { animation-duration: 1.6s; }

.wfai-open .wfai-fab { display: none; }

/* Sarlavhadagi avatar */
.wfai-ava.wfai-has-robot { background: #fff; overflow: hidden; place-items: end center; border: 2px solid rgba(255,255,255,.85); }
.wfai-ava.wfai-has-robot svg { width: 36px; height: 36px; transform: translateY(3px); }

@media (prefers-reduced-motion: reduce) {
    .wfai-wave { animation: none; }
}

.wfai-panel {
    position: absolute; right: 0; bottom: 0; width: 370px; height: min(580px, calc(100vh - 40px));
    background: var(--wfai-bg); border-radius: 18px; overflow: hidden;
    box-shadow: 0 20px 60px rgba(15, 23, 42, .25); display: flex; flex-direction: column;
    animation: wfai-in .22s ease-out;
}
.wfai-panel[hidden] { display: none; }
@keyframes wfai-in { from { opacity: 0; transform: translateY(14px); } }

.wfai-head {
    display: flex; align-items: center; gap: 10px; padding: 14px 14px 14px 16px;
    background: linear-gradient(135deg, var(--wfai-brand), var(--wfai-brand-2)); color: #fff;
}
.wfai-ava {
    width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.2);
    display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none;
}
.wfai-ttl { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.wfai-ttl small { opacity: .85; font-size: 12px; }
.wfai-x {
    background: none; border: 0; color: #fff; font-size: 26px; line-height: 1;
    width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
}
.wfai-x:hover { background: rgba(255,255,255,.15); }

.wfai-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--wfai-soft); }
.wfai-msg { max-width: 85%; padding: 10px 13px; border-radius: 14px; word-wrap: break-word; }
.wfai-bot { align-self: flex-start; background: var(--wfai-bg); border: 1px solid var(--wfai-line); border-bottom-left-radius: 4px; }
.wfai-user { align-self: flex-end; background: var(--wfai-brand); color: #fff; border-bottom-right-radius: 4px; }
.wfai-msg a { color: inherit; font-weight: 600; text-decoration: underline; }
.wfai-bot a[href^="tel:"] { color: var(--wfai-brand); white-space: nowrap; }
.wfai-li { display: block; padding-left: 14px; position: relative; }
.wfai-li::before { content: "•"; position: absolute; left: 2px; }

.wfai-typing { display: flex; gap: 4px; padding: 14px; }
.wfai-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--wfai-muted); animation: wfai-dot 1s infinite; }
.wfai-typing i:nth-child(2) { animation-delay: .15s; }
.wfai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes wfai-dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.wfai-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px; background: var(--wfai-soft); }
.wfai-chips:not(:empty) { padding-bottom: 12px; }
.wfai-chip {
    border: 1px solid var(--wfai-brand); color: var(--wfai-brand); background: var(--wfai-bg);
    border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.wfai-chip:hover { background: var(--wfai-brand); color: #fff; }

.wfai-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; border-top: 1px solid var(--wfai-line); background: var(--wfai-bg); }
.wfai-in {
    flex: 1; resize: none; border: 1px solid var(--wfai-line); border-radius: 12px; padding: 10px 12px;
    font: inherit; color: inherit; background: var(--wfai-bg); outline: none; max-height: 110px;
    overflow-y: auto; scrollbar-width: none;
}
.wfai-in::-webkit-scrollbar { display: none; }
.wfai-in:focus { border-color: var(--wfai-brand); }
.wfai-send {
    width: 42px; height: 42px; flex: none; border: 0; border-radius: 12px; cursor: pointer;
    background: var(--wfai-brand); color: #fff; display: grid; place-items: center;
}

/* Telefon va planshet: tugma kichikroq, iPhone pastki chizig'i (safe-area) hisobga olinadi */
@media (max-width: 767px) {
    #wfai-root { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); --wfai-fab: 72px; }
}
/* Telefonda panel ochiq: orqadagi sahifa qotadi, panel ichidagi scroll sahifaga o'tmaydi */
html.wfai-lock, html.wfai-lock body { overflow: hidden !important; overscroll-behavior: none; }
.wfai-body { overscroll-behavior: contain; }

@media (max-width: 480px) {
    .wfai-open { inset: 0; right: 0 !important; bottom: 0 !important; }
    .wfai-open .wfai-panel { position: fixed; inset: 0; width: auto; height: 100%; border-radius: 0; }
}

/*
 * Saytning "yuqoriga" (back-to-top, 44px) tugmasi maslahatchi tugmasining aynan ustida, bir o'qda turadi:
 *   right  = root.right + (fab - 44) / 2
 *   bottom = root.bottom + fab + oraliq (to'lqin uchun joy)
 */
.back-to-top-wrapper.back-to-top-btn-show { right: 42px !important; bottom: 132px !important; }
@media (max-width: 767px) {
    .back-to-top-wrapper.back-to-top-btn-show {
        right: 30px !important;
        bottom: calc(108px + env(safe-area-inset-bottom, 0px)) !important;
    }
}
/* Mobil panel to'liq ekran ochilganda "yuqoriga" tugmasi ko'rinmasin */
body:has(#wfai-root.wfai-open) .back-to-top-wrapper { visibility: hidden !important; }
