:root {
  color-scheme: light dark;
  --fond: #fbfaf7;
  --surface: #ffffff;
  --texte: #1f1d1a;
  --discret: #6b665e;
  --ligne: #e4e0d8;
  --accent: #2f5d8a;
  --selection: #e3edf7;
  --danger: #a8322d;
  --rayon: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #171614;
    --surface: #201f1c;
    --texte: #ece8e1;
    --discret: #a29c92;
    --ligne: #34322e;
    --accent: #8db7e0;
    --selection: #26384b;
    --danger: #e0807a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fond); color: var(--texte); line-height: 1.45; }
a { color: var(--accent); }
kbd {
  font: 0.8em ui-monospace, monospace;
  border: 1px solid var(--ligne);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 0.3em;
  color: var(--discret);
}
button, input {
  font: inherit;
  color: inherit;
}
button {
  background: var(--surface);
  border: 1px solid var(--ligne);
  border-radius: var(--rayon);
  padding: 0.35em 0.8em;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.danger { color: var(--danger); }
input {
  background: var(--surface);
  border: 1px solid var(--ligne);
  border-radius: var(--rayon);
  padding: 0.4em 0.6em;
}
.accueil { max-width: 26rem; margin: 12vh auto; padding: 0 16px; }
.accueil form { display: grid; gap: 0.9rem; }
.accueil label { display: grid; gap: 0.3rem; }
.erreur { color: var(--danger); }
.barre {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 16px;
  border-bottom: 1px solid var(--ligne);
  background: var(--surface);
}
.marque { font-weight: 600; text-decoration: none; color: var(--texte); }
.ariane ol { display: flex; flex-wrap: wrap; list-style: none; margin: 0; padding: 0; gap: 0.3rem; }
.ariane li + li::before { content: "/"; color: var(--discret); margin-right: 0.3rem; }
.page-fichiers {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16rem;
  gap: 1.5rem;
  max-width: 72rem;
  margin: 1rem auto;
  padding: 0 16px;
}
@media (max-width: 760px) { .page-fichiers { grid-template-columns: minmax(0, 1fr); } }
.outils { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.8rem; }
.outils input[type="search"] { flex: 1 1 12rem; }
.liste { list-style: none; margin: 0; padding: 0; border: 1px solid var(--ligne); border-radius: var(--rayon); background: var(--surface); }
.liste li {
  display: grid;
  grid-template-columns: 1.2rem minmax(0, 1fr) 5rem 9rem;
  gap: 0.6rem;
  padding: 0.35rem 0.7rem;
  border-bottom: 1px solid var(--ligne);
  cursor: default;
}
.liste li:last-child { border-bottom: 0; }
.liste li[aria-selected="true"] { background: var(--selection); }
.liste li[hidden] { display: none; }
.liste a { text-decoration: none; color: var(--texte); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.liste .icone, .liste .taille, .liste time { color: var(--discret); font-size: 0.9em; }
.liste .taille { text-align: right; }
@media (max-width: 520px) { .liste li { grid-template-columns: 1.2rem minmax(0, 1fr); } .liste .taille, .liste time { display: none; } }
.vide { color: var(--discret); }
.recents h2 { font-size: 1rem; margin: 0.3rem 0 0.6rem; }
.recents ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.recents a { text-decoration: none; word-break: break-all; }
.colonne { display: grid; gap: 1.2rem; align-content: start; }
.noyaux h2 { font-size: 1rem; margin: 0.3rem 0 0.6rem; }
.noyaux ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.noyaux li { display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; }
.noyaux a { text-decoration: none; word-break: break-all; }
#message:empty { display: none; }
#message { color: var(--danger); }
dialog {
  border: 1px solid var(--ligne);
  border-radius: 10px;
  background: var(--surface);
  color: var(--texte);
  padding: 1.2rem;
  min-width: min(26rem, 90vw);
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog form { display: grid; gap: 0.8rem; }
dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0 0 1rem; }
dialog dd { margin: 0; }
.boutons { display: flex; justify-content: flex-end; gap: 0.5rem; }
.dialogue { max-width: 50rem; margin: 2rem auto; padding: 0 16px; }

/* --- Dialog page (F-1.6 to F-1.12) --------------------------------------------------------- */
main.dialogue { max-width: 90rem; margin: 0 auto; padding: 0 16px 2rem; }
.dialogue-tete {
  position: sticky; top: 0; z-index: 2; background: var(--fond);
  display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center;
  padding: 0.6rem 0; border-bottom: 1px solid var(--ligne);
}
.dialogue-tete h1 { margin: 0; font-size: 1.15rem; }
.dialogue-tete h1 button { border: 0; background: none; padding: 0; font-weight: 600; }
.barre-outils {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-left: auto;
  padding: 2px 4px; border: 1px solid var(--ligne); border-radius: var(--rayon); background: var(--surface);
}
.barre-outils select { padding: 0.15em 0.3em; font-size: 0.9em; max-width: 12rem; }
.barre-outils .ic { width: 18px; height: 18px; }
.barre-outils .separateur { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--ligne); }
.invisible {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.icones { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; display: block;
}
.ic-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px; border: 1px solid transparent; border-radius: 4px;
  background: none; color: var(--discret); line-height: 0; cursor: pointer;
}
.ic-btn:hover, .ic-btn:focus-visible { color: var(--accent); background: var(--selection); border-color: transparent; }
.ic-btn.bascule[aria-pressed="true"] { color: #fff; background: var(--accent); }
.noyau { color: var(--discret); font-size: 0.9em; }
.noyau::before { content: "●"; margin-right: 0.3em; }
.noyau[data-kernel-state="idle"]::before { color: #3c8d4e; }
.noyau[data-kernel-state="busy"]::before { color: #c58a1a; }
.noyau[data-kernel-state="starting"]::before { color: #c58a1a; }
article.msg.running > .msg-in { border-left-color: #c58a1a; }
article.msg.queued > .msg-in { border-left-style: dashed; }
.kernel-prompt { margin-top: 0.4rem; }
.kernel-prompt label { display: flex; gap: 0.5rem; align-items: center; font-family: var(--mono, monospace); }
.kernel-prompt input { flex: 1 1 auto; }
select, textarea {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 0.3em 0.5em;
}
/* A message: its input, then its output or reply shifted to the right below it, each with a
   coloured line on the left (F-1.6). The selected message is framed. */
.messages { display: grid; gap: 0.6rem; padding: 0.8rem 0; }
.msg {
  --lisere: #8a8578; display: grid; gap: 0.3rem; min-width: 0;
  border: 2px solid transparent; border-radius: calc(var(--rayon) + 2px); padding: 2px;
}
.msg[hidden] { display: none; }
.msg-code { --lisere: #3d7cc0; }
.msg-note { --lisere: #3c8d4e; }
.msg-prompt { --lisere: #c2453d; }
.msg-raw { --lisere: #8a8578; }
.msg-in, .msg-out {
  position: relative; min-width: 0; background: var(--surface);
  border: 1px solid var(--ligne); border-left: 4px solid var(--lisere);
  border-radius: var(--rayon); padding: 0.3rem 0.8rem 0.4rem;
}
.msg-out { margin-left: 2.5rem; }
@media (max-width: 520px) { .msg-out { margin-left: 1rem; } }
.msg-out:has(> .msg-output:empty):not(:has(> .editor)) { display: none; }
.msg[aria-selected="true"] { border-color: var(--accent); }
.msg[aria-selected="true"] > .msg-in, .msg[aria-selected="true"] > .msg-out { background: var(--selection); }
.msg.editing > .msg-in { border-left-color: #c58a1a; }
.msg.editing-reply > .msg-in { border-left-color: var(--lisere); }
.msg.editing-reply > .msg-out { border-left-color: #c58a1a; }
.msg-head, .out-head {
  display: flex; gap: 0.6rem; align-items: baseline; min-height: 1.6em;
  font-size: 0.8em; color: var(--discret);
}
.msg-kind, .out-kind { font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.badge { border: 1px solid var(--ligne); border-radius: 999px; padding: 0 0.5em; }
.section-tokens { font-style: italic; }
.msg.is-skipped { opacity: 0.55; filter: grayscale(1); }
.msg.is-pinned > .msg-in { border-left-style: double; border-left-width: 6px; }
/* Toolbars of the message under the mouse or selected (ADR-029) */
.msg-tools, .out-tools {
  position: absolute; top: 2px; right: 4px; z-index: 1;
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 1px; max-width: calc(100% - 8rem);
  padding: 1px; border-radius: var(--rayon); background: var(--surface);
}
.msg[aria-selected="true"] .msg-tools, .msg[aria-selected="true"] .out-tools { background: var(--selection); }
.msg:not(.msg-prompt) [data-only="prompt"] { display: none; }
@media (hover: none) { .msg:not([aria-selected="true"]) :is(.msg-tools, .out-tools) { display: none; } }
.msg-input pre, .msg-output pre {
  margin: 0.3rem 0; overflow-x: auto; white-space: pre; font: 0.9em/1.4 ui-monospace, monospace;
}
.msg-raw .msg-input pre, .out-stream, .out-error { white-space: pre-wrap; }
.prompt-text { white-space: pre-wrap; margin: 0.3rem 0; }
.msg-note .msg-input { line-height: 1.55; }
.markdown h1, .markdown h2, .markdown h3 { margin: 0.4rem 0; }
.markdown img, .out-image { max-width: 100%; height: auto; }
.markdown table, .out-html table { border-collapse: collapse; }
.markdown td, .markdown th, .out-html td, .out-html th { border: 1px solid var(--ligne); padding: 0.2em 0.5em; }
.msg-output:empty { display: none; }
.msg-output { overflow-x: auto; }
.out-stderr { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.out-error { color: var(--danger); }
.msg.i-collapsed .msg-input { max-height: 1.6em; overflow: hidden; opacity: 0.6; }
.msg.o-collapsed .msg-output { max-height: 1.6em; overflow: hidden; opacity: 0.6; }
.msg.o-scroll .msg-output { max-height: 50vh; overflow-y: auto; }
.msg.heading-collapsed .msg-input::after { content: " …"; color: var(--discret); }
.msg.editing:not(.editing-reply) .msg-input { display: none; }
.msg.editing-reply .msg-output { display: none; }
.msg-prompt .msg-output pre:not(.tool-args, .tool-result) { cursor: copy; }
.editor { min-height: 2.5em; margin: 0.3rem 0; border: 1px solid var(--ligne); border-radius: 4px; }
.editor-text { width: 100%; font: 0.9em/1.4 ui-monospace, monospace; border: 0; }
.saisie-message {
  position: sticky; bottom: 0; background: var(--fond); padding: 0.6rem 0;
  border-top: 1px solid var(--ligne); display: grid; gap: 0.4rem;
}
.saisie-message .types { display: flex; gap: 0.3rem; }
.saisie-message [aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.saisie-message textarea { width: 100%; resize: vertical; font-family: ui-monospace, monospace; }
.saisie-message .envoi { display: flex; justify-content: flex-end; }
#notice { min-height: 1.4em; color: var(--discret); font-size: 0.9em; margin: 0; }

/* --- Settings page (F-2.1, F-2.2, F-2.9) --------------------------------------------------- */
.lien-reglages { margin-left: auto; }
.page-reglages { max-width: 60rem; margin: 1rem auto 3rem; padding: 0 16px; }
.reglages { display: grid; gap: 1.2rem; }
.reglages fieldset {
  display: grid; gap: 0.7rem; border: 1px solid var(--ligne); border-radius: var(--rayon);
  padding: 0.8rem 1rem 1rem; background: var(--surface); min-width: 0;
}
.reglages legend { font-weight: 600; padding: 0 0.3rem; }
.champ { display: grid; gap: 0.3rem; max-width: 28rem; }
.case { display: flex; gap: 0.5rem; align-items: center; }
.reglages textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 0.9em; }
.aide { margin: 0; color: var(--discret); font-size: 0.9em; }
.tableau { border-collapse: collapse; width: 100%; font-size: 0.9em; display: block; overflow-x: auto; }
.tableau th, .tableau td { text-align: left; padding: 0.3rem 0.6rem; border-bottom: 1px solid var(--ligne); }
.tableau .nombre { text-align: right; white-space: nowrap; }
.etat-cle[data-present] { color: #3c8d4e; }
.champ.large { max-width: none; }
.abonnements { margin-bottom: 1.2rem; }
.abonnements h2 { font-size: 1.15em; margin: 0 0 0.3rem; }
.carte-abonnement {
  display: grid; gap: 0.6rem; margin-top: 0.7rem; padding: 0.8rem 1rem;
  border: 1px solid var(--ligne); border-radius: var(--rayon); background: var(--surface);
}
.entete-abonnement { display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; align-items: center; }
.entete-abonnement form { margin-left: auto; }
.carte-abonnement ol { margin: 0; padding-left: 1.4rem; }
.carte-abonnement textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 0.9em; }
.carte-abonnement .boutons { margin-top: 0.5rem; }

/* --- Prompts (F-2.8, F-2.16, F-2.17, F-2.19) ----------------------------------------------- */
article.msg.answering > .msg-out { border-left-color: var(--accent); }
.reply-live { white-space: pre-wrap; }
.msg-usage { margin: 0.3rem 0 0; font-size: 0.8em; color: var(--discret); display: flex; flex-wrap: wrap; gap: 0 1rem; }
.usage-detail { display: none; }
main.dialogue[data-show-usage="1"] .usage-detail { display: inline; }
details.tool { border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 0.2rem 0.6rem; margin: 0.4rem 0; font-size: 0.9em; }
details.tool summary { cursor: pointer; color: var(--discret); }
details.tool pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0.3rem 0; }
.tool-result { border-top: 1px dashed var(--ligne); padding-top: 0.3rem; }

/* Terminal (F-3.2): the whole tab, xterm.js draws inside #ecran */
body:has(main.terminal) { background: #000; height: 100vh; overflow: hidden; }
main.terminal { display: flex; flex-direction: column; height: 100vh; }
main.terminal #ecran { flex: 1; min-height: 0; padding: 4px 0 0 6px; }
main.terminal #notice:empty { display: none; }
main.terminal #notice {
  margin: 0;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  color: var(--texte);
  border-top: 1px solid var(--ligne);
}

/* Uploads (F-3.9): the whole page accepts dropped files and folders */
body.depot main.fichiers { outline: 2px dashed var(--accent); outline-offset: 4px; }

/* Editor of any text file (F-3.8) */
body:has(main.editeur) { height: 100vh; display: flex; flex-direction: column; }
main.editeur { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.editeur-barre {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.4rem 16px;
  border-bottom: 1px solid var(--ligne);
  flex-wrap: wrap;
}
.editeur-barre #position { color: var(--discret); font-variant-numeric: tabular-nums; }
.editeur-barre #etat { margin-left: auto; color: var(--discret); }
main.editeur .editeur-monaco { flex: 1; min-height: 0; }
main.editeur textarea#contenu {
  flex: 1;
  min-height: 0;
  margin: 0;
  border: 0;
  padding: 0.5rem 16px;
  resize: none;
  font: 14px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  background: var(--surface);
}

/* Published app (F-3.12, F-3.13) */
.app-publiee h2 { font-size: 1rem; margin: 0.3rem 0 0.6rem; }
.app-publiee ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.app-publiee li { display: flex; flex-wrap: wrap; gap: 0.2rem 0.5rem; align-items: center; }
.app-publiee a { word-break: break-all; }
.app-publiee .etat-port { flex-basis: 100%; font-size: 0.85rem; color: var(--discret); }
.app-publiee li[data-listening="1"] .etat-port { color: var(--danger); }
.app-publiee .avertissement {
  margin: 0.6rem 0 0;
  padding: 0.5rem 0.7rem;
  border-left: 3px solid var(--danger);
  background: var(--surface);
  font-size: 0.9rem;
}

/* USE_VIM (F-3.7): the Vim status line under an editor */
.vim-etat { font: 12px/1.6 ui-monospace, monospace; color: var(--discret); padding: 0 16px; }
.vim-etat input { font: inherit; border: 0; background: transparent; color: inherit; }
/* USE_KATEX (F-3.7): a displayed formula takes its own line */
span.math[data-display="1"] { display: block; overflow-x: auto; }
