/* ==========================================================================
   PropTeach Chatbot Widget (Intercom Style)
   ========================================================================== */

/* Variables communes (partagées avec le thème) */
:root {
    --chat-primary: #000091; /* Bleu France */
    --chat-primary-hover: #1b2a85;
    --chat-bg: #ffffff;
    --chat-text: #1e1e1e;
    --chat-muted: #666666;
    --chat-border: rgba(0, 0, 0, 0.1);
    --chat-user-bg: #f5f5fe;
    --chat-bot-bg: #000091;
    --chat-bot-text: #ffffff;
    --chat-shadow: 0 12px 40px rgba(0, 0, 145, 0.15);
    --chat-z-index: 999999;
}

/* ==========================================================================
   Bouton Flottant (Bulle)
   ========================================================================== */
.propteach-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--chat-primary);
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(0, 0, 145, 0.3);
    cursor: pointer;
    z-index: var(--chat-z-index);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s;
    border: none;
    outline: none;
}

.propteach-chat-launcher:hover {
    transform: scale(1.05);
    background: var(--chat-primary-hover);
}

.propteach-chat-launcher:active {
    transform: scale(0.95);
}

.propteach-chat-launcher svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: #ffffff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: opacity 0.2s, transform 0.2s;
    position: absolute;
}

.propteach-chat-launcher .chat-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.propteach-chat-launcher.is-open .chat-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.propteach-chat-launcher.is-open .chat-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* ==========================================================================
   Fenêtre de Chat (Widget)
   ========================================================================== */
.propteach-chat-widget {
    position: fixed;
    bottom: 100px; /* Au dessus du bouton */
    right: 24px;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: var(--chat-shadow);
    z-index: var(--chat-z-index);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.propteach-chat-widget.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* En-tête (Header) */
.propteach-chat-header {
    background: var(--chat-primary);
    color: #ffffff;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.propteach-chat-header h3 {
    margin: 0 0 4px 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.propteach-chat-header p {
    margin: 0;
    font-size: 13px;
    opacity: 0.9;
}

/* Zone des messages */
.propteach-chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fdfdfd;
}

/* Scrollbar personnalisée */
.propteach-chat-body::-webkit-scrollbar {
    width: 6px;
}
.propteach-chat-body::-webkit-scrollbar-track {
    background: transparent;
}
.propteach-chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

/* Bulles de message */
.chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: chatPopIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes chatPopIn {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-msg.bot {
    align-self: flex-start;
    background: var(--chat-user-bg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--chat-bot-bg);
    color: var(--chat-bot-text);
    border-bottom-right-radius: 4px;
}

/* Liens dans les réponses du bot */
.chat-msg.bot a {
    color: var(--chat-primary);
    text-decoration: underline;
    font-weight: 500;
}

/* Zone de saisie (Footer) */
.propteach-chat-footer {
    padding: 12px 16px;
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.propteach-chat-input {
    flex: 1;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    background: #f9f9f9;
    transition: border-color 0.2s, background 0.2s;
    font-family: inherit;
}

.propteach-chat-input:focus {
    border-color: var(--chat-primary);
    background: #ffffff;
}

.propteach-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.propteach-chat-send:disabled {
    background: #cccccc;
    cursor: not-allowed;
    transform: none;
}

.propteach-chat-send:not(:disabled):hover {
    transform: scale(1.05);
    background: var(--chat-primary-hover);
}

.propteach-chat-send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    margin-left: 2px;
}

/* Indicateur de frappe (Typing) */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 16px 20px;
    background: var(--chat-user-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: fit-content;
}

.chat-typing .dot {
    width: 6px;
    height: 6px;
    background: var(--chat-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.chat-typing .dot:nth-child(1) { animation-delay: -0.32s; }
.chat-typing .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Bouton fermer dans le header (Mobile surtout) */
.chat-header-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    display: none; /* Masqué par défaut sur desktop, visible sur mobile */
    outline: none;
}
.chat-header-close svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
}

/* Le lien cookies du pied de page ouvre les préférences, sans bouton flottant. */
#CookiebotWidget,
#CookiebotSession {
    display: none !important;
}

/* ========================================================================== 
   Mobile Responsive 
   ========================================================================== */
@media (max-width: 480px) {
    .propteach-chat-widget {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100dvh; /* Dynamic viewport height pour éviter la barre d'adresse/clavier */
        max-width: 100%;
        max-height: none;
        border-radius: 0;
        transform: translateY(100%);
        transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    .propteach-chat-widget.is-open {
        transform: translateY(0);
    }
    
    .propteach-chat-header {
        border-radius: 0;
    }

    .propteach-chat-launcher {
        bottom: 20px;
        right: 20px;
    }

    /* Masquer le bouton flottant du chat quand la fenetre est ouverte pour ne pas gener */
    .propteach-chat-launcher.is-open {
        display: none !important;
    }

    /* Afficher la croix dans l'en-tête */
    .chat-header-close {
        display: block;
    }
}
