/* =========================================================
   AI Chatbot – Public Widget Styles
   WhatsApp-style floating chat widget with dark/light mode
   ========================================================= */

/* ── CSS Custom Properties (Light mode defaults) ───────────────────── */
:root {
    --cb-primary: #25D366;
    --cb-primary-dark: #128C7E;
    --cb-primary-text: #ffffff;
    --cb-bg: #ffffff;
    --cb-surface: #f0f2f5;
    --cb-border: #e0e0e0;
    --cb-text: #111b21;
    --cb-text-muted: #667781;
    --cb-user-bubble: #dcf8c6;
    --cb-user-text: #111b21;
    --cb-bot-bubble: #ffffff;
    --cb-bot-text: #111b21;
    --cb-shadow: 0 8px 32px rgba(0, 0, 0, .18);
    --cb-radius: 16px;
    --cb-toggle-size: 60px;
    --cb-window-w: 368px;
    --cb-window-h: 520px;
    --cb-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --cb-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ── Dark Mode ──────────────────────────────────────────────────────── */
.chatbot-widget[data-theme="dark"] {
    --cb-bg: #0b141a;
    --cb-surface: #182229;
    --cb-border: #2a3942;
    --cb-text: #e9edef;
    --cb-text-muted: #8696a0;
    --cb-user-bubble: #005c4b;
    --cb-user-text: #e9edef;
    --cb-bot-bubble: #202c33;
    --cb-bot-text: #e9edef;
    --cb-shadow: 0 8px 32px rgba(0, 0, 0, .45);
}

/* ── Base Reset ──────────────────────────────────────────────────────── */
.chatbot-widget *,
.chatbot-widget *::before,
.chatbot-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Floating Container ─────────────────────────────────────────────── */
.chatbot-floating {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: var(--cb-font);
}

/* ── Inline Container ───────────────────────────────────────────────── */
.chatbot-inline {
    position: relative;
    display: flex;
    justify-content: center;
    font-family: var(--cb-font);
    margin: 20px 0;
}

.chatbot-inline .chatbot-window {
    position: relative !important;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: all !important;
    display: flex !important;
}

/* ── Toggle Button ──────────────────────────────────────────────────── */
.chatbot-toggle {
    position: relative;
    width: var(--cb-toggle-size);
    height: var(--cb-toggle-size);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-dark));
    color: var(--cb-primary-text);
    box-shadow: 0 4px 20px rgba(37, 211, 102, .4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--cb-transition), box-shadow var(--cb-transition);
    outline: none;
}

.chatbot-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(37, 211, 102, .55);
}

.chatbot-toggle:focus-visible {
    outline: 3px solid var(--cb-primary);
    outline-offset: 3px;
}

.chatbot-toggle svg {
    width: 26px;
    height: 26px;
    transition: opacity var(--cb-transition), transform var(--cb-transition);
}

.chatbot-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.chatbot-widget.is-open .chatbot-icon-open {
    opacity: 0;
    transform: rotate(90deg);
}

.chatbot-widget.is-open .chatbot-icon-close {
    opacity: 1;
    transform: rotate(0);
}

/* Unread badge */
.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: cb-bounce 0.6s ease;
}

/* ── Chat Window ────────────────────────────────────────────────────── */
.chatbot-window {
    position: absolute;
    bottom: calc(var(--cb-toggle-size) + 12px);
    right: 0;
    width: var(--cb-window-w);
    height: var(--cb-window-h);
    background: var(--cb-bg);
    border-radius: var(--cb-radius);
    box-shadow: var(--cb-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0.85) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: transform var(--cb-transition), opacity var(--cb-transition);
    border: 1px solid var(--cb-border);
}

.chatbot-widget.is-open .chatbot-window {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────────────── */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--cb-primary-dark), var(--cb-primary));
    color: #fff;
    flex-shrink: 0;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.2);
    padding: 4px;
}

.chatbot-bot-name {
    display: block;
    font-weight: 700;
    font-size: 15px;
    line-height: 1;
}

.chatbot-status {
    display: block;
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
}

.chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chatbot-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, .85);
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--cb-transition), color var(--cb-transition);
    outline: none;
}

.chatbot-icon-btn:hover {
    background: rgba(255, 255, 255, .15);
    color: #fff;
}

.chatbot-icon-btn:focus-visible {
    outline: 2px solid #fff;
}

/* ── GDPR Banner ────────────────────────────────────────────────────── */
.chatbot-gdpr {
    margin: 12px;
    padding: 14px;
    background: var(--cb-surface);
    border-radius: 10px;
    border: 1px solid var(--cb-border);
    flex-shrink: 0;
}

.chatbot-gdpr-text {
    font-size: 13px;
    color: var(--cb-text);
    line-height: 1.5;
    margin-bottom: 10px;
}

.chatbot-gdpr-btn {
    display: block;
    width: 100%;
    padding: 9px;
    background: var(--cb-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--cb-transition);
    outline: none;
}

.chatbot-gdpr-btn:hover {
    background: var(--cb-primary-dark);
}

/* ── Messages Area ──────────────────────────────────────────────────── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: var(--cb-surface);
}

/* Scrollbar */
.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--cb-border);
    border-radius: 3px;
}

/* ── Message Bubbles ────────────────────────────────────────────────── */
.chatbot-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 92%;
    animation: cb-slide-in var(--cb-transition);
}

.chatbot-message.bot {
    align-self: flex-start;
}

.chatbot-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chatbot-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--cb-primary);
    padding: 4px;
    flex-shrink: 0;
}

.chatbot-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    position: relative;
}

.chatbot-message.bot .chatbot-bubble {
    background: var(--cb-bot-bubble);
    color: var(--cb-bot-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}

.chatbot-message.user .chatbot-bubble {
    background: var(--cb-user-bubble);
    color: var(--cb-user-text);
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}

.chatbot-timestamp {
    display: block;
    font-size: 10px;
    color: var(--cb-text-muted);
    margin-top: 4px;
    text-align: right;
}

/* ── Typing Indicator ───────────────────────────────────────────────── */
.chatbot-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 16px;
    background: var(--cb-surface);
    flex-shrink: 0;
}

.chatbot-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cb-text-muted);
    display: inline-block;
    animation: cb-typing 1.2s infinite;
}

.chatbot-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

/* ── Input Area ─────────────────────────────────────────────────────── */
.chatbot-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--cb-border);
    background: var(--cb-bg);
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--cb-border);
    border-radius: 20px;
    padding: 9px 14px;
    font-family: var(--cb-font);
    font-size: 14px;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
    background: var(--cb-surface);
    color: var(--cb-text);
    outline: none;
    transition: border-color var(--cb-transition);
}

.chatbot-input:focus {
    border-color: var(--cb-primary);
}

.chatbot-input::placeholder {
    color: var(--cb-text-muted);
}

.chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--cb-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--cb-transition), transform var(--cb-transition);
    outline: none;
}

.chatbot-send-btn:hover {
    background: var(--cb-primary-dark);
    transform: scale(1.05);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chatbot-send-btn:focus-visible {
    outline: 3px solid var(--cb-primary);
    outline-offset: 2px;
}

/* ── Animations ─────────────────────────────────────────────────────── */
@keyframes cb-slide-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cb-bounce {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }
}

@keyframes cb-typing {

    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: .4;
    }

    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .chatbot-floating {
        bottom: 16px;
        right: 12px;
    }

    .chatbot-window {
        width: calc(100vw - 24px);
        height: calc(100dvh - 100px);
        right: 0;
        max-width: 400px;
    }
}