/* ============================================
   Chatbot widget — Centre d'Aide Biborne
   ============================================ */

#chatbot-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

#chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35), 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#chatbot-toggle:hover {
    transform: scale(1.06);
    box-shadow: 0 12px 32px rgba(37, 99, 235, 0.45), 0 4px 12px rgba(0,0,0,0.2);
}
#chatbot-toggle.active {
    background: linear-gradient(135deg, #4b5563 0%, #1f2937 100%);
}
#chatbot-toggle .chatbot-icon {
    line-height: 1;
}

.chatbot-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}
.chatbot-panel.hidden {
    display: none;
}

.chatbot-header {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.chatbot-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.chatbot-avatar {
    font-size: 26px;
    flex-shrink: 0;
}
.chatbot-header-title strong {
    display: block;
    font-size: 15px;
    line-height: 1.2;
}
.chatbot-header-title small {
    display: block;
    font-size: 11px;
    opacity: 0.85;
    margin-top: 2px;
}
.chatbot-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.chatbot-icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.chatbot-icon-btn:hover {
    background: rgba(255,255,255,0.28);
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}
.chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chatbot-msg {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}
.chatbot-msg-user {
    align-self: flex-end;
    align-items: flex-end;
}
.chatbot-msg-bot {
    align-self: flex-start;
    align-items: flex-start;
}

.chatbot-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}
.chatbot-msg-user .chatbot-bubble {
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}
.chatbot-msg-bot .chatbot-bubble {
    background: white;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}
.chatbot-bubble p { margin: 0 0 10px 0; }
.chatbot-bubble p:last-child { margin-bottom: 0; }
.chatbot-bubble ul, .chatbot-bubble ol {
    margin: 8px 0 12px 0;
    padding-left: 22px;
}
.chatbot-bubble li {
    margin: 4px 0;
    line-height: 1.55;
}
.chatbot-bubble li > ul, .chatbot-bubble li > ol {
    margin: 4px 0 4px 0;
}
.chatbot-bubble strong {
    font-weight: 600;
    color: #0f172a;
}
.chatbot-msg-user .chatbot-bubble strong { color: white; }
.chatbot-bubble code {
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12.5px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    color: #be185d;
}
.chatbot-msg-user .chatbot-bubble code {
    background: rgba(255,255,255,0.18);
    color: white;
}
.chatbot-bubble h1, .chatbot-bubble h2, .chatbot-bubble h3, .chatbot-bubble h4 {
    margin: 10px 0 6px 0;
    font-size: 14px;
    font-weight: 600;
}

/* ============ Galerie d'images des sources ============ */
.chatbot-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
    margin-top: 8px;
    max-width: 100%;
}
.chatbot-img-link {
    display: block;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    cursor: zoom-in;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.chatbot-img-link:hover {
    transform: scale(1.05);
    border-color: #2563eb;
}
.chatbot-img-link img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ============ Lightbox image ============ */
#chatbot-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: chatbot-fadein 0.15s ease;
}
@keyframes chatbot-fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}
.chatbot-lightbox-inner {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
}
.chatbot-lightbox-inner img {
    max-width: 92vw;
    max-height: 92vh;
    width: auto;
    height: auto;
    border-radius: 8px;
    display: block;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.chatbot-lightbox-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: white;
    color: #1f2937;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.chatbot-lightbox-close:hover { background: #f3f4f6; }

.chatbot-sources {
    margin-top: 8px;
    padding: 8px 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    font-size: 12px;
    color: #1e3a8a;
    max-width: 100%;
}
.chatbot-sources strong {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #1e40af;
}
.chatbot-sources ul {
    margin: 0;
    padding-left: 16px;
}
.chatbot-sources li {
    margin: 3px 0;
}
.chatbot-sources a {
    color: #1d4ed8;
    text-decoration: none;
}
.chatbot-sources a:hover {
    text-decoration: underline;
}

.chatbot-typing {
    display: inline-flex;
    gap: 4px;
    padding: 14px 16px;
}
.chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: chatbot-bounce 1.4s infinite ease-in-out;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.16s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes chatbot-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.chatbot-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: white;
    border-top: 1px solid #e5e7eb;
    align-items: flex-end;
}
#chatbot-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 120px;
    transition: border-color 0.15s ease;
}
#chatbot-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
#chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: #2563eb;
    color: white;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
#chatbot-send:hover:not(:disabled) {
    background: #1e40af;
}
#chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-footer {
    padding: 8px 12px;
    font-size: 11px;
    color: #6b7280;
    background: #f9fafb;
    text-align: center;
    border-top: 1px solid #e5e7eb;
}

@media (max-width: 480px) {
    #chatbot-widget {
        right: 16px;
        bottom: 16px;
    }
    .chatbot-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        right: 0;
        bottom: 76px;
    }
}
