/* ============================================== */
/* --- AGENT IA — Chat Interface                --- */
/* ============================================== */

/* Header button */
.btn-ai {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.25);
    color: rgba(255,255,255,0.85);
    padding: 7px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: var(--transition);
}

.btn-ai:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    border-color: rgba(255,255,255,0.4);
}

#ai-chat-view {
    display: flex;
    height: calc(100dvh - 180px);
    background: var(--chanv-blanc);
    position: relative;
}

/* --- Sidebar Toggle Button (visible on all screens) --- */
.ai-sidebar-toggle {
    position: fixed;
    top: 50%;
    left: 280px;
    transform: translateY(-50%);
    z-index: 101;
    width: 20px;
    height: 48px;
    border: none;
    border-radius: 0 8px 8px 0;
    background: var(--chanv-terre);
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: left 0.3s ease, background 0.2s;
    padding: 0;
}

.ai-sidebar-toggle:hover {
    background: var(--chanv-beige);
    color: var(--chanv-terre);
}

.ai-sidebar-toggle .toggle-arrow {
    transition: transform 0.3s ease;
}

.ai-sidebar.collapsed ~ .ai-chat-main .ai-sidebar-toggle,
#ai-chat-view.sidebar-collapsed .ai-sidebar-toggle {
    left: 0;
}

#ai-chat-view.sidebar-collapsed .ai-sidebar-toggle .toggle-arrow {
    transform: rotate(180deg);
}

/* --- Sidebar --- */
.ai-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--chanv-terre);
    color: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255,255,255,0.05);
    z-index: 100;
    transition: left 0.3s ease;
}

#ai-chat-view.sidebar-collapsed .ai-sidebar {
    left: -280px;
}

.ai-sidebar-header {
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.ai-sidebar-back {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.7);
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    text-align: left;
}

.ai-sidebar-back:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.ai-sidebar-new {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: var(--transition);
    text-align: left;
}

.ai-sidebar-new:hover {
    background: rgba(255,255,255,0.25);
}

.ai-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.ai-sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.ai-sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

/* Sidebar agent section (bottom) — plafonnée + scrollable pour ne jamais
   déborder hors écran, même avec de nombreux agents partagés */
.ai-sidebar-agents {
    padding: 0 12px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
    max-height: 48vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.ai-sidebar-agents::-webkit-scrollbar { width: 4px; }
.ai-sidebar-agents::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

.ai-sidebar-agents-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Reste visible pendant le scroll de la liste d'agents */
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--chanv-terre);
    padding: 12px 0 10px;
}

.ai-sidebar-agents-title {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255,255,255,0.45);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.ai-sidebar-agents-btns {
    display: flex;
    gap: 4px;
}

.ai-agent-quick-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    padding: 0;
}

.ai-agent-quick-btn:hover {
    background: rgba(255,255,255,0.15);
    color: white;
    border-color: var(--chanv-beige);
}

/* Agent pills grid */
.ai-agent-pills {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-agent-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
    background: transparent;
}

.ai-agent-pill:hover {
    background: rgba(255,255,255,0.08);
}

.ai-agent-pill.active {
    background: rgba(201,168,118,0.15);
    border-color: var(--chanv-beige);
}

.ai-agent-pill-icon {
    font-size: 20px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.08);
    border-radius: 8px;
    flex-shrink: 0;
}

.ai-agent-pill.active .ai-agent-pill-icon {
    background: rgba(201,168,118,0.25);
}

.ai-agent-pill-info {
    flex: 1;
    min-width: 0;
}

.ai-agent-pill-name {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-agent-pill-desc {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.ai-agent-pill.active .ai-agent-pill-name {
    color: var(--chanv-beige);
}

.ai-agent-pill-check {
    font-size: 12px;
    color: var(--chanv-beige);
    opacity: 0;
    transition: opacity 0.15s;
}

.ai-agent-pill.active .ai-agent-pill-check {
    opacity: 1;
}

/* Empty state */
.ai-agents-empty {
    padding: 12px;
    text-align: center;
    font-size: 11px;
    color: rgba(255,255,255,0.3);
    line-height: 1.5;
}

/* Team agents section */
.ai-agent-team-section {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.ai-agent-team-label {
    font-size: 10px;
    font-weight: 700;
    color: rgba(255,255,255,0.3);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
    padding-left: 4px;
}

/* En-têtes de groupe (marque) dans la liste des agents partagés */
.ai-agent-brand-group { margin-bottom: 6px; }
.ai-agent-brand-header {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(255,255,255,0.35);
    padding: 6px 4px 3px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    margin-bottom: 4px;
}

/* Réponses cliquables (question à choix de l'assistant) */
.ai-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0 4px;
}
.ai-choice-btn {
    padding: 9px 16px;
    border: 1.5px solid var(--chanv-beige);
    border-radius: 999px;
    background: white;
    color: var(--chanv-terre);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
}
.ai-choice-btn:hover {
    background: var(--chanv-fibre);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(40,40,40,0.1);
}
.ai-choice-btn.ai-choice-other {
    border-style: dashed;
    color: #8a8172;
}
.ai-choices.answered .ai-choice-btn {
    opacity: 0.45;
    pointer-events: none;
}
.ai-choices.answered .ai-choice-btn.picked {
    opacity: 1;
    background: var(--chanv-terre);
    color: #fff;
    border-color: var(--chanv-terre);
}

/* Bouton repliable de la section Agents partagés */
.ai-agent-team-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.15s ease, color 0.15s ease;
}
.ai-agent-team-toggle:hover {
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.55);
}
.ai-agent-team-chevron {
    font-size: 9px;
    width: 10px;
    display: inline-block;
    color: rgba(255,255,255,0.4);
}
.ai-agent-team-count {
    margin-left: auto;
    font-size: 9px;
    font-weight: 700;
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.55);
    border-radius: 8px;
    padding: 1px 7px;
}

/* --- Sidebar "Mes documents" button --- */
.ai-sidebar-docs-btn-wrapper {
    padding: 6px 12px 0;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.ai-sidebar-docs-btn {
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px dashed rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.6);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    letter-spacing: 0.2px;
}
.ai-sidebar-docs-btn:hover {
    background: rgba(201,168,118,0.12);
    border-color: rgba(201,168,118,0.4);
    color: rgba(255,255,255,0.9);
}

/* --- Modal Gestion Fichiers GANDALF --- */
.gandalf-docs-modal {
    background: var(--card-bg, #1e1e1e);
    border: 1px solid var(--border-color, #333);
    border-radius: 18px;
    padding: 0;
    max-width: 640px;
    width: 94%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.gandalf-docs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.gandalf-docs-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary, #f0f0f0);
}
.gandalf-docs-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;
}
.gandalf-docs-close:hover { color: #ff6b6b; background: rgba(255,100,100,0.1); }
.gandalf-docs-hint {
    margin: 0;
    padding: 10px 24px;
    font-size: 12px;
    color: rgba(255,255,255,0.45);
    line-height: 1.5;
}
.gandalf-docs-dropzone {
    margin: 0 20px 12px;
    padding: 24px;
    border: 2px dashed rgba(201,168,118,0.25);
    border-radius: 12px;
    background: rgba(201,168,118,0.04);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    transition: all 0.25s;
}
.gandalf-docs-dropzone.drag-over {
    border-color: var(--chanv-beige, #C9A876);
    background: rgba(201,168,118,0.12);
}
.gandalf-docs-drop-icon { font-size: 28px; opacity: 0.6; }
.gandalf-docs-upload-btn {
    padding: 8px 18px !important;
    font-size: 12px !important;
    border-radius: 8px !important;
}
.gandalf-docs-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px;
    max-height: 320px;
}
.gandalf-docs-loading { text-align: center; padding: 20px; color: rgba(255,255,255,0.3); font-size: 13px; }
.gandalf-docs-empty { text-align: center; padding: 24px; color: rgba(255,255,255,0.3); font-size: 13px; line-height: 1.6; }

/* File row */
.gandalf-doc-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.gandalf-doc-row:hover { background: rgba(255,255,255,0.04); }
.gandalf-doc-icon { font-size: 20px; flex-shrink: 0; }
.gandalf-doc-info { flex: 1; min-width: 0; }
.gandalf-doc-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #f0f0f0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gandalf-doc-meta {
    font-size: 11px;
    color: rgba(255,255,255,0.3);
    margin-top: 2px;
}
.gandalf-doc-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}
.gandalf-doc-row:hover .gandalf-doc-actions { opacity: 1; }
.gandalf-doc-action {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: all 0.15s;
}
.gandalf-doc-action:hover { background: rgba(255,255,255,0.12); color: white; }
.gandalf-doc-action.delete:hover { background: rgba(255,100,100,0.15); color: #ff6b6b; }

/* Rename input inline */
.gandalf-doc-rename {
    font-size: 13px;
    padding: 4px 8px;
    border: 1px solid var(--chanv-beige, #C9A876);
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
    color: var(--text-primary, #f0f0f0);
    font-family: inherit;
    outline: none;
    width: 100%;
}

.gandalf-docs-footer {
    padding: 12px 24px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    text-align: center;
}
.gandalf-docs-drive-link {
    font-size: 12px;
    color: var(--chanv-beige, #C9A876);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.gandalf-docs-drive-link:hover { opacity: 1; }

.ai-convo-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    position: relative;
}

.ai-convo-item:hover {
    background: rgba(255,255,255,0.1);
}

.ai-convo-item.active {
    background: rgba(255,255,255,0.15);
}

.ai-convo-item.pinned {
    border-left: 2px solid var(--chanv-beige, #C9A876);
    padding-left: 10px;
}

.ai-convo-pin-icon {
    font-size: 11px;
    opacity: 0.7;
}

.ai-convo-title {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 24px;
}

.ai-sidebar-search {
    padding: 8px 12px 4px;
}

.ai-sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    color: white;
    font-family: inherit;
    font-size: 12px;
    outline: none;
    transition: var(--transition);
    box-sizing: border-box;
}

.ai-sidebar-search input::placeholder {
    color: rgba(255,255,255,0.35);
}

.ai-sidebar-search input:focus {
    border-color: var(--chanv-beige);
    background: rgba(255,255,255,0.1);
}

.ai-convo-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 3px;
}

.ai-convo-date {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
}

.ai-convo-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.ai-convo-item:hover .ai-convo-actions {
    opacity: 1;
}
/* Tactile : pas de survol → actions (renommer/supprimer/épingler) toujours
   visibles, sinon inatteignables au doigt. */
@media (hover: none) { .ai-convo-actions { opacity: 1; } }

.ai-convo-actions button {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    /* 0.4 → trop pâle sur fond sombre (retour Dany, réunion 20/07) */
    color: rgba(255, 255, 255, 0.78);
    cursor: pointer;
    font-size: 13px;
    padding: 3px 6px;
    border-radius: 6px;
    transition: var(--transition);
}

.ai-convo-actions button:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.ai-convo-actions button:last-child:hover {
    color: #ff6b6b;
}

.ai-convo-rename-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--chanv-beige);
    border-radius: 6px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-family: inherit;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
}

.ai-action-regen {
    border-color: var(--chanv-beige) !important;
    color: var(--chanv-terre) !important;
    font-weight: 700 !important;
}

/* --- Main Chat Area --- */
.ai-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-left: 280px;
    transition: margin-left 0.3s ease;
}

#ai-chat-view.sidebar-collapsed .ai-chat-main {
    margin-left: 0;
}

.ai-chat-header {
    padding: 12px 24px;
    border-bottom: 1px solid var(--chanv-fibre);
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    flex-shrink: 0;
    flex-wrap: wrap; /* mobile ≤390px : les chips passent à la ligne au lieu de déborder */
}

.ai-model-select {
    padding: 8px 14px;
    border: 1px solid var(--chanv-fibre);
    border-radius: 10px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    background: white;
    color: var(--chanv-terre);
    cursor: pointer;
    outline: none;
    transition: var(--transition);
    min-width: 200px;
}

.ai-model-select:hover,
.ai-model-select:focus {
    border-color: var(--chanv-beige);
}

.ai-model-label {
    font-size: 12px;
    color: #999;
    font-weight: 500;
    white-space: nowrap;
}

/* --- Ruban de modes (✦ Auto · 🖼️ Image · 💻 Code · ✍️ Rédac) --- */
/* Segmented control persistant, à côté du sélecteur de modèle. Additif :
   'auto' = comportement historique, la puce est déjà active par défaut. */
.ai-mode-ribbon {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--chanv-fibre);
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 10px;
    flex-shrink: 0;
}

.ai-mode-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--chanv-terre);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.ai-mode-chip-icon {
    font-size: 13px;
    line-height: 1;
}

.ai-mode-chip:hover {
    background: rgba(255, 255, 255, 0.7);
}

.ai-mode-chip.active {
    background: var(--chanv-terre);
    color: #fff;
    box-shadow: 0 2px 8px rgba(40, 40, 40, 0.18);
}

@media (max-width: 768px) {
    .ai-mode-ribbon { gap: 1px; padding: 2px; }
    .ai-mode-chip { padding: 6px 8px; }
    .ai-mode-chip span:not(.ai-mode-chip-icon) { display: none; }
}

/* --- Sélecteur de modèle : réservé Super Admins (wrapper masquable) --- */
.ai-model-admin {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.ai-model-admin.hidden { display: none; }

/* --- Toggle vitesse ⚡ Rapide / 🧠 Réflexion --- */
/* Segmenté (les 2 états visibles côte à côte) — même vocabulaire visuel que
   le ruban de modes : conteneur + puce active en relief. */
.ai-speed-switch {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--chanv-fibre);
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 10px;
    flex-shrink: 0;
}
.ai-speed-opt {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--chanv-terre);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}
.ai-speed-opt:hover { background: rgba(255, 255, 255, 0.7); }
.ai-speed-opt.active {
    background: var(--chanv-terre);
    color: #fff;
    box-shadow: 0 2px 8px rgba(40, 40, 40, 0.18);
}
@media (max-width: 768px) {
    .ai-speed-switch { gap: 1px; padding: 2px; }
    .ai-speed-opt { padding: 6px 8px; }
    .ai-speed-opt-label { display: none; }
}

/* --- Panneau Mode Image (mini-studio) : presets de format + intention --- */
/* Barre compacte entre les messages et la saisie, visible seulement en mode Image
   (attribut [hidden] piloté par updateAiImagePanel). Reprend les tokens du ruban. */
.ai-image-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid rgba(221, 203, 164, 0.45);
    background: rgba(241, 234, 218, 0.55);
}
.ai-image-panel[hidden] { display: none; } /* bat le [hidden] UA face au display:flex */

.ai-img-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.ai-img-row-label {
    flex-shrink: 0;
    min-width: 62px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #a3937a;
}
.ai-img-chips {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.ai-img-chip,
.ai-img-intent-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 8px;
    background: #fff;
    color: var(--chanv-terre);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}
.ai-img-chip:hover,
.ai-img-intent-btn:hover {
    background: var(--chanv-fibre);
    border-color: var(--chanv-beige);
}
.ai-img-chip.active,
.ai-img-intent-btn.active {
    background: var(--chanv-terre);
    color: #fff;
    border-color: var(--chanv-terre);
    box-shadow: 0 2px 8px rgba(40, 40, 40, 0.18);
}
.ai-img-chip-sub { font-size: 10.5px; font-weight: 500; opacity: 0.72; }
/* Position par défaut suggérée (4:5) : liseré pointillé discret, mais NON présélectionnée. */
.ai-img-chip-suggested:not(.active) { border-style: dashed; border-color: var(--chanv-beige); }

.ai-img-custom-inputs {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.ai-img-custom-inputs.hidden { display: none; }
.ai-img-custom-input {
    width: 56px;
    padding: 5px 6px;
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 8px;
    background: #fff;
    color: var(--chanv-terre);
    font-family: inherit;
    font-size: 12.5px;
}
.ai-img-custom-x { color: #a3937a; font-size: 12px; }

.ai-img-intent { display: inline-flex; gap: 6px; }
.ai-img-hint {
    margin-left: auto;
    font-size: 11.5px;
    font-style: italic;
    color: #a3937a;
}
.ai-img-hint.hidden { display: none; }

@media (max-width: 768px) {
    .ai-image-panel { padding: 8px 12px; }
    .ai-img-row-label { min-width: 0; }
    .ai-img-hint { margin-left: 0; width: 100%; }
}

/* ── Puce « Mode détecté » (coordinateur v1) — au-dessus de la réponse ──
   Tokens de couleur de l'app → lisible en thème clair ET sombre (voir plus bas). */
.ai-mode-detected {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
    margin: 0 0 8px;
    padding: 3px 12px;
    background: var(--chanv-fibre);
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: var(--chanv-terre);
    line-height: 1.5;
}
.ai-mode-detected.inferred { padding-right: 4px; }
.ai-mode-detected-label { white-space: nowrap; }
.ai-mode-detected-correct {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.6);
    color: var(--chanv-terre);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}
.ai-mode-detected-correct:hover { background: #fff; }
.ai-mode-detected-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 130px;
    padding: 4px;
    background: #fff;
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(40, 40, 40, 0.16);
}
.ai-mode-detected-menu.hidden { display: none; }
.ai-mode-detected-opt {
    padding: 6px 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--chanv-terre);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
}
.ai-mode-detected-opt:hover { background: var(--chanv-fibre); }

.ai-share-btn {
    margin-left: auto;
    background: none;
    border: 1px solid var(--chanv-fibre);
    color: var(--chanv-terre);
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-share-btn:hover {
    background: var(--chanv-beige);
    transform: scale(1.05);
}

/* Bouton « détacher dans une fenêtre » (🗗) — même gabarit que Partager. */
.ai-popup-btn {
    background: none;
    border: 1px solid var(--chanv-fibre);
    color: var(--chanv-terre);
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-popup-btn:hover {
    background: var(--chanv-beige);
    transform: scale(1.05);
}

/* Voice conversation mode button */
.ai-voice-mode-btn {
    margin-left: auto;
    background: none;
    border: 1px solid var(--chanv-fibre);
    color: var(--chanv-terre);
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-voice-mode-btn:hover {
    background: var(--chanv-beige);
    transform: scale(1.05);
}

.ai-voice-mode-btn.ai-voice-mode-active {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    border-color: #2ecc71;
    color: white;
    animation: ai-voice-mode-glow 2s ease-in-out infinite;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.3);
}

@keyframes ai-voice-mode-glow {
    0%, 100% { box-shadow: 0 0 8px rgba(46, 204, 113, 0.3); }
    50% { box-shadow: 0 0 16px rgba(46, 204, 113, 0.5); }
}

.ai-voice-mode-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

@media (max-width: 768px) {
    .ai-voice-mode-label { display: none; }
}

.ai-active-agent-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, #C9A876 0%, #E8D5B7 100%);
    color: #1a1a2e;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    white-space: nowrap;
    margin-right: 4px;
}

.ai-active-agent-badge.hidden {
    display: none;
}

/* --- Messages Area --- */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 24px 80px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: auto;
    scrollbar-color: rgba(107, 94, 71, 0.25) transparent;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 10px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(107, 94, 71, 0.25);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(107, 94, 71, 0.4);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Welcome screen when no messages */
.ai-chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--chanv-terre);
    gap: 10px;
    padding: 40px;
    text-align: center;
    animation: ai-welcome-in 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes ai-welcome-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Monogramme GANDALF — remplace l'emoji robot par une identité de marque */
.ai-chat-welcome-icon {
    width: 76px;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 38px;
    color: var(--chanv-terre);
    background: linear-gradient(140deg, var(--chanv-beige) 0%, #ede0c4 100%);
    border-radius: 50%;
    opacity: 1;
    box-shadow: 0 10px 30px rgba(221, 203, 164, 0.5), inset 0 1px 2px rgba(255,255,255,0.6);
    position: relative;
    margin-bottom: 6px;
}
/* Halo respirant autour du monogramme */
.ai-chat-welcome-icon::after {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 1.5px solid rgba(221, 203, 164, 0.45);
    animation: ai-halo 3.2s ease-in-out infinite;
}
@keyframes ai-halo {
    0%, 100% { transform: scale(1);    opacity: 0.55; }
    50%      { transform: scale(1.12); opacity: 0;    }
}

.ai-chat-welcome h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 26px;
    color: var(--chanv-terre);
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
}

.ai-chat-welcome p {
    font-size: 14.5px;
    max-width: 440px;
    line-height: 1.55;
    color: #7a7266;
    margin: 0;
}

/* ── Sélecteur d'experts de marque (accueil) ── */
.ai-expert-picker {
    width: 100%;
    max-width: 560px;
    margin-top: 22px;
    padding: 18px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(221, 203, 164, 0.55);
    border-radius: 18px;
}
.ai-expert-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #a3937a;
    margin-bottom: 12px;
}
.ai-brand-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.ai-brand-chip {
    padding: 9px 20px;
    border-radius: 999px;
    border: 1.5px solid var(--brand, var(--chanv-beige));
    background: white;
    color: var(--brand, var(--chanv-terre));
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.ai-brand-chip:hover { background: var(--brand-soft, var(--chanv-fibre)); transform: translateY(-1px); }
.ai-brand-chip.active {
    background: var(--brand, var(--chanv-terre));
    color: #fff;
    box-shadow: 0 6px 16px rgba(40,40,40,0.18);
}
.ai-metier-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
    animation: ai-welcome-in 0.35s cubic-bezier(0.22,1,0.36,1) both;
}
.ai-metier-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 14px;
    background: white;
    cursor: pointer;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--chanv-terre);
    text-align: left;
    transition: transform 0.2s cubic-bezier(0.22,1,0.36,1), box-shadow 0.2s ease, border-color 0.2s ease;
}
.ai-metier-card:hover {
    transform: translateY(-2px);
    border-color: var(--chanv-beige);
    box-shadow: 0 10px 22px rgba(40,40,40,0.1);
}
.ai-metier-icon { font-size: 20px; }
@media (max-width: 560px) { .ai-metier-grid { grid-template-columns: 1fr; } }

/* --- Cartes de mode à l'accueil (Image · Rédaction · Code · Discussion) --- */
/* Surface de découverte/pédagogie pour le ruban (spec §5) : cliquer sélectionne
   le mode (ruban synchronisé) sans rien changer d'autre à l'écran d'accueil. */
.ai-mode-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 22px;
    max-width: 560px;
    width: 100%;
}

.ai-mode-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 10px;
    border: 1.5px solid rgba(221, 203, 164, 0.55);
    border-radius: 16px;
    background: white;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    transition: transform 0.2s cubic-bezier(0.22,1,0.36,1), box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.ai-mode-card:hover {
    transform: translateY(-2px);
    border-color: var(--chanv-beige);
    box-shadow: 0 10px 22px rgba(40,40,40,0.1);
}

.ai-mode-card.active {
    background: var(--chanv-terre);
    border-color: var(--chanv-terre);
}

.ai-mode-card.active .ai-mode-card-title,
.ai-mode-card.active .ai-mode-card-desc {
    color: rgba(255,255,255,0.92);
}

.ai-mode-card-icon { font-size: 24px; line-height: 1; }

.ai-mode-card-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--chanv-terre);
}

.ai-mode-card-desc {
    font-size: 11px;
    color: #a3937a;
    line-height: 1.3;
}

@media (max-width: 560px) {
    .ai-mode-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* --- Puces de mode (accueil ÉPURÉ) : icône + titre, description en tooltip --- */
.ai-mode-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 20px;
    max-width: 560px;
}
.ai-mode-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 16px;
    border: 1.5px solid rgba(221, 203, 164, 0.55);
    border-radius: 999px;
    background: white;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--chanv-terre);
    transition: transform 0.2s cubic-bezier(0.22,1,0.36,1), box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.ai-mode-pill:hover {
    transform: translateY(-1px);
    border-color: var(--chanv-beige);
    box-shadow: 0 6px 16px rgba(40,40,40,0.1);
}
.ai-mode-pill.active {
    background: var(--chanv-terre);
    border-color: var(--chanv-terre);
    color: rgba(255,255,255,0.92);
}
.ai-mode-pill-icon { font-size: 16px; line-height: 1; }
@media (max-width: 560px) {
    .ai-mode-pills { gap: 6px; }
    .ai-mode-pill { padding: 8px 12px; font-size: 12px; }
    .ai-mode-pill-icon { font-size: 14px; }
}

/* --- Lien « Travailler avec un expert de marque » (replié par défaut) --- */
.ai-expert-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 18px;
    padding: 8px 14px;
    border: none;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #a3937a;
    transition: var(--transition);
}
.ai-expert-toggle:hover { color: var(--chanv-terre); background: rgba(221, 203, 164, 0.18); }
.ai-expert-picker .ai-expert-toggle { margin-top: 0; margin-bottom: 10px; }
.ai-expert-caret { font-size: 10px; }

/* Suggested prompts — cartes qui mettent en vitrine les capacités internes */
.ai-suggestions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 26px;
    max-width: 560px;
    width: 100%;
}

.ai-suggestion {
    padding: 15px 18px;
    border: 1px solid rgba(221, 203, 164, 0.6);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.75);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: var(--chanv-terre);
    font-size: 13.5px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.22,1,0.36,1), box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
    text-align: left;
    line-height: 1.45;
    position: relative;
    overflow: hidden;
}
/* Liseré doré qui balaie la carte au survol */
.ai-suggestion::before {
    content: "";
    position: absolute;
    top: 0; left: -120%;
    width: 80%; height: 100%;
    background: linear-gradient(100deg, transparent, rgba(255,255,255,0.55), transparent);
    transition: left 0.6s ease;
}
.ai-suggestion:hover {
    background: rgba(255, 255, 255, 0.95);
    border-color: var(--chanv-beige);
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(40, 40, 40, 0.1);
}
.ai-suggestion:hover::before { left: 130%; }
.ai-suggestion:active { transform: translateY(-1px); }

@media (max-width: 560px) {
    .ai-suggestions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
    .ai-chat-welcome, .ai-chat-welcome-icon::after, .ai-suggestion, .ai-suggestion::before { animation: none; transition: none; }
}

/* Code blocks with Prism */
.ai-code-block {
    margin: 12px 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.1);
}

.ai-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    background: #2d2d2d;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.ai-code-lang {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-code-copy {
    background: rgba(255,255,255,0.1);
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.ai-code-copy:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

/* Extrait de recherche plein texte sous le titre d'une conversation */
.ai-convo-snippet {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 2px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.35;
}

/* Bouton 👁️ Aperçu (blocs html/svg/xml) — même style que Copier */
.ai-code-preview {
    background: rgba(255,255,255,0.1);
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 11px;
    padding: 3px 10px;
    margin-right: 6px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.ai-code-preview:hover { background: rgba(255,255,255,0.2); color: white; }

/* --- Aperçu sandbox (P5) : modal + iframe isolé --- */
.ai-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 18, 14, 0.6);
    backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10050;
    padding: 24px;
}
.ai-preview-overlay.open { display: flex; }
.ai-preview-modal {
    background: white;
    border-radius: 16px;
    width: min(960px, 100%);
    height: min(80vh, 900px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.45);
}
.ai-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--chanv-fibre);
    border-bottom: 1px solid rgba(221, 203, 164, 0.6);
}
.ai-preview-title { font-size: 13px; font-weight: 700; color: var(--chanv-terre); }
.ai-preview-close {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--chanv-terre);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
}
.ai-preview-close:hover { background: rgba(40,40,40,0.08); }
.ai-preview-frame { flex: 1; border: none; width: 100%; background: white; }
body[data-gtheme="dark"] .ai-preview-modal { background: #201d19; }
body[data-gtheme="dark"] .ai-preview-header { background: #2b2823; border-bottom-color: rgba(221,203,164,.16); }
body[data-gtheme="dark"] .ai-preview-title,
body[data-gtheme="dark"] .ai-preview-close { color: rgba(255,255,255,.85); }
body[data-gtheme="dark"] .ai-preview-close:hover { background: rgba(221,203,164,.13); }

.ai-code-block pre {
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    font-size: 13px !important;
    max-height: 400px;
    overflow: auto;
}

/* Feedback buttons */
.ai-feedback-btn {
    opacity: 0.5;
    transition: all 0.15s !important;
}

.ai-feedback-btn:hover {
    opacity: 1 !important;
}

.ai-feedback-btn.active {
    opacity: 1;
    background: var(--chanv-beige) !important;
    border-color: var(--chanv-beige) !important;
}

/* --- Markdown elements in AI messages --- */

/* Tables */
.ai-table-wrap {
    overflow-x: auto;
    margin: 12px 0;
    border-radius: 10px;
    border: 1px solid rgba(0,0,0,0.1);
}

.ai-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.ai-table th {
    background: var(--chanv-terre, #2D2A26);
    color: #F1EADA;
    padding: 8px 14px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    white-space: nowrap;
}

.ai-table td {
    padding: 8px 14px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    vertical-align: top;
}

.ai-table tbody tr:nth-child(even) {
    background: rgba(200,173,127,0.05);
}

.ai-table tbody tr:hover {
    background: rgba(200,173,127,0.1);
}

.ai-table tbody tr:last-child td {
    border-bottom: none;
}

.ai-table code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
}

/* Blockquotes */
.ai-msg blockquote {
    margin: 10px 0;
    padding: 8px 16px;
    border-left: 3px solid var(--chanv-beige, #C9A876);
    background: rgba(200,173,127,0.06);
    border-radius: 0 8px 8px 0;
    color: inherit;
    font-style: italic;
}

/* Horizontal rules */
.ai-msg hr {
    border: none;
    border-top: 1px solid rgba(0,0,0,0.1);
    margin: 16px 0;
}

/* Ordered lists */
.ai-msg ol {
    margin: 8px 0;
    padding-left: 24px;
}

.ai-msg ol li {
    margin-bottom: 4px;
}

/* Unordered lists — improved spacing */
.ai-msg ul {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-msg ul li {
    margin-bottom: 4px;
}

/* Strikethrough */
.ai-msg del {
    text-decoration: line-through;
    opacity: 0.6;
}

/* Checkboxes */
.ai-msg .ai-checkbox {
    list-style: none;
    margin-left: -20px;
}

.ai-msg .ai-cb {
    margin-right: 4px;
    font-size: 15px;
}

.ai-msg .ai-checkbox.checked .ai-cb {
    color: #2ecc71;
}

/* Headings in messages */
.ai-msg h2, .ai-msg h3, .ai-msg h4, .ai-msg h5 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    margin: 18px 0 8px 0;
    line-height: 1.3;
    letter-spacing: -0.005em;
}
/* Premier titre : pas d'espace mort au-dessus */
.ai-msg > h2:first-child, .ai-msg > h3:first-child, .ai-msg > h4:first-child,
.ai-msg p:first-child > h2:first-child, .ai-msg p:first-child > h3:first-child { margin-top: 2px; }

.ai-msg h2 {
    font-size: 1.22em;
    padding-bottom: 6px;
    border-bottom: 2px solid rgba(221, 203, 164, 0.5);
}
.ai-msg h3 { font-size: 1.1em; }
.ai-msg h4 { font-size: 1em; }
.ai-msg h5 { font-size: 0.95em; opacity: 0.8; }

/* Paragraphes aérés dans les réponses */
.ai-msg p { margin: 0 0 10px; }
.ai-msg p:last-child { margin-bottom: 0; }

/* Message bubbles */
.ai-msg {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 0;
    position: relative;
    /* Entrée douce à l'apparition de chaque bulle */
    animation: ai-msg-in 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes ai-msg-in {
    from { opacity: 0; transform: translateY(10px) scale(0.985); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #333230 0%, var(--chanv-terre) 100%);
    color: white;
    border-bottom-right-radius: 5px;
    box-shadow: 0 6px 18px rgba(40, 40, 40, 0.14);
}

.ai-msg-assistant {
    align-self: flex-start;
    background: var(--chanv-blanc);
    color: var(--chanv-terre);
    border: 1px solid rgba(221, 203, 164, 0.55);
    border-bottom-left-radius: 5px;
    box-shadow: 0 4px 18px rgba(40, 40, 40, 0.05);
}

@media (prefers-reduced-motion: reduce) {
    .ai-msg { animation: none; }
}

.ai-msg-model-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
    opacity: 0.6;
}

.ai-msg-user .ai-msg-model-badge {
    color: rgba(255,255,255,0.6);
}

/* Streaming loader */
.ai-loader-wrap {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.ai-loader-hint {
    font-size: 13px;
    color: #6B5E47;
    font-style: italic;
}

/* Indicateur de réflexion — trois points qui ondulent (signature sobre) */
.ai-thinking-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 2px;
}
.ai-thinking-dots i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chanv-beige);
    animation: ai-dot-wave 1.25s ease-in-out infinite;
}
.ai-thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.ai-thinking-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-dot-wave {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.45; }
    30%           { transform: translateY(-5px); opacity: 1;    }
}
@media (prefers-reduced-motion: reduce) {
    .ai-thinking-dots i { animation: none; opacity: 0.7; }
}

.ai-msg-streaming {
    min-height: auto;
}

/* --- Input Area --- */
.ai-chat-input {
    padding: 12px 24px 20px;
    border-top: 1px solid var(--chanv-fibre);
    background: white;
    flex-shrink: 0;
    position: relative;
    margin-bottom: 4px;
}

.ai-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

/* File preview zone */
/* Drag & drop overlay */
.ai-chat-main {
    position: relative;
}

.ai-chat-main.ai-drag-over::after {
    content: '📎 Déposer les fichiers ici';
    position: absolute;
    inset: 0;
    background: rgba(99, 102, 241, 0.12);
    border: 2.5px dashed rgba(99, 102, 241, 0.5);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: rgba(99, 102, 241, 0.9);
    z-index: 100;
    pointer-events: none;
    backdrop-filter: blur(2px);
}

.ai-file-preview {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-bottom: 10px;
}

.ai-file-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--chanv-fibre);
}

.ai-file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-file-thumb-doc {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f7f5f0;
    gap: 2px;
}

.ai-file-thumb-doc span {
    font-size: 22px;
}

.ai-file-thumb-name {
    font-size: 8px;
    color: #666;
    text-align: center;
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-file-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Attach button */
.ai-attach-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--chanv-fibre);
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.ai-attach-btn:hover {
    background: var(--chanv-fibre);
    transform: scale(1.05);
}

/* File chips in messages */
.ai-msg-files {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.ai-msg-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    background: rgba(201, 168, 118, 0.15);
    color: #6B5E47;
}

.ai-msg-user .ai-msg-file-chip {
    background: rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.9);
}

/* Generated images */
.ai-msg-generated-image {
    margin-top: 10px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 512px;
    position: relative;
}

.ai-msg-generated-image img {
    width: 100%;
    display: block;
    border-radius: 12px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.ai-msg-generated-image img:hover {
    opacity: 0.85;
}

.ai-img-download-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(0,0,0,0.55);
    color: white;
    font-size: 16px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.ai-msg-generated-image:hover .ai-img-download-btn {
    opacity: 1;
}

.ai-img-download-btn:hover {
    background: rgba(0,0,0,0.8);
}

.ai-img-open-btn {
    right: 52px;
}

.ai-img-provider-badge {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0,0,0,0.55);
    color: rgba(255,255,255,0.85);
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 500;
    letter-spacing: 0.3px;
    pointer-events: none;
    backdrop-filter: blur(4px);
}

/* Generated PDFs */
.ai-msg-generated-pdf {
    margin-top: 10px;
}

.ai-pdf-download-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #E8D5B7 0%, #C9A876 100%);
    color: var(--chanv-terre, #2D2A26);
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(201, 168, 118, 0.3);
}

.ai-pdf-download-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(201, 168, 118, 0.4);
    filter: brightness(1.05);
}

.ai-gen-img-btn {
    background: linear-gradient(135deg, #E8D5B7 0%, #C9A876 100%);
    border-color: #C9A876;
}

.ai-gen-img-btn:hover {
    background: linear-gradient(135deg, #C9A876 0%, #a88c5e 100%);
}

/* Message actions */
.ai-msg-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-msg:hover .ai-msg-actions {
    opacity: 1;
}

.ai-msg-actions button {
    padding: 3px 10px;
    border: 1px solid var(--chanv-fibre);
    border-radius: 8px;
    background: white;
    color: #6B5E47;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.ai-msg-actions button:hover {
    background: var(--chanv-fibre);
    border-color: var(--chanv-beige);
}

/* TTS button states */
.ai-tts-btn {
    transition: all 0.2s ease;
}

.ai-tts-playing {
    background: rgba(46, 204, 113, 0.12) !important;
    border-color: #2ecc71 !important;
    color: #2ecc71 !important;
    animation: ai-tts-pulse 1.5s ease-in-out infinite;
}

.ai-tts-loading {
    opacity: 0.7;
    animation: ai-tts-spin 1s linear infinite;
}

.ai-tts-paused {
    background: rgba(230, 126, 34, 0.12) !important;
    border-color: #e67e22 !important;
    color: #e67e22 !important;
}

@keyframes ai-tts-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.3); }
    50% { box-shadow: 0 0 0 4px rgba(46, 204, 113, 0); }
}

@keyframes ai-tts-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.ai-chat-textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--chanv-fibre);
    border-radius: 16px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    resize: none;
    min-height: 44px;
    max-height: 150px;
    transition: var(--transition);
}

.ai-chat-textarea:focus {
    border-color: var(--chanv-beige);
}

.ai-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--chanv-terre);
    color: white;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.ai-chat-send:hover {
    background: #1a1a1a;
    transform: scale(1.05);
}

.ai-chat-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.ai-chat-send.ai-chat-stop {
    background: #e74c3c;
    font-size: 14px;
    animation: ai-stop-pulse 1.5s ease-in-out infinite;
}

.ai-chat-send.ai-chat-stop:hover {
    background: #c0392b;
    transform: scale(1.05);
}

@keyframes ai-stop-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
}

/* Voice input active state */
.ai-voice-active {
    background: #e74c3c !important;
    color: white !important;
    animation: ai-voice-pulse 1s ease-in-out infinite;
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.25);
}

@keyframes ai-voice-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.25); }
    50% { transform: scale(1.08); box-shadow: 0 0 0 6px rgba(231, 76, 60, 0.1); }
}

/* ===== Voice Recording Overlay ===== */
.ai-voice-overlay {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 6px;
    background: rgba(30, 27, 22, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    border: 1px solid rgba(196, 169, 125, 0.2);
    padding: 16px;
    z-index: 50;
    animation: ai-voice-slide-up 0.25s ease-out;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
}

.ai-voice-overlay.hidden {
    display: none;
}

@keyframes ai-voice-slide-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Top bar: status + controls */
.ai-voice-overlay-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.ai-voice-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #F1EADA;
}

.ai-voice-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #e74c3c;
    animation: ai-voice-dot-blink 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

.ai-voice-dot.countdown {
    background: #e67e22;
    animation: ai-voice-dot-blink 0.6s ease-in-out infinite;
}

@keyframes ai-voice-dot-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.ai-voice-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-voice-lang {
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid rgba(196, 169, 125, 0.3);
    background: rgba(196, 169, 125, 0.1);
    color: #DDCBA4;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.ai-voice-lang:hover {
    background: rgba(196, 169, 125, 0.2);
    border-color: rgba(196, 169, 125, 0.5);
}

.ai-voice-cancel {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(231, 76, 60, 0.3);
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-voice-cancel:hover {
    background: rgba(231, 76, 60, 0.25);
    border-color: rgba(231, 76, 60, 0.5);
}

/* Audio level bar */
.ai-voice-level-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}

.ai-voice-level {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #2ecc71, #f1c40f, #e74c3c);
    border-radius: 2px;
    transition: width 0.08s linear;
}

/* Transcript area */
.ai-voice-transcript {
    min-height: 36px;
    max-height: 80px;
    overflow-y: auto;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 10px;
    font-size: 14px;
    line-height: 1.5;
    color: #F1EADA;
}

.ai-voice-placeholder {
    color: rgba(241, 234, 218, 0.35);
    font-style: italic;
}

.ai-voice-interim {
    color: rgba(241, 234, 218, 0.5);
    font-style: italic;
}

/* Footer: countdown + send */
.ai-voice-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-voice-countdown {
    font-size: 12px;
    font-weight: 600;
    color: #e67e22;
    animation: ai-voice-countdown-pulse 0.8s ease-in-out infinite;
}

.ai-voice-countdown.hidden {
    display: none;
}

@keyframes ai-voice-countdown-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ai-voice-send-now {
    padding: 6px 16px;
    border-radius: 10px;
    border: none;
    background: var(--chanv-terre, #282828);
    color: #F1EADA;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    margin-left: auto;
}

.ai-voice-send-now:hover {
    background: #3D3425;
    transform: scale(1.03);
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    #ai-chat-view {
        height: 100dvh;
        height: calc(100vh - 56px);
    }

    .ai-chat-main {
        margin-left: 0;
        height: 100%;
    }

    #ai-chat-view.sidebar-collapsed .ai-chat-main {
        margin-left: 0;
    }

    .ai-sidebar-toggle {
        display: none;
    }

    .ai-sidebar {
        left: -300px;
        z-index: 1000;
        transition: left 0.3s ease;
    }

    .ai-sidebar.open {
        left: 0;
    }

    .ai-sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .ai-sidebar-overlay.open {
        opacity: 1;
        pointer-events: auto;
    }

    /* Header — compact */
    .ai-chat-header {
        padding: 8px 12px;
        gap: 6px;
    }

    .ai-model-select {
        min-width: 0;
        max-width: 140px;
        font-size: 12px;
        padding: 6px 8px;
    }

    .ai-model-label {
        display: none;
    }

    .ai-active-agent-badge {
        font-size: 10px;
        padding: 2px 6px;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ai-share-btn {
        padding: 4px 8px;
        font-size: 12px;
    }

    .ai-voice-mode-btn {
        padding: 4px 8px;
        font-size: 14px;
    }

    .ai-mobile-menu-btn {
        display: flex !important;
    }

    /* Messages — proper spacing */
    .ai-chat-messages {
        padding: 12px 12px 16px;
        gap: 10px;
    }

    .ai-msg {
        max-width: 92%;
        padding: 10px 14px;
        font-size: 13px;
        line-height: 1.5;
    }

    .ai-msg-model-badge {
        font-size: 9px;
        margin-bottom: 4px;
    }

    .ai-msg-actions {
        opacity: 1;
        gap: 3px;
        flex-wrap: wrap;
    }

    .ai-msg-actions button {
        font-size: 10px;
        padding: 2px 8px;
    }

    /* Generated images — fit mobile */
    .ai-msg-generated-image {
        max-width: 100%;
    }

    .ai-img-download-btn {
        opacity: 1;
    }

    /* Input area — compact, safe bottom */
    .ai-chat-input {
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    /* En shell, la vue est épinglée au-dessus de la tabbar qui compense DÉJÀ
       env(safe-area-inset-bottom) : le repli safe-area du composeur comptait
       l'inset une 2e fois → bande morte ~48px sous l'input (Android 15
       edge-to-edge, ticket Lh7zXAFyXperO3frUKNJ). Même doctrine que
       .chat-composer (0bc3454) : l'inset vient du conteneur, pas du composeur. */
    body.shell-on .ai-chat-input {
        padding-bottom: 8px;
        margin-bottom: 0; /* le margin 4px desktop laissait un liseré de fond */
    }

    .ai-input-row {
        gap: 6px;
    }

    .ai-chat-textarea {
        padding: 10px 12px;
        font-size: 14px;
        min-height: 40px;
        border-radius: 14px;
    }

    .ai-attach-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .ai-chat-send {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    /* File previews — smaller */
    .ai-file-thumb {
        width: 52px;
        height: 52px;
    }

    /* Welcome screen — compact */
    .ai-chat-welcome {
        padding: 24px 16px;
        gap: 8px;
    }

    .ai-chat-welcome-icon {
        font-size: 36px;
    }

    .ai-chat-welcome h3 {
        font-size: 18px;
    }

    .ai-chat-welcome p {
        font-size: 13px;
    }

    .ai-suggestions {
        gap: 6px;
    }

    .ai-suggestion {
        font-size: 12px;
        padding: 8px 12px;
    }

    /* Code blocks — prevent overflow */
    .ai-code-block pre {
        font-size: 11px !important;
        max-height: 300px;
    }

    /* Voice mode controls */
    .ai-voice-recording-bar {
        padding: 8px 12px;
    }
}

@media (min-width: 769px) {
    .ai-mobile-menu-btn {
        display: none !important;
    }

    .ai-sidebar-overlay {
        display: none !important;
    }
}

/* Mobile menu button */
.ai-mobile-menu-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--chanv-fibre);
    background: white;
    cursor: pointer;
    font-size: 16px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-mobile-menu-btn:hover {
    background: var(--chanv-fibre);
}

/* ============================================== */
/* --- AGENT IA — Admin Panel                 --- */
/* ============================================== */

.ai-admin-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.ai-stat-card {
    background: var(--chanv-fibre);
    border-radius: 12px;
    padding: 20px 24px;
    flex: 1;
    min-width: 120px;
    text-align: center;
}

.ai-stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--chanv-terre);
    font-family: 'Outfit', sans-serif;
}

.ai-stat-label {
    font-size: 12px;
    color: #888;
    margin-top: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-admin-section {
    margin-bottom: 28px;
}

.ai-admin-section h4 {
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--chanv-terre);
    margin-bottom: 12px;
}

.ai-admin-hint {
    font-size: 13px;
    color: #999;
    margin-top: 8px;
}

.ai-block-form {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.ai-block-input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid var(--chanv-fibre);
    border-radius: 10px;
    font-family: inherit;
    font-size: 13px;
    outline: none;
}

.ai-block-input:focus {
    border-color: var(--chanv-beige);
}

.ai-blocked-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--chanv-fibre);
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 13px;
}

.btn-sm {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 6px;
    border: 1px solid var(--chanv-fibre);
    background: white;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}

.btn-sm:hover {
    background: var(--chanv-fibre);
}

/* Syntheses list */
.ai-syntheses-list {
    margin-top: 12px;
}

.ai-synthesis-item {
    padding: 12px 16px;
    background: var(--chanv-fibre);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.ai-synthesis-item:hover {
    background: var(--chanv-beige);
    transform: translateX(2px);
}

.ai-synthesis-date {
    font-size: 13px;
    font-weight: 600;
    color: var(--chanv-terre);
}

.ai-synthesis-meta {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

/* Synthesis & Convo Detail Modals */
.ai-synthesis-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.ai-synthesis-modal.hidden {
    display: none;
}

.ai-synthesis-content {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 800px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-bold);
}

.ai-synthesis-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    transition: var(--transition);
}

.ai-synthesis-close:hover {
    color: var(--chanv-terre);
}

.ai-synthesis-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    color: var(--chanv-terre);
    margin-bottom: 8px;
}

.ai-synthesis-meta-detail {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 13px;
    color: #888;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--chanv-fibre);
}

.ai-synthesis-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--chanv-terre);
}

.ai-synthesis-text h2 { font-size: 18px; margin: 20px 0 8px; font-family: 'Outfit', sans-serif; }
.ai-synthesis-text h3 { font-size: 16px; margin: 16px 0 6px; font-family: 'Outfit', sans-serif; }
.ai-synthesis-text h4 { font-size: 14px; margin: 12px 0 4px; font-family: 'Outfit', sans-serif; }
.ai-synthesis-text ul { padding-left: 20px; margin: 8px 0; }
.ai-synthesis-text li { margin-bottom: 4px; }

/* Conversation detail */
.ai-detail-info {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: #888;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--chanv-fibre);
}

.ai-detail-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-detail-msg {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
}

.ai-detail-user {
    background: var(--chanv-terre);
    color: white;
    align-self: flex-end;
    margin-left: 40px;
}

.ai-detail-assistant {
    background: var(--chanv-fibre);
    color: var(--chanv-terre);
    margin-right: 40px;
}

.ai-detail-meta {
    font-size: 10px;
    opacity: 0.6;
    margin-bottom: 4px;
}

.ai-detail-badge {
    background: rgba(255,255,255,0.2);
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-detail-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ============================================== */
/* --- AGENT IA — Agents personnalisés        --- */
/* ============================================== */

.ai-agent-manage-btn {
    background: none;
    border: 1px solid var(--chanv-fibre);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
    flex-shrink: 0;
}

.ai-agent-manage-btn:hover {
    background: var(--chanv-fibre);
}

.ai-agent-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--chanv-fibre);
    border-radius: 10px;
    margin-bottom: 8px;
    transition: var(--transition);
}

.ai-agent-card:hover {
    transform: translateX(2px);
}

.ai-agent-card-icon {
    font-size: 24px;
    flex-shrink: 0;
    width: 36px;
    text-align: center;
}

.ai-agent-card-info {
    flex: 1;
    min-width: 0;
}

.ai-agent-card-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--chanv-terre);
}

.ai-agent-card-desc {
    font-size: 12px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-agent-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.ai-agent-form {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--chanv-fibre);
}

.ai-agent-form .form-group {
    margin-bottom: 12px;
}

.ai-agent-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--chanv-terre);
    margin-bottom: 4px;
}

.ai-agent-form input,
.ai-agent-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--chanv-fibre);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    transition: var(--transition);
}

.ai-agent-form input:focus,
.ai-agent-form textarea:focus {
    border-color: var(--chanv-beige);
}

.ai-agent-form textarea {
    resize: vertical;
    min-height: 80px;
}

.ai-agent-form select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--chanv-fibre);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
    background: white;
}

.ai-agent-form select:focus {
    border-color: var(--chanv-beige);
}

/* Form row (side by side) */
.ai-agent-form-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

/* AI generate prompt button */
.ai-generate-prompt-btn {
    margin-top: 6px;
    background: linear-gradient(135deg, #f0e6d6 0%, #e8d5b7 100%);
    border: 1px solid var(--chanv-fibre);
    color: var(--chanv-terre);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-generate-prompt-btn:hover {
    background: linear-gradient(135deg, #e8d5b7 0%, #C9A876 100%);
    transform: translateY(-1px);
}

.ai-generate-prompt-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* Agent modal wider */
.ai-agent-modal-content {
    max-width: 620px !important;
}

/* Templates gallery */
.ai-agent-templates {
    margin-bottom: 20px;
    padding: 14px;
    background: rgba(201,168,118,0.06);
    border: 1px solid rgba(201,168,118,0.15);
    border-radius: 12px;
}

.ai-agent-templates-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--chanv-terre);
    margin-bottom: 10px;
}

.ai-agent-templates-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.ai-agent-template {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    border-radius: 10px;
    border: 1px solid rgba(201,168,118,0.2);
    background: white;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 22px;
}

.ai-agent-template span {
    font-size: 10px;
    font-weight: 600;
    color: #666;
    text-align: center;
    line-height: 1.2;
}

.ai-agent-template:hover {
    border-color: var(--chanv-fibre);
    background: rgba(201,168,118,0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* Agent card stats */
.ai-agent-card-stats {
    font-size: 10px;
    color: var(--chanv-fibre);
    margin-top: 2px;
}

/* Google Drive section */
.ai-agent-drive-info {
    padding: 12px;
    background: rgba(66,133,244,0.06);
    border: 1px solid rgba(66,133,244,0.15);
    border-radius: 10px;
}

.ai-agent-drive-info p {
    font-size: 12px;
    color: #666;
    margin: 0 0 8px;
    line-height: 1.4;
}

.ai-drive-btn {
    background: linear-gradient(135deg, #4285f4 0%, #356ac3 100%) !important;
    color: white !important;
    border: none !important;
}

.ai-drive-btn:hover {
    opacity: 0.9;
}

.ai-drive-connected {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #34a853;
    font-weight: 600;
}

.ai-drive-folder-link {
    color: #4285f4;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
}

.ai-drive-folder-link:hover {
    text-decoration: underline;
}

/* Drive dropzone area */
.ai-drive-dropzone-area {
    margin-top: 8px;
}

.ai-drive-dropzone {
    border: 2px dashed rgba(66,133,244,0.3);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
    background: rgba(66,133,244,0.03);
}

.ai-drive-dropzone:hover,
.ai-drive-dropzone.dragover {
    border-color: #4285f4;
    background: rgba(66,133,244,0.08);
}

.ai-drive-dropzone.dragover {
    transform: scale(1.01);
}

.ai-drive-dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #888;
    font-size: 13px;
}

.ai-drive-dropzone-icon {
    font-size: 28px;
    margin-bottom: 2px;
}

.ai-drive-dropzone-or {
    font-size: 10px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Drive file list */
.ai-drive-file-list {
    margin-bottom: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.ai-drive-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(66,133,244,0.05);
    border-radius: 8px;
    margin-bottom: 4px;
    font-size: 13px;
    transition: background 0.15s;
}

.ai-drive-file-item:hover {
    background: rgba(66,133,244,0.1);
}

.ai-drive-file-icon {
    flex-shrink: 0;
}

.ai-drive-file-name {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #333;
}

.ai-drive-file-size {
    color: #888;
    font-size: 11px;
    white-space: nowrap;
}

.ai-drive-empty {
    padding: 12px;
    text-align: center;
    font-size: 12px;
    color: #999;
    line-height: 1.5;
}

.ai-drive-upload-status {
    font-size: 12px;
    color: #4285f4;
    font-weight: 500;
    min-height: 18px;
    margin-top: 4px;
}

/* Drive sync row */
.ai-drive-sync-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(52,168,83,0.06);
    border: 1px solid rgba(52,168,83,0.15);
    border-radius: 8px;
}

.ai-drive-sync-btn {
    background: linear-gradient(135deg, #34a853 0%, #2d8f47 100%) !important;
    color: white !important;
    border: none !important;
    font-weight: 600;
    white-space: nowrap;
}

.ai-drive-sync-btn:hover {
    opacity: 0.9;
}

.ai-drive-sync-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.ai-drive-sync-status {
    font-size: 12px;
    color: #666;
    flex: 1;
}

.ai-drive-sync-status.ai-drive-synced {
    color: #34a853;
    font-weight: 500;
}

/* --- Agent Knowledge Documents --- */
.agent-docs-list {
    margin: 8px 0;
    max-height: 200px;
    overflow-y: auto;
}

.agent-doc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(0,0,0,0.04);
    border-radius: 8px;
    margin-bottom: 4px;
    font-size: 13px;
}

.agent-doc-icon {
    flex-shrink: 0;
}

.agent-doc-name {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-doc-size {
    color: #888;
    font-size: 11px;
    white-space: nowrap;
}

.agent-doc-delete {
    background: none;
    border: none;
    color: #ff6b6b;
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.agent-doc-delete:hover {
    opacity: 1;
}

.agent-doc-upload-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.agent-doc-status {
    font-size: 12px;
    color: #C9A876;
}

/* --- Image Generation Loading Indicator --- */
.ai-img-generating {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin-top: 12px;
    background: linear-gradient(135deg, rgba(201,168,118,0.08) 0%, rgba(232,213,183,0.12) 100%);
    border: 1px solid rgba(201,168,118,0.2);
    border-radius: 10px;
    color: #C9A876;
    font-size: 13px;
    font-weight: 500;
    animation: imgGenPulse 2s ease-in-out infinite;
}

.ai-img-generating-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(201,168,118,0.3);
    border-top: 2px solid #C9A876;
    border-radius: 50%;
    animation: imgGenSpin 0.8s linear infinite;
}

@keyframes imgGenSpin {
    to { transform: rotate(360deg); }
}

@keyframes imgGenPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* --- Message Timestamps --- */
.ai-msg-timestamp {
    display: block;
    font-size: 10px;
    color: #b0a89a;
    margin-top: 4px;
    padding-top: 4px;
    text-align: right;
    opacity: 0.5;
    line-height: 1;
}

.ai-msg-user .ai-msg-timestamp {
    color: rgba(255,255,255,0.4);
}

/* =====================================================================
 * --- MÉMOIRE UTILISATEUR PERSISTANTE (panneau 🧠) ---
 * ===================================================================== */

.ai-memory-btn {
    background: none;
    border: 1px solid var(--chanv-fibre);
    color: var(--chanv-terre);
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}
.ai-memory-btn-label {
    font-size: 12.5px;
    font-weight: 600;
}

.ai-memory-btn:hover {
    background: linear-gradient(135deg, rgba(201,168,118,0.15), rgba(201,168,118,0.3));
    border-color: var(--chanv-beige);
    transform: scale(1.05);
}

.ai-memory-panel {
    position: absolute;
    top: 56px;
    right: 16px;
    width: 380px;
    max-height: calc(100vh - 120px);
    z-index: 200;
    border-radius: 16px;
    background: rgba(255,255,255,0.97);
    border: 1px solid rgba(201,168,118,0.3);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15), 0 0 0 1px rgba(201,168,118,0.1);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    animation: ai-memory-slide-in 0.25s ease-out;
    overflow: hidden;
}

@keyframes ai-memory-slide-in {
    from { opacity: 0; transform: translateY(-10px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-memory-panel.hidden {
    display: none;
}

.ai-memory-panel-content {
    display: flex;
    flex-direction: column;
    max-height: inherit;
}

.ai-memory-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(201,168,118,0.15);
}

.ai-memory-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--chanv-terre);
    margin: 0;
}

.ai-memory-close {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #999;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.ai-memory-close:hover {
    background: rgba(0,0,0,0.06);
    color: var(--chanv-terre);
}

.ai-memory-hint {
    padding: 8px 20px 12px;
    font-size: 12px;
    color: #888;
    line-height: 1.5;
    margin: 0;
}

.ai-memory-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 16px 12px;
    max-height: 420px;
}

.ai-memory-list::-webkit-scrollbar {
    width: 4px;
}

.ai-memory-list::-webkit-scrollbar-thumb {
    background: rgba(201,168,118,0.3);
    border-radius: 4px;
}

.ai-memory-loading {
    text-align: center;
    padding: 32px 16px;
    color: #aaa;
    font-size: 13px;
}

.ai-memory-empty {
    text-align: center;
    padding: 32px 16px;
    color: #aaa;
    font-size: 13px;
    line-height: 1.6;
}

.ai-memory-category {
    margin-bottom: 16px;
}

.ai-memory-category-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--chanv-beige);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 4px 4px 6px;
    border-bottom: 1px solid rgba(201,168,118,0.12);
    margin-bottom: 6px;
}

.ai-memory-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    transition: all 0.2s ease;
    margin-bottom: 2px;
    overflow: hidden;
}

.ai-memory-item:hover {
    background: rgba(201,168,118,0.08);
}

.ai-memory-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-memory-text {
    font-size: 13px;
    color: var(--chanv-terre);
    line-height: 1.45;
    word-break: break-word;
}

.ai-memory-date {
    font-size: 10px;
    color: #bbb;
}

.ai-memory-delete {
    width: 24px;
    height: 24px;
    min-width: 24px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #ccc;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    opacity: 0;
    flex-shrink: 0;
    margin-top: 2px;
}

.ai-memory-item:hover .ai-memory-delete {
    opacity: 1;
}

.ai-memory-delete:hover {
    background: rgba(255,107,107,0.12);
    color: #ff6b6b;
}

.ai-memory-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px 14px;
    border-top: 1px solid rgba(201,168,118,0.12);
}

.ai-memory-count {
    font-size: 12px;
    color: #aaa;
    font-weight: 500;
}

.btn-danger-sm {
    background: transparent;
    border: 1px solid rgba(255,107,107,0.3);
    color: #ff6b6b;
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-danger-sm:hover {
    background: rgba(255,107,107,0.1);
    border-color: #ff6b6b;
}

/* Responsive */
@media (max-width: 768px) {
    .ai-memory-panel {
        width: calc(100vw - 32px);
        right: 16px;
        top: 48px;
    }

    .ai-memory-btn {
        padding: 4px 8px;
        font-size: 16px;
    }
    .ai-memory-btn-label { display: none; } /* mobile : icône 📔 seule */
}

/* ============================================== */
/* --- Image Preview Overlay                  --- */
/* ============================================== */

.ai-img-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.25s ease;
    cursor: zoom-out;
}

.ai-img-preview-overlay.visible {
    background: rgba(0, 0, 0, 0.85);
}

.ai-img-preview-close {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
    z-index: 10;
}

.ai-img-preview-close:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.1);
}

.ai-img-preview-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 80vw;
    max-height: 80vh;
    cursor: default;
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.ai-img-preview-overlay.visible .ai-img-preview-container {
    opacity: 1;
    transform: scale(1);
}

.ai-img-preview-img {
    max-width: 80vw;
    max-height: 72vh;
    border-radius: 8px;
    object-fit: contain;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.ai-img-preview-download {
    padding: 10px 28px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
    letter-spacing: 0.5px;
}

.ai-img-preview-download:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    .ai-img-preview-container {
        max-width: 95vw;
        max-height: 90vh;
    }
    .ai-img-preview-img {
        max-width: 95vw;
        max-height: 80vh;
    }
    .ai-img-preview-close {
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
}

/* ==================== STUDIO CHANV IMAGE PICKER ==================== */

.ai-studio-btn {
    position: relative;
}
.ai-studio-btn::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 6px;
    height: 6px;
    background: #667eea;
    border-radius: 50%;
}

.ai-studio-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: aiStudioFadeIn .2s ease;
}
@keyframes aiStudioFadeIn { from { opacity: 0; } to { opacity: 1; } }

.ai-studio-modal {
    background: #1e1e1e;
    border-radius: 16px;
    width: min(90vw, 840px);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
    border: 1px solid #333;
    overflow: hidden;
}
.ai-studio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #333;
}
.ai-studio-header h3 {
    margin: 0;
    font-size: 16px;
    color: #fff;
    font-weight: 600;
}
.ai-studio-close {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all .15s;
}
.ai-studio-close:hover { color: #fff; background: #333; }

.ai-studio-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.ai-studio-back {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 13px;
    padding: 4px 0;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color .15s;
}
.ai-studio-back:hover { color: #fff; }

.ai-studio-project-label {
    color: #667eea;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.ai-studio-projects {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.ai-studio-project-card {
    background: #2a2a2a;
    border-radius: 10px;
    padding: 14px;
    cursor: pointer;
    border: 1px solid #3a3a3a;
    transition: all .2s;
}
.ai-studio-project-card:hover {
    border-color: #667eea;
    background: #2e2e3e;
    transform: translateY(-2px);
}
.ai-studio-project-card h4 {
    margin: 0 0 6px;
    font-size: 14px;
    color: #fff;
    font-weight: 600;
}
.ai-studio-project-card span {
    font-size: 12px;
    color: #888;
}

.ai-studio-assets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}
.ai-studio-asset {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all .2s;
}
.ai-studio-asset:hover {
    border-color: #667eea;
    transform: scale(1.03);
}
.ai-studio-asset img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ai-studio-asset-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    color: #fff;
    font-size: 11px;
    padding: 16px 6px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-studio-loading {
    text-align: center;
    color: #888;
    padding: 40px;
    font-size: 14px;
}
.ai-studio-empty {
    text-align: center;
    color: #666;
    padding: 40px;
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    .ai-studio-modal {
        width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        height: 100vh;
    }
    .ai-studio-projects {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .ai-studio-assets {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 6px;
    }
    .ai-studio-body { padding: 12px; }
    .ai-studio-header { padding: 12px 14px; }
}
@media (max-width: 480px) {
    .ai-studio-projects { grid-template-columns: 1fr; }
    .ai-studio-assets { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}

/* ── Studio Save Button on generated images ── */
.ai-img-studio-btn {
    background: rgba(102,126,234,0.15) !important;
}
.ai-img-studio-btn:hover {
    background: #667eea !important;
    color: #fff !important;
}

/* ── Save modal extras ── */
.ai-studio-name-row {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid #333;
}
.ai-studio-name-label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ai-studio-name-input {
    width: 100%;
    padding: 10px 14px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color .2s;
}
.ai-studio-name-input:focus {
    border-color: #667eea;
    outline: none;
}
.ai-studio-save-subtitle {
    font-size: 13px;
    color: #aaa;
    margin-bottom: 12px;
    font-weight: 500;
}

/* ═══ Shell Gandalf : le panneau de conversations s'empile À DROITE du rail
   (il recouvrait le menu principal). Réductible comme avant : il glisse sous
   le rail, la poignée reste au bord. Mobile (≤860px, rail masqué) : inchangé. */
body.shell-on .ai-sidebar { left: var(--gs-rail-w); z-index: 80; }
body.shell-on #ai-chat-view.sidebar-collapsed .ai-sidebar { left: calc(var(--gs-rail-w) - 280px); }
body.shell-on .ai-sidebar-toggle { left: calc(var(--gs-rail-w) + 280px); z-index: 85; }
body.shell-on #ai-chat-view.sidebar-collapsed .ai-sidebar-toggle { left: var(--gs-rail-w); }
/* Replié : le panneau se range SOUS le rail (z-index 80 < rail 90) — le rail
   reste intact, le panneau disparaît entièrement derrière lui. */
@media (max-width: 860px) {
  /* La vue IA est ÉPINGLÉE au viewport entre la topbar et la tabbar :
     un calc de hauteur en flux dépendait de ce qui rend au-dessus (toolbar
     modèle, marges) et le composer passait sous le pli — les utilisateurs
     croyaient qu'on ne peut pas écrire. position:fixed = déterministe. */
  body.shell-on #ai-chat-view {
    position: fixed;
    top: calc(47px + env(safe-area-inset-top)); /* même offset que chat/tasks */
    bottom: calc(var(--gs-tabbar-h, 62px) + env(safe-area-inset-bottom));
    left: 0; right: 0;
    height: auto;
    z-index: 50; /* au-dessus du contenu, sous topbar(80)/tabbar */
    overflow: hidden;
  }
  body.shell-on .ai-sidebar { left: 0; z-index: 100; }
  body.shell-on #ai-chat-view.sidebar-collapsed .ai-sidebar { left: -300px; }
  /* display:flex ré-annule le display:none mobile historique — sans ce bouton,
     le panneau de conversations est indélogeable sur mobile. */
  body.shell-on .ai-sidebar-toggle { display: flex; left: 280px; z-index: 101; }
  body.shell-on #ai-chat-view.sidebar-collapsed .ai-sidebar-toggle { left: 0; }
  /* Panneau ouvert : flèche bien visible, collée au bord droit du panneau
     (avant : petit onglet terre-sur-terre quasi invisible). */
  body.shell-on #ai-chat-view:not(.sidebar-collapsed) .ai-sidebar-toggle {
    width: 26px; height: 60px;
    background: #A8863F; color: #fff;
    box-shadow: 2px 0 8px rgba(0,0,0,.35);
  }
  /* Tap en dehors du panneau = fermer (l'overlay appelle closeAiSidebar) */
  body.shell-on .ai-sidebar-overlay.open {
    display: block; position: fixed; inset: 0;
    z-index: 99; background: rgba(15,12,8,.45);
  }
}

/* =====================================================================
   MODE SOMBRE — surcharges body[data-gtheme="dark"] (vue Agent IA)
   Palette shell : fond #201d19, panneaux #2b2823 / #332f28,
   texte rgba(255,255,255,.92/.62/.40), lignes rgba(221,203,164,.14),
   accent or #DDCBA4, ombres rgba(0,0,0,.3).
   Ne modifie aucune règle claire : uniquement des surcharges.
   ===================================================================== */

/* ---- Vue & en-tête ---- */
body[data-gtheme="dark"] #ai-chat-view { background: #201d19; }
body[data-gtheme="dark"] .ai-chat-header {
    background: #2b2823;
    border-bottom-color: rgba(221,203,164,.14);
}
body[data-gtheme="dark"] .ai-model-select {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.92);
}
body[data-gtheme="dark"] .ai-model-select:hover,
body[data-gtheme="dark"] .ai-model-select:focus { border-color: rgba(221,203,164,.35); }
body[data-gtheme="dark"] .ai-model-label { color: rgba(255,255,255,.40); }
body[data-gtheme="dark"] .ai-mode-ribbon {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
}
body[data-gtheme="dark"] .ai-mode-chip { color: rgba(255,255,255,.72); }
body[data-gtheme="dark"] .ai-mode-chip:hover { background: rgba(221,203,164,.13); }
body[data-gtheme="dark"] .ai-mode-chip.active {
    background: #DDCBA4;
    color: #201d19;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
body[data-gtheme="dark"] .ai-speed-switch {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
}
body[data-gtheme="dark"] .ai-speed-opt { color: rgba(255,255,255,.72); }
body[data-gtheme="dark"] .ai-speed-opt:hover { background: rgba(221,203,164,.13); }
body[data-gtheme="dark"] .ai-speed-opt.active {
    background: #DDCBA4;
    color: #201d19;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
/* ── Panneau Mode Image (mini-studio) — thème sombre ── */
body[data-gtheme="dark"] .ai-image-panel {
    background: rgba(30, 28, 24, 0.5);
    border-top-color: rgba(221, 203, 164, 0.14);
}
body[data-gtheme="dark"] .ai-img-chip,
body[data-gtheme="dark"] .ai-img-intent-btn,
body[data-gtheme="dark"] .ai-img-custom-input {
    background: #2b2823;
    border-color: rgba(221, 203, 164, 0.18);
    color: rgba(255, 255, 255, 0.82);
}
body[data-gtheme="dark"] .ai-img-chip:hover,
body[data-gtheme="dark"] .ai-img-intent-btn:hover {
    background: rgba(221, 203, 164, 0.13);
    border-color: rgba(221, 203, 164, 0.4);
}
body[data-gtheme="dark"] .ai-img-chip.active,
body[data-gtheme="dark"] .ai-img-intent-btn.active {
    background: #DDCBA4;
    color: #201d19;
    border-color: #DDCBA4;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
body[data-gtheme="dark"] .ai-img-chip-suggested:not(.active) { border-color: rgba(221, 203, 164, 0.4); }
body[data-gtheme="dark"] .ai-img-row-label,
body[data-gtheme="dark"] .ai-img-hint,
body[data-gtheme="dark"] .ai-img-custom-x { color: rgba(255, 255, 255, 0.5); }
/* ── Puce « Mode détecté » (coordinateur v1) — thème sombre ── */
body[data-gtheme="dark"] .ai-mode-detected {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.82);
}
body[data-gtheme="dark"] .ai-mode-detected-correct {
    background: rgba(221,203,164,.13);
    color: rgba(255,255,255,.82);
}
body[data-gtheme="dark"] .ai-mode-detected-correct:hover { background: rgba(221,203,164,.22); }
body[data-gtheme="dark"] .ai-mode-detected-menu {
    background: #2b2823;
    border-color: rgba(221,203,164,.22);
    box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
body[data-gtheme="dark"] .ai-mode-detected-opt { color: rgba(255,255,255,.82); }
body[data-gtheme="dark"] .ai-mode-detected-opt:hover { background: rgba(221,203,164,.13); }
body[data-gtheme="dark"] .ai-share-btn,
body[data-gtheme="dark"] .ai-voice-mode-btn,
body[data-gtheme="dark"] .ai-popup-btn,
body[data-gtheme="dark"] .ai-memory-btn {
    border-color: rgba(221,203,164,.22);
    color: rgba(255,255,255,.72);
}
body[data-gtheme="dark"] .ai-share-btn:hover,
body[data-gtheme="dark"] .ai-voice-mode-btn:hover,
body[data-gtheme="dark"] .ai-popup-btn:hover,
body[data-gtheme="dark"] .ai-memory-btn:hover {
    background: rgba(221,203,164,.13);
    color: rgba(255,255,255,.92);
}

/* ============================================== */
/* --- Mode POPUP — assistant IA détaché         --- */
/* Fenêtre séparée (?view=ai&popup=1) : on masque TOUTE la coquille du hub   */
/* (rail, topbar/tabbar mobiles, header, dashboard, footer, widgets flottants)*/
/* pour que l'assistant occupe 100 % de la fenêtre. On ne touche qu'au layout*/
/* (display/tailles) — aucune couleur : les deux thèmes restent corrects via */
/* les variables existantes.                                                  */
/* ============================================== */
body.ai-popup-mode .gshell-rail,
body.ai-popup-mode .gshell-topbar,
body.ai-popup-mode .gshell-tabbar,
body.ai-popup-mode .main-header,
body.ai-popup-mode main.container-dashboard,
body.ai-popup-mode .app-footer,
body.ai-popup-mode #chatbot-toggle,
body.ai-popup-mode #bug-report-btn {
    display: none !important;
}

/* La coquille décale #app-content pour le rail (padding-left) et la tabbar
   (padding-bottom) : en mode popup on repart de zéro. */
body.ai-popup-mode #app-content {
    padding-left: 0 !important;
    padding-bottom: 0 !important;
}

/* L'assistant prend toute la fenêtre popup. On IMPOSE le layout complet
   (!important) : le mode shell épingle #ai-chat-view sous sa topbar (masquée
   ici) et repositionnait la sidebar → chevauchement du header du chat. */
body.ai-popup-mode #ai-chat-view {
    position: fixed !important;
    top: 0 !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 50;
}
/* ≥769px : sidebar fixe à gauche + chat décalé (côte à côte, comme au bureau). */
@media (min-width: 769px) {
    body.ai-popup-mode .ai-sidebar { position: fixed !important; top: 0 !important; bottom: 0 !important; left: 0 !important; width: 280px !important; transform: none !important; }
    body.ai-popup-mode .ai-chat-main { margin-left: 280px !important; }
    body.ai-popup-mode #ai-chat-view.sidebar-collapsed .ai-sidebar { left: -280px !important; }
    body.ai-popup-mode #ai-chat-view.sidebar-collapsed .ai-chat-main { margin-left: 0 !important; }
    body.ai-popup-mode .ai-sidebar-overlay { display: none !important; }
}
/* ≤768px : on laisse le comportement mobile existant (drawer + hamburger). */

/* Dans une fenêtre déjà détachée : ni « détacher », ni « Retour à Gandalf »
   (la fenêtre EST l'assistant ; elle se ferme par la croix système). */
body.ai-popup-mode #ai-popup-btn,
body.ai-popup-mode .ai-sidebar-back {
    display: none !important;
}

/* Bouton de repli de la sidebar : le shell le calait à rail+280px, mais le
   rail est masqué en popup → il flottait au milieu. Ici : collé à la sidebar. */
body.ai-popup-mode .ai-sidebar-toggle { left: 280px !important; }
body.ai-popup-mode #ai-chat-view.sidebar-collapsed .ai-sidebar-toggle { left: 0 !important; }
body[data-gtheme="dark"] .ai-mobile-menu-btn {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.85);
}
body[data-gtheme="dark"] .ai-mobile-menu-btn:hover { background: rgba(221,203,164,.13); }

/* ---- Écran d'accueil (welcome) ---- */
body[data-gtheme="dark"] .ai-chat-welcome { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-chat-welcome h3 { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-chat-welcome p { color: rgba(255,255,255,.62); }
body[data-gtheme="dark"] .ai-expert-picker {
    background: rgba(43,40,35,.72);
    border-color: rgba(221,203,164,.22);
}
body[data-gtheme="dark"] .ai-expert-title { color: rgba(255,255,255,.45); }
body[data-gtheme="dark"] .ai-brand-chip {
    background: #2b2823;
    color: var(--brand, #DDCBA4);
}
body[data-gtheme="dark"] .ai-brand-chip:hover { background: rgba(221,203,164,.13); }
body[data-gtheme="dark"] .ai-brand-chip.active {
    background: var(--brand, #DDCBA4);
    color: #201d19;
    box-shadow: 0 6px 16px rgba(0,0,0,.4);
}
body[data-gtheme="dark"] .ai-metier-card {
    background: #2b2823;
    border-color: rgba(221,203,164,.18);
    color: rgba(255,255,255,.85);
}
body[data-gtheme="dark"] .ai-metier-card:hover {
    border-color: rgba(221,203,164,.4);
    box-shadow: 0 10px 22px rgba(0,0,0,.4);
}
body[data-gtheme="dark"] .ai-mode-card {
    background: #2b2823;
    border-color: rgba(221,203,164,.18);
}
body[data-gtheme="dark"] .ai-mode-card:hover {
    border-color: rgba(221,203,164,.4);
    box-shadow: 0 10px 22px rgba(0,0,0,.4);
}
body[data-gtheme="dark"] .ai-mode-card-title { color: rgba(255,255,255,.85); }
body[data-gtheme="dark"] .ai-mode-card-desc { color: rgba(255,255,255,.5); }
body[data-gtheme="dark"] .ai-mode-card.active {
    background: #DDCBA4;
    border-color: #DDCBA4;
}
body[data-gtheme="dark"] .ai-mode-card.active .ai-mode-card-title,
body[data-gtheme="dark"] .ai-mode-card.active .ai-mode-card-desc {
    color: #201d19;
}
body[data-gtheme="dark"] .ai-mode-pill {
    background: #2b2823;
    border-color: rgba(221,203,164,.18);
    color: rgba(255,255,255,.85);
}
body[data-gtheme="dark"] .ai-mode-pill:hover {
    border-color: rgba(221,203,164,.4);
    box-shadow: 0 6px 16px rgba(0,0,0,.4);
}
body[data-gtheme="dark"] .ai-mode-pill.active {
    background: #DDCBA4;
    border-color: #DDCBA4;
    color: #201d19;
}
body[data-gtheme="dark"] .ai-expert-toggle { color: rgba(255,255,255,.5); }
body[data-gtheme="dark"] .ai-expert-toggle:hover {
    color: rgba(255,255,255,.85);
    background: rgba(221,203,164,.13);
}
body[data-gtheme="dark"] .ai-suggestion {
    background: rgba(43,40,35,.78);
    border-color: rgba(221,203,164,.2);
    color: rgba(255,255,255,.8);
}
body[data-gtheme="dark"] .ai-suggestion:hover {
    background: rgba(51,47,40,.95);
    border-color: rgba(221,203,164,.4);
    box-shadow: 0 12px 28px rgba(0,0,0,.4);
}
body[data-gtheme="dark"] .ai-suggestion::before {
    background: linear-gradient(100deg, transparent, rgba(255,255,255,.08), transparent);
}

/* ---- Bulles de messages & contenu Markdown ---- */
body[data-gtheme="dark"] .ai-msg-assistant {
    background: #2b2823;
    color: rgba(255,255,255,.88);
    border-color: rgba(221,203,164,.16);
    box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
body[data-gtheme="dark"] .ai-msg-user {
    background: linear-gradient(135deg, #3d382f 0%, #332f28 100%);
    box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
body[data-gtheme="dark"] .ai-msg h2 { border-bottom-color: rgba(221,203,164,.3); }
body[data-gtheme="dark"] .ai-msg hr { border-top-color: rgba(255,255,255,.12); }
body[data-gtheme="dark"] .ai-table-wrap { border-color: rgba(221,203,164,.14); }
body[data-gtheme="dark"] .ai-table td { border-bottom-color: rgba(255,255,255,.08); }
body[data-gtheme="dark"] .ai-table code { background: rgba(255,255,255,.08); }
body[data-gtheme="dark"] .ai-code-block { border-color: rgba(255,255,255,.1); }
body[data-gtheme="dark"] .ai-loader-hint { color: rgba(255,255,255,.55); }
body[data-gtheme="dark"] .ai-msg-file-chip {
    background: rgba(221,203,164,.15);
    color: rgba(255,255,255,.7);
}

/* Réponses cliquables */
body[data-gtheme="dark"] .ai-choice-btn {
    background: #332f28;
    border-color: rgba(221,203,164,.35);
    color: #DDCBA4;
}
body[data-gtheme="dark"] .ai-choice-btn:hover {
    background: rgba(221,203,164,.13);
    box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
body[data-gtheme="dark"] .ai-choice-btn.ai-choice-other { color: rgba(255,255,255,.5); }
body[data-gtheme="dark"] .ai-choices.answered .ai-choice-btn.picked {
    background: #DDCBA4;
    color: #201d19;
    border-color: #DDCBA4;
}

/* Actions sous les messages */
body[data-gtheme="dark"] .ai-msg-actions button {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.62);
}
body[data-gtheme="dark"] .ai-msg-actions button:hover {
    background: rgba(221,203,164,.13);
    border-color: rgba(221,203,164,.3);
    color: rgba(255,255,255,.85);
}
body[data-gtheme="dark"] .ai-action-regen {
    border-color: rgba(221,203,164,.35) !important;
    color: #DDCBA4 !important;
}
body[data-gtheme="dark"] .ai-feedback-btn.active {
    background: rgba(221,203,164,.25) !important;
    border-color: #DDCBA4 !important;
    color: #DDCBA4;
}

/* ---- Composer (zone de saisie) ---- */
body[data-gtheme="dark"] .ai-chat-input {
    background: #2b2823;
    border-top-color: rgba(221,203,164,.14);
}
body[data-gtheme="dark"] .ai-chat-textarea {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.92);
}
body[data-gtheme="dark"] .ai-chat-textarea::placeholder { color: rgba(255,255,255,.40); }
body[data-gtheme="dark"] .ai-chat-textarea:focus { border-color: rgba(221,203,164,.45); }
body[data-gtheme="dark"] .ai-attach-btn {
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.7);
}
body[data-gtheme="dark"] .ai-attach-btn:hover { background: rgba(221,203,164,.13); }
body[data-gtheme="dark"] .ai-file-thumb { border-color: rgba(221,203,164,.16); }
body[data-gtheme="dark"] .ai-file-thumb-doc { background: #332f28; }
body[data-gtheme="dark"] .ai-file-thumb-name { color: rgba(255,255,255,.55); }

/* ---- Panneau admin Gandalf (stats, blocages, synthèses) ---- */
body[data-gtheme="dark"] .ai-stat-card { background: #332f28; }
body[data-gtheme="dark"] .ai-stat-value { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-admin-section h4 { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-block-input {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.92);
}
body[data-gtheme="dark"] .ai-blocked-item {
    background: #332f28;
    color: rgba(255,255,255,.85);
}
body[data-gtheme="dark"] .btn-sm {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.85);
}
body[data-gtheme="dark"] .btn-sm:hover { background: rgba(221,203,164,.13); }
body[data-gtheme="dark"] .ai-synthesis-item { background: #332f28; }
body[data-gtheme="dark"] .ai-synthesis-item:hover { background: rgba(221,203,164,.2); }
body[data-gtheme="dark"] .ai-synthesis-date { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-synthesis-content {
    background: #2b2823;
    color: rgba(255,255,255,.85);
    box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
body[data-gtheme="dark"] .ai-synthesis-header h3 { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-synthesis-text { color: rgba(255,255,255,.85); }
body[data-gtheme="dark"] .ai-synthesis-meta-detail { border-bottom-color: rgba(221,203,164,.14); }
body[data-gtheme="dark"] .ai-synthesis-close:hover { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-detail-info { border-bottom-color: rgba(221,203,164,.14); }
body[data-gtheme="dark"] .ai-detail-user { background: #3d382f; }
body[data-gtheme="dark"] .ai-detail-assistant {
    background: #332f28;
    color: rgba(255,255,255,.85);
}

/* ---- Agents personnalisés (formulaire, cartes, templates) ---- */
body[data-gtheme="dark"] .ai-agent-form { border-top-color: rgba(221,203,164,.14); }
body[data-gtheme="dark"] .ai-agent-form label { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-agent-form input,
body[data-gtheme="dark"] .ai-agent-form textarea,
body[data-gtheme="dark"] .ai-agent-form select {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.92);
}
body[data-gtheme="dark"] .ai-agent-form input:focus,
body[data-gtheme="dark"] .ai-agent-form textarea:focus,
body[data-gtheme="dark"] .ai-agent-form select:focus { border-color: rgba(221,203,164,.45); }
body[data-gtheme="dark"] .ai-agent-card { background: #332f28; }
body[data-gtheme="dark"] .ai-agent-card-name { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-agent-manage-btn {
    border-color: rgba(221,203,164,.16);
    color: rgba(255,255,255,.85);
}
body[data-gtheme="dark"] .ai-agent-manage-btn:hover { background: rgba(221,203,164,.13); }
body[data-gtheme="dark"] .ai-agent-templates {
    background: rgba(221,203,164,.06);
    border-color: rgba(221,203,164,.16);
}
body[data-gtheme="dark"] .ai-agent-templates-label { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-agent-template {
    background: #332f28;
    border-color: rgba(221,203,164,.16);
}
body[data-gtheme="dark"] .ai-agent-template span { color: rgba(255,255,255,.62); }
body[data-gtheme="dark"] .ai-agent-template:hover {
    background: rgba(221,203,164,.13);
    border-color: rgba(221,203,164,.35);
    box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
body[data-gtheme="dark"] .ai-agent-drive-info p { color: rgba(255,255,255,.62); }
body[data-gtheme="dark"] .ai-drive-file-name { color: rgba(255,255,255,.85); }
body[data-gtheme="dark"] .agent-doc-item { background: rgba(255,255,255,.05); }

/* ---- Panneau mémoire (🧠) ---- */
body[data-gtheme="dark"] .ai-memory-panel {
    background: rgba(43,40,35,.97);
    border-color: rgba(221,203,164,.25);
    box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(221,203,164,.1);
}
body[data-gtheme="dark"] .ai-memory-header h3 { color: rgba(255,255,255,.92); }
body[data-gtheme="dark"] .ai-memory-close:hover {
    background: rgba(255,255,255,.08);
    color: rgba(255,255,255,.92);
}
body[data-gtheme="dark"] .ai-memory-hint { color: rgba(255,255,255,.5); }
body[data-gtheme="dark"] .ai-memory-text { color: rgba(255,255,255,.85); }

/* Accueil GANDALF : médaillon officiel (l'image contient chapeau + anneau or) */
.ai-chat-welcome-icon.ai-welcome-gandalf{background:none;box-shadow:none}
.ai-chat-welcome-icon.ai-welcome-gandalf img{width:112px;height:112px;margin-top:-14px;filter:drop-shadow(0 10px 26px rgba(40,34,24,.35))}
.ai-chat-welcome-icon.ai-welcome-gandalf::after{inset:2px 2px -2px 2px}

/* --- Vidéo générée (Mode Vidéo Veo) --- */
.ai-msg-generated-video {
    position: relative;
    margin-top: 10px;
    max-width: 480px;
}
.ai-msg-generated-video video {
    width: 100%;
    border-radius: 12px;
    background: #000;
    display: block;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}
.ai-msg-generated-video:hover .ai-img-download-btn,
.ai-msg-generated-video:focus-within .ai-img-download-btn { opacity: 1; }
.ai-msg-generated-video .ai-img-download-btn {
    position: absolute;
    top: 8px;
    right: 8px;
}
.ai-msg-generated-video .ai-img-studio-btn,
.ai-msg-generated-video button + button {
    position: absolute;
    top: 8px;
    right: 48px;
}

/* --- Navigation entre variantes de réponse (régénération non destructive) --- */
.ai-variant-nav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 11.5px;
    color: #a3937a;
}
.ai-variant-nav button {
    border: 1px solid rgba(120, 100, 70, 0.3);
    background: transparent;
    border-radius: 6px;
    width: 22px; height: 22px;
    cursor: pointer;
    color: inherit;
    font-size: 13px;
    line-height: 1;
}
.ai-variant-nav button:disabled { opacity: 0.35; cursor: default; }
.ai-variant-nav button:not(:disabled):hover { background: rgba(221, 203, 164, 0.2); }
body[data-gtheme="dark"] .ai-variant-nav { color: rgba(255,255,255,.5); }
body[data-gtheme="dark"] .ai-variant-nav button { border-color: rgba(221,203,164,.25); }
body[data-gtheme="dark"] .ai-variant-nav button:not(:disabled):hover { background: rgba(221,203,164,.13); }

/* ===== GANDALF Voice — session vocale temps réel ===== */
.ai-voice-live {
    position: absolute; inset: 0; z-index: 60;
    display: flex; flex-direction: column; gap: 12px;
    background: rgba(30, 27, 22, 0.98);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-radius: 16px; padding: 20px;
}
.ai-voice-live.hidden { display: none; }
.ai-voice-live-head { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; color: #F1EADA; }
.ai-voice-live-timer { margin-left: auto; font-variant-numeric: tabular-nums; opacity: 0.7; }
.ai-voice-live-voicebtn { background: rgba(255,255,255,0.06); border: 1px solid rgba(196,169,125,0.25); color: #F1EADA; border-radius: 10px; padding: 3px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }
.ai-voice-live-voicebtn:hover { background: rgba(196,169,125,0.18); }
.ai-voice-live-orb { width: 14px; height: 14px; border-radius: 50%; background: #27ae60; animation: ai-voice-dot-blink 1.2s ease-in-out infinite; }
.ai-voice-live[data-state="thinking"] .ai-voice-live-orb { background: #e67e22; }
.ai-voice-live[data-state="speaking"] .ai-voice-live-orb { background: #C4A97D; }
.ai-voice-live[data-state="reconnecting"] .ai-voice-live-orb { background: #e74c3c; }
.ai-voice-live-transcript { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.45; color: #F1EADA; }
.ai-voice-live-line.ai-voice-live-user { align-self: flex-end; background: rgba(196, 169, 125, 0.18); border-radius: 12px 12px 2px 12px; padding: 8px 12px; max-width: 85%; }
.ai-voice-live-line.ai-voice-live-assistant { align-self: flex-start; background: rgba(255, 255, 255, 0.06); border-radius: 12px 12px 12px 2px; padding: 8px 12px; max-width: 85%; }
.ai-voice-live-actions { display: flex; gap: 12px; }
.ai-voice-live-btn {
    flex: 1; min-height: 56px; border: 1px solid rgba(196, 169, 125, 0.25); border-radius: 14px;
    background: rgba(255, 255, 255, 0.06); color: #F1EADA; font-size: 16px; font-weight: 600; cursor: pointer;
}
.ai-voice-live-btn.ai-voice-live-muted { background: rgba(231, 76, 60, 0.25); border-color: #e74c3c; }
.ai-voice-live-hangup { background: rgba(231, 76, 60, 0.85); border-color: transparent; }

/* ===== Carte de confirmation « action sensible » (chat écrit) — calquée sur .ai-draft-send ===== */
.ai-pending-action { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: rgba(231, 126, 34, 0.10); border: 1px solid rgba(231, 126, 34, 0.35); }
.ai-pending-info { font-size: 13px; color: inherit; }
.ai-pending-btn { border: 1px solid rgba(196,169,125,0.35); border-radius: 10px; padding: 4px 12px; font-size: 13px; font-weight: 600; cursor: pointer; background: rgba(255,255,255,0.06); color: inherit; }
.ai-pending-confirm { background: rgba(39, 174, 96, 0.2); border-color: rgba(39,174,96,0.5); }
.ai-pending-btn:disabled { opacity: 0.5; cursor: default; }
.ai-pending-status { font-size: 13px; font-weight: 600; }
@media (max-width: 768px) { .ai-voice-live { border-radius: 0; padding: 16px; } .ai-voice-live-btn { min-height: 64px; } }

/* ===== Assistant Hey Gandalf (essai) ===== */
@media (max-width: 768px) { .ai-popup-btn { display: none; } } /* 🗗 inutile au doigt */
.ai-wake-btn { min-width: 34px; }
.ai-wake-btn.ai-wake-armed { background: rgba(39, 174, 96, 0.25); border-color: rgba(39, 174, 96, 0.6); box-shadow: 0 0 8px rgba(39, 174, 96, 0.4); }
.ai-wake-banner { display: flex; flex-direction: column; align-items: center; gap: 2px; justify-content: center; padding: 4px 10px; font-size: 12.5px; opacity: 0.85; border-radius: 10px; margin: 0 0 4px; background: rgba(39, 174, 96, 0.12); border: 1px dashed rgba(39, 174, 96, 0.4); }
.ai-wake-privacy { font-size: 11px; opacity: 0.8; text-align: center; }
.ai-wake-banner.hidden { display: none; }
