/* Outils IA. Assistant (/assistant/) : page en plein écran, avec l'en-tête du site, la conversation, et la zone de saisie
   collée en bas de l'écran. Les couleurs viennent de site.css (thème clair et sombre). */
.page-assistant { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.chat { flex: 1; display: flex; flex-direction: column; width: min(780px, 100% - 32px); margin-inline: auto; }
.lecteur { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.chat-barre { display: flex; justify-content: space-between; gap: 8px; padding-top: 16px; }
.chat-barre .btn { gap: 8px; }
.chat-barre .ph { width: 16px; height: 16px; }

/* Accueil, avant le premier message */
.accueil { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 0 28px; text-align: center; }
.accueil-art { width: 112px; height: auto; margin-bottom: 18px; }
.accueil h1 { margin: 0; font-size: clamp(34px, 2vw + 24px, 46px); line-height: 1.1; letter-spacing: -.015em; }
.accueil p { margin: 12px 0 28px; max-width: 30em; color: var(--muted); font-size: 18px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; margin: 0; padding: 0; list-style: none; }
.suggestion {
  width: 100%; height: 100%; padding: 14px 16px; border: 2px solid var(--line); border-radius: 14px; background: none;
  color: var(--ink); font: 500 15px/1.4 var(--text); text-align: left; cursor: pointer; transition: border-color .15s ease, background-color .15s ease;
}
.suggestion:hover { border-color: var(--line-mid); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.accueil-lien { margin: 22px 0 0; color: var(--muted); font-size: 15px; }
.accueil-lien a { color: var(--ink); font-weight: 600; text-decoration: underline var(--soleil) 2px; text-underline-offset: 4px; }

/* Conversation */
.fil { flex: 1; margin: 0; padding: 24px 0 12px; list-style: none; }
.fil:empty { display: none; }
.msg + .msg { margin-top: 24px; }
.msg-eleve { display: flex; justify-content: flex-end; }
.bulle { max-width: min(85%, 36em); padding: 11px 16px; border-radius: 18px 18px 6px 18px; background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere; }
/* En attente du premier mot : le soleil respire */
.msg-ia.attente .md::before, .resultat-md.attente::before { content: ""; display: block; width: 14px; height: 14px; margin: 6px 0; border-radius: 50%; background: var(--soleil); animation: respire 1.1s ease-in-out infinite; }
@keyframes respire { 50% { transform: scale(.6); opacity: .55; } }

/* Réflexion (mode Réfléchi), repliée par défaut */
.reflexion { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.reflexion summary {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px; border-radius: 999px;
  background: var(--surface); font-weight: 500; cursor: pointer; list-style: none;
}
.reflexion summary::-webkit-details-marker { display: none; }
.reflexion summary::after { content: ""; width: 6px; height: 6px; margin-left: 2px; border-right: 1.5px solid; border-bottom: 1.5px solid; transform: translateY(-2px) rotate(45deg); }
.reflexion[open] summary::after { transform: translateY(1px) rotate(-135deg); }
.reflexion.en-cours summary::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--soleil); animation: respire 1.1s ease-in-out infinite; }
.reflexion-texte { max-height: 22em; overflow: auto; margin-top: 10px; padding: 2px 0 2px 14px; border-left: 2px solid var(--line-mid); font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; }

/* Réponse (Markdown) */
.md { font-size: 16.5px; line-height: 1.65; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md .md-titre { margin: 24px 0 8px; font-family: var(--title); font-weight: 500; line-height: 1.25; }
.md h2 { font-size: 25px; }
.md h3 { font-size: 21px; }
.md h4, .md h5, .md h6 { font-size: 18px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 1.45em; }
.md li { margin: 4px 0; }
.md li > ul, .md li > ol { margin: 4px 0 0; }
.md li::marker { color: var(--muted); }
.md strong { font-weight: 650; }
.md a { text-decoration: underline var(--soleil) 2px; text-underline-offset: 3px; }
.md a:hover { text-decoration-thickness: 3px; }
.md blockquote { margin: 0 0 12px; padding: 2px 0 2px 16px; border-left: 3px solid var(--soleil); color: var(--muted); }
.md hr { margin: 22px 0; border: 0; border-top: 1px solid var(--line-mid); }
.md code, .md-tex { padding: 1px 5px; border-radius: 6px; background: var(--surface); font: .9em/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.md-tex { white-space: pre-wrap; overflow-wrap: anywhere; }
.md-code { margin: 0 0 14px; overflow: hidden; border: 1px solid var(--line-mid); border-radius: 12px; }
.md-code-tete { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; padding: 2px 4px 2px 14px; background: var(--surface); color: var(--muted); font-size: 13px; }
.md-code pre { margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--field); font: 14px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace; tab-size: 4; }
.md-code pre code { padding: 0; background: none; font: inherit; }
.md-tableau { margin: 0 0 14px; overflow-x: auto; border: 1px solid var(--line-mid); border-radius: 12px; }
.md table { width: 100%; border-collapse: collapse; font-size: 15px; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { background: var(--surface); font-weight: 600; }
.md tbody tr:last-child td { border-bottom: 0; }
.md .md-droite { text-align: right; }
.md .md-centre { text-align: center; }
.md-maths { margin: 0 0 14px; padding: 2px 0; overflow-x: auto; overflow-y: hidden; }
.md-maths .katex-display { margin: 0; }
.md .katex { font-size: 1.08em; }
.md-tableau:focus-visible, .md-code pre:focus-visible { outline-offset: -2px; }

/* Sous la réponse : note, erreur, actions */
.msg-note { margin: 8px 0 0; color: var(--muted); font-size: 14px; font-style: italic; }
.msg-erreur { display: flex; align-items: flex-start; gap: 8px; margin: 8px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: 15px; }
.msg-erreur .ph { width: 18px; height: 18px; margin-top: 2px; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 2px; margin: 6px 0 0 -8px; }
.mini {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 0; border-radius: 8px;
  background: none; color: var(--muted); font: 500 13.5px/1.2 var(--text); cursor: pointer;
}
.mini:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.mini .ph { width: 16px; height: 16px; }

/* Zone de saisie, collée en bas de l'écran */
.compose-zone { position: sticky; bottom: 0; z-index: 2; padding: 14px 0 max(10px, env(safe-area-inset-bottom)); background: linear-gradient(to bottom, transparent, var(--bg) 18px); }
.compose {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 16px; border: 1.5px solid var(--line-strong);
  border-radius: 20px; background: var(--field); box-shadow: 0 10px 28px -18px rgb(30 28 23 / .45);
}
.compose:focus-within { border-color: var(--ink); outline: 3px solid var(--soleil); outline-offset: 1px; }
.compose textarea {
  flex: 1; min-width: 0; min-height: 40px; max-height: 40vh; padding: 8px 0; border: 0; outline: 0; resize: none;
  background: none; color: var(--ink); font: 16px/1.5 var(--text);
}
.compose textarea::placeholder { color: var(--muted); opacity: .9; }
.envoyer, .arreter {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%;
  background: var(--btn); color: var(--btn-ink); cursor: pointer; transition: background-color .15s ease, opacity .15s ease;
}
.envoyer:hover:not(:disabled), .arreter:hover { background: var(--btn-hover); }
.envoyer:disabled { opacity: .3; cursor: default; }
.envoyer .ph { width: 19px; height: 19px; }
.arreter .ph { width: 14px; height: 14px; }
.compose-restant { margin: 8px 4px 0; color: var(--ink); font-size: 14px; font-weight: 500; text-align: center; }
.compose-note { margin: 8px 4px 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; text-align: center; }
.compose-note a { text-decoration-thickness: 1px; text-underline-offset: 2px; }
.compose-note a:hover { color: var(--ink); text-decoration-color: var(--soleil); text-decoration-thickness: 2px; }
.vers-bas { position: absolute; top: -40px; left: 50%; width: 38px; height: 38px; translate: -50% 0; background: var(--bg); border-color: var(--line-mid); box-shadow: 0 6px 16px -8px rgb(30 28 23 / .4); }
.vers-bas:hover { background: var(--surface); }
.vers-bas .ph { width: 18px; height: 18px; }

/* Historique des conversations */
.historique {
  width: min(460px, 100% - 32px); max-height: min(640px, 100dvh - 48px); padding: 22px 22px 18px; border: 0; border-radius: 22px;
  background: var(--bg); color: var(--ink); box-shadow: 0 24px 60px -20px rgb(0 0 0 / .45);
}
.historique[open] { display: flex; flex-direction: column; }
.historique::backdrop { background: rgb(30 28 23 / .45); }
.historique-tete { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.historique h2 { margin: 0; font-size: 28px; line-height: 1.15; }
.historique-note { margin: 6px 0 14px; color: var(--muted); font-size: 14px; }
.historique-liste { flex: 1; min-height: 0; margin: 0 -8px; padding: 0; overflow-y: auto; list-style: none; }
.historique-liste li { display: flex; align-items: center; gap: 4px; }
.historique-ouvrir { flex: 1; min-width: 0; display: grid; gap: 2px; padding: 10px 12px; border: 0; border-radius: 12px; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.historique-ouvrir:hover, .historique-ouvrir[aria-current="true"] { background: var(--surface); }
.historique-titre { overflow: hidden; font-weight: 600; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.historique-date { color: var(--muted); font-size: 13px; }
.historique-suppr { width: 38px; height: 38px; border-color: transparent; }
.historique-suppr .ph { width: 18px; height: 18px; }
.historique-vide { margin: 8px 0; color: var(--muted); }
#historique-effacer { align-self: flex-start; margin-top: 14px; }

@media (max-width: 640px) {
  .chat { width: min(780px, 100% - 24px); }
  .accueil { padding-top: 20px; }
  .accueil p { margin-bottom: 22px; font-size: 16.5px; }
  .suggestions { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .suggestion { padding: 12px 14px; }
  .bulle { max-width: 90%; }
  .md { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .msg-ia.attente .md::before, .resultat-md.attente::before, .reflexion.en-cours summary::before { animation: none; }
}

/* Résumer un cours (/resume/) : page classique, avec le pied de page du site */
.resume { padding: 48px 0 72px; }
.resume-wrap { width: min(760px, 100% - 32px); margin-inline: auto; }
.resume-tete h1 { margin: 0; font-size: clamp(34px, 2vw + 24px, 46px); line-height: 1.1; letter-spacing: -.015em; }
.resume-tete p { margin: 12px 0 28px; max-width: 34em; color: var(--muted); font-size: 18px; }
.resume-tete strong { color: var(--ink); font-weight: 600; }
.resume-form { padding: 28px; border-radius: 24px; background: var(--surface); }
.resume-label, .formats legend { display: block; margin-bottom: 8px; padding: 0; font-weight: 600; font-size: 15px; }
.resume-cours {
  display: block; width: 100%; min-height: 240px; max-height: 60vh; padding: 14px 16px; border: 1.5px solid var(--line-strong);
  border-radius: 14px; background: var(--field); color: var(--ink); font: 16px/1.55 var(--text); resize: vertical;
}
.resume-cours:focus { border-color: var(--ink); outline: 3px solid var(--soleil); outline-offset: 1px; }
.resume-cours::placeholder { color: var(--muted); opacity: .9; }
.resume-sous { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-top: 8px; color: var(--muted); font-size: 14px; }
.resume-sous .mini { margin-right: -8px; }
.formats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; min-width: 0; margin: 22px 0 0; padding: 0; border: 0; }
.formats legend { margin-bottom: 10px; }
.format {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 2px solid var(--line-mid);
  border-radius: 14px; background: var(--bg); cursor: pointer; transition: border-color .15s ease;
}
.format:hover { border-color: var(--line-strong); }
.format input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.format:has(input:checked) { border-color: var(--ink); }
.format:has(input:focus-visible) { outline: 3px solid var(--soleil); outline-offset: 2px; }
.format-titre { font-weight: 600; font-size: 16px; }
.format-texte { color: var(--muted); font-size: 14px; line-height: 1.4; }
.format:has(input:checked) .format-titre::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 8px; border-radius: 50%; background: var(--soleil); vertical-align: .08em; }
.resume-form .form-error { margin: 18px 0 0; }
.resume-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-top: 22px; }
.resume-restant { color: var(--muted); font-size: 15px; }

.resultat { margin-top: 40px; scroll-margin-top: 16px; }
.resultat-tete { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.resultat-tete h2 { margin: 0; font-size: 30px; line-height: 1.15; }
.resultat-actions { display: flex; flex-wrap: wrap; gap: 2px; margin-right: -8px; }
.resultat-date { margin: 12px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.resultat-md { margin-top: 20px; }
.resume-note { margin: 44px 0 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.resume-autre { margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.resume-note a, .resume-autre a { color: var(--ink); text-decoration: underline var(--soleil) 2px; text-underline-offset: 3px; }
.resume-autre a { font-weight: 600; }

@media (max-width: 640px) {
  .resume { padding: 32px 0 56px; }
  .resume-tete p { font-size: 16.5px; }
  .resume-form { padding: 20px 16px; border-radius: 20px; }
  .formats { grid-template-columns: minmax(0, 1fr); }
  .resultat-tete h2 { font-size: 26px; }
}

/* Impression du résumé : le document seul, en clair */
@media print {
  :root, :root[data-theme] { --bg: #fff; --ink: #1e1c17; --muted: #5c5345; --surface: #f3eee2; --line: #ddd5c4; --line-mid: #cdc3ae; --field: #fff; }
  .page-resume .top, .page-resume .resume-tete, .page-resume .resume-form, .page-resume .resultat-actions,
  .page-resume .resume-note, .page-resume .resume-autre, .page-resume .foot { display: none !important; }
  .page-resume .resume { padding: 0; }
  .page-resume .resultat { margin: 0; }
  .page-resume .md-code pre, .page-resume .md-tableau { overflow: visible; }
}
