/* ─── Chat Widget CSS Variables (light / dark mode) ─── */
#ppz-chat-widget {
    --ppz-chat-brand: var(--ppz-color-brand-primary, #E91E63);
    --ppz-chat-bg: #fff;
    --ppz-chat-text: #1f2937;
    --ppz-chat-text-secondary: #374151;
    --ppz-chat-text-muted: #6b7280;
    --ppz-chat-text-subtle: #9ca3af;
    --ppz-chat-border: #e5e7eb;
    --ppz-chat-border-light: #d1d5db;
    --ppz-chat-surface: #f9fafb;
    --ppz-chat-msg-bg: #f3f4f6;
    --ppz-chat-accent-subtle: #fce4ec;
    --ppz-chat-accent-dark: #c2185b;
    --ppz-chat-tool-bg: #fef3c7;
    --ppz-chat-tool-text: #92400e;
    --ppz-chat-tool-spinner: #fbbf24;
    --ppz-chat-code-bg: #1f2937;
    --ppz-chat-code-text: #e5e7eb;
    --ppz-chat-shadow-md: var(--ppz-shadow-md, 0 8px 24px rgba(15, 23, 42, 0.18));
    --ppz-chat-surface-elevated: var(--ppz-bg-surface, #fff);
    --ppz-chat-surface-subtle: var(--ppz-bg-subtle, #f5f6f7);
    --ppz-chat-border-default: var(--ppz-border-default, #d1d5db);
    --ppz-chat-text-primary: var(--ppz-text-primary, #111827);
    --ppz-chat-text-secondary-strong: var(--ppz-text-secondary, #6b7280);
}
@media (prefers-color-scheme: dark) {
    #ppz-chat-widget {
        --ppz-chat-bg: #1e293b;
        --ppz-chat-text: #f1f5f9;
        --ppz-chat-text-secondary: #cbd5e1;
        --ppz-chat-text-muted: #94a3b8;
        --ppz-chat-text-subtle: #64748b;
        --ppz-chat-border: #334155;
        --ppz-chat-border-light: #475569;
        --ppz-chat-surface: #0f172a;
        --ppz-chat-msg-bg: #334155;
        --ppz-chat-accent-subtle: #3d1129;
        --ppz-chat-accent-dark: #f06292;
        --ppz-chat-tool-bg: #2a1f00;
        --ppz-chat-tool-text: #fbbf24;
        --ppz-chat-tool-spinner: #92400e;
        --ppz-chat-code-bg: #0f172a;
        --ppz-chat-code-text: #e2e8f0;
    }
}

/* ─── Chat Widget Styles ─── */
#ppz-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--ppz-chat-text);
}

#ppz-chat-toggle {
    width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--ppz-chat-brand); color: #fff;
    box-shadow: 0 4px 12px rgba(233,30,99,0.4);
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: ppz-pulse 2s ease-in-out infinite;
}
#ppz-chat-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 16px rgba(233,30,99,0.5); animation: none; }

@keyframes ppz-pulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(233,30,99,0.4); }
    50% { box-shadow: 0 4px 20px rgba(233,30,99,0.6); }
}

#ppz-chat-panel {
    position: absolute; bottom: 68px; right: 0;
    width: 440px; height: 620px; border-radius: 16px; overflow: hidden;
    background: var(--ppz-chat-bg); box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    display: flex; flex-direction: column;
    transition: opacity 0.25s ease, transform 0.25s ease;
    border: 1px solid rgba(15, 23, 42, 0.06);
}
#ppz-chat-panel.ppz-chat-hidden { display: none; }

#ppz-chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; background: var(--ppz-chat-brand); color: #fff;
    flex-shrink: 0;
    min-height: 56px;
}
.ppz-chat-header-left { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.ppz-chat-header-actions { display: flex; gap: 4px; }
.ppz-chat-header-actions button {
    background: none; border: none; color: #fff; cursor: pointer; padding: 6px;
    border-radius: 6px; opacity: 0.85;
}
.ppz-chat-header-actions button:hover { opacity: 1; background: rgba(255,255,255,0.15); }

#ppz-chat-messages {
    flex: 1; overflow-y: auto; padding: 16px; min-height: 0;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--ppz-chat-bg);
}

/* Welcome screen */
.ppz-chat-welcome { text-align: center; padding: 20px 8px; }
.ppz-chat-welcome-icon { margin-bottom: 12px; }
.ppz-chat-welcome-title { font-size: 16px; font-weight: 600; color: var(--ppz-chat-text); margin: 0 0 4px; }
.ppz-chat-welcome-sub { font-size: 13px; color: var(--ppz-chat-text-muted); margin: 0 0 20px; }

/* Example question chips */
.ppz-chat-examples { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.ppz-chat-example-btn {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; border-radius: 10px;
    border: 1px solid var(--ppz-chat-border); background: var(--ppz-chat-surface); cursor: pointer;
    font-size: 13px; color: var(--ppz-chat-text-secondary); text-align: left;
    transition: all 0.15s;
}
.ppz-chat-example-btn svg { flex-shrink: 0; opacity: 0.6; }
.ppz-chat-example-btn:hover svg { opacity: 1; stroke: var(--ppz-chat-brand); }
.ppz-chat-example-btn:hover {
    background: var(--ppz-chat-accent-subtle); border-color: var(--ppz-chat-brand); color: var(--ppz-chat-brand);
}
.ppz-chat-example-btn--write {
    border-color: #f59e0b; color: #92400e;
}
.ppz-chat-example-btn--write:hover {
    background: #fef3c7; border-color: #d97706; color: #78350f;
}
.ppz-chat-example-btn--write:hover svg { opacity: 1; stroke: #d97706; }

/* Messages — la bulle EST le composant du DS (`ppz-msg`, classé par le JS du
   widget) : fond, encre, espacement, rayon et alignement viennent des jetons du
   DS, donc les quatre combinaisons thème × contraste suivent sans règle locale.
   Ici on ne garde QUE la queue de bulle, propre au panneau flottant. */
.ppz-chat-msg { word-wrap: break-word; }
.ppz-chat-msg-user { border-bottom-right-radius: 4px; }
.ppz-chat-msg-assistant { border-bottom-left-radius: 4px; }
.ppz-chat-msg-assistant p { margin: 4px 0; }
.ppz-chat-msg-assistant p:first-child { margin-top: 0; }
.ppz-chat-msg-assistant p:last-child { margin-bottom: 0; }
.ppz-chat-msg-assistant ul, .ppz-chat-msg-assistant ol { margin: 4px 0; padding-left: 18px; }
.ppz-chat-msg-assistant li { margin: 2px 0; }
.ppz-chat-msg-assistant h1, .ppz-chat-msg-assistant h2, .ppz-chat-msg-assistant h3 { margin: 8px 0 4px; font-size: 14px; font-weight: 700; }
.ppz-chat-msg-assistant code { background: var(--ppz-chat-border); padding: 1px 4px; border-radius: 3px; font-size: 12px; color: var(--ppz-chat-text); }
.ppz-chat-msg-assistant pre { background: var(--ppz-chat-code-bg); color: var(--ppz-chat-code-text); padding: 8px; border-radius: 6px; overflow-x: auto; margin: 6px 0; }
.ppz-chat-msg-assistant pre code { background: none; color: inherit; }
.ppz-chat-msg-assistant table { border-collapse: collapse; width: 100%; margin: 6px 0; font-size: 13px; }
.ppz-chat-msg-assistant th, .ppz-chat-msg-assistant td { border: 1px solid var(--ppz-chat-border-light); padding: 4px 8px; text-align: left; }
.ppz-chat-msg-assistant th { background: var(--ppz-chat-border); font-weight: 600; color: var(--ppz-chat-text); }
.ppz-chat-msg-assistant tr:nth-child(even) td { background: var(--ppz-chat-surface); }
.ppz-chat-msg-assistant a { color: var(--ppz-chat-brand); text-decoration: underline; }
.ppz-chat-msg-assistant a:hover { color: var(--ppz-chat-accent-dark); }

/* Typing indicator */
#ppz-chat-typing {
    display: flex; align-items: center; gap: 8px; padding: 8px 16px;
    font-size: 12px; color: var(--ppz-chat-text-subtle); flex-shrink: 0;
    background: var(--ppz-chat-bg);
}
#ppz-chat-typing.ppz-chat-hidden { display: none; }
.ppz-chat-typing-dots { display: flex; gap: 4px; }
.ppz-chat-typing-dots span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--ppz-chat-brand);
    animation: ppz-typing-bounce 1.4s infinite ease-in-out both;
}
.ppz-chat-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.ppz-chat-typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.ppz-chat-typing-dots span:nth-child(3) { animation-delay: 0s; }
@keyframes ppz-typing-bounce {
    0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}
.ppz-chat-typing-text { font-style: italic; }

/* Tool indicator */
#ppz-chat-tool-indicator {
    display: flex; align-items: center; gap: 8px; padding: 8px 16px;
    font-size: 12px; color: var(--ppz-chat-tool-text); background: var(--ppz-chat-tool-bg); flex-shrink: 0;
}
#ppz-chat-tool-indicator.ppz-chat-hidden { display: none; }
.ppz-chat-tool-spinner {
    width: 14px; height: 14px; border: 2px solid var(--ppz-chat-tool-spinner); border-top-color: var(--ppz-chat-brand);
    border-radius: 50%; animation: ppz-spin 0.8s linear infinite;
}
@keyframes ppz-spin { to { transform: rotate(360deg); } }
#ppz-chat-tool-indicator.ppz-chat-tool-write {
    --ppz-chat-tool-bg: #fff7ed; --ppz-chat-tool-text: #9a3412;
}
#ppz-chat-tool-indicator.ppz-chat-tool-write .ppz-chat-tool-spinner {
    border-color: #fed7aa; border-top-color: #ea580c;
}

/* Input area — la zone de saisie EST le composant du DS (`ppz-composer`) : on ne
   garde ici que ce qui est propre au panneau flottant (position du panneau de
   mentions, fond du panneau, hauteur max). */
#ppz-chat-input-area {
    position: relative;
    flex-shrink: 0;
    background: var(--ppz-chat-bg);
}
#ppz-chat-input { outline: none; max-height: 80px; }
#ppz-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

#ppz-chat-mentions {
    position: absolute;
    left: 14px;
    right: 60px;
    bottom: calc(100% + 8px);
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--ppz-chat-border-default);
    border-radius: 12px;
    background: var(--ppz-chat-surface-elevated);
    box-shadow: var(--ppz-chat-shadow-md);
    padding: 6px;
    z-index: 3;
}
#ppz-chat-mentions.ppz-chat-hidden { display: none; }
.ppz-chat-mention-item {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: var(--ppz-space-2);
    border: 0;
    background: transparent;
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    text-align: left;
}
.ppz-chat-mention-item:hover,
.ppz-chat-mention-item.is-active {
    background: var(--ppz-chat-surface-subtle);
}
.ppz-chat-mention-item__icon {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--ppz-chat-surface-subtle);
    color: var(--ppz-chat-brand);
}
.ppz-chat-mention-item__body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ppz-chat-mention-item__label {
    color: var(--ppz-chat-text-primary);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
}
.ppz-chat-mention-item__meta {
    color: var(--ppz-chat-text-secondary-strong);
    font-size: 12px;
    line-height: 1.35;
}
.ppz-chat-mention-empty {
    padding: 10px;
    color: var(--ppz-chat-text-secondary-strong);
    font-size: 12px;
}

/* Conversations panel */
#ppz-chat-conversations { position: absolute; top: 50px; left: 0; right: 0; bottom: 0; background: var(--ppz-chat-bg); z-index: 1; overflow-y: auto; }
#ppz-chat-conversations.ppz-chat-hidden { display: none; }
.ppz-chat-conv-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--ppz-chat-border); font-size: 14px; font-weight: 600; color: var(--ppz-chat-text); }
.ppz-chat-conv-header button { background: none; border: none; cursor: pointer; color: var(--ppz-chat-text-muted); padding: 4px; }
#ppz-chat-conv-list { padding: 8px; }
.ppz-chat-conv-item {
    padding: 12px 14px; border-radius: 10px; cursor: pointer; font-size: 13px;
    margin-bottom: 4px; transition: background 0.15s;
}
.ppz-chat-conv-item:hover { background: var(--ppz-chat-msg-bg); }
.ppz-chat-conv-item-title { font-weight: 500; color: var(--ppz-chat-text); }
.ppz-chat-conv-item-date { font-size: 11px; color: var(--ppz-chat-text-subtle); margin-top: 2px; }

/* Responsive */
@media (max-width: 520px) {
    #ppz-chat-panel { width: calc(100vw - 24px); right: -8px; bottom: 64px; height: 75vh; }
}
/* ─── Demo mode: full-screen modal overlay (www landing page) ─── */
#ppz-chat-widget[data-demo="1"] {
    position: fixed !important; inset: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,.6); display: flex; align-items: center;
    justify-content: center; padding: 1rem; bottom: auto; right: auto; z-index: 10000;
}
#ppz-chat-widget[data-demo="1"] #ppz-chat-toggle { display: none !important; }
#ppz-chat-widget[data-demo="1"] #ppz-chat-panel {
    position: relative !important; bottom: auto !important; right: auto !important;
    width: 100% !important; max-width: 520px !important;
    height: 85vh !important; max-height: 680px !important;
}

/* ── Nudge de Marie + « le chat qui commence » ───────────────────────────────
   POURQUOI : une passe RGAA (05/10) a retiré les <style> du corps du document
   (invalides hors en-tête) et re-hébergé leurs règles ici — ce bloc, oublié,
   laissait le teaser brut en bas de page (vu sur www.popi.nz le 06/10).
   Coucou : 2,5 s après ~2 min, une fois par chargement, stop au clic. */
@keyframes ppz-marie-nudge {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    12%  { transform: translateY(-5px) rotate(-5deg); }
    36%  { transform: translateY(0) rotate(4deg); }
    60%  { transform: translateY(-3px) rotate(-2deg); }
    84%  { transform: translateY(0) rotate(0deg); }
}
#ppz-chat-toggle.ppz-nudge {
    animation: ppz-marie-nudge 2.5s ease-in-out 120s 1;
    will-change: transform;
}
@media (prefers-reduced-motion: reduce) {
    #ppz-chat-toggle.ppz-nudge { animation: none; }
}

/* « Le chat qui commence » : petite bulle de Marie, une fois par page. */
#ppz-marie-teaser {
    position: fixed;
    right: 92px;
    bottom: 22px;
    z-index: 99998;
    max-width: 270px;
    background: #ffffff;
    color: #1b1f2a;
    border: 1px solid rgba(15, 17, 26, .10);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(15, 17, 26, .18);
    padding: 12px 34px 12px 14px;
    font-size: 14px;
    line-height: 1.45;
    opacity: 0;
    pointer-events: none;
    /*
     * visibility, et pas seulement opacity : au repos le teaser est invisible
     * et hors de portee de la souris, mais son bouton « Fermer » restait dans
     * le parcours du clavier. On tabulait sur un bouton qu'on ne voit pas.
     * visibility:hidden l'en retire ; la transition la retarde pour que
     * l'apparition reste animee.
     */
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity .35s ease, transform .35s ease, visibility 0s linear .35s;
}
#ppz-marie-teaser.ppz-visible { opacity: 1; pointer-events: auto; visibility: visible; transform: translateY(0); transition: opacity .35s ease, transform .35s ease, visibility 0s; }
#ppz-marie-teaser.ppz-nudge-hidden { display: none; }
#ppz-marie-teaser .ppz-teaser-close {
    position: absolute; top: 6px; right: 8px;
    border: 0; background: transparent; cursor: pointer;
    font-size: 15px; line-height: 1; color: #8a90a0; padding: 4px;
}
#ppz-marie-teaser .ppz-teaser-cta { color: #e5006d; font-weight: 600; }
#ppz-marie-teaser::after {
    content: "";
    position: absolute; right: -6px; bottom: 18px;
    width: 12px; height: 12px;
    background: #ffffff;
    border-right: 1px solid rgba(15, 17, 26, .10);
    border-top: 1px solid rgba(15, 17, 26, .10);
    transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
    #ppz-marie-teaser { transition: none; }
}

/* ─── Marie — page pleine (/marie) ────────────────────────────────────────────
   La même surface que la bulle, servie EN LIGNE dans la zone de contenu : le menu
   de gauche de l'app reste visible, ce n'est pas une modale plein écran. On
   neutralise donc le positionnement flottant et on étire le panneau. */
.ppz-marie-page {
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 16px 16px 0;
    box-sizing: border-box;
}
.ppz-marie-page #ppz-chat-widget {
    position: static;
    inset: auto;
    bottom: auto;
    right: auto;
    width: 100%;
    max-width: 1080px;
    height: auto;
    z-index: 1;
}
.ppz-marie-page #ppz-chat-panel {
    position: static;
    inset: auto;
    bottom: auto;
    right: auto;
    width: 100%;
    height: calc(100vh - 190px);
    min-height: 360px;
    max-height: 900px;
    border-radius: 14px;
}
@media (max-width: 760px) {
    .ppz-marie-page { padding: 0; }
    .ppz-marie-page #ppz-chat-panel {
        height: calc(100vh - 150px);
        border-radius: 0;
    }
}
