/* =============================================================================
   CHATBOT WIDGET - ETNA Pack
   ============================================================================= */

/* Bouton flottant */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary, #6366f1);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.chat-fab svg {
    width: 24px;
    height: 24px;
}

.chat-fab .chat-fab-close {
    display: none;
}

.chat-fab.open .chat-fab-icon {
    display: none;
}

.chat-fab.open .chat-fab-close {
    display: block;
}

/* Fenetre de chat */
.chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 500px;
    height: 70vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 999;
    overflow: hidden;
    border: 1px solid var(--gray-200, #e5e7eb);
}

.chat-window.open {
    display: flex;
}

/* Header du chat */
.chat-header {
    padding: 16px 20px;
    background: var(--primary, #6366f1);
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-header-icon {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header-icon svg {
    width: 20px;
    height: 20px;
}

.chat-header-info h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.chat-header-info p {
    margin: 0;
    font-size: 11px;
    opacity: 0.8;
}

.chat-header-actions {
    margin-left: auto;
    display: flex;
    gap: 4px;
}

.chat-header-actions button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.chat-header-actions button:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.chat-header-actions button svg {
    width: 16px;
    height: 16px;
}

/* Zone de messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--gray-50, #f9fafb);
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--gray-300, #d1d5db);
    border-radius: 2px;
}

/* Message */
.chat-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: chatFadeIn 0.3s ease;
}

@keyframes chatFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.user .chat-message-bubble {
    background: var(--primary, #6366f1);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-message-bubble {
    background: white;
    color: var(--gray-800, #1f2937);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-bottom-left-radius: 4px;
}

/* Markdown dans les bulles assistant */
.chat-message.assistant .chat-message-bubble p {
    margin: 0 0 8px 0;
}
.chat-message.assistant .chat-message-bubble p:last-child {
    margin-bottom: 0;
}
.chat-message.assistant .chat-message-bubble strong {
    color: var(--gray-900, #111827);
    font-weight: 600;
}
.chat-message.assistant .chat-message-bubble ul {
    margin: 6px 0;
    padding-left: 18px;
}
.chat-message.assistant .chat-message-bubble li {
    margin-bottom: 3px;
}
.chat-message.assistant .chat-message-bubble hr {
    border: none;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    margin: 10px 0;
}
.chat-message.assistant .chat-message-bubble h3,
.chat-message.assistant .chat-message-bubble h4 {
    margin: 8px 0 4px 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--primary, #6366f1);
}

/* Sources */
.chat-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    font-size: 11px;
    color: var(--gray-500, #6b7280);
}

.chat-sources strong {
    color: var(--gray-600, #4b5563);
}

/* Message de bienvenue */
.chat-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--gray-500, #6b7280);
}

.chat-welcome-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    background: var(--gray-100, #f3f4f6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-welcome-icon svg {
    width: 24px;
    height: 24px;
    stroke: var(--gray-400, #9ca3af);
}

.chat-welcome h4 {
    margin: 0 0 4px;
    font-size: 14px;
    color: var(--gray-700, #374151);
}

.chat-welcome p {
    margin: 0;
    font-size: 12px;
}

/* Suggestions */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    justify-content: center;
}

.chat-suggestion-btn {
    padding: 6px 12px;
    border: 1px solid var(--gray-200, #e5e7eb);
    background: white;
    border-radius: 16px;
    font-size: 11px;
    color: var(--gray-600, #4b5563);
    cursor: pointer;
    transition: all 0.2s;
}

.chat-suggestion-btn:hover {
    border-color: var(--primary, #6366f1);
    color: var(--primary, #6366f1);
    background: rgba(99, 102, 241, 0.05);
}

/* Zone de saisie */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: white;
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 80px;
    min-height: 40px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.chat-input-area textarea:focus {
    border-color: var(--primary, #6366f1);
}

.chat-input-area textarea::placeholder {
    color: var(--gray-400, #9ca3af);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary, #6366f1);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-send-btn:hover {
    background: var(--primary-dark, #4f46e5);
}

.chat-send-btn:disabled {
    background: var(--gray-300, #d1d5db);
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-items: center;
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--gray-400, #9ca3af);
    border-radius: 50%;
    animation: chatTyping 1.2s infinite;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Feedback */
.chat-feedback {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.chat-feedback button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.chat-feedback button:hover {
    opacity: 1;
}

.chat-feedback button.active {
    opacity: 1;
}

.chat-feedback button svg {
    width: 14px;
    height: 14px;
}

/* Liens devis cliquables */
.chat-devis-link {
    color: var(--primary, #6366f1);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 1px dashed var(--primary, #6366f1);
    transition: opacity 0.2s;
}

.chat-devis-link:hover {
    opacity: 0.7;
}

/* Status text during streaming */
.chat-status-text {
    color: var(--gray-400, #9ca3af);
    font-style: italic;
    font-size: 12px;
}

.chat-streaming-bubble {
    min-height: 20px;
    white-space: pre-wrap;
}

/* Simulation intro block */
.chat-simulation-intro {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(99, 102, 241, 0.1)) !important;
    border: 1px solid rgba(99, 102, 241, 0.2) !important;
    font-size: 12px;
    line-height: 1.6;
}

.chat-simulation-intro strong {
    color: var(--primary, #6366f1);
    font-size: 13px;
}

.chat-sim-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.chat-sim-btn {
    padding: 6px 12px;
    border: 1px solid rgba(99, 102, 241, 0.3);
    background: white;
    border-radius: 16px;
    font-size: 11px;
    color: var(--primary, #6366f1);
    cursor: pointer;
    transition: all 0.2s;
}

.chat-sim-btn:hover {
    background: var(--primary, #6366f1);
    color: white;
    border-color: var(--primary, #6366f1);
}

/* Responsive */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 120px);
        right: 8px;
        bottom: 80px;
        border-radius: 12px;
    }
}

/* Tables dans le chat */
.chat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    margin: 8px 0;
    overflow-x: auto;
    display: block;
}
.chat-table thead th {
    background: var(--primary, #2d3748);
    color: white;
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 10px;
    white-space: nowrap;
}
.chat-table tbody td {
    padding: 5px 8px;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: top;
    font-size: 11px;
    line-height: 1.4;
}
.chat-table tbody tr:nth-child(even) {
    background: #f7fafc;
}
.chat-table tbody tr:hover {
    background: #edf2f7;
}
