#chatbot-widget {
    --cb-grad: var(--grad-brand, linear-gradient(115deg, #7b2ff7 0%, #b91bbf 55%, #d90e90 100%));
    --cb-ink: var(--c-ink, #221b40);
    --cb-text: var(--c-text, #453e66);
    --cb-muted: var(--c-muted, #6f6890);
    --cb-tint: var(--c-tint, #f7f5fb);
    --cb-line: var(--c-line, #e7e2f1);
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 9999;
    font-family: var(--font-body, 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
}

#chatbot-widget svg {
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#chatbot-widget .chatbot-icon-spark {
    fill: currentColor;
    stroke: none;
}

/* ---------- Floating toggle ---------- */
#chatbot-toggle {
    position: relative;
    width: 62px;
    height: 62px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: var(--cb-grad);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 14px 30px -8px rgba(159, 26, 177, 0.65), 0 4px 10px rgba(25, 19, 51, 0.25);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

#chatbot-toggle:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 18px 34px -8px rgba(159, 26, 177, 0.75), 0 6px 14px rgba(25, 19, 51, 0.3);
}

#chatbot-toggle:focus-visible,
#chatbot-close:focus-visible,
#chatbot-send:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(123, 47, 247, 0.6);
}

#chatbot-toggle svg {
    width: 30px;
    height: 30px;
}

#chatbot-toggle::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 2px solid rgba(185, 27, 191, 0.55);
    animation: chatbot-ring 2.6s ease-out infinite;
    pointer-events: none;
}

#chatbot-widget.is-open #chatbot-toggle::after {
    animation: none;
    opacity: 0;
}

@keyframes chatbot-ring {
    0% { transform: scale(1); opacity: 0.9; }
    70%, 100% { transform: scale(1.5); opacity: 0; }
}

.chatbot-status-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22c55e;
    border: 2.5px solid #fff;
}

#chatbot-toggle .chatbot-icon-close {
    display: none;
    width: 26px;
    height: 26px;
    stroke-width: 2.2;
}

#chatbot-widget.is-open #chatbot-toggle .chatbot-icon-open,
#chatbot-widget.is-open .chatbot-status-dot {
    display: none;
}

#chatbot-widget.is-open #chatbot-toggle .chatbot-icon-close {
    display: block;
}

/* ---------- Panel ---------- */
#chatbot-panel {
    position: absolute;
    right: 0;
    bottom: 78px;
    width: 380px;
    max-width: calc(100vw - 2.5rem);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 30px 70px -18px rgba(25, 19, 51, 0.55), 0 0 0 1px rgba(34, 27, 64, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: chatbot-pop 0.22s ease-out;
}

/* Author `display:flex` above would otherwise override the browser's [hidden] rule. */
#chatbot-panel[hidden] {
    display: none;
}

@keyframes chatbot-pop {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

.chatbot-header {
    background: var(--cb-grad);
    color: #fff;
    padding: 0.95rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chatbot-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-avatar svg {
    width: 24px;
    height: 24px;
}

.chatbot-heading {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chatbot-title {
    font-weight: 800;
    font-size: 0.98rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-subtitle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    opacity: 0.92;
}

.chatbot-subtitle-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

#chatbot-close {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
}

#chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

#chatbot-close svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.2;
}

/* ---------- Messages ---------- */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: var(--cb-tint);
    scroll-behavior: smooth;
}

.chatbot-row {
    display: flex;
}

.chatbot-row--user {
    justify-content: flex-end;
}

.chatbot-row--assistant {
    justify-content: flex-start;
}

.chatbot-bubble {
    max-width: 82%;
    padding: 0.65rem 0.9rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.chatbot-bubble--user {
    background: var(--cb-grad);
    color: #fff;
    border-bottom-right-radius: 5px;
}

.chatbot-bubble--assistant {
    background: #fff;
    color: var(--cb-text);
    border: 1px solid var(--cb-line);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(34, 27, 64, 0.05);
}

.chatbot-bubble--assistant a {
    color: var(--c-brand, #8c2fc7);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chatbot-typing .chatbot-bubble {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 0.8rem 1rem;
}

.chatbot-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #a79cc6;
    animation: chatbot-blink 1.2s infinite ease-in-out;
}

.chatbot-dot:nth-child(2) { animation-delay: 0.2s; }
.chatbot-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* ---------- Composer ---------- */
#chatbot-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--cb-line);
    background: #fff;
}

#chatbot-input {
    flex: 1;
    min-width: 0;
    border: 1.5px solid var(--cb-line);
    border-radius: 999px;
    padding: 0.65rem 1rem;
    font: inherit;
    font-size: 0.9rem;
    color: var(--cb-ink);
    background: var(--cb-tint);
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

#chatbot-input::placeholder {
    color: var(--cb-muted);
}

#chatbot-input:focus {
    border-color: #a53cd4;
    background: #fff;
}

#chatbot-send {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--cb-grad);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

#chatbot-send:hover {
    transform: scale(1.06);
}

#chatbot-send svg {
    width: 19px;
    height: 19px;
    stroke-width: 1.9;
}

#chatbot-input:disabled,
#chatbot-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chatbot-footer {
    text-align: center;
    font-size: 0.7rem;
    color: var(--cb-muted);
    padding: 0 0.75rem 0.6rem;
    background: #fff;
}

/* ---------- Small screens: full-screen sheet ---------- */
@media (max-width: 520px) {
    #chatbot-widget {
        right: 1rem;
        bottom: 1rem;
    }

    #chatbot-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }

    #chatbot-widget.is-open #chatbot-toggle {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #chatbot-toggle::after,
    #chatbot-panel,
    .chatbot-dot {
        animation: none;
    }

    #chatbot-toggle,
    #chatbot-send {
        transition: none;
    }
}
