/* ============================================================
   Xatbot IA — Dashboard Electoral AnalisiLocal.cat
   ============================================================ */

/* ---------- Botó flotant ---------------------------------------- */
#chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: #82C341;
    color: #fff;
    border: none;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.30);
    z-index: 1100;
    transition: background-color 0.2s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
#chat-toggle-btn:hover {
    background-color: #6aab2e;
    transform: scale(1.07);
}

/* ---------- Panel de xat --------------------------------------- */
#chat-panel-div {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 360px;
    height: 520px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    z-index: 1099;
    overflow: hidden;
    animation: chat-fadein 0.2s ease;
}

@keyframes chat-fadein {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

/* ---------- Capçalera ------------------------------------------ */
.chat-header {
    background: linear-gradient(135deg, #82C341, #5e9e25);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-header-title {
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 7px;
}
.chat-header-title span.badge-model {
    font-size: 10px;
    font-weight: 500;
    background: rgba(255,255,255,0.25);
    padding: 2px 6px;
    border-radius: 8px;
    letter-spacing: 0.3px;
}
#chat-close-btn {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    opacity: 0.85;
    transition: opacity 0.15s;
}
#chat-close-btn:hover { opacity: 1; }

/* ---------- Àrea de missatges ---------------------------------- */
#chat-messages-display {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8f9fa;
}

/* Missatge d'usuari */
.chat-msg-user {
    align-self: flex-end;
    background: #82C341;
    color: #fff;
    padding: 8px 12px;
    border-radius: 14px 14px 4px 14px;
    font-size: 13.5px;
    max-width: 82%;
    word-break: break-word;
    line-height: 1.45;
}

/* Missatge de l'assistent */
.chat-msg-assistant {
    align-self: flex-start;
    background: #fff;
    color: #222;
    padding: 8px 12px;
    border-radius: 14px 14px 14px 4px;
    font-size: 13.5px;
    max-width: 88%;
    word-break: break-word;
    line-height: 1.5;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    white-space: pre-wrap;
}

/* Missatge de càrrega / error */
.chat-msg-loading {
    align-self: flex-start;
    color: #888;
    font-size: 13px;
    font-style: italic;
    padding: 4px 8px;
}
.chat-msg-error {
    align-self: flex-start;
    background: #ffeaea;
    color: #c0392b;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    max-width: 88%;
}

/* Missatge benvinguda */
.chat-msg-welcome {
    align-self: flex-start;
    background: #eaf6d8;
    color: #2d6a0a;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 13px;
    max-width: 90%;
    line-height: 1.5;
    border-left: 3px solid #82C341;
}

/* ---------- Comptador de missatges restants -------------------- */
#chat-rate-info {
    font-size: 11px;
    color: #999;
    text-align: center;
    padding: 3px 10px;
    background: #f8f9fa;
    flex-shrink: 0;
}

/* ---------- Àrea d'entrada ------------------------------------- */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 12px;
    border-top: 1px solid #e8e8e8;
    background: #fff;
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: 1px solid #d0d0d0;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}
#chat-input:focus {
    border-color: #82C341;
}

#chat-send-btn {
    background: #82C341;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}
#chat-send-btn:hover {
    background: #6aab2e;
    transform: scale(1.05);
}
#chat-send-btn:disabled {
    background: #ccc;
    cursor: default;
    transform: none;
}

/* ---------- Responsive ----------------------------------------- */
@media (max-width: 420px) {
    #chat-panel-div {
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 80vh;
        border-radius: 14px 14px 0 0;
    }
    #chat-toggle-btn {
        right: 16px;
        bottom: 16px;
    }
}
