:root {
    --cb-primary: #242A5A;
    --cb-primary-20: #2e3570;

    /* JS can override these from admin */
    --cb-right: 18px;
    --cb-bottom: 18px;

    --cb-bg: #fff;
    --cb-text: #0f172a;
    --cb-muted: #6b7280;
    --cb-border: #e5e7eb;
    --cb-user: #f5f6fb;
    --cb-assistant: #eef2ff;
    --cb-shadow: 0 10px 30px rgba(0, 0, 0, .15);
}

.cb-root {
    position: fixed;
    right: calc(var(--cb-right) + env(safe-area-inset-right, 0px));
    bottom: calc(var(--cb-bottom) + env(safe-area-inset-bottom, 0px));
    z-index: 2147480000;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .25s ease, transform .25s ease;
}

.cb-root.cb-show {
    opacity: 1;
    transform: none;
}

/* Toggle button */
.cb-toggle {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 9999px;
    border: none;
    background: var(--cb-primary);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: var(--cb-shadow);
    cursor: pointer;
    transition: background .2s ease;
}

.cb-toggle:hover {
    background: var(--cb-primary-20);
}

.cb-toggle svg {
    fill: #fff;
}

.cb-toggle.cb-attn {
    animation: cb-glow 1.8s ease-in-out infinite;
}

.cb-toggle.cb-attn::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 9999px;
    border: 3px solid rgba(36, 42, 90, .35);
    animation: cb-pulse 1.8s ease-out infinite;
}

@keyframes cb-glow {

    0%,
    100% {
        box-shadow: var(--cb-shadow), 0 0 0 rgba(36, 42, 90, 0);
        transform: scale(1)
    }

    50% {
        box-shadow: var(--cb-shadow), 0 0 18px rgba(36, 42, 90, .45);
        transform: scale(1.03)
    }
}

@keyframes cb-pulse {
    0% {
        transform: scale(1);
        opacity: .65
    }

    100% {
        transform: scale(1.6);
        opacity: 0
    }
}

/* Tooltip */
.cb-tip {
    position: absolute;
    right: 70px;
    bottom: 6px;
    background: var(--cb-primary);
    color: #fff;
    padding: 8px 12px;
    border-radius: 9999px;
    box-shadow: var(--cb-shadow);
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}

.cb-tip.show {
    opacity: 1;
    transform: translateY(0)
}

/* Panel */
.cb-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: min(360px, calc(100vw - 28px));
    height: 520px;
    display: flex;
    flex-direction: column;
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: 16px;
    box-shadow: var(--cb-shadow);
    overflow: hidden;
}

/* Header */
.cb-header {
    background: var(--cb-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cb-title {
    font-weight: 700;
}

.cb-close {
    color: #fff;
    background: transparent;
    border: none;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    opacity: .9;
}

.cb-close:hover {
    opacity: 1;
}

/* Messages */
.cb-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px;
    background: #fafafa;
    scrollbar-gutter: stable;
}

/* Each message row */
.cb-msg {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 10px;
    margin: 10px 0;
    /* FIX: top-align avatar and bubble so they start on the same baseline */
    align-items: flex-start;
}

.cb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 9999px;
    background: var(--cb-primary);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    flex-shrink: 0;
}

.cb-msg.user .cb-avatar {
    background: #0ea5e9;
}

/* bubble + time wrapper */
.cb-msg>.cb-body {
    width: 100%;
}

/* bubble itself */
.cb-bubble {
    background: var(--cb-assistant);
    border: 1px solid var(--cb-border);
    border-radius: 12px;
    padding: 10px 12px;
    color: var(--cb-text);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
    box-sizing: border-box;
}

.cb-msg.user .cb-bubble {
    background: var(--cb-user);
    margin-left: auto;
}

/* time */
.cb-time {
    font-size: 12px;
    color: var(--cb-muted);
    margin-top: 4px;
}

.cb-msg.user .cb-time {
    text-align: right;
}

/* Right-side layout for user */
.cb-msg.user {
    grid-template-columns: 1fr 36px;
}

.cb-msg.user .cb-avatar {
    order: 2;
}

.cb-msg.user .cb-body {
    order: 1;
    text-align: right;
}

/* Composer */
.cb-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--cb-border);
    background: #fff;
}

.cb-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--cb-border);
    border-radius: 10px;
    outline: none;
    font-size: 14px;
}

.cb-input:focus {
    border-color: var(--cb-primary);
    box-shadow: 0 0 0 3px rgba(36, 42, 90, .12);
}

.cb-send {
    background: var(--cb-primary);
    color: #fff;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
    min-width: 64px;
}

.cb-send:hover {
    background: var(--cb-primary-20);
}

.cb-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
    border-right-color: transparent;
    animation: cbspin .8s linear infinite;
    margin-left: 8px;
}

@keyframes cbspin {
    to {
        transform: rotate(360deg)
    }
}

@media (prefers-reduced-motion:reduce) {

    .cb-toggle.cb-attn,
    .cb-toggle.cb-attn::after {
        animation: none !important
    }
}

@media (max-width:420px) {
    .cb-panel {
        height: 75vh;
    }
}