/* SiteBrain Chat Widget — v1.3 */
#sitebrain-root * {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Position ────────────────────────────────────────────────────────── */
#sitebrain-root { position: fixed; bottom: 24px; right: 24px; z-index: 999999; }
#sitebrain-root.sb-pos-left { right: auto; left: 24px; }
#sitebrain-root.sb-pos-left .sb-window { right: auto; left: 0; transform-origin: bottom left; }

/* ── FAB ─────────────────────────────────────────────────────────────── */
.sb-fab {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--sb-primary, #4F46E5);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(79,70,229,.42);
    transition: transform .2s, box-shadow .2s;
    position: relative; outline: none; overflow: hidden;
}
.sb-fab:hover  { transform: scale(1.08); box-shadow: 0 6px 28px rgba(79,70,229,.55); }
.sb-fab:active { transform: scale(0.95); }

/* When logo set: remove background so PNG transparency shows through */
.sb-fab.sb-fab-logo {
    background: transparent !important;
    box-shadow: none;
    padding: 0;
}
.sb-fab.sb-fab-logo:hover { transform: scale(1.08); box-shadow: none; }

.sb-unread-badge {
    position: absolute; top: -3px; right: -3px;
    width: 20px; height: 20px; background: #EF4444;
    border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700;
    display: none; align-items: center; justify-content: center; border: 2px solid #fff;
}

/* ── Chat window ─────────────────────────────────────────────────────── */
.sb-window {
    position: absolute; bottom: 70px; right: 0;
    width: 350px; height: 520px;
    background: #fff; border-radius: 18px;
    box-shadow: 0 10px 56px rgba(0,0,0,.18);
    display: flex; flex-direction: column; overflow: hidden;
    transform-origin: bottom right;
    transition: transform .28s cubic-bezier(.34,1.56,.64,1), opacity .22s ease;
    border: 1px solid rgba(0,0,0,.06);
}
.sb-window.sb-hidden  { transform: scale(0.84); opacity: 0; pointer-events: none; }
.sb-window.sb-visible { transform: scale(1);    opacity: 1; pointer-events: all; }

@media (max-width: 380px) {
    .sb-window { width: calc(100vw - 32px); right: -8px; height: 490px; }
}

/* ── Header ──────────────────────────────────────────────────────────── */
.sb-header {
    background: var(--sb-primary, #4F46E5);
    padding: 12px 14px; display: flex; align-items: center;
    justify-content: space-between; flex-shrink: 0;
}
.sb-header-left  { display: flex; align-items: center; gap: 10px; }
.sb-bot-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; overflow: hidden;
}
.sb-bot-name { color: #fff; font-size: 14px; font-weight: 600; line-height: 1.2; }
.sb-bot-status {
    color: rgba(255,255,255,.8); font-size: 11px;
    display: flex; align-items: center; gap: 4px; margin-top: 1px;
}
.sb-online-dot {
    width: 7px; height: 7px; background: #4ADE80;
    border-radius: 50%; display: inline-block;
    animation: sbPulse 2s infinite;
}
@keyframes sbPulse { 0%,100%{opacity:1} 50%{opacity:.45} }
.sb-header-close {
    background: rgba(255,255,255,.15); border: none;
    width: 28px; height: 28px; border-radius: 50%;
    cursor: pointer; color: rgba(255,255,255,.9);
    display: flex; align-items: center; justify-content: center;
    transition: background .15s; padding: 0; flex-shrink: 0;
}
.sb-header-close:hover { background: rgba(255,255,255,.28); }

/* ── Body (chat area) ────────────────────────────────────────────────── */
.sb-body {
    flex: 1; overflow-y: auto; padding: 14px 12px;
    background: #F5F7FA; display: flex; flex-direction: column;
    gap: 10px; scroll-behavior: smooth;
}
.sb-body::-webkit-scrollbar { width: 4px; }
.sb-body::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 2px; }

/* ── Message rows ────────────────────────────────────────────────────── */
.sb-msg-row {
    display: flex; align-items: flex-end; gap: 7px;
    opacity: 0; transform: translateY(8px);
    transition: opacity .22s ease, transform .22s ease;
}
.sb-msg-row.sb-msg-in { opacity: 1; transform: translateY(0); }
.sb-msg-row.sb-bot-row  { align-self: flex-start; max-width: 94%; }
.sb-msg-row.sb-user-row { align-self: flex-end; max-width: 88%; justify-content: flex-end; }

.sb-bot-col  { display: flex; flex-direction: column; gap: 3px; }
.sb-user-col { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }

/* ── Avatars ─────────────────────────────────────────────────────────── */
.sb-msg-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 600; overflow: hidden;
}
.sb-bot-av  { background: #EEF2FF; color: var(--sb-primary, #4F46E5); }
.sb-user-av { background: var(--sb-primary, #4F46E5); color: #fff; font-size: 11px; }

/* ── Bubbles ─────────────────────────────────────────────────────────── */
.sb-bubble {
    padding: 10px 13px; border-radius: 14px;
    font-size: 13.5px; line-height: 1.6; word-break: break-word;
}
.sb-bot-bubble {
    background: #fff; color: #1F2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,.07);
    border: 0.5px solid #E5E7EB; max-width: 264px;
}
.sb-user-bubble {
    background: var(--sb-primary, #4F46E5); color: #fff;
    border-bottom-right-radius: 4px; max-width: 230px;
}

/* ── Source badge (small tag under answer) ───────────────────────────── */
.sb-source-badge {
    font-size: 10.5px; color: #6B7280;
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 8px; background: #F3F4F6;
    border-radius: 20px; align-self: flex-start;
    max-width: 220px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
    border: 0.5px solid #E5E7EB;
}

/* ── Source link button (Step 8) ─────────────────────────────────────── */
.sb-source-link-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; background: #EEF2FF;
    border: 1px solid #C7D2FE; border-radius: 20px;
    font-size: 12.5px; font-weight: 500;
    color: var(--sb-primary, #4F46E5) !important;
    text-decoration: none; transition: all .15s; margin-left: 35px;
}
.sb-source-link-btn:hover {
    background: var(--sb-primary, #4F46E5);
    color: #fff !important; border-color: var(--sb-primary, #4F46E5);
    text-decoration: none;
}

/* ── Timestamps ──────────────────────────────────────────────────────── */
.sb-timestamp { font-size: 10px; color: #9CA3AF; padding: 0 2px; }
.sb-ts-user   { text-align: right; }

/* ── Link pills block ────────────────────────────────────────────────── */
.sb-links-bubble {
    background: #EEF2FF !important;
    border-color: #C7D2FE !important;
    display: flex; flex-direction: column; gap: 6px; max-width: 264px;
}
.sb-links-intro { font-size: 12px; font-weight: 600; color: #3730A3; margin-bottom: 2px; }
.sb-link-pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 12px; background: #fff;
    border: 1px solid #C7D2FE; border-radius: 20px;
    font-size: 12.5px; font-weight: 500;
    color: var(--sb-primary, #4F46E5) !important;
    text-decoration: none; transition: all .15s; word-break: break-all;
}
.sb-link-pill:hover {
    background: var(--sb-primary, #4F46E5);
    color: #fff !important; border-color: var(--sb-primary, #4F46E5);
    text-decoration: none;
}

/* ── Quick option buttons ────────────────────────────────────────────── */
.sb-quick-title {
    font-size: 12.5px; font-weight: 600; color: #374151;
    margin-bottom: 8px;
}
.sb-quick-btn {
    display: block; width: 100%; text-align: left;
    padding: 8px 12px; margin-bottom: 5px; border-radius: 8px;
    background: #F9FAFB; border: 1px solid #E5E7EB;
    font-size: 13px; font-weight: 500; color: #374151;
    cursor: pointer; transition: all .15s; font-family: inherit;
}
.sb-quick-btn:last-child { margin-bottom: 0; }
.sb-quick-btn:hover {
    background: var(--sb-primary, #4F46E5);
    color: #fff; border-color: var(--sb-primary, #4F46E5);
}

/* ── Suggestion chips ────────────────────────────────────────────────── */
.sb-suggestions {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding-left: 35px; align-self: flex-start;
}
.sb-chip {
    padding: 5px 11px;
    border: 1px solid var(--sb-primary, #4F46E5);
    color: var(--sb-primary, #4F46E5); border-radius: 20px;
    font-size: 12px; cursor: pointer; background: #fff;
    transition: all .15s; font-weight: 500; font-family: inherit;
}
.sb-chip:hover { background: var(--sb-primary, #4F46E5); color: #fff; }

/* ── System message ──────────────────────────────────────────────────── */
.sb-sys-msg {
    text-align: center; font-size: 11px; color: #9CA3AF;
    padding: 2px 12px; align-self: center;
}

/* ── Typing indicator — "HelpBot is typing..." ───────────────────────── */
.sb-typing-row {
    display: flex; align-items: flex-end; gap: 7px; align-self: flex-start;
}
.sb-typing-bubble {
    background: #fff; border-radius: 14px; border-bottom-left-radius: 4px;
    padding: 10px 14px; display: flex; align-items: center; gap: 6px;
    border: 0.5px solid #E5E7EB; box-shadow: 0 1px 3px rgba(0,0,0,.07);
    max-width: 200px;
}
.sb-typing-name {
    font-size: 12.5px; color: #6B7280; font-style: italic; white-space: nowrap;
}
.sb-typing-dots {
    display: flex; gap: 3px; align-items: center; flex-shrink: 0;
}
.sb-typing-dots span {
    width: 6px; height: 6px; background: #9CA3AF; border-radius: 50%;
    animation: sbBounce 1.2s ease infinite;
}
.sb-typing-dots span:nth-child(2) { animation-delay: .2s; }
.sb-typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes sbBounce {
    0%,60%,100% { transform: translateY(0); }
    30%          { transform: translateY(-5px); }
}

/* ── Lead form ───────────────────────────────────────────────────────── */
.sb-lead-card {
    background: #fff; border: 1px solid #E5E7EB; border-radius: 14px;
    padding: 13px; max-width: 255px;
    box-shadow: 0 1px 3px rgba(0,0,0,.07);
}
.sb-lead-card p { font-size: 12px; color: #6B7280; margin: 0 0 10px; }
.sb-lead-input {
    width: 100%; padding: 8px 10px;
    border: 1px solid #E5E7EB; border-radius: 8px;
    font-size: 12.5px; margin-bottom: 7px; outline: none;
    transition: border .15s; font-family: inherit; color: #1F2937; background: #FAFAFA;
}
.sb-lead-input:focus { border-color: var(--sb-primary, #4F46E5); background: #fff; }
.sb-lead-submit {
    width: 100%; padding: 9px; background: var(--sb-secondary, #22C55E);
    color: #fff; border: none; border-radius: 8px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: opacity .15s; font-family: inherit;
}
.sb-lead-submit:hover    { opacity: .92; }
.sb-lead-submit:disabled { opacity: .6; cursor: not-allowed; }

/* ── Footer / input ──────────────────────────────────────────────────── */
.sb-footer {
    padding: 10px 12px; border-top: 1px solid #E5E7EB;
    display: flex; gap: 8px; align-items: center;
    background: #fff; flex-shrink: 0;
}
.sb-input-field {
    flex: 1; padding: 9px 14px;
    border: 1px solid #E5E7EB; border-radius: 24px;
    font-size: 13px; outline: none; background: #F5F7FA;
    color: #1F2937; transition: border .15s; font-family: inherit;
}
.sb-input-field:focus { border-color: var(--sb-primary, #4F46E5); background: #fff; }
.sb-input-field::placeholder { color: #9CA3AF; }
.sb-input-field:disabled { opacity: .6; }

.sb-send-btn {
    width: 36px; height: 36px;
    background: var(--sb-primary, #4F46E5);
    border: none; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: opacity .15s, transform .1s;
}
.sb-send-btn:hover    { opacity: .9; }
.sb-send-btn:active   { transform: scale(.92); }
.sb-send-btn:disabled { opacity: .5; cursor: not-allowed; }
