/* Atelier IA chat — thème du site (sombre, dense, pro). */
.ai-page {
    max-width: 860px;
    margin: 0 auto;
    padding: 2.2rem 1rem 4rem;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 220px);
}

.ai-head {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-bottom: 1.1rem;
}

.ai-head-top {
    display: flex;
    align-items: center;
    gap: .7rem;
    flex-wrap: wrap;
}

.ai-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: 0;
}

.ai-bolt {
    color: #f7931a;
    filter: drop-shadow(0 0 10px rgba(247, 147, 26, .45));
}

.ai-badge {
    font-size: .72rem;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .18rem .6rem;
    background: var(--surface-1);
}

/* Sélecteur de modèle : deux cartes-radio, la promesse (sous-titre) vient
   du catalogue. États : aria-checked = choisi, data-etat = actif | chargement
   | echec, data-disponible=false = fichier pas encore téléchargé. */
.ai-models {
    display: grid;
    grid-template-columns: 1fr;
    gap: .5rem;
    margin-top: .3rem;
}

@media (min-width: 520px) {
    .ai-models { grid-template-columns: repeat(2, 1fr); }
}

.ai-model {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name tag" "sub tag";
    align-items: center;
    column-gap: .6rem;
    row-gap: .1rem;
    text-align: left;
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    transition: border-color .18s, background .18s, transform .12s;
}

.ai-model:hover { border-color: var(--border-accent); background: var(--accent-dim); }
.ai-model:active { transform: translateY(1px); }
.ai-model:focus-visible { outline: 2px solid #f7931a; outline-offset: 2px; }

.ai-model[aria-checked="true"] {
    border-color: #f7931a;
    background: rgba(247, 147, 26, .08);
    box-shadow: inset 0 0 0 1px rgba(247, 147, 26, .35);
}

.ai-model[data-disponible="false"] {
    opacity: .55;
    cursor: not-allowed;
}

.ai-model[disabled] { cursor: wait; }

.ai-model-name {
    grid-area: name;
    font-weight: 700;
    font-size: .92rem;
    letter-spacing: -0.01em;
}

.ai-model-sub {
    grid-area: sub;
    font-size: .76rem;
    color: var(--text-3);
}

.ai-model-tag {
    grid-area: tag;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .66rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .12rem .5rem;
}

.ai-model-tag:empty { display: none; }

.ai-model[data-etat="actif"] .ai-model-tag { color: #6fd39a; border-color: rgba(111, 211, 154, .45); }
.ai-model[data-etat="chargement"] .ai-model-tag { color: #f7931a; border-color: rgba(247, 147, 26, .5); animation: ai-blink 1.2s steps(1) infinite; }
.ai-model[data-etat="echec"] .ai-model-tag { color: #ff9d9d; border-color: rgba(220, 60, 60, .4); }

@keyframes ai-blink { 50% { opacity: .35; } }

.ai-model-desc {
    margin: .15rem 0 0;
    font-size: .82rem;
    line-height: 1.5;
    color: var(--text-2);
}

.ai-model-note {
    margin: 0;
    font-size: .76rem;
    line-height: 1.5;
}

.ai-model-note[data-kind="chargement"] { color: #f7931a; }
.ai-model-note[data-kind="echec"] { color: #ff9d9d; }

.ai-model-note .btn { margin-left: .4rem; vertical-align: baseline; }

.ai-meta {
    display: flex;
    gap: .9rem;
    flex-wrap: wrap;
    font-size: .78rem;
    color: var(--text-3);
}

.ai-wallet {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .74rem;
}

/* Indicateur d'état pense / écrit / repos — petite pastille + libellé.
   Le libellé n'est pas figé : un balayage de lumière le traverse et des
   points de suspension s'égrènent (rendus en pseudo-élément, donc invisibles
   pour les lecteurs d'écran : aucune annonce répétée). */
.ai-state {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .74rem;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .15rem .65rem;
    background: var(--surface-1);
    width: fit-content;
    margin-top: .15rem;
    transition: border-color .4s, color .4s;
}

.ai-state-orb {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3a3d42;
    transition: background .4s, box-shadow .4s;
}

.ai-state[data-state="think"] {
    border-color: rgba(255,169,64,.5);
    color: var(--text-2);
}
.ai-state[data-state="think"] .ai-state-orb {
    background: #f7931a;
    box-shadow: 0 0 10px rgba(247,147,26,.8);
    animation: ai-orb-pulse 1s ease-in-out infinite;
}

.ai-state[data-state="write"] {
    border-color: rgba(255,200,120,.7);
    color: var(--text);
}
.ai-state[data-state="write"] .ai-state-orb {
    background: #ffd9a0;
    box-shadow: 0 0 14px rgba(255,200,120,1);
    animation: ai-orb-write .8s steps(1) infinite;
}

@keyframes ai-orb-pulse {
    0%, 100% { transform: scale(1); opacity: .9; }
    50% { transform: scale(1.45); opacity: 1; }
}

@keyframes ai-orb-write {
    0%, 49% { transform: scale(1.15); }
    50%, 100% { transform: scale(.8); }
}

/* ── Le libellé d'état vit : balayage + points qui s'égrènent ── */
.ai-state-label {
    /* réserve la place des points pour éviter tout saut de largeur */
    white-space: nowrap;
}

.ai-state[data-state="think"] .ai-state-label,
.ai-state[data-state="write"] .ai-state-label {
    background-image: linear-gradient(100deg,
        var(--text-2) 0%, var(--text-2) 38%,
        #ffd9a0 50%,
        var(--text-2) 62%, var(--text-2) 100%);
    background-size: 280% 100%;
    background-position: 100% 0;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: ai-shimmer 3s linear infinite;
}

.ai-state[data-state="write"] .ai-state-label {
    background-image: linear-gradient(100deg,
        var(--text) 0%, var(--text) 38%,
        #ffe6c0 50%,
        var(--text) 62%, var(--text) 100%);
    animation-duration: 1.9s;
}

/* Les points : toujours présents dans le flux (pas de reflow), révélés un à
   un par clip-path — animation de compositing, zéro impact sur la mise en page. */
.ai-state[data-state="think"] .ai-state-label::after,
.ai-state[data-state="write"] .ai-state-label::after {
    content: '···';
    letter-spacing: .05em;
    animation: ai-ellipsis 1.5s infinite;
}

@keyframes ai-shimmer {
    to { background-position: -180% 0; }
}

@keyframes ai-ellipsis {
    0%,   24%  { clip-path: inset(0 100% 0 0); }
    25%,  49%  { clip-path: inset(0 66.7% 0 0); }
    50%,  74%  { clip-path: inset(0 33.4% 0 0); }
    75%, 100%  { clip-path: inset(0 0 0 0); }
}

/* Mini-spectre d'ondes : n'apparaît qu'en écriture, écho du choc du trou noir */
.ai-state-wave {
    display: none;
    align-items: flex-end;
    gap: 2px;
    height: 9px;
    margin-left: .05rem;
}

.ai-state[data-state="write"] .ai-state-wave { display: inline-flex; }

.ai-state-wave i {
    width: 2px;
    height: 100%;
    border-radius: 1px;
    background: #ffd9a0;
    box-shadow: 0 0 6px rgba(255, 200, 120, .55);
    transform: scaleY(.25);
    transform-origin: bottom;
    animation: ai-wave .9s ease-in-out infinite;
}
.ai-state-wave i:nth-child(2) { animation-delay: .15s; }
.ai-state-wave i:nth-child(3) { animation-delay: .3s; }

@keyframes ai-wave {
    0%, 100% { transform: scaleY(.25); }
    50%      { transform: scaleY(1); }
}

/* Pastille « slots GPU libres » — temps réel */
.ai-slots {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .74rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .15rem .65rem;
    background: var(--surface-1);
    width: fit-content;
    margin-top: .15rem;
    transition: border-color .4s, color .4s;
}

.ai-slots-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3a3d42;
    transition: background .4s, box-shadow .4s;
}

.ai-slots[data-level="full"] {
    border-color: rgba(120, 220, 120, .45);
    color: var(--text-2);
}
.ai-slots[data-level="full"] .ai-slots-dot {
    background: #5ecf6a;
    box-shadow: 0 0 8px rgba(94, 207, 106, .6);
}

.ai-slots[data-level="half"] {
    border-color: rgba(255, 200, 120, .5);
}
.ai-slots[data-level="half"] .ai-slots-dot {
    background: #f7931a;
    box-shadow: 0 0 8px rgba(247, 147, 26, .6);
}

.ai-slots[data-level="busy"] {
    border-color: rgba(255, 100, 100, .5);
}
.ai-slots[data-level="busy"] .ai-slots-dot {
    background: #ff5f5f;
    box-shadow: 0 0 8px rgba(255, 95, 95, .6);
    animation: ai-orb-pulse .8s ease-in-out infinite;
}

.ai-chat {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .9rem;
    padding: .4rem 0 1rem;
    min-height: 320px;
    max-height: 58vh;
}

.ai-empty {
    text-align: center;
    margin: auto;
    color: var(--text-3);
    font-size: .92rem;
    line-height: 1.6;
}

.ai-empty p { margin: .2rem 0; }

.ai-msg {
    max-width: 88%;
    padding: .7rem .95rem;
    border-radius: 14px;
    font-size: .92rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg b, .ai-msg strong { color: var(--text); }
.ai-msg em { color: var(--text-2); }
.ai-msg code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .82em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: .05rem .3rem;
}
.ai-msg pre {
    background: #0b0c0e;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .7rem .9rem;
    overflow-x: auto;
    font-size: .8rem;
    line-height: 1.45;
}
.ai-msg pre code { background: none; border: none; padding: 0; }

/* ── Bloc de code isolé : conteneur propre, copiable, téléchargeable ── */
.ai-msg .code-block {
    margin: .6rem 0;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #08090b;
    overflow: hidden;
    white-space: normal;
}

.code-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .3rem .35rem .3rem .7rem;
    background: rgba(255, 255, 255, .025);
    border-bottom: 1px solid var(--border);
}

.code-block-lang {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .7rem;
    letter-spacing: .03em;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.code-block-actions {
    display: flex;
    gap: .3rem;
    flex-shrink: 0;
}

/* Boutons répétés EN BAS du bloc de code : après une longue réponse, on ne
   remonte plus chercher celui du haut. */
.code-block-foot {
    display: flex;
    justify-content: flex-end;
    padding: .28rem .35rem;
    border-top: 1px solid rgba(255, 255, 255, .06);
    background: rgba(255, 255, 255, .02);
}

/* Barre de fin de réponse : copier / télécharger toute la réponse. */
.ai-msg-actions {
    display: flex;
    gap: .4rem;
    justify-content: flex-end;
    margin-top: .55rem;
}

.code-block-btn {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .7rem;
    line-height: 1.4;
    color: var(--text-3);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .12rem .5rem;
    cursor: pointer;
    white-space: nowrap;
    transition: color .18s, background .18s, border-color .18s;
}

.code-block-btn:hover {
    color: var(--text);
    background: rgba(247, 147, 26, .12);
    border-color: rgba(247, 147, 26, .5);
}

.code-block-btn:active { transform: translateY(1px); }

.code-block-btn.is-done {
    color: #ffd9a0;
    background: rgba(247, 147, 26, .16);
    border-color: rgba(247, 147, 26, .6);
}

/* Bouton « Nouvelle » en attente de confirmation (deux temps, sur place —
   pas de dialogue système qui jurerait avec le reste de la page). */
.ai-composer .btn.is-warn {
    color: #ffd9a0;
    border-color: rgba(247, 147, 26, .6);
    background: rgba(247, 147, 26, .12);
}

.ai-msg .code-block pre {
    margin: 0;
    border: none;
    border-radius: 0;
    background: none;
    white-space: pre;       /* code long : défilement horizontal, pas de casse */
    word-break: normal;
}
.ai-msg ul, .ai-msg ol { margin: .3rem 0 .3rem 1.2rem; padding: 0; }
.ai-msg h1, .ai-msg h2, .ai-msg h3 { font-size: 1rem; margin: .5rem 0 .2rem; }

.ai-msg--user {
    align-self: flex-end;
    background: rgba(247, 147, 26, .12);
    border: 1px solid rgba(247, 147, 26, .28);
    border-bottom-right-radius: 4px;
}

.ai-msg--assistant {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.ai-msg--error {
    align-self: center;
    background: rgba(220, 60, 60, .1);
    border: 1px solid rgba(220, 60, 60, .3);
    color: #ff9d9d;
    font-size: .85rem;
    max-width: 100%;
}

/* Avis système (modèle prêt) : centré, discret, hors export .zip */
.ai-msg--notice {
    align-self: center;
    background: rgba(111, 211, 154, .08);
    border: 1px solid rgba(111, 211, 154, .3);
    color: #9fe3bc;
    font-size: .85rem;
    max-width: 100%;
}

.ai-msg--busy .ai-dots::after {
    content: '…';
    animation: ai-blink 1.2s steps(1) infinite;
}

/* Message en cours de streaming : petit curseur de frappe */
.ai-msg--streaming::after {
    content: '▍';
    color: #f7931a;
    margin-left: 2px;
    animation: ai-caret 0.9s steps(1) infinite;
}

@keyframes ai-caret { 50% { opacity: 0; } }

.ai-composer {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    background: var(--bg-panel);
    padding: .6rem;
}

.ai-composer textarea {
    width: 100%;
    border: none;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: .92rem;
    resize: none;
    outline: none;
    padding: .3rem .4rem;
    line-height: 1.45;
    max-height: 180px;
}

.ai-composer textarea::placeholder { color: var(--text-4); }

.ai-composer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
}

/* ── Fil d'étapes : ce que fait le modèle, en direct ──
   Une ligne par événement `etape` du serveur ; la ligne en cours porte
   [data-etat="debut"] (point orange qui pulse + temps écoulé), les autres
   sont closes (✓) ou en erreur (✕). Rien ici n'est écrit par le JS de lui-même. */
.ai-etapes {
    margin: .55rem 0 0;
    padding: .5rem .8rem .45rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-1);
    font-size: .78rem;
    color: var(--text-2);
}

.ai-etapes-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .18rem;
    /* Hauteur bornée + défilement propre : le fil peut s'allonger sans jamais
       pousser le bouton Envoyer hors de l'écran (demande du propriétaire). */
    max-height: 4.8rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ai-etape {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    line-height: 1.35;
}

.ai-etape-ico {
    flex: 0 0 auto;
    width: .9em;
    text-align: center;
    color: var(--text-3);
}

.ai-etape[data-etat="debut"] .ai-etape-ico {
    color: #f7931a;
    animation: ai-orb-pulse 1s ease-in-out infinite;
}
.ai-etape[data-etat="fin"] .ai-etape-ico { color: #8fbf6a; }
.ai-etape[data-etat="erreur"] .ai-etape-ico { color: #e06c5a; }

.ai-etape-txt { flex: 1 1 auto; }
.ai-etape[data-etat="debut"] .ai-etape-txt { color: var(--text); }
.ai-etape[data-quoi="outil"] .ai-etape-txt { color: #ffd9a0; }
.ai-etape[data-quoi="contexte"] .ai-etape-txt,
.ai-etape[data-quoi="arret"] .ai-etape-txt { font-style: italic; }
.ai-etape[data-quoi="fin"][data-coupe="true"] .ai-etape-txt { color: #ffb347; }

.ai-etape-meta {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    color: var(--text-3);
    font-size: .72rem;
}

.ai-etapes-actions {
    display: flex;
    justify-content: flex-end;
    gap: .4rem;
    margin-top: .35rem;
}
.ai-etapes-actions:empty,
.ai-etapes-actions:not(:has(button:not([hidden]))) { display: none; }

/* Pastille d'état : appel d'outil — discret, ambre fixe (pas de shimmer) */
.ai-state[data-state="tool"] {
    border-color: rgba(255,217,160,.55);
    color: #ffd9a0;
}
.ai-state[data-state="tool"] .ai-state-orb {
    background: #ffd9a0;
    box-shadow: 0 0 8px rgba(255,217,160,.7);
}

.ai-status {
    min-height: 1.1rem;
    font-size: .78rem;
    text-align: center;
    margin: .4rem 0 0;
}

/* Le texte visible est dans .ai-status-fx (aria-hidden) : il peut tourner et
   se fondre sans que le lecteur d'écran ré-annonce à chaque rotation. */
.ai-status-fx {
    display: inline-block;
    transition: opacity .18s ease, transform .18s ease;
}

.ai-status-fx.is-out {
    opacity: 0;
    transform: translateY(2px);
}

.ai-status.is-busy .ai-status-fx {
    background-image: linear-gradient(100deg,
        var(--text-3) 0%, var(--text-3) 38%,
        #ffd9a0 50%,
        var(--text-3) 62%, var(--text-3) 100%);
    background-size: 280% 100%;
    background-position: 100% 0;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: ai-shimmer 3.2s linear infinite;
}

.ai-export:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* Fichiers détectés dans une réponse */
.ai-files {
    margin-top: .45rem;
    padding-top: .45rem;
    border-top: 1px dashed var(--border-strong);
    font-size: .78rem;
    color: var(--text-3);
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.ai-file-tag {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: .05rem .4rem;
    color: var(--text-2);
}

/* ══ Popup de bienvenue : la tarification, une fois, sans blabla ══
   Superposée au chat, jamais bloquante : la carte défile toute seule si
   l'écran est court (max-height + overflow), le scroll de la page reste
   intact derrière. */
.ai-modal {
    position: fixed;
    inset: 0;
    z-index: 300;   /* au-dessus de la nav sticky (100) et du skip-link (200) */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.ai-modal[hidden] { display: none; }

.ai-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 5, 6, .78);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: ai-modal-fade .22s ease both;
}

.ai-modal-card {
    position: relative;
    width: min(100%, 520px);
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.7rem 1.5rem 1.4rem;
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    /* halo ambre au sommet : l'accent du site, jamais criard */
    background:
        radial-gradient(120% 70% at 50% 0%, rgba(247, 147, 26, .09), transparent 62%),
        var(--bg-panel);
    box-shadow: 0 26px 70px rgba(0, 0, 0, .62);
    animation: ai-modal-rise .26s cubic-bezier(.2, .75, .3, 1) both;
}

.ai-modal-x {
    position: absolute;
    top: .5rem;
    right: .5rem;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    line-height: 1;
    color: var(--text-3);
    background: none;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: color .18s, background .18s, border-color .18s;
}

.ai-modal-x:hover {
    color: var(--text);
    background: var(--surface-2);
    border-color: var(--border);
}

.ai-modal-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: 0 2.2rem .35rem 0;
    font-size: 1.28rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.ai-modal-sub {
    margin: 0 0 1.35rem;
    font-size: .88rem;
    line-height: 1.5;
    color: var(--text-3);
}

/* ── Les trois points tarifaires : aérés, numérotés, séparés ── */
.ai-price-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.ai-price {
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    padding: .85rem .95rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-1);
}

.ai-price-num {
    flex: 0 0 auto;
    width: 27px;
    height: 27px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: .78rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid var(--border-accent);
    border-radius: 9px;
}

.ai-price-body { min-width: 0; }

.ai-price-h {
    margin: .12rem 0 .25rem;
    font-size: .96rem;
    font-weight: 620;
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--text);
}

.ai-price-key { color: var(--accent-hover); white-space: nowrap; }

.ai-price-p {
    margin: 0;
    font-size: .845rem;
    line-height: 1.55;
    color: var(--text-3);
}

.ai-modal-foot {
    margin: 1.15rem 0 1.1rem;
    padding-top: .9rem;
    border-top: 1px solid var(--border);
    font-size: .74rem;
    line-height: 1.5;
    text-align: center;
    color: var(--text-4);
}

.ai-modal-cta {
    width: 100%;
    padding-top: .78rem;
    padding-bottom: .78rem;
}

@keyframes ai-modal-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes ai-modal-rise {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

/* ── Recharge Lightning ──
   Panneau discret sous la conversation, jamais affiché tant qu'il reste du
   quota gratuit : il ne doit pas ressembler à un paywall permanent. */
.ai-topup {
    margin: .2rem 0 .9rem;
    padding: 1rem 1.05rem 1.05rem;
    border: 1px solid var(--border-accent);
    border-radius: 14px;
    background:
        radial-gradient(120% 140% at 0% 0%, rgba(247, 147, 26, .07), transparent 60%),
        var(--surface-1);
    animation: ai-topup-rise .28s ease both;
}

.ai-topup[hidden] { display: none; }

.ai-topup-head { margin-bottom: .85rem; }

.ai-topup-title {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: 0 0 .25rem;
    font-size: 1.02rem;
    font-weight: 640;
    letter-spacing: -0.01em;
    color: var(--text);
}

.ai-topup-sub {
    margin: 0;
    font-size: .82rem;
    line-height: 1.55;
    color: var(--text-3);
}

/* Paliers : mobile d'abord une colonne, puis trois dès qu'il y a la place. */
.ai-topup-tiers {
    display: grid;
    grid-template-columns: 1fr;
    gap: .55rem;
}

.ai-topup-tiers[hidden] { display: none; }

@media (min-width: 520px) {
    .ai-topup-tiers { grid-template-columns: repeat(3, 1fr); }
}

.ai-tier {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .15rem;
    padding: .7rem .6rem;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: border-color .18s, background .18s, transform .12s;
}

.ai-tier:hover {
    border-color: var(--border-accent);
    background: var(--accent-dim);
}

.ai-tier:active { transform: translateY(1px); }

.ai-tier-sats {
    font-family: var(--mono);
    font-size: .95rem;
    font-weight: 700;
    color: var(--accent-hover);
}

.ai-tier-tokens {
    font-size: .74rem;
    color: var(--text-3);
}

/* Facture : QR à gauche, bolt11 + actions à droite (empilés sur mobile). */
.ai-topup-invoice {
    display: flex;
    flex-wrap: wrap;
    gap: .9rem;
    align-items: flex-start;
}

.ai-topup-invoice[hidden] { display: none; }

.ai-topup-qr {
    flex: 0 0 auto;
    width: 168px;
    padding: .5rem;
    border-radius: 10px;
    background: #fff;          /* les scanners ont besoin du fond clair */
    line-height: 0;
}

.ai-topup-qr:empty { display: none; }
.ai-topup-qr svg { width: 100%; height: auto; display: block; }

.ai-topup-inv-body {
    flex: 1 1 260px;
    min-width: 0;
}

.ai-topup-amount {
    margin: 0 0 .5rem;
    font-family: var(--mono);
    font-size: .84rem;
    color: var(--text-2);
}

/* Le conteneur .code-block du chat est scopé sous .ai-msg : ici on rejoue son
   apparence, pour que la facture ait exactement la même identité visuelle. */
.ai-topup-invoice .code-block {
    margin: 0 0 .65rem;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #08090b;
    overflow: hidden;
}

/* Un bolt11 fait ~400 caractères : il se casse, sinon il déborde la carte. */
.ai-topup-invoice pre {
    margin: 0;
    border: none;
    border-radius: 0;
    background: none;
    max-height: 128px;
    overflow: auto;
    padding: .55rem .7rem;
}

.ai-topup-invoice code {
    font-family: var(--mono);
    font-size: .68rem;
    line-height: 1.5;
    color: var(--text-2);
    background: none;
    padding: 0;
    word-break: break-all;
    white-space: pre-wrap;
}

.ai-topup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.ai-topup-msg {
    margin: .75rem 0 0;
    font-size: .8rem;
    line-height: 1.5;
    color: var(--text-3);
    min-height: 1.2em;
}

.ai-topup-msg:empty { margin: 0; min-height: 0; }
.ai-topup-msg[data-kind="ok"]   { color: #7ee2a8; }
.ai-topup-msg[data-kind="warn"] { color: #ffd9a0; }
.ai-topup-msg[data-kind="err"]  { color: #ff9d9d; }   /* même rouge que .ai-msg--error */

@keyframes ai-topup-rise {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

/* ── Pièces jointes (dépôt de fichier, 100 % navigateur) ──
   Une puce par fichier au-dessus du textarea ; croix pour retirer avant
   l'envoi. Les puces « trop gros » proposent de garder la fin (un journal
   montre sa panne à la fin), jamais un refus sec. */
.ai-composer-left {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.ai-attach {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.ai-chip {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    max-width: 100%;
    padding: .3rem .5rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-1);
    font-size: .78rem;
    color: var(--text-2);
    line-height: 1.3;
}

.ai-chip-thumb {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    flex: none;
}

.ai-chip-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.ai-chip-name {
    color: var(--text);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}

.ai-chip-meta { color: var(--text-3); }

.ai-chip-x {
    border: none;
    background: none;
    color: var(--text-3);
    font-size: .95rem;
    line-height: 1;
    padding: .15rem .25rem;
    border-radius: 6px;
    cursor: pointer;
    flex: none;
}
.ai-chip-x:hover { color: #ff9d9d; background: var(--surface-2); }

.ai-chip.is-oversize { border-color: rgba(255, 217, 160, .55); }
.ai-chip.is-oversize .ai-chip-meta { color: #ffd9a0; }
.ai-chip.is-vision-off { border-color: rgba(255, 217, 160, .55); }
.ai-chip.is-vision-off .ai-chip-meta { color: #ffd9a0; }
.ai-chip.is-error { border-color: rgba(255, 100, 100, .5); }
.ai-chip.is-error .ai-chip-name { color: #ff9d9d; font-weight: 400; }

.ai-chip-tail {
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font-size: .74rem;
    padding: .2rem .5rem;
    border-radius: 7px;
    cursor: pointer;
    flex: none;
}
.ai-chip-tail:hover { border-color: #f7931a; color: #f7931a; }

/* Voile de glisser-déposer : n'apparaît QUE pendant qu'un fichier survole la page.
   ⚠️ `display: flex` ci-dessous écrasait l'attribut `hidden` du gabarit : le voile
   restait affiché en permanence et recouvrait toute la conversation. D'où cette
   règle explicite, sans laquelle le bug revient au premier nettoyage du CSS. */
.ai-page { position: relative; }

.ai-drop-hint[hidden] { display: none; }

.ai-drop-hint {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed rgba(247, 147, 26, .55);
    border-radius: 14px;
    background: rgba(11, 12, 14, .55);
    pointer-events: none;
}

.ai-drop-hint-txt {
    font-size: .8rem;
    color: var(--text);
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    padding: .4rem .85rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}

@media (max-width: 640px) {
    .ai-msg { max-width: 94%; }
    .ai-page { padding-top: 1.2rem; }
    .ai-chat { max-height: 62vh; min-height: 240px; }
    .code-block-lang { max-width: 40%; }
    .ai-chip-name { max-width: 140px; }

    /* Popup sur téléphone : collée en bas, pouce-friendly, texte intact */
    .ai-modal { padding: .6rem; align-items: flex-end; }
    .ai-modal-card {
        padding: 1.4rem 1.1rem 1.2rem;
        max-height: calc(100vh - 1.2rem);
        max-height: calc(100dvh - 1.2rem);
    }
    .ai-modal-title { font-size: 1.15rem; }
    .ai-price { padding: .8rem .85rem; gap: .7rem; }
    .ai-price-key { white-space: normal; }

    /* Recharge sur téléphone : QR centré, boutons pleine largeur au pouce */
    .ai-topup { padding: .9rem .85rem 1rem; }
    .ai-topup-qr { width: 100%; max-width: 220px; margin: 0 auto; }
    .ai-topup-actions .btn { flex: 1 1 100%; text-align: center; }
}

/* Accessibilité : plus rien ne bouge, mais tout reste lisible
   (points de suspension complets, texte rendu en couleur pleine). */
@media (prefers-reduced-motion: reduce) {
    .ai-state-orb,
    .ai-state-label,
    .ai-state-label::after,
    .ai-state-wave i,
    .ai-etape-ico,
    .ai-slots-dot,
    .ai-status.is-busy .ai-status-fx,
    .ai-msg--streaming::after,
    .ai-msg--busy .ai-dots::after,
    .ai-modal-backdrop,
    .ai-modal-card,
    .ai-topup {
        animation: none !important;
    }
    .ai-state-label::after { clip-path: none; }
    .ai-state[data-state="think"] .ai-state-label,
    .ai-state[data-state="write"] .ai-state-label,
    .ai-status.is-busy .ai-status-fx {
        background-image: none;
        -webkit-text-fill-color: currentColor;
        color: var(--text-2);
    }
    .ai-status.is-busy .ai-status-fx { color: var(--text-3); }
    .ai-status-fx { transition: none; }
    .ai-status-fx.is-out { opacity: 1; transform: none; }
    .ai-state-wave i { transform: scaleY(.6); }
}
