/* =========================================================
   === CUSTOM CHATBOX & FLOATING INPUT ===
   ========================================================= */

body {
    font-family: 'Poppins Medium', sans-serif;
    margin: 0;
    background-color: #f0f0f0; /* Just for demo visibility */
}

/* --- Floating Widget Wrapper --- */
#floating-prompt-wrapper {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    display: inline-flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 0;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    pointer-events: none;
}

/* Only pill and suggestions receive pointer events */
#quick-prompt-pill,
#quick-suggestions {
    pointer-events: auto;
}

/* --- Quick Suggestions --- */
#quick-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
    opacity: 0;
    transform: translateY(5px);
    transition: all 0.3s ease;
    pointer-events: none;
    padding-bottom: 12px;
}

#quick-prompt-pill:hover + #quick-suggestions,
#quick-suggestions:hover,
#floating-prompt-wrapper:focus-within #quick-suggestions {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* --- Capabilities Block --- */
.capabilities-block {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
    padding: 16px 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateY(8px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    width: 390px;
    box-sizing: border-box;
}

#quick-prompt-pill:hover + #quick-suggestions .capabilities-block,
#quick-suggestions:hover .capabilities-block,
#floating-prompt-wrapper:focus-within .capabilities-block {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.capabilities-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.capabilities-title {
    font-family: 'Poppins', sans-serif;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #333;
}

.beta-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-family: 'Poppins', sans-serif;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 3px 8px;
    border-radius: 10px;
}

.capabilities-desc {
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
    color: #666;
    line-height: 1.5;
    margin: 0 0 14px 0;
}

.capabilities-list {
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
    color: #555;
    line-height: 1.6;
    margin: 0 0 14px 0;
    padding-left: 0;
    list-style: none;
}

.capabilities-list li {
    position: relative;
    padding-left: 16px;
    margin-bottom: 4px;
}

.capabilities-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 5px;
    height: 5px;
    background: #D5BAA1;
    border-radius: 50%;
}

.capabilities-buttons {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.capability-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    background: #f8f8f8;
    border: 1px solid rgba(0,0,0,0.06);
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: #333;
    transition: all 0.2s ease;
    text-align: center;
    white-space: nowrap;
}

.capability-btn svg {
    flex-shrink: 0;
    color: #666;
    transition: color 0.2s ease;
}

.capability-btn:hover {
    background: #000;
    color: #fff;
    border-color: #000;
}

.capability-btn:hover svg {
    color: #fff;
}


/* --- Quick Prompt Pill (Bottom Right) --- */
#quick-prompt-pill {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #ffffff !important;
    padding: 0 !important;
    border-radius: 50px !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05) !important;
    width: 56px;
    height: 56px !important;
    overflow: hidden !important;
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
}

#quick-prompt-pill:hover,
#floating-prompt-wrapper:has(#quick-suggestions:hover) #quick-prompt-pill,
#floating-prompt-wrapper:focus-within #quick-prompt-pill {
    width: 390px;
    padding: 0 8px !important;
    justify-content: flex-start !important;
}

/* --- Aide Label (visible when collapsed) --- */
#aide-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    transition: opacity 0.2s ease, transform 0.2s ease;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

#quick-prompt-pill:hover #aide-label,
#floating-prompt-wrapper:has(#quick-suggestions:hover) #aide-label,
#floating-prompt-wrapper:focus-within #aide-label {
    opacity: 0;
    transform: translateX(-50%) scale(0.8);
    pointer-events: none;
}

/* --- Quick Mic Button (in floating pill) --- */
#quick-mic-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    color: #333;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0;
    transform: scale(0) translateX(20px);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition-delay: 0.15s;
    margin-right: 8px;
}

#floating-prompt-wrapper:hover #quick-mic-btn,
#floating-prompt-wrapper:focus-within #quick-mic-btn {
    opacity: 1;
    transform: scale(1) translateX(0);
}

#quick-mic-btn:hover {
    background: #e0e0e0;
    transform: scale(1.05) translateX(0);
}

#quick-mic-btn.recording {
    background: #ff4444;
    color: #fff;
    animation: pulse-recording 1.5s infinite;
}

#quick-mic-btn.processing {
    background: #ffaa00;
    color: #fff;
    cursor: wait;
}

#quick-prompt-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0 0 0 8px;
    font-size: 14px;
    font-family: inherit;
    color: #000;
    outline: none;
    opacity: 0;
    width: 0;
    height: 100%;
    transition: opacity 0.3s ease 0.1s;
    white-space: nowrap;
}

#quick-prompt-pill:hover #quick-prompt-input,
#floating-prompt-wrapper:has(#quick-suggestions:hover) #quick-prompt-input,
#floating-prompt-wrapper:focus-within #quick-prompt-input {
    opacity: 1;
    width: auto;
}

#quick-prompt-submit {
    width: 56px !important;
    height: 56px !important;
    min-width: 30px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #000 0%, #333 100%) !important;
    color: #fff !important;
    border: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    transition: transform 0.2s ease, opacity 0.2s ease !important;
    opacity: 0;
    transform: scale(0);
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    border: 5px solid #fff !important;
}

#quick-prompt-pill:hover #quick-prompt-submit,
#floating-prompt-wrapper:has(#quick-suggestions:hover) #quick-prompt-submit,
#floating-prompt-wrapper:focus-within #quick-prompt-submit {
    opacity: 1;
    transform: scale(1);
}

#quick-prompt-submit:hover {
    transform: scale(1.05);
}

#quick-prompt-submit svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* --- Chat Window (Hidden initially) --- */
.chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 600px;
    min-width: 300px;
    min-height: 400px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 48px);
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 10001;
    overflow: hidden;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Désactiver la transition pendant le redimensionnement */
.chat-window.resizing {
    transition: none !important;
}

/* --- Poignée de redimensionnement (coin haut-gauche) --- */
.chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 10;
    border-top-left-radius: 24px;
}

.chat-resize-handle::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 8px;
    height: 8px;
    border-left: 2px solid rgba(0,0,0,0.2);
    border-top: 2px solid rgba(0,0,0,0.2);
    transition: border-color 0.2s;
}

.chat-resize-handle:hover::before {
    border-color: rgba(0,0,0,0.5);
}

.chat-window.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* Header */
.chat-header {
    padding: 16px 20px;
    background: #ffffff;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
    color: #000;
}

#chat-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    color: #666;
    transition: background 0.2s;
}

#chat-close-btn:hover {
    background: #f5f5f5;
    color: #000;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #fafafa;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
}

/* Standard HTML Elements in Messages (Markdown) */
.message-content {
    text-align: left;
    overflow-wrap: break-word;
}

.message-content * {
    text-indent: 0 !important; /* Kill any global text indent */
}

.message-content p {
    margin: 0 0 12px 0;
    white-space: normal; /* Collapse sequences of whitespace */
}
.message-content p:last-child {
    margin: 0;
}
.message-content a {
    color: #D5BAA1;
    text-decoration: underline;
    font-weight: 600;
}
.message-content a:hover {
    text-decoration: none;
}
.message-content strong {
    font-weight: 700;
}
.message-content ul, .message-content ol {
    margin: 12px 0 !important;
    padding-left: 24px !important;
    list-style-position: outside !important;
    display: block !important;
}
.message-content ul {
    list-style-type: disc !important;
}
.message-content ol {
    list-style-type: decimal !important;
}
.message-content li {
    margin-bottom: 6px !important;
    padding-left: 4px !important;
    display: list-item !important;
    list-style: inherit !important;
}
.message-content li::marker {
    color: #666;
}
.message-content pre {
    background: #f5f5f5;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    font-family: monospace;
    font-size: 0.9em;
    margin: 8px 0;
}
.message-content code {
    font-family: monospace;
    background: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}
.message-content br {
    display: block;
    content: "";
    margin: 0; /* Let margins handle spacing, breaks are just breaks */
}

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

.message.bot {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    color: #333;
    border-bottom-left-radius: 4px;
}

.message.user {
    align-self: flex-end;
    background: #000000;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

/* Typing Indicator */
.message.bot .typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.message.bot .typing span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.message.bot .typing span:nth-child(1) { animation-delay: -0.32s; }
.message.bot .typing span:nth-child(2) { animation-delay: -0.16s; }

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

/* Input Area */
.chat-input-area {
    padding: 16px;
    background: #ffffff;
    border-top: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
}

#chat-inner-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 100px;
    background: #f9f9f9;
}

#chat-inner-input:focus {
    border-color: #000;
    background: #fff;
}

#chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #D5BAA1; /* Your theme accent color */
    color: #000;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter 0.2s;
    flex-shrink: 0;
}

#chat-send-btn:hover {
    filter: brightness(0.95);
}

/* --- Mic Button (Speech-to-Text) --- */
#chat-mic-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    color: #333;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#chat-mic-btn:hover {
    background: #e0e0e0;
}

#chat-mic-btn.recording {
    background: #ff4444;
    color: #fff;
    animation: pulse-recording 1.5s infinite;
}

#chat-mic-btn.processing {
    background: #ffaa00;
    color: #fff;
    cursor: wait;
}

@keyframes pulse-recording {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.4); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 8px rgba(255, 68, 68, 0); }
}

/* ===== CARROUSEL HORIZONTAL POUR TABLES MARKDOWN ===== */
:root {
    --card-min: 180px;
    --card-ideal: 220px;
    --card-max: 260px;
    --image-height: 180px;
}

.message-content table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-snap-type: x mandatory !important;
    padding: .25rem 0 1rem !important;
    border-spacing: 0 !important;
    border: none !important;
}

/* Grille pour les cartes produit */
.message-content table tbody,
.message-content table thead {
    display: grid !important;
    grid-auto-flow: column !important;
    grid-auto-columns: clamp(var(--card-min), 28vw, var(--card-ideal)) !important;
    gap: 1rem !important;
    align-items: stretch !important;
    justify-items: stretch !important;
}

.message-content table tr {
    display: contents !important;
}

/* Cartes produit */
.message-content table td,
.message-content table th {
    display: block !important;
    min-width: clamp(var(--card-min), 28vw, var(--card-ideal)) !important;
    max-width: var(--card-max) !important;
    scroll-snap-align: start !important;
    border-radius: 14px !important;
    padding: 1rem !important;
    background: #fff !important;
    box-shadow: 0 2px 8px rgba(44,44,44,.06) !important;
    text-align: center !important;
    border: none !important;
}

/* Image produit */
.message-content table td a img,
.message-content table th a img {
    display: block !important;
    width: 100% !important;
    height: var(--image-height) !important;
    object-fit: contain !important;
    object-position: center !important;
    border-radius: 10px !important;
    margin: .5rem 0 !important;
    max-width: none !important;
}

/* Troncature titre et prix */
.message-content table td strong,
.message-content table th strong {
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    white-space: normal !important;
    text-overflow: ellipsis !important;
}

/* Masquer les cellules vides */
.message-content table td:empty,
.message-content table th:empty {
    display: none !important;
}

/* PATCH: Tables avec THEAD seulement */
.message-content table:not(:has(tbody)) thead,
.message-content table:not(:has(tbody)) thead * {
    display: revert !important;
    visibility: visible !important;
    height: auto !important;
    padding: revert !important;
    margin: revert !important;
    line-height: normal !important;
}

/* Grille directement sur THEAD si seulement lui existe */
.message-content table:not(:has(tbody)) thead {
    display: grid !important;
    grid-auto-flow: column !important;
    grid-auto-columns: clamp(var(--card-min), 28vw, var(--card-ideal)) !important;
    gap: 1rem !important;
    align-items: stretch !important;
    justify-items: stretch !important;
}

/* Masquer THEAD seulement quand suivi par tbody (mode vraie table) */
.message-content table:has(tbody) thead,
.message-content table:has(tbody) thead * {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Supprimer seulement les cartes vraiment vides */
.message-content table td:not(:has(a,img,strong)):not(:has(*:not(br))),
.message-content table th:not(:has(a,img,strong)):not(:has(*:not(br))) {
    display: none !important;
}

/* Style de la scrollbar */
.message-content table::-webkit-scrollbar {
    height: 8px;
}
.message-content table::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,.15);
    border-radius: 8px;
}

/* ===== RESPONSIVE CARROUSEL ===== */
@media (max-width: 520px) {
    .message-content table thead,
    .message-content table tbody {
        grid-auto-columns: clamp(220px, 80vw, var(--card-ideal)) !important;
        gap: .75rem !important;
    }
    :root {
        --image-height: 160px;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .chat-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-height: 100vh;
    }
    
    #floating-prompt-wrapper {
        width: auto;
        right: 16px;
        bottom: 16px;
    }
    
    #quick-prompt-pill {
        max-width: calc(100vw - 32px);
    }
}