/* AI Chatbot widget — all rules scoped under .aicb to avoid clashing with Bootstrap/AdminLTE */
.aicb { --aicb-accent: #2563eb; --aicb-accent-hover: #1d4ed8; --aicb-bg: #ffffff; --aicb-panel-bg: #f7f8fa; --aicb-user-bg: #2563eb; --aicb-user-fg: #ffffff; --aicb-bot-bg: #ffffff; --aicb-bot-fg: #1f2733; --aicb-muted: #6b7280; --aicb-border: #e5e7eb; --aicb-radius: 14px; --aicb-shadow: 0 12px 40px rgba(15, 23, 42, .18); --aicb-font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; position: fixed; right: 24px; bottom: 24px; z-index: 1080; font-family: var(--aicb-font); }

/* Launcher */
.aicb__launcher { width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--aicb-accent); color: #fff; cursor: pointer; box-shadow: var(--aicb-shadow); display: grid; place-items: center; transition: transform .15s ease, background .15s ease; }
    .aicb__launcher:hover { background: var(--aicb-accent-hover); transform: translateY(-2px); }
.aicb__launcher-icon { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.aicb__launcher-icon--close { display: none; }
.aicb.is-open .aicb__launcher-icon--chat { display: none; }
.aicb.is-open .aicb__launcher-icon--close { display: block; }

/* Panel */
.aicb__panel { position: absolute; right: 0; bottom: 72px; width: 380px; max-width: calc(100vw - 32px); height: 560px; max-height: calc(100vh - 120px); background: var(--aicb-panel-bg); border: 1px solid var(--aicb-border); border-radius: var(--aicb-radius); box-shadow: var(--aicb-shadow); display: flex; flex-direction: column; overflow: hidden; animation: aicb-in .18s ease; }

@keyframes aicb-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* Header */
.aicb__header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--aicb-bg); border-bottom: 1px solid var(--aicb-border); }
.aicb__brand { display: flex; align-items: center; gap: 8px; }
.aicb__status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.aicb__title { font-weight: 600; font-size: 15px; color: var(--aicb-bot-fg); }
.aicb__actions { display: flex; gap: 4px; }
.aicb__icon-btn { width: 32px; height: 32px; border: none; background: transparent; color: var(--aicb-muted); border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
    .aicb__icon-btn:hover { background: var(--aicb-panel-bg); color: var(--aicb-bot-fg); }
    .aicb__icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Messages */
.aicb__messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.aicb__row { display: flex; }
.aicb__row--user { justify-content: flex-end; }
.aicb__row--bot { justify-content: flex-start; }

.aicb__bubble { max-width: 82%; padding: 10px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; unicode-bidi: plaintext; }
.aicb__row--user .aicb__bubble { background: var(--aicb-user-bg); color: var(--aicb-user-fg); border-bottom-right-radius: 4px; }
.aicb__row--bot .aicb__bubble { background: var(--aicb-bot-bg); color: var(--aicb-bot-fg); border: 1px solid var(--aicb-border); border-bottom-left-radius: 4px; }
.aicb__bubble--ungrounded { color: var(--aicb-muted); font-style: italic; }
.aicb__bubble--error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; font-style: normal; }
/* Right-to-left answers (Urdu, Sindhi, Kashmiri). `dir="auto"` on the element makes the browser
   infer direction from the first strong character, and unicode-bidi: plaintext applies the same
   inference per paragraph — so a mixed answer with English terms still lays out correctly. */
.aicb__bubble[dir="rtl"] { text-align: right; }
    .aicb__bubble[dir="rtl"] .aicb__cites { justify-content: flex-end; }
    .aicb__bubble[dir="rtl"] .aicb__list { padding-right: 1rem; padding-left: 0; }

/* Citations */
.aicb__cites { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.aicb__cite { display: inline-flex; align-items: center; gap: 5px; background: #eef2ff; color: #3730a3; border: 1px solid #e0e7ff; padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; max-width: 100%; }
    .aicb__cite b { font-weight: 700; }
.aicb__cite-doc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.aicb__cite-ref { color: #6366f1; }

/* Typing indicator */
.aicb__typing { display: inline-flex; gap: 4px; padding: 12px; }
    .aicb__typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--aicb-muted); opacity: .4; animation: aicb-blink 1.2s infinite; }
        .aicb__typing span:nth-child(2) { animation-delay: .2s; }
        .aicb__typing span:nth-child(3) { animation-delay: .4s; }

@keyframes aicb-blink {
    0%, 60%, 100% { opacity: .25; }
    30% { opacity: 1; }
}

/* Composer */
.aicb__composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px; background: var(--aicb-bg); border-top: 1px solid var(--aicb-border); }
.aicb__input { flex: 1; resize: none; border: 1px solid var(--aicb-border); border-radius: 10px; padding: 9px 12px; font: inherit; font-size: 14px; line-height: 1.4; max-height: 120px; outline: none; background: #fff; color: var(--aicb-bot-fg); }
    .aicb__input:focus { border-color: var(--aicb-accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.aicb__send { width: 40px; height: 40px; flex: 0 0 auto; border: none; border-radius: 10px; background: var(--aicb-accent); color: #fff; cursor: pointer; display: grid; place-items: center; transition: background .15s ease; }
    .aicb__send:hover:not(:disabled) { background: var(--aicb-accent-hover); }
    .aicb__send:disabled { opacity: .45; cursor: not-allowed; }
    .aicb__send svg { width: 18px; height: 18px; fill: currentColor; }
    .aicb__send svg { transform: scaleX(-1); }

.aicb__empty { margin: auto; text-align: center; color: var(--aicb-muted); font-size: 13px; padding: 24px; }

@media (max-width: 480px) {
    .aicb { right: 12px; bottom: 12px; }
    .aicb__panel { width: calc(100vw - 24px); height: calc(100vh - 90px); bottom: 68px; }
}

/* Inline citation links ([S#] markers rendered by renderAnswerWithLinks) */
.aicb__cite-link { display: inline-flex; align-items: center; justify-content: center; vertical-align: super; font-size: 10px; line-height: 1; font-weight: 600; padding: 1px 4px; margin: 0 1px; border-radius: 5px; color: var(--aicb-accent, #2563eb); background: #eef2ff; border: 1px solid #e0e7ff; text-decoration: none; cursor: pointer; transition: background .12s ease, color .12s ease; white-space: nowrap; }
    .aicb__cite-link:hover { background: var(--aicb-accent, #2563eb); color: #fff; border-color: var(--aicb-accent, #2563eb); text-decoration: none; }
.aicb__source-link { color: var(--aicb-accent, #2563eb); text-decoration: underline; word-break: break-all; }

.aicb__list { margin-top: 4px; }
    .aicb__list li { margin-bottom: 4px; }
    .aicb__list ol { margin-top: 4px; }
