:root {
  --fond: #f6f7f8; --surface: #ffffff; --surface-2: #eef1f3; --bord: #dde2e6;
  --texte: #16202a; --discret: #5b6873; --accent: #0f6f9e; --accent-fort: #0b5a80;
  --accent-doux: #e3f0f7; --ok: #1f7a4d; --ok-doux: #e4f3ea; --alerte: #a33a2b; --alerte-doux: #f8e6e3;
  --ombre: 0 1px 2px rgba(16,32,42,.06), 0 4px 16px rgba(16,32,42,.05);
  --rayon: 10px;
  --titre: "Archivo", system-ui, sans-serif; --corps: "Source Sans 3", system-ui, sans-serif; --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #0f1418; --surface: #161d23; --surface-2: #1d262d; --bord: #2a353e;
    --texte: #e6ecf0; --discret: #93a1ac; --accent: #4fb0de; --accent-fort: #7cc6ea;
    --accent-doux: #16303f; --ok: #5cc48f; --ok-doux: #15301f; --alerte: #ef8a7a; --alerte-doux: #3a1d19;
    --ombre: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #0f1418; --surface: #161d23; --surface-2: #1d262d; --bord: #2a353e;
  --texte: #e6ecf0; --discret: #93a1ac; --accent: #4fb0de; --accent-fort: #7cc6ea;
  --accent-doux: #16303f; --ok: #5cc48f; --ok-doux: #15301f; --alerte: #ef8a7a; --alerte-doux: #3a1d19;
  --ombre: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--fond); color: var(--texte); font: 16px/1.5 var(--corps); }
h1, h2, h3, h4 { font-family: var(--titre); line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
textarea, input { font: inherit; color: var(--texte); background: var(--surface); border: 1px solid var(--bord); border-radius: 8px; padding: .6rem .7rem; width: 100%; }
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
[hidden] { display: none !important; }
.discret { color: var(--discret); } .petit { font-size: .85rem; }
.erreur { color: var(--alerte); }

.principal { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: .55rem 1rem; font-weight: 600; }
.principal:hover { background: var(--accent-fort); }
.principal:disabled { opacity: .5; cursor: not-allowed; }
.secondaire { background: var(--surface); color: var(--texte); border: 1px solid var(--bord); border-radius: 8px; padding: .5rem .9rem; }
.lien { background: none; border: 0; color: var(--accent); padding: 0; }
.plein { width: 100%; }

/* connexion */
.connexion { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.carte-connexion { background: var(--surface); border: 1px solid var(--bord); border-radius: 14px; padding: 2rem; width: min(380px, 100%); display: grid; gap: 1rem; box-shadow: var(--ombre); }
.carte-connexion h1 { margin: 0; font-size: 1.5rem; }
.carte-connexion p { margin: -.6rem 0 0; }
.qui { border: 0; padding: 0; margin: 0; }
.qui legend { font-weight: 600; margin-bottom: .4rem; }
#choix-noms { display: flex; gap: .5rem; }
#choix-noms label { flex: 1; }
#choix-noms input { position: absolute; opacity: 0; width: 0; }
#choix-noms span { display: block; text-align: center; padding: .55rem; border: 1px solid var(--bord); border-radius: 8px; cursor: pointer; }
#choix-noms input:checked + span { background: var(--accent-doux); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.carte-connexion label { display: grid; gap: .3rem; font-weight: 600; }

/* entête */
.entete { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--bord); position: sticky; top: 0; z-index: 5; }
.marque { font-family: var(--titre); font-weight: 700; color: var(--accent); white-space: nowrap; }
.marque span { color: var(--discret); font-weight: 500; }
.onglets { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.onglets button { background: none; border: 0; padding: .45rem .8rem; border-radius: 8px; color: var(--discret); font-weight: 600; white-space: nowrap; }
.onglets button.actif { background: var(--accent-doux); color: var(--accent); }
.moi { white-space: nowrap; font-size: .9rem; }

/* pages à deux colonnes */
.page { display: grid; grid-template-columns: 280px 1fr; height: calc(100vh - 53px); }
.colonne { border-right: 1px solid var(--bord); background: var(--surface); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; }
.liste { display: flex; flex-direction: column; gap: 2px; }
.liste button { text-align: left; background: none; border: 0; border-radius: 8px; padding: .5rem .6rem; color: var(--texte); }
.liste button:hover { background: var(--surface-2); }
.liste button.actif { background: var(--accent-doux); }
.liste .sous { display: block; font-size: .8rem; color: var(--discret); }
.liste .jour { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--discret); margin: .6rem .6rem .1rem; font-weight: 600; }
.contenu { overflow-y: auto; padding: 20px clamp(16px, 3vw, 40px); }
.vide { max-width: 560px; margin: 10vh auto; text-align: center; }

/* chat */
.fil { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px clamp(16px, 3vw, 40px); display: flex; flex-direction: column; gap: 1rem; }
.msg { max-width: 820px; width: 100%; margin: 0 auto; }
.msg.user .bulle { background: var(--accent-doux); margin-left: auto; max-width: 85%; width: fit-content; }
.msg .bulle { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: .7rem 1rem; overflow-x: auto; }
.msg.user .bulle { border-color: transparent; }
.msg .meta { font-size: .78rem; color: var(--discret); margin-top: .3rem; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.puce { display: inline-block; font-size: .78rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--discret); text-decoration: none; }
a.puce { color: var(--accent); }
.puce.ko { background: var(--alerte-doux); color: var(--alerte); }
.attente { color: var(--discret); font-style: italic; }
.saisie { display: flex; gap: .6rem; padding: 12px clamp(16px, 3vw, 40px) 16px; border-top: 1px solid var(--bord); background: var(--surface); }
.saisie textarea { resize: none; }
.accueil-vide { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .5rem; margin-top: 1.2rem; }
.suggestions button { text-align: left; background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: .7rem .9rem; color: var(--texte); }
.suggestions button:hover { border-color: var(--accent); }
.bandeau { margin: 12px clamp(16px, 3vw, 40px) 0; padding: .6rem .9rem; border-radius: 8px; background: var(--alerte-doux); color: var(--alerte); font-size: .9rem; }

/* markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: .5em 0; }
.md ul, .md ol { padding-left: 1.3em; }
.md table { border-collapse: collapse; margin: .6em 0; font-size: .92rem; }
.md th, .md td { border: 1px solid var(--bord); padding: .3rem .55rem; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .05em .3em; border-radius: 4px; }
.md blockquote { margin: .5em 0; padding-left: .8em; border-left: 3px solid var(--bord); color: var(--discret); }

/* doctrine */
.doc-entete { padding: .3rem .4rem .6rem; border-bottom: 1px solid var(--bord); }
.version { font-family: var(--titre); font-weight: 700; font-size: 1.15rem; }
.titre-bloc { font-family: var(--titre); font-weight: 600; display: block; margin-bottom: .4rem; }
.doctrine-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; max-width: 980px; }
.doctrine-actions .bloc { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 14px; min-width: 0; }
.doctrine-actions .aide { margin: -.2rem 0 .5rem; }
.doctrine-actions input[type=checkbox] { width: auto; }
.reponse { background: var(--accent-doux); border-radius: 8px; padding: .6rem .8rem; margin-top: .8rem; }
#demandes-attente { grid-column: 1 / -1; background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; }
#demandes-attente ul { margin: .3rem 0 0; padding-left: 1.2em; }
.actions { display: flex; align-items: center; gap: .8rem; margin-top: .6rem; flex-wrap: wrap; }
.section-doc { max-width: 980px; }
.section-doc h2 { font-family: var(--mono); font-size: 1.05rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.regle { padding: .35rem 0; border-bottom: 1px solid var(--bord); white-space: pre-wrap; }
.provenance { color: var(--discret); font-style: italic; font-size: .88rem; padding: .1rem 0 .35rem 1rem; white-space: pre-wrap; }
.resume { background: var(--accent-doux); border-radius: 8px; padding: .6rem .8rem; margin-top: .8rem; }
.avert { background: var(--alerte-doux); color: var(--alerte); border-radius: 8px; padding: .5rem .8rem; margin-top: .6rem; font-size: .9rem; }

/* débriefs */
.filtres { display: flex; gap: .25rem; }
.filtres button { flex: 1; background: var(--surface-2); border: 0; border-radius: 8px; padding: .4rem; font-size: .88rem; color: var(--discret); }
.filtres button.actif { background: var(--accent-doux); color: var(--accent); font-weight: 600; }
.debrief { max-width: 860px; }

dialog { border: 1px solid var(--bord); border-radius: 12px; background: var(--surface); color: var(--texte); max-width: min(720px, 94vw); padding: 1.2rem; }
dialog::backdrop { background: rgba(0,0,0,.35); }

@media (max-width: 760px) {
  .page { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 53px); }
  .colonne { border-right: 0; border-bottom: 1px solid var(--bord); max-height: 38vh; }
  .page-chat .colonne { max-height: none; }
  .page-chat .liste { display: none; }
  .fil { height: calc(100vh - 110px); }
  .entete { gap: .6rem; }
  .marque span, #moi-nom { display: none; }
  .doctrine-actions { grid-template-columns: 1fr; }
}
