/* ============================================================
   ChatBot Widget v1.0 — Estils encapsulats amb prefix chatbot-
   ============================================================ */

/* --- Variables del tema --- */
:root {
    --chatbot-primary: #4f46e5;
    --chatbot-primary-hover: #4338ca;
    --chatbot-bg: #ffffff;
    --chatbot-bg-header: #4f46e5;
    --chatbot-bg-messages: #f9fafb;
    --chatbot-msg-user: #4f46e5;
    --chatbot-msg-user-text: #ffffff;
    --chatbot-msg-bot: #e5e7eb;
    --chatbot-msg-bot-text: #1f2937;
    --chatbot-text: #374151;
    --chatbot-text-light: #9ca3af;
    --chatbot-border: #e5e7eb;
    --chatbot-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --chatbot-radius: 16px;
    --chatbot-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* --- Botó flotant --- */
.chatbot-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    z-index: 99999;
    transition: transform 0.2s ease, background 0.2s ease;
}

.chatbot-fab:hover {
    background: var(--chatbot-primary-hover);
    transform: scale(1.08);
}

.chatbot-fab.chatbot-fab--open .chatbot-fab__icon-chat {
    display: none;
}
.chatbot-fab.chatbot-fab--open .chatbot-fab__icon-close {
    display: inline;
}
.chatbot-fab:not(.chatbot-fab--open) .chatbot-fab__icon-chat {
    display: inline;
}
.chatbot-fab:not(.chatbot-fab--open) .chatbot-fab__icon-close {
    display: none;
}

/* --- Finestra del xat --- */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 99998;
    font-family: var(--chatbot-font);
    font-size: 14px;
    color: var(--chatbot-text);
    animation: chatbot-slideUp 0.25s ease-out;
}

.chatbot-window.chatbot-window--open {
    display: flex;
}

@keyframes chatbot-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Capçalera --- */
.chatbot-header {
    background: var(--chatbot-bg-header);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chatbot-header__title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chatbot-header__close {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.chatbot-header__close:hover {
    opacity: 1;
}

/* --- Àrea de missatges --- */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--chatbot-bg-messages);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* --- Missatge individual --- */
.chatbot-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chatbot-msg--user {
    align-self: flex-end;
    background: var(--chatbot-msg-user);
    color: var(--chatbot-msg-user-text);
    border-bottom-right-radius: 4px;
}

.chatbot-msg--bot {
    align-self: flex-start;
    background: var(--chatbot-msg-bot);
    color: var(--chatbot-msg-bot-text);
    border-bottom-left-radius: 4px;
}

/* --- Indicador d'escriptura animat --- */
.chatbot-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: var(--chatbot-msg-bot);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.chatbot-typing__dot {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: chatbot-bounce 1.2s ease-in-out infinite;
}

.chatbot-typing__dot:nth-child(2) {
    animation-delay: 0.15s;
}

.chatbot-typing__dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatbot-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* --- Barra d'input --- */
.chatbot-input-bar {
    display: flex;
    padding: 12px;
    border-top: 1px solid var(--chatbot-border);
    background: var(--chatbot-bg);
    gap: 8px;
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--chatbot-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--chatbot-font);
    outline: none;
    transition: border-color 0.15s;
    color: var(--chatbot-text);
    background: var(--chatbot-bg);
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary);
}

.chatbot-input:disabled {
    background: #f3f4f6;
    color: var(--chatbot-text-light);
}

.chatbot-send {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--chatbot-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.chatbot-send:hover:not(:disabled) {
    background: var(--chatbot-primary-hover);
}

.chatbot-send:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

/* --- Missatge benvinguda --- */
.chatbot-welcome {
    text-align: center;
    color: var(--chatbot-text-light);
    font-size: 13px;
    padding: 20px 10px;
}

/* --- Responsive mòbil --- */
@media (max-width: 480px) {
    .chatbot-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .chatbot-fab {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
        font-size: 24px;
    }
}
