/* Quête et Racines — Chatbot Généalogie v1.1 */

#qrc-chatbot-root {
    --qrc-primary: #8b5a2b;
    --qrc-primary-dark: #6b4423;
    --qrc-accent: #c9874f;
    --qrc-bg: #fdfaf5;
    --qrc-user-bg: #8b5a2b;
    --qrc-user-text: #ffffff;
    --qrc-bot-bg: #f0e9dc;
    --qrc-bot-text: #2c1810;
    --qrc-border: #d4c5a9;
    --qrc-success: #2d6a4f;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* === Mode flottant === */
.qrc-bottom-right, .qrc-bottom-left {
    position: fixed;
    bottom: 24px;
    z-index: 99999;
}
.qrc-bottom-right { right: 24px; }
.qrc-bottom-left  { left:  24px; }

.qrc-toggle-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 14px;
    min-width: 62px;
    height: auto;
    border-radius: 28px;
    background: #fdfaf5;
    border: 2px solid var(--qrc-primary);
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(139, 90, 43, 0.28);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    animation: qrc-pulse-ring 4s ease-in-out infinite;
}
.qrc-toggle-btn:hover {
    background: #f5ede0;
    transform: scale(1.04) translateY(-2px);
    box-shadow: 0 6px 18px rgba(139, 90, 43, 0.38);
    animation: none;
}
.qrc-bottom-right.qrc-open .qrc-toggle-btn,
.qrc-bottom-left.qrc-open .qrc-toggle-btn {
    animation: none;
    background: var(--qrc-primary);
}
.qrc-bottom-right.qrc-open .qrc-toggle-btn svg,
.qrc-bottom-left.qrc-open .qrc-toggle-btn svg {
    fill: white;
}
.qrc-bottom-right.qrc-open .qrc-toggle-btn .qrc-toggle-label,
.qrc-bottom-left.qrc-open .qrc-toggle-btn .qrc-toggle-label {
    color: white;
}
.qrc-toggle-btn svg { width: 24px; height: 24px; fill: var(--qrc-primary); }
.qrc-toggle-btn svg circle { fill: var(--qrc-primary); }
.qrc-toggle-btn svg line { stroke: var(--qrc-primary); }
.qrc-bottom-right.qrc-open .qrc-toggle-btn svg circle,
.qrc-bottom-left.qrc-open .qrc-toggle-btn svg circle { fill: white; }
.qrc-bottom-right.qrc-open .qrc-toggle-btn svg line,
.qrc-bottom-left.qrc-open .qrc-toggle-btn svg line { stroke: white; }
.qrc-toggle-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--qrc-primary);
    letter-spacing: 0.03em;
    line-height: 1;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@keyframes qrc-pulse-ring {
    0%, 100% { box-shadow: 0 3px 12px rgba(139, 90, 43, 0.28); }
    50% { box-shadow: 0 3px 12px rgba(139, 90, 43, 0.28), 0 0 0 5px rgba(139, 90, 43, 0.10); }
}

.qrc-bottom-right .qrc-window,
.qrc-bottom-left  .qrc-window {
    position: absolute;
    bottom: 76px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 580px;
    max-height: calc(100vh - 120px);
    background: var(--qrc-bg);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: qrc-slide-up 0.25s ease-out;
}
.qrc-bottom-right .qrc-window { right: 0; }
.qrc-bottom-left  .qrc-window { left:  0; }

.qrc-bottom-right.qrc-open .qrc-window,
.qrc-bottom-left.qrc-open  .qrc-window { display: flex; }

@keyframes qrc-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === Mode inline === */
.qrc-inline {
    width: 100%;
    border: 1px solid var(--qrc-border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--qrc-bg);
    display: flex;
    flex-direction: column;
}
.qrc-inline .qrc-toggle-btn { display: none; }
.qrc-inline .qrc-window {
    display: flex !important;
    flex-direction: column;
    height: 100%;
    flex: 1;
}

/* === En-tête === */
.qrc-header {
    background: var(--qrc-primary);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}
.qrc-header-info { min-width: 0; }
.qrc-header-title    { font-weight: 600; font-size: 15px; margin: 0; }
.qrc-header-subtitle { font-size: 12px; opacity: 0.85; margin: 2px 0 0; }

.qrc-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.qrc-devis-btn {
    background: rgba(255,255,255,0.18);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s;
    font-family: inherit;
}
.qrc-devis-btn:hover { background: rgba(255,255,255,0.3); color: white; }

.qrc-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    font-size: 22px;
    line-height: 1;
    opacity: 0.8;
}
.qrc-close-btn:hover { opacity: 1; }
.qrc-inline .qrc-close-btn { display: none; }

/* === Messages === */
.qrc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.qrc-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}
.qrc-msg-user {
    background: var(--qrc-user-bg);
    color: var(--qrc-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.qrc-msg-bot {
    background: var(--qrc-bot-bg);
    color: var(--qrc-bot-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.qrc-msg-bot p { margin: 0 0 8px; }
.qrc-msg-bot p:last-child { margin-bottom: 0; }
.qrc-msg-bot strong { color: var(--qrc-primary-dark); }
.qrc-msg-bot ul, .qrc-msg-bot ol { margin: 6px 0; padding-left: 20px; }
.qrc-msg-bot a { color: var(--qrc-primary-dark); text-decoration: underline; }
.qrc-msg-bot code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.9em;
}

.qrc-msg-error {
    background: #fce4e4;
    color: #8b1a1a;
    align-self: center;
    font-size: 13px;
    text-align: center;
    max-width: 95%;
}

/* === Indicateur "en train d'écrire" === */
.qrc-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--qrc-bot-bg);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: fit-content;
}
.qrc-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--qrc-primary);
    animation: qrc-bounce 1.4s infinite ease-in-out both;
}
.qrc-typing span:nth-child(1) { animation-delay: -0.32s; }
.qrc-typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes qrc-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* === Suggestions cliquables === */
.qrc-suggestions {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 12px;
    flex-shrink: 0;
}
.qrc-suggestion-chip {
    background: white;
    border: 1px solid var(--qrc-border);
    color: var(--qrc-primary-dark);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, border-color 0.2s;
    text-align: left;
    line-height: 1.3;
}
.qrc-suggestion-chip:hover {
    background: var(--qrc-bot-bg);
    border-color: var(--qrc-primary);
}

/* === Formulaire capture lead === */
.qrc-lead-form {
    background: white;
    border: 2px solid var(--qrc-accent);
    border-radius: 12px;
    padding: 16px;
    margin: 4px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 2px 10px rgba(139, 90, 43, 0.1);
    animation: qrc-slide-up 0.3s ease-out;
}
.qrc-lead-title {
    font-weight: 600;
    color: var(--qrc-primary-dark);
    font-size: 14px;
}
.qrc-lead-desc {
    margin: 0;
    font-size: 13px;
    color: #4a3a2a;
    line-height: 1.4;
}
.qrc-lead-form input, .qrc-lead-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--qrc-border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    box-sizing: border-box;
    outline: none;
    resize: vertical;
}
.qrc-lead-form input:focus, .qrc-lead-form textarea:focus {
    border-color: var(--qrc-primary);
}
.qrc-lead-actions {
    display: flex;
    gap: 8px;
}
.qrc-lead-submit {
    flex: 1;
    background: var(--qrc-primary);
    color: white;
    border: none;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    font-size: 13px;
    transition: background 0.2s;
}
.qrc-lead-submit:hover:not(:disabled) { background: var(--qrc-primary-dark); }
.qrc-lead-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.qrc-lead-dismiss {
    background: transparent;
    color: #777;
    border: 1px solid #ccc;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
}
.qrc-lead-dismiss:hover { background: #f5f5f5; }

.qrc-lead-error {
    color: #b91c1c;
    font-size: 12px;
    margin: -4px 0 0;
}
.qrc-lead-rgpd {
    font-size: 10px;
    color: #888;
    margin: 4px 0 0;
    line-height: 1.3;
}
.qrc-lead-success {
    color: var(--qrc-success);
    font-weight: 500;
    text-align: center;
    padding: 12px;
    font-size: 14px;
}

/* === Zone de saisie === */
.qrc-input-area {
    border-top: 1px solid var(--qrc-border);
    padding: 12px;
    display: flex;
    gap: 8px;
    background: white;
    flex-shrink: 0;
}
.qrc-input {
    flex: 1;
    border: 1px solid var(--qrc-border);
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
}
.qrc-input:focus { border-color: var(--qrc-primary); }

.qrc-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--qrc-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.qrc-send-btn:hover:not(:disabled) { background: var(--qrc-primary-dark); }
.qrc-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.qrc-send-btn svg { width: 18px; height: 18px; fill: white; }

/* === Footer + disclaimer === */
.qrc-footer {
    background: white;
    padding: 6px 12px 8px;
    border-top: 1px solid #f0e9dc;
    flex-shrink: 0;
}
.qrc-disclaimer {
    display: block;
    font-size: 10.5px;
    color: #999;
    text-align: center;
    line-height: 1.3;
}

/* === Responsive === */
@media (max-width: 480px) {
    .qrc-bottom-right .qrc-window,
    .qrc-bottom-left  .qrc-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 110px);
        bottom: 76px;
    }
    .qrc-bottom-right { right: 12px; bottom: 12px; }
    .qrc-bottom-left  { left:  12px; bottom: 12px; }
    .qrc-devis-btn { padding: 5px 8px; font-size: 11px; }
}