/* ============================================================
   BiggestBot Chat — Widget
   ============================================================ */

:root {
    --bbc-primary:      #4F46E5;
    --bbc-primary-dark: #3730A3;
    --bbc-bg:           #ffffff;
    --bbc-surface:      #F9FAFB;
    --bbc-border:       #E5E7EB;
    --bbc-text:         #111827;
    --bbc-text-muted:   #6B7280;
    --bbc-user-bg:      var(--bbc-primary);
    --bbc-user-text:    #ffffff;
    --bbc-bot-bg:       #F3F4F6;
    --bbc-bot-text:     #111827;
    --bbc-radius:       16px;
    --bbc-shadow:       0 8px 32px rgba(0,0,0,.18);
    --bbc-z:            999999;
}

/* ── Contenedor raíz ─────────────────────────────────────── */
#bbc-widget-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--bbc-z);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

#bbc-widget-root.bbc-pos-bottom-left {
    right: auto;
    left: 24px;
    align-items: flex-start;
}

/* ── Botón flotante ──────────────────────────────────────── */
#bbc-toggle-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--bbc-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(79,70,229,.45);
    transition: transform .2s, box-shadow .2s, background .2s;
    flex-shrink: 0;
}

#bbc-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(79,70,229,.55);
    background: var(--bbc-primary-dark);
}

#bbc-toggle-btn img,
#bbc-toggle-btn .bbc-icon-default {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    pointer-events: none;
}

#bbc-toggle-btn .bbc-icon-default {
    font-size: 26px;
    line-height: 1;
}

/* Badge de notificación */
#bbc-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #EF4444;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}

#bbc-badge.visible { display: block; }

/* ── Ventana de chat ─────────────────────────────────────── */
#bbc-chat-window {
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--bbc-bg);
    border-radius: var(--bbc-radius);
    box-shadow: var(--bbc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: opacity .22s ease, transform .22s ease;
    opacity: 1;
    transform: scale(1) translateY(0);
}

#bbc-widget-root.bbc-pos-bottom-left #bbc-chat-window {
    transform-origin: bottom left;
}

#bbc-chat-window.bbc-hidden {
    opacity: 0;
    transform: scale(.92) translateY(12px);
    pointer-events: none;
}

/* Header */
#bbc-chat-header {
    background: var(--bbc-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.bbc-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}

.bbc-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bbc-header-info { flex: 1; min-width: 0; }
.bbc-header-info strong { display: block; font-size: 15px; }
.bbc-header-status { font-size: 12px; opacity: .8; }

#bbc-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,.8);
    cursor: pointer;
    font-size: 22px;
    padding: 0 4px;
    line-height: 1;
    transition: color .15s;
}
#bbc-close-btn:hover { color: #fff; }

/* Messages */
/* Messages wrap — ocupa el espacio disponible y permite scroll */
#bbc-messages-wrap {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0; /* crítico para que flex respete el overflow */
}

#bbc-messages {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    scroll-behavior: smooth;
}

#bbc-messages-wrap::-webkit-scrollbar { width: 4px; }
#bbc-messages-wrap::-webkit-scrollbar-thumb { background: var(--bbc-border); border-radius: 4px; }

.bbc-msg {
    display: flex;
    gap: 8px;
    max-width: 90%;
    animation: bbcFadeIn .2s ease;
}

@keyframes bbcFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bbc-msg.bbc-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.bbc-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    word-break: break-word;
    line-height: 1.5;
}

.bbc-msg.bbc-bot  .bbc-bubble { background: var(--bbc-bot-bg);  color: var(--bbc-bot-text);  border-bottom-left-radius: 4px; }
.bbc-msg.bbc-user .bbc-bubble { background: var(--bbc-user-bg); color: var(--bbc-user-text); border-bottom-right-radius: 4px; }

/* Typing indicator */
#bbc-typing {
    display: none;
    gap: 5px;
    padding: 12px 16px;
    align-items: center;
}
#bbc-typing.visible { display: flex; }
#bbc-typing span {
    width: 7px; height: 7px;
    background: var(--bbc-text-muted);
    border-radius: 50%;
    animation: bbcDot 1.2s infinite;
}
#bbc-typing span:nth-child(2) { animation-delay: .2s; }
#bbc-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bbcDot {
    0%,80%,100% { transform: scale(.7); opacity:.5; }
    40%          { transform: scale(1);  opacity:1;  }
}

/* Input area */
#bbc-input-area {
    border-top: 1px solid var(--bbc-border);
    padding: 12px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--bbc-bg);
}

#bbc-input {
    flex: 1;
    border: 1px solid var(--bbc-border);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.4;
    color: var(--bbc-text);
    background: var(--bbc-surface);
    transition: border-color .15s;
}

#bbc-input:focus { border-color: var(--bbc-primary); }

#bbc-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #C8C8CC;
    border: none;
    cursor: not-allowed;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: background .2s, transform .15s;
    flex-shrink: 0;
}

#bbc-send-btn.bbc-send-active {
    background: var(--bbc-primary);
    cursor: pointer;
}
#bbc-send-btn.bbc-send-active:hover  { background: var(--bbc-primary-dark); transform: scale(1.05); }
#bbc-send-btn.bbc-send-active:active { transform: scale(.96); }

/* Input deshabilitado mientras el bot habla */
#bbc-input:disabled {
    background: var(--bbc-surface);
    color: var(--bbc-text-muted);
    cursor: not-allowed;
}

#bbc-send-btn svg { width: 18px; height: 18px; }

/* Powered by */
#bbc-powered {
    text-align: center;
    font-size: 10px;
    color: var(--bbc-text-muted);
    padding: 4px 0 8px;
    flex-shrink: 0;
}

/* ── Responsive mobile ───────────────────────────────────── */
@media (max-width: 480px) {
    #bbc-widget-root {
        bottom: 16px;
        right: 16px;
    }
    #bbc-widget-root.bbc-pos-bottom-left {
        left: 16px;
        right: auto;
    }
    #bbc-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        max-height: none;
        border-radius: 14px;
    }
}

/* ── Admin: notices ──────────────────────────────────────── */

/* ── Options bar (bifurcador / opciones múltiples) ─── */
#bbc-options-bar {
    padding: 8px 12px 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
    border-top: 1px solid var(--bbc-border);
}
#bbc-options-bar.bbc-hidden { display: none; }

.bbc-opt-btn {
    padding: 7px 14px;
    border: 1px solid var(--bbc-primary);
    border-radius: 20px;
    background: transparent;
    color: var(--bbc-primary);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s, color .15s;
}
.bbc-opt-btn:hover {
    background: var(--bbc-primary);
    color: #fff;
}

/* ── Link button ─────────────────────────────────────── */
.bbc-link-btn {
    display: inline-block;
    padding: 8px 16px;
    background: var(--bbc-primary);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-family: inherit;
    transition: background .15s;
}
.bbc-link-btn:hover { background: var(--bbc-primary-dark); }
