:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --panel: #ffffff;
  --fg: #1f1d1a;
  --muted: #6b665c;
  --line: #e2ded5;
  --field-line: #8a8478;      /* bordure des champs au repos : 3,41:1 sur --bg (#21) */
  --accent: #c2410c;          /* fond des boutons (texte blanc 5,18:1) */
  --accent-fg: #ffffff;
  --link: #c2410c;            /* liens et marque (#21) */
  --user: #fff3ea;
  --tool: #6b665c;            /* étapes : lisibles en clair (#18) */
  --code: #f0eee8;
  --err: #b91c1c;
  --warn-bg: #fdf2dc;
  --warn-fg: #6b4a0f;
  --warn-line: #e8cf9a;
  --scroll-shadow: rgba(31, 29, 26, .22);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --panel: #1f1d1a;
    --fg: #ece9e2;
    --muted: #a39e93;
    --line: #34312c;
    --field-line: #8f897d;    /* 4,84:1 sur --panel */
    --link: #fb923c;          /* 7,43:1 sur --panel ; --accent y tombait à 3,25:1 */
    --user: #2b221c;
    --tool: #8f897d;
    --code: #2a2824;
    --err: #f87171;
    --warn-bg: #2e2a22;       /* ambré désaturé : ne crie pas le soir */
    --warn-fg: #e6d3ad;
    --warn-line: #574a33;
    --scroll-shadow: rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; height: 100dvh; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; min-width: 44px;
       border: 1px solid var(--line); background: var(--panel); color: var(--fg); border-radius: 8px; padding: 0 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn:disabled { opacity: .5; cursor: default; }
.link { display: inline-flex; align-items: center; min-height: 44px; background: none; border: 0; color: var(--muted);
        padding: 0 6px; text-decoration: underline; font-size: 13px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
                   overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

.brand { font-weight: 700; letter-spacing: .02em; font-size: 18px; color: var(--link); }
.logout { margin: 0; }

/* ------------------------------------------------------------------ en-tête : une ligne, ≤ 56 px (#27) */
.chat { height: 100%; height: 100dvh; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 5px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head h1 { font-size: 16px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new .plus { font-size: 18px; line-height: 1; }
.model { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.model select { font: inherit; font-size: 16px; min-height: 44px; padding: 0 8px; border-radius: 8px;
                border: 1px solid var(--field-line); background: var(--panel); color: var(--fg); }

/* « ⋯ » : Réponse + Se déconnecter. Menu déroulant sous 760 px ; sur bureau, contenu affiché en ligne
   quand le navigateur sait styler ::details-content (sinon le menu « ⋯ » reste, ce qui marche aussi). */
.more { position: relative; }
.more > summary { list-style: none; display: flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px;
                  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--fg); font-size: 20px; line-height: 1; cursor: pointer; user-select: none; -webkit-user-select: none; }
.more > summary::-webkit-details-marker { display: none; }
.more[open] > summary { background: var(--code); }
.more-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 230px; padding: 6px;
             display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--line);
             border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.more-menu .model { justify-content: space-between; padding: 0 0 0 10px; font-size: 15px; color: var(--fg); }
.more-menu .logout .link { width: 100%; padding: 0 10px; font-size: 15px; color: var(--fg); text-decoration: none; border-radius: 8px; }
.more-menu .logout .link:hover { background: var(--code); }
@media (min-width: 761px) {
  @supports selector(::details-content) {
    .more { display: flex; align-items: center; }
    .more > summary { display: none; }
    .more::details-content { display: contents; content-visibility: visible; }
    .more-menu { display: contents; }
    .more-menu .model { padding: 0; font-size: 13px; color: var(--muted); }
    .more-menu .logout .link { width: auto; padding: 0 6px; font-size: 13px; color: var(--muted); text-decoration: underline; }
    .more-menu .logout .link:hover { background: none; color: var(--fg); }
    .chat-head .more { gap: 12px; }
  }
}

/* ------------------------------------------------------------------ fil */
.log { flex: 1; overflow-y: auto; padding: 20px; }
.empty { max-width: 640px; margin: 12vh auto 0; text-align: center; color: var(--muted); }
.empty .hint { font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 18px 0 22px; }
.chip { min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
        color: var(--fg); font-size: 15px; text-align: left; }
.chip:hover { border-color: var(--field-line); }
.chip:disabled { opacity: .5; cursor: default; }

.msg { max-width: 820px; margin: 0 auto 16px; padding: 12px 16px; border-radius: 12px; overflow-wrap: break-word; }
.msg p, .msg li { overflow-wrap: anywhere; }
.msg.user { background: var(--user); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); }
.msg.incomplete { border: 1px dashed var(--field-line); }
.msg.cleared { display: none; }
.msg .tools { font-size: 12px; color: var(--tool); margin-bottom: 6px; }
.msg .tools div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg .tools .tool-mail { white-space: normal; overflow: visible; color: var(--link); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg .tools, .msg .meta, .msg .actions { user-select: none; -webkit-user-select: none; }
.msg .actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.msg .actions button { min-height: 44px; min-width: 44px; padding: 0 10px; border: 1px solid transparent; border-radius: 8px;
                       background: none; color: var(--muted); font-size: 13px; }
.msg .actions button:hover, .msg .actions button:focus-visible { border-color: var(--line); color: var(--fg); }
.msg .error { color: var(--err); font-size: 13px; margin-top: 6px; }
.msg.pending .body:empty::after { content: "…"; color: var(--muted); }
.msg details.steps { margin-top: 6px; font-size: 12px; color: var(--tool); }
.msg details.steps > summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; user-select: none; -webkit-user-select: none; }
.msg details.steps > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg p { margin: .4em 0; }
.msg ul, .msg ol { margin: .4em 0; padding-left: 1.4em; }
.msg h1, .msg h2, .msg h3, .msg h4 { font-size: 1.05em; margin: .8em 0 .3em; }
.msg a { color: var(--link); }
.msg .ext { display: inline-block; margin-left: 4px; padding: 0 5px; border: 1px solid var(--warn-line); border-radius: 4px;
            background: var(--warn-bg); color: var(--warn-fg); font-size: .82em; white-space: nowrap; }
.msg code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: .92em; }
.msg pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg pre code { background: none; padding: 0; }
.msg hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.msg blockquote { margin: .5em 0; color: var(--fg); background: var(--code); border-left: 3px solid var(--accent);
                  padding: 8px 12px; border-radius: 0 8px 8px 0; }

/* Tableaux (#20) : on ne coupe plus les mots ; si ça déborde, la table défile, avec une ombre
   du côté où il reste à voir (CSS pur : couvercles « local » sur ombres « scroll »).
   hyphens: manual et non auto : mesuré le 05/10, la césure française entre dans la largeur
   minimale des colonnes et la table se recomprime en « Lu-mière », « Produc-tions » au lieu
   de défiler. Un mot plus long que 7ch reste entier ; seul un mot plus large que toute la table
   serait cassé (break-word). */
.msg table { display: block; width: fit-content; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: .5em 0; font-size: .94em;
             background:
               linear-gradient(to right, var(--panel) 30%, transparent) left center / 28px 100% no-repeat local,
               linear-gradient(to left, var(--panel) 30%, transparent) right center / 28px 100% no-repeat local,
               radial-gradient(farthest-side at 0 50%, var(--scroll-shadow), transparent) left center / 12px 100% no-repeat scroll,
               radial-gradient(farthest-side at 100% 50%, var(--scroll-shadow), transparent) right center / 12px 100% no-repeat scroll;
             background-color: var(--panel); }
.msg th, .msg td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top;
                   overflow-wrap: break-word; word-break: normal; hyphens: manual; -webkit-hyphens: manual; min-width: 7ch; }
.msg td.num { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.msg td a { white-space: nowrap; }

/* Pastilles des sources citées (#36) */
.msg .cited { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.msg .cited a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line);
                border-radius: 999px; background: var(--bg); color: var(--link); text-decoration: none; font-size: 14px; white-space: nowrap; }
/* fond --bg et non --code : #c2410c sur --code = 4,46:1 (< 4,5, texte 14 px) ; sur --bg = 4,75:1 (relecture) */

/* Statut pendant la réponse (#4) : collé en haut du fil, lisible, points figés si mouvement réduit */
.status { position: sticky; top: 0; z-index: 3; max-width: 820px; margin: 0 auto 8px; padding: 8px 12px; border: 1px solid var(--line);
          border-radius: 10px; background: var(--panel); color: var(--muted); font-size: 13px; }
.status .dots::after { content: "…"; display: inline-block; animation: phare-dots 1.2s steps(4, end) infinite; overflow: hidden; vertical-align: bottom; width: 1.2em; }
@keyframes phare-dots { from { width: 0; } to { width: 1.2em; } }

/* Avertissement (#5) */
.notice { max-width: 820px; margin: 0 auto 12px; padding: 8px 12px; border: 1px solid var(--warn-line); border-radius: 10px;
          background: var(--warn-bg); color: var(--warn-fg); font-size: 13px; line-height: 1.45; white-space: normal; overflow-wrap: break-word; }
.msg .notice { margin: 6px 0; }

/* Annuler l'effacement (#7) */
.undo-bar { max-width: 820px; margin: 0 auto 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
            padding: 4px 4px 4px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--muted); font-size: 14px; }
.undo-bar button { min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--fg); }

/* Réessayer (#8) */
.retry { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; margin-top: 6px; padding: 0 14px;
         border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--fg); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .status .dots::after { animation: none; width: 1.2em; }
  .status *, .status *::before, .status *::after { animation: none !important; }
}

/* ------------------------------------------------------------------ zone de saisie */
/* Fond et bordure sur toute la largeur ; champ + bouton contraints à 852 px au milieu (#34). */
.ask { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 10px; width: 100%;
       padding: 12px max(20px, calc((100% - 852px) / 2)) calc(16px + env(safe-area-inset-bottom));
       border-top: 1px solid var(--line); background: var(--panel); }
.ask textarea { flex: 1 1 0; min-width: 0; min-height: 44px; resize: none; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 10px;
                border: 1px solid var(--field-line); background: var(--bg); color: var(--fg); max-height: 40vh; }
.ask .kbd-hint, .ask .queued { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--muted); }
.ask .queued { font-size: 13px; }
.ask .kbd-hint { display: none; }
@media (hover: hover) and (pointer: fine) { .ask .kbd-hint { display: block; } }
/* Zoom 300 % (1280×720 → 427×240 px CSS) : le fil tombait à 62 px. Sous 480 px de haut, on rend
   l'aide clavier et du padding au fil (relecture, mesuré). */
@media (max-height: 480px) {
  .ask .kbd-hint { display: none; }
  .ask { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}

/* « ↓ suite » : visible quand l'utilisateur a remonté pendant qu'une réponse défile (04/10).
   Placé juste au-dessus de la zone de saisie quelle que soit sa hauteur : élément flex de taille
   nulle (marges négatives = sa hauteur), rangé visuellement entre le fil et la saisie. */
.log { order: 1; }
.jump { order: 2; z-index: 5; align-self: flex-end; height: 36px; margin: -48px 24px 12px 0; padding: 0 14px; border-radius: 999px;
        border: 1px solid var(--line); background: var(--panel); color: var(--fg); font: inherit; font-size: 13px; cursor: pointer;
        box-shadow: 0 2px 10px rgba(0, 0, 0, .15); }
.jump[hidden] { display: none; }
.ask { order: 3; }

/* ------------------------------------------------------------------ connexion */
body.login { display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(360px, calc(100% - 32px)); }
.login-box h1 { margin: 0; color: var(--link); }
.login-box .sub { color: var(--muted); margin: 2px 0 18px; }
.login-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.login-box input { width: 100%; min-height: 44px; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 8px;
                   border: 1px solid var(--field-line); background: var(--bg); color: var(--fg); }
.login-box button { margin-top: 14px; width: 100%; min-height: 44px; padding: 9px; border-radius: 8px; border: 0; background: var(--accent); color: var(--accent-fg); }
.err { color: var(--err); }

@media (max-width: 760px) {
  .chat-head { gap: 8px; }
  .new .lbl { display: none; }
  .new { padding: 0; width: 44px; }
  .log { padding: 12px 16px; }
  .chat-head { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .ask { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .jump { margin-right: max(16px, env(safe-area-inset-right)); }
}
