/* ─── BB Chat Widget ─────────────────────────────────────────────── */

.bb-hidden { display: none !important; }

#bb-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bb-color, #e91e8c);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.22);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    transition: transform .2s, box-shadow .2s;
}
#bb-chat-btn:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,.28); }
#bb-chat-btn svg  { width: 26px; height: 26px; fill: #fff; }

#bb-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #ff4444;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}

/* ─── Panel ──────────────────────────────────────────────────────── */

#bb-chat-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 340px;
    max-height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    display: flex;
    flex-direction: column;
    z-index: 99997;
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(.97);
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}
#bb-chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
#bb-chat-header {
    background: var(--bb-color, #e91e8c);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
#bb-chat-header .bb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
#bb-chat-header .bb-title  { font-weight: 700; font-size: 15px; line-height: 1.2; }
#bb-chat-header .bb-status { font-size: 12px; opacity: .85; }
#bb-chat-close {
    margin-left: auto;
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 0 4px;
    opacity: .8;
}
#bb-chat-close:hover { opacity: 1; }

/* Messages */
#bb-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
#bb-chat-messages::-webkit-scrollbar { width: 4px; }
#bb-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.bb-msg {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    animation: bbMsgIn .18s ease;
}
@keyframes bbMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.bb-msg.user {
    background: var(--bb-color, #e91e8c);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.bb-msg.assistant, .bb-msg.owner {
    background: #f1f1f1;
    color: #1a1a1a;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.bb-msg.owner { background: #e8f5e9; border-left: 3px solid #4caf50; }
.bb-msg-label {
    font-size: 11px;
    color: #888;
    margin-bottom: 2px;
    font-weight: 600;
}
.bb-msg-label.owner { color: #4caf50; }

/* Typing indicator */
#bb-typing {
    display: none;
    align-self: flex-start;
    padding: 9px 14px;
    background: #f1f1f1;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    gap: 4px;
    align-items: center;
}
#bb-typing.visible { display: flex; }
.bb-dot {
    width: 7px; height: 7px;
    background: #aaa;
    border-radius: 50%;
    animation: bbBounce 1.2s infinite;
}
.bb-dot:nth-child(2) { animation-delay: .2s; }
.bb-dot:nth-child(3) { animation-delay: .4s; }
@keyframes bbBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-6px); }
}

/* Status banner */
#bb-chat-status-bar {
    display: none;
    background: #fff8e1;
    color: #795548;
    font-size: 12px;
    padding: 7px 14px;
    text-align: center;
    flex-shrink: 0;
}
#bb-chat-status-bar.visible { display: block; }

/* Input */
#bb-chat-footer {
    padding: 10px 12px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}
#bb-chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
}
#bb-chat-input:focus { border-color: var(--bb-color, #e91e8c); }
#bb-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bb-color, #e91e8c);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
    transition: background .15s;
}
#bb-chat-send:hover { filter: brightness(1.1); }
#bb-chat-send:disabled { opacity: .5; cursor: default; }
#bb-chat-send svg { width: 18px; height: 18px; fill: #fff; }

/* ─── Mobile ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #bb-chat-panel {
        width: calc(100vw - 16px);
        right: 8px;
        bottom: 80px;
        max-height: 70vh;
    }
    #bb-chat-btn { bottom: 16px; right: 16px; }
}

/* ─── Pre-chat name / age form ───────────────────────────────────── */

#bb-prechat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
}
#bb-prechat-inner {
    width: 100%;
    text-align: center;
}
.bb-prechat-emoji {
    font-size: 40px;
    margin-bottom: 12px;
}
.bb-prechat-greeting {
    font-size: 18px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0 0 6px;
}
.bb-prechat-msg {
    font-size: 14px;
    color: #555;
    margin: 0 0 6px;
}
.bb-prechat-age {
    font-size: 12px;
    color: #999;
    line-height: 1.5;
    margin: 0 0 20px;
}
#bb-name-input {
    width: 100%;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    text-align: center;
    box-sizing: border-box;
    margin-bottom: 10px;
    transition: border-color .15s;
}
#bb-name-input:focus { border-color: var(--bb-color, #e91e8c); }
#bb-start-chat {
    width: 100%;
    background: var(--bb-color, #e91e8c);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 13px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: filter .15s;
}
#bb-start-chat:hover    { filter: brightness(1.08); }
#bb-start-chat:disabled { opacity: .6; cursor: default; }

/* ─── Admin thread styles ─────────────────────────────────────────── */
.bb-admin-msg { padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.bb-admin-msg.user      { background: #fce4f0; }
.bb-admin-msg.assistant { background: #f5f5f5; }
.bb-admin-msg.owner     { background: #e8f5e9; border-left: 3px solid #4caf50; }
.bb-admin-msg-who       { font-weight: 700; font-size: 12px; margin-bottom: 3px; color: #888; }
