/* ============================================================
   Assistant IA — Chat widget
   Le Bois du Meunier
   ============================================================
   Architecture :
   - Bouton flottant (FAB) ancré viewport bottom-right
   - Panneau overlay positionné fixed, placé en enfant direct
     de <body> pour éviter tout containing-block parent
   - Variables CSS héritées de l'inline style d'index.html
     (--oak, --cream, --walnut-dark, etc.)
   ============================================================ */


/* ─── 1. Bouton flottant (FAB) ─────────────────────────────── */

.chat-fab {
    position: fixed;
    bottom: clamp(1rem, 3vw, 1.75rem);
    right: clamp(1rem, 3vw, 1.75rem);
    z-index: 998;          /* sous mobile-menu (999) et nav (1000) */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 60px;
    height: 60px;
    padding: 0 18px;
    border: none;
    border-radius: 30px;
    background: var(--oak);
    color: var(--cream);
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    overflow: hidden;
    box-shadow:
        0 10px 28px rgba(46, 31, 20, 0.4),
        0 4px 10px rgba(46, 31, 20, 0.25),
        inset 0 1px 0 rgba(245, 240, 232, 0.15);
    transition: width 0.4s cubic-bezier(.4,0,.2,1),
                background 0.3s ease,
                transform 0.3s ease,
                box-shadow 0.3s ease,
                opacity 0.3s ease;
}

.chat-fab:hover {
    width: 200px;
    background: var(--oak-deep);
    transform: translateY(-3px);
    box-shadow:
        0 16px 36px rgba(46, 31, 20, 0.5),
        0 6px 14px rgba(46, 31, 20, 0.3),
        inset 0 1px 0 rgba(245, 240, 232, 0.2);
}

.chat-fab:focus-visible {
    outline: 2px solid var(--cream);
    outline-offset: 4px;
}

.chat-fab.hidden {
    transform: scale(0.6) translateY(20px);
    opacity: 0;
    pointer-events: none;
}

/* Anneau pulsant pour attirer l'œil */
.chat-fab::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid var(--oak);
    pointer-events: none;
    animation: lbm-fab-pulse 3s ease-out infinite;
}

.chat-fab.hidden::before { display: none; }

@keyframes lbm-fab-pulse {
    0%   { transform: scale(1);    opacity: 0.55; }
    70%  { transform: scale(1.45); opacity: 0; }
    100% { transform: scale(1.45); opacity: 0; }
}

.chat-fab-icon {
    position: relative;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-fab-icon svg { width: 100%; height: 100%; }

.chat-fab-spark {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 9px;
    height: 9px;
    color: var(--cream);
    opacity: 0.9;
    animation: lbm-spark-twinkle 2.6s ease-in-out infinite;
}
.chat-fab-spark svg { width: 100%; height: 100%; }

@keyframes lbm-spark-twinkle {
    0%, 100% { transform: scale(1) rotate(0deg);    opacity: 0.6; }
    50%      { transform: scale(1.3) rotate(45deg); opacity: 1; }
}

.chat-fab-label {
    white-space: nowrap;
    opacity: 0;
    max-width: 0;
    transition: opacity 0.2s ease 0.05s,
                max-width 0.4s cubic-bezier(.4,0,.2,1);
}
.chat-fab:hover .chat-fab-label {
    opacity: 1;
    max-width: 130px;
}

/* Mobile : FAB compact, pas d'expansion au hover (pas de vrai hover) */
@media (max-width: 480px) {
    .chat-fab {
        bottom: max(1rem, env(safe-area-inset-bottom, 0px));
        right: 1rem;
        width: 56px;
        height: 56px;
        padding: 0;
    }
    .chat-fab:hover { width: 56px; }
    .chat-fab:hover .chat-fab-label {
        opacity: 0;
        max-width: 0;
    }
}


/* ─── 2. Panneau Chat — overlay fixed ──────────────────────── */

.chat-panel {
    /* Positionnement : ancré viewport bottom-right (desktop)
       ou plein écran (mobile, voir media query plus bas) */
    position: fixed;
    bottom: clamp(1rem, 3vw, 1.75rem);
    right: clamp(1rem, 3vw, 1.75rem);
    width: 400px;
    max-width: calc(100vw - 2rem);
    height: 75vh;
    max-height: 720px;
    z-index: 1001;

    /* Création d'un stacking context isolé pour éviter les fuites
       de z-index/blend modes depuis ou vers le reste de la page */
    isolation: isolate;

    /* Layout interne en colonne */
    display: none;
    flex-direction: column;
    overflow: hidden;

    /* Look */
    background: var(--walnut-dark);
    border: 1px solid rgba(212, 197, 169, 0.25);
    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.55),
        0 8px 20px rgba(0, 0, 0, 0.3);

    /* Animation d'entrée */
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    transition: transform 0.35s cubic-bezier(.4,0,.2,1),
                opacity 0.3s ease;
}

.chat-panel.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Mobile : plein écran */
@media (max-width: 600px) {
    .chat-panel {
        inset: 0;
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border: none;
        transform-origin: center;
    }
}


/* ─── 3. Header du panneau ────────────────────────────────── */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.1rem;
    background: rgba(74, 55, 40, 0.4);
    border-bottom: 1px solid rgba(212, 197, 169, 0.2);
    flex-shrink: 0;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--cream);
    font-size: 0.82rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 600;
}
.chat-header-title svg {
    width: 16px;
    height: 16px;
    opacity: 0.85;
}

.chat-close {
    background: none;
    border: 1px solid rgba(212, 197, 169, 0.25);
    color: var(--sawdust);
    font-size: 1rem;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.chat-close:hover {
    border-color: var(--oak);
    color: var(--cream);
    background: rgba(139, 105, 20, 0.15);
}


/* ─── 4. Zone de contenu (wrapper masqué en fin de flow) ──── */
/* Tout ce qui peut être masqué d'un coup quand la conversation
   est terminée (état success). */

.chat-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;          /* indispensable pour flex + scroll */
    overflow: hidden;
}

.chat-body[hidden] { display: none; }


/* ─── 5. Messages ─────────────────────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.2rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    scroll-behavior: smooth;
}

.chat-msg {
    max-width: 85%;
    line-height: 1.55;
    font-size: 0.92rem;
}

.chat-msg-bubble {
    padding: 0.7rem 0.95rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-msg-role {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.55;
    margin-bottom: 0.3rem;
    color: var(--sawdust);
}

.chat-msg-user { align-self: flex-end; }
.chat-msg-user .chat-msg-bubble {
    background: var(--oak);
    color: var(--cream);
}

.chat-msg-assistant { align-self: flex-start; }
.chat-msg-assistant .chat-msg-bubble {
    background: rgba(245, 240, 232, 0.08);
    color: var(--cream);
    border: 1px solid rgba(212, 197, 169, 0.18);
}

.chat-msg-photos {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 0.4rem;
}
.chat-msg-photos img {
    max-width: 110px;
    max-height: 110px;
    object-fit: cover;
    border: 1px solid rgba(212, 197, 169, 0.25);
}

.chat-msg-error {
    align-self: center;
    color: #e8a0a0;
    font-size: 0.82rem;
    font-style: italic;
    text-align: center;
    max-width: 95%;
}

/* Indicateur de saisie (3 points qui sautillent) */
.chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.7rem 0.95rem;
}
.chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--sawdust);
    border-radius: 50%;
    opacity: 0.4;
    animation: lbm-typing 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lbm-typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}


/* ─── 6. Photo tray (vignettes des photos en attente) ─────── */

.chat-photo-tray {
    display: none;
    gap: 0.5rem;
    padding: 0.5rem 1.1rem 0;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.chat-photo-tray.visible { display: flex; }

.chat-photo-chip {
    position: relative;
    width: 56px;
    height: 56px;
}
.chat-photo-chip img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 1px solid rgba(212, 197, 169, 0.3);
}
.chat-photo-chip button {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: var(--walnut-dark);
    color: var(--cream);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
}


/* ─── 7. Zone de saisie ───────────────────────────────────── */

.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    padding: 0.85rem 1.1rem;
    border-top: 1px solid rgba(212, 197, 169, 0.2);
    background: rgba(46, 31, 20, 0.3);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: rgba(245, 240, 232, 0.06);
    border: 1px solid rgba(212, 197, 169, 0.2);
    color: var(--cream);
    padding: 0.7rem 0.9rem;
    font-family: var(--font-body);
    font-size: 0.92rem;
    line-height: 1.4;
    resize: none;
    min-height: 42px;
    max-height: 140px;
}
.chat-input:focus {
    outline: none;
    border-color: var(--oak);
}

.chat-icon-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(245, 240, 232, 0.06);
    border: 1px solid rgba(212, 197, 169, 0.2);
    color: var(--sawdust);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.chat-icon-btn:hover {
    border-color: var(--oak);
    color: var(--cream);
}
.chat-icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.chat-icon-btn svg { width: 18px; height: 18px; }

.chat-send {
    background: var(--oak);
    color: var(--cream);
    border-color: var(--oak);
}
.chat-send:hover {
    background: var(--oak-deep);
    border-color: var(--oak-deep);
}


/* ─── 8. Footer (bouton "envoyer à Antoine") ──────────────── */
/* Caché tant que l'IA n'a pas signalé le brief comme complet
   via le marqueur [BRIEF_OK] (intercepté côté JS). */

.chat-footer {
    display: none;
    padding: 0.65rem 1.1rem;
    border-top: 1px solid rgba(212, 197, 169, 0.15);
    background: rgba(46, 31, 20, 0.4);
    flex-shrink: 0;
}
.chat-footer.ready {
    display: block;
    animation: lbm-footer-reveal 0.5s cubic-bezier(.4,0,.2,1);
}

@keyframes lbm-footer-reveal {
    from { opacity: 0; transform: translateY(12px); max-height: 0; }
    to   { opacity: 1; transform: translateY(0);    max-height: 200px; }
}

.chat-submit-recap {
    width: 100%;
    background: var(--forest);
    color: var(--cream);
    border: none;
    padding: 0.85rem;
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s;
}
.chat-submit-recap:hover:not(:disabled) {
    background: var(--forest-muted);
}
.chat-submit-recap:disabled {
    background: rgba(58, 90, 64, 0.3);
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-submit-recap-hint {
    margin-top: 0.4rem;
    text-align: center;
    font-size: 0.72rem;
    font-style: italic;
    color: rgba(212, 197, 169, 0.55);
}


/* ─── 9. Mini-formulaire de récap (nom / email / tél) ─────── */

.chat-recap-form {
    display: none;
    flex-direction: column;
    gap: 0.7rem;
    padding: 1rem 1.1rem;
    border-top: 1px solid rgba(212, 197, 169, 0.15);
    background: rgba(46, 31, 20, 0.4);
    flex-shrink: 0;
}
.chat-recap-form.visible { display: flex; }

.chat-recap-form input {
    background: rgba(245, 240, 232, 0.06);
    border: 1px solid rgba(212, 197, 169, 0.2);
    color: var(--cream);
    padding: 0.6rem 0.85rem;
    font-family: var(--font-body);
    font-size: 0.88rem;
}
.chat-recap-form input:focus {
    outline: none;
    border-color: var(--oak);
}

.chat-recap-form button {
    background: var(--forest);
    color: var(--cream);
    border: none;
    padding: 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}
.chat-recap-form button:hover {
    background: var(--forest-muted);
}


/* ─── 10. État succès (après envoi du récap) ──────────────── */

.chat-success {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--cream);
}
.chat-success[hidden] { display: none; }

.chat-success-title {
    font-size: 1.1rem;
    margin-bottom: 0.8rem;
}
.chat-success-body {
    opacity: 0.8;
    line-height: 1.6;
}
