/* AI Assistant widget */
.bai-root {
    --bai-primary: #ff9800;
    --bai-offset: 20px;
    --bai-bg: #ffffff;
    --bai-bg-soft: #f4f5f7;
    --bai-border: #e4e6eb;
    --bai-text: #1f2328;
    --bai-muted: #6b7280;
    --bai-user-bg: var(--bai-primary);
    --bai-user-text: #fff;
    --bai-bot-bg: #f1f2f4;
    --bai-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.7;
    color: var(--bai-text);
    direction: rtl;
    text-align: right;
    box-sizing: border-box;
}

.bai-root *, .bai-root *::before, .bai-root *::after { box-sizing: border-box; }
.bai-root [hidden] { display: none !important; }
.bai-root button { font-family: inherit; cursor: pointer; }
.bai-root svg { width: 20px; height: 20px; display: block; }

/* Thin custom scrollbars (chat, history, textarea, code blocks) */
/* Firefox only — in Chrome these standard properties would override the 4px webkit styles below */
@supports not selector(::-webkit-scrollbar) {
    .bai-root * {
        scrollbar-width: thin;
        scrollbar-color: var(--bai-scroll) transparent;
    }
}
.bai-root *::-webkit-scrollbar { width: 4px; height: 4px; }
.bai-root *::-webkit-scrollbar-track { background: transparent; }
.bai-root *::-webkit-scrollbar-thumb { background: var(--bai-scroll); border-radius: 10px; }
.bai-root *::-webkit-scrollbar-thumb:hover { background: var(--bai-primary); }
.bai-root *::-webkit-scrollbar-corner { background: transparent; }
.bai-root { --bai-scroll: rgba(127, 127, 127, .35); }

/* Dark scheme: explicit, or follow the theme's [data-theme="dark"] switch */
.bai-root.bai-scheme-dark,
[data-theme="dark"] .bai-root.bai-scheme-auto {
    --bai-bg: #1c1d21;
    --bai-bg-soft: #26282d;
    --bai-border: #33363d;
    --bai-text: #eceef2;
    --bai-muted: #9aa1ad;
    --bai-bot-bg: #2a2c32;
    --bai-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}

/* ---------- Floating ---------- */
.bai-floating {
    position: fixed;
    bottom: var(--bai-offset);
    z-index: 999990;
}
.bai-floating.bai-pos-left { left: 20px; }
.bai-floating.bai-pos-right { right: 20px; }

.bai-launcher {
    width: 58px;
    height: 58px;
    border: 0;
    border-radius: 50%;
    background: var(--bai-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative;
    padding: 0;
}
.bai-launcher:hover { transform: scale(1.06); }
.bai-launcher svg { width: 28px; height: 28px; }
.bai-launcher-open, .bai-launcher-close { position: absolute; transition: opacity .2s, transform .2s; }
.bai-launcher-close { opacity: 0; transform: rotate(-90deg); }
.bai-open .bai-launcher-open { opacity: 0; transform: rotate(90deg); }
.bai-open .bai-launcher-close { opacity: 1; transform: none; }

.bai-floating .bai-panel {
    position: absolute;
    bottom: 72px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 110px);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(.98);
    transition: opacity .22s ease, transform .22s ease, visibility .22s;
}
.bai-floating.bai-pos-left .bai-panel { left: 0; transform-origin: bottom left; }
.bai-floating.bai-pos-right .bai-panel { right: 0; transform-origin: bottom right; }
.bai-floating.bai-open .bai-panel { opacity: 1; visibility: visible; transform: none; }

/* ---------- Inline (shortcode) ---------- */
.bai-mount[data-mode="inline"] { width: 100%; }
.bai-inline { height: 100%; }
.bai-inline .bai-panel { width: 100%; height: 100%; }

/* ---------- Panel ---------- */
.bai-panel {
    display: flex;
    flex-direction: column;
    background: var(--bai-bg);
    border: 1px solid var(--bai-border);
    border-radius: 18px;
    box-shadow: var(--bai-shadow);
    overflow: hidden;
}

.bai-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bai-primary);
    color: #fff;
    flex-shrink: 0;
}
.bai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bai-avatar svg { width: 24px; height: 24px; }
.bai-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.bai-titles strong { font-size: 15px; }
.bai-titles span { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bai-actions { display: flex; gap: 2px; }
.bai-actions button {
    background: transparent;
    border: 0;
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.bai-actions button:hover { background: rgba(255, 255, 255, .18); }
.bai-actions svg { width: 19px; height: 19px; }

.bai-body { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.bai-view { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.bai-view-chat { padding: 14px 12px; display: flex; flex-direction: column; }

/* ---------- Messages ---------- */
.bai-messages { display: flex; flex-direction: column; gap: 10px; }
.bai-msg { display: flex; align-items: flex-end; gap: 4px; max-width: 100%; }
.bai-msg-user { justify-content: flex-start; }
.bai-msg-assistant, .bai-msg-error, .bai-msg-stopped { justify-content: flex-end; }
.bai-msg-stopped .bai-bubble {
    background: transparent;
    border: 1px dashed var(--bai-border);
    color: var(--bai-muted);
    font-size: 12.5px;
    padding: 5px 12px;
}

.bai-bubble {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    unicode-bidi: plaintext;
}
.bai-msg-user .bai-bubble { background: var(--bai-user-bg); color: var(--bai-user-text); border-bottom-right-radius: 4px; }
.bai-msg-assistant .bai-bubble { background: var(--bai-bot-bg); border-bottom-left-radius: 4px; }
.bai-msg-error .bai-bubble { background: rgba(220, 38, 38, .1); color: #dc2626; border: 1px solid rgba(220, 38, 38, .25); font-size: 13px; }
.bai-admin-detail {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed rgba(220, 38, 38, .35);
    font-size: 11.5px;
    opacity: .85;
    direction: ltr;
    text-align: left;
}
.bai-admin-detail::before { content: "Admin: "; font-weight: 700; }

/* ---------- Site content cards ---------- */
.bai-cards { display: flex; flex-direction: column; gap: 6px; margin: -2px 0 2px; max-width: 92%; align-self: flex-end; width: 100%; }
.bai-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px;
    background: var(--bai-bg);
    border: 1px solid var(--bai-border);
    border-radius: 12px;
    color: var(--bai-text) !important;
    text-decoration: none !important;
    transition: border-color .15s, transform .15s, box-shadow .15s;
}
.bai-card:hover { border-color: var(--bai-primary); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 0, 0, .08); }
.bai-card-thumb {
    width: 46px;
    height: 64px;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bai-bg-soft);
    color: var(--bai-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}
.bai-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bai-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.5; }
.bai-card-body strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bai-card-body em { font-style: normal; font-size: 11.5px; color: var(--bai-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.bai-card-meta { font-size: 11.5px; color: var(--bai-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bai-card-score {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 700;
    color: #f5a623;
    padding-left: 4px;
    direction: ltr;
}
.bai-card-score svg { width: 14px; height: 14px; }

.bai-bubble p { margin: 0 0 6px; }
.bai-bubble p:last-child { margin-bottom: 0; }
.bai-bubble h4 { font-size: 14px; margin: 8px 0 4px; font-weight: 700; color: inherit; }
.bai-bubble ul, .bai-bubble ol { margin: 4px 0 6px; padding: 0 20px 0 0; }
.bai-bubble li { margin: 2px 0; }
.bai-bubble a { color: var(--bai-primary); text-decoration: underline; }
.bai-bubble hr { border: 0; border-top: 1px solid var(--bai-border); margin: 8px 0; }
.bai-bubble code {
    background: rgba(127, 127, 127, .15);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: Consolas, Monaco, monospace;
    font-size: 12.5px;
    direction: ltr;
    unicode-bidi: embed;
}
.bai-bubble pre {
    background: #16171b;
    color: #e6e6e6;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    margin: 6px 0;
}
.bai-bubble pre code { background: none; padding: 0; color: inherit; }

.bai-copy {
    background: transparent;
    border: 0;
    color: var(--bai-muted);
    padding: 4px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity .15s;
}
.bai-msg:hover .bai-copy, .bai-copy:focus { opacity: 1; }
.bai-copy svg { width: 15px; height: 15px; }
.bai-copy.bai-copied { color: #16a34a; opacity: 1; }

.bai-typing .bai-bubble { display: flex; gap: 4px; padding: 13px 15px; }
.bai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--bai-muted);
    animation: bai-blink 1.2s infinite ease-in-out;
}
.bai-typing span:nth-child(2) { animation-delay: .15s; }
.bai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bai-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.bai-loading, .bai-empty { text-align: center; color: var(--bai-muted); padding: 24px 10px; font-size: 13px; list-style: none; }

/* ---------- Suggestions ---------- */
.bai-suggestions { margin-top: 12px; }
.bai-suggestions:empty { display: none; }
.bai-chip-group { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.bai-chip-title { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: var(--bai-muted); margin: 2px 0 6px; }
.bai-chip-title svg { width: 15px; height: 15px; }
.bai-root .bai-faq { flex-direction: column; align-items: stretch; gap: 5px; }
.bai-root .bai-faq button {
    border-radius: 10px;
    border-color: var(--bai-border);
    background: var(--bai-bg-soft);
    color: var(--bai-text);
    padding: 7px 12px;
}
.bai-root .bai-faq button::before { content: "؟ "; color: var(--bai-primary); font-weight: 700; }
.bai-suggestions button {
    background: transparent;
    border: 1px solid var(--bai-primary);
    color: var(--bai-primary);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12.5px;
    line-height: 1.6;
    text-align: right;
    transition: background .15s, color .15s;
}
.bai-suggestions button:hover { background: var(--bai-primary); color: #fff; }

/* ---------- Composer ---------- */
.bai-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--bai-border);
    background: var(--bai-bg);
    margin: 0;
    flex-shrink: 0;
}
.bai-composer textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--bai-border);
    background: var(--bai-bg-soft);
    color: var(--bai-text);
    border-radius: 12px;
    padding: 9px 12px;
    font: inherit;
    font-size: 14px;
    line-height: 1.6;
    max-height: 140px;
    min-height: 42px;
    outline: none;
    margin: 0;
    box-shadow: none;
    unicode-bidi: plaintext;
}
.bai-composer textarea:focus { border-color: var(--bai-primary); }
.bai-send {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: 0;
    border-radius: 12px;
    background: var(--bai-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: opacity .15s;
}
.bai-send svg { transform: scaleX(-1); }
.bai-send:disabled { opacity: .5; cursor: not-allowed; }
.bai-send.bai-stop { background: #dc2626; position: relative; }
.bai-send.bai-stop svg { transform: none; width: 18px; height: 18px; }
.bai-send.bai-stop::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 14px;
    border: 2px solid #dc2626;
    opacity: .5;
    animation: bai-pulse 1.4s ease-out infinite;
}
@keyframes bai-pulse { 0% { transform: scale(.92); opacity: .6; } 100% { transform: scale(1.12); opacity: 0; } }

.bai-footer {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 0 14px 8px;
    font-size: 11.5px;
    color: var(--bai-muted);
    background: var(--bai-bg);
    min-height: 8px;
    flex-shrink: 0;
}
.bai-quota-low { color: #dc2626; }

/* ---------- History ---------- */
.bai-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--bai-border);
    position: sticky;
    top: 0;
    background: var(--bai-bg);
}
.bai-history-head button {
    background: transparent;
    border: 0;
    color: var(--bai-muted);
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 12.5px;
    padding: 4px 6px;
    border-radius: 6px;
}
.bai-history-head button:hover { background: var(--bai-bg-soft); }
.bai-history-head svg { width: 16px; height: 16px; }
.bai-history-head .bai-danger { color: #dc2626; }
.bai-history-list { list-style: none; margin: 0; padding: 6px; }
.bai-history-item { display: flex; align-items: center; border-radius: 10px; margin: 0; }
.bai-history-item:hover, .bai-history-item.bai-active { background: var(--bai-bg-soft); }
.bai-history-open {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    color: var(--bai-text);
    text-align: right;
    padding: 9px 10px;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}
.bai-history-open strong { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bai-history-open span { font-size: 11.5px; color: var(--bai-muted); }
.bai-history-del {
    background: transparent;
    border: 0;
    color: var(--bai-muted);
    padding: 8px;
    border-radius: 8px;
}
.bai-history-del:hover { color: #dc2626; }
.bai-history-del svg { width: 17px; height: 17px; }

/* ---------- Locked ---------- */
.bai-view-locked {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 30px 24px;
    gap: 12px;
}
.bai-lock-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--bai-bg-soft);
    color: var(--bai-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.bai-lock-icon svg { width: 34px; height: 34px; }
.bai-lock-msg { margin: 0; color: var(--bai-text); font-size: 14px; }
.bai-btn {
    display: inline-block;
    background: var(--bai-primary);
    color: #fff !important;
    text-decoration: none !important;
    padding: 9px 22px;
    border-radius: 10px;
    font-weight: 600;
}
.bai-btn:hover { opacity: .9; }
.bai-locked .bai-composer { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
    .bai-floating { bottom: calc(var(--bai-offset) - 6px); }
    .bai-floating.bai-pos-left { left: 14px; }
    .bai-floating.bai-pos-right { right: 14px; }
    .bai-floating .bai-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
        border: 0;
    }
    .bai-floating.bai-open .bai-launcher { display: none; }
    .bai-no-mobile { display: none !important; }
    .bai-composer textarea { font-size: 16px; } /* prevents iOS zoom */
}

/* ---------- Answer tools (copy, feedback) & streaming ---------- */
.bai-msg-tools { display: flex; flex-direction: column; gap: 1px; align-self: flex-end; }
.bai-fb.bai-on { opacity: 1; color: var(--bai-primary); }
.bai-fb:disabled { cursor: wait; }
.bai-typing .bai-status-text { font-style: normal; font-size: 12px; color: var(--bai-muted); margin-inline-start: 6px; align-self: center; }
.bai-typing .bai-status-text:empty { display: none; }
.bai-live .bai-bubble > :last-child::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 1em;
    margin-inline-start: 2px;
    vertical-align: text-bottom;
    background: currentColor;
    opacity: .5;
    animation: bai-caret 1s steps(2) infinite;
}
@keyframes bai-caret { 50% { opacity: 0; } }
.bai-pending-link { font-weight: 600; }
