/* ================================================================
   Widget Chat IA - Vente De Conteneur
   ================================================================ */

/* ---- Bouton flottant ---- */
#chat-bubble {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9990;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

#chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2c5282, #1a365d);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(44, 82, 130, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    position: relative;
}

#chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(44, 82, 130, 0.55);
}

#chat-toggle-btn .chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e53e3e;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

#chat-toggle-btn .chat-unread-badge.visible {
    display: flex;
}

/* Tooltip callout */
#chat-callout {
    background: #fff;
    color: #333;
    padding: 10px 14px;
    border-radius: 20px 20px 4px 20px;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    max-width: 220px;
    text-align: right;
    cursor: pointer;
    animation: chatBounce 0.4s ease;
    border: 1px solid #e2e8f0;
}

@keyframes chatBounce {
    0%   { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

#chat-callout.hiding {
    opacity: 0 !important;
    transform: scale(0.8) !important;
}

/* ---- Fenêtre chat ---- */
#chat-window {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 370px;
    max-height: 560px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    z-index: 9991;
    overflow: hidden;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s cubic-bezier(.34,1.56,.64,1), opacity 0.22s ease;
}

#chat-window.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Header */
#chat-header {
    background: linear-gradient(135deg, #2c5282, #1a365d);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#chat-header .chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #ffd700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #1a365d;
    flex-shrink: 0;
}

#chat-header .chat-info h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
}

#chat-header .chat-info p {
    margin: 0;
    font-size: 0.72rem;
    opacity: 0.8;
}

#chat-header .chat-status-dot {
    width: 8px;
    height: 8px;
    background: #48bb78;
    border-radius: 50%;
    margin-right: 4px;
    display: inline-block;
}

#chat-close-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}
#chat-close-btn:hover { color: #fff; }

/* ---- Formulaire d'identification ---- */
#chat-identify {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#chat-identify p {
    color: #4a5568;
    font-size: 0.875rem;
    margin: 0;
    line-height: 1.5;
}

#chat-identify input {
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

#chat-identify input:focus {
    border-color: #2c5282;
}

#chat-identify .chat-start-btn {
    background: linear-gradient(135deg, #ffd700, #f6c200);
    color: #1a365d;
    border: none;
    padding: 11px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#chat-identify .chat-start-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

#chat-identify .chat-error {
    color: #e53e3e;
    font-size: 0.8rem;
    display: none;
}

/* ---- Zone messages ---- */
#chat-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#chat-messages-area::-webkit-scrollbar { width: 4px; }
#chat-messages-area::-webkit-scrollbar-track { background: #f7fafc; }
#chat-messages-area::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 2px; }

/* Messages */
.chat-msg {
    display: flex;
    gap: 8px;
    animation: msgSlide 0.25s ease;
    max-width: 100%;
}

@keyframes msgSlide {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg.user {
    flex-direction: row-reverse;
}

.chat-msg .msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg.assistant .msg-avatar,
.chat-msg.admin .msg-avatar {
    background: #2c5282;
    color: #ffd700;
}

.chat-msg.user .msg-avatar {
    background: #e2e8f0;
    color: #4a5568;
}

/* Wrapper interne — doit pouvoir rétrécir */
.chat-msg > div:last-child {
    min-width: 0;
    max-width: 82%;
}

.chat-msg .msg-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.55;
    overflow-wrap: break-word;
    word-break: normal;
    white-space: pre-wrap;
    display: inline-block;
    max-width: 100%;
    box-sizing: border-box;
}

.chat-msg.assistant .msg-bubble,
.chat-msg.admin .msg-bubble {
    background: #f7fafc;
    color: #2d3748;
    border-radius: 4px 14px 14px 14px;
    border: 1px solid #e2e8f0;
}

.chat-msg.admin .msg-bubble {
    border-left: 3px solid #ffd700;
}

.chat-msg.user .msg-bubble {
    background: linear-gradient(135deg, #2c5282, #1a365d);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
}

.chat-msg .msg-time {
    font-size: 0.65rem;
    color: #a0aec0;
    margin-top: 3px;
    text-align: right;
}

.chat-msg.user .msg-time {
    text-align: right;
}

/* Quote card */
.chat-quote-card {
    background: linear-gradient(135deg, #ebf8ff, #e6fffa);
    border: 1.5px solid #81e6d9;
    border-radius: 12px;
    padding: 12px 14px;
    margin-top: 6px;
    font-size: 0.82rem;
}

.chat-quote-card h5 {
    margin: 0 0 6px;
    color: #2c7a7b;
    font-size: 0.85rem;
}

.chat-quote-card .quote-total {
    font-size: 1rem;
    font-weight: 700;
    color: #2c7a7b;
}

.chat-quote-card a.download-quote {
    display: inline-block;
    margin-top: 8px;
    background: #2c7a7b;
    color: #fff;
    padding: 5px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 600;
}

/* Upload proof */
.chat-upload-proof {
    background: #fffff0;
    border: 1.5px dashed #d69e2e;
    border-radius: 10px;
    padding: 10px 12px;
    margin-top: 6px;
    font-size: 0.8rem;
}

.chat-upload-proof p {
    margin: 0 0 8px;
    color: #744210;
}

.chat-upload-proof label {
    display: inline-block;
    background: #f6ad55;
    color: #fff;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
}

.chat-upload-proof input[type="file"] {
    display: none;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-typing .typing-dots {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px 14px 14px 14px;
    padding: 10px 14px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #a0aec0;
    animation: typingBounce 1.2s infinite;
}

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

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-6px); }
}

/* ---- Input zone ---- */
#chat-input-area {
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}

#chat-input-area .chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chat-input-area textarea {
    flex: 1;
    padding: 9px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    resize: none;
    font-size: 0.875rem;
    font-family: inherit;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.4;
}

#chat-input-area textarea:focus {
    border-color: #2c5282;
}

#chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #2c5282;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}

#chat-send-btn:hover { background: #1a365d; }
#chat-send-btn:active { transform: scale(0.93); }
#chat-send-btn:disabled { background: #a0aec0; cursor: not-allowed; }

/* Upload button in input */
#chat-attach-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #fff;
    color: #718096;
    border: 1.5px solid #e2e8f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: border-color 0.2s, color 0.2s;
    flex-shrink: 0;
}
#chat-attach-btn:hover { border-color: #2c5282; color: #2c5282; }

#chat-file-input { display: none; }

.chat-ai-off-banner {
    text-align: center;
    font-size: 0.75rem;
    color: #718096;
    padding: 4px 0;
    border-top: 1px solid #e2e8f0;
    margin-top: 4px;
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
    #chat-window {
        right: 12px;
        left: 12px;
        width: auto;
        bottom: 90px;
    }
    #chat-bubble {
        right: 16px;
        bottom: 20px;
    }
}
