:root {
  --fond: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --texte: #1c2330;
  --discret: #5b6576;
  --bord: #d8dde5;
  --accent: #1f5fbf;
  --accent-texte: #ffffff;
  --accent-doux: #e3ecfa;
  --vert: #1d7a46;
  --vert-doux: #e2f3e9;
  --orange: #a35a00;
  --orange-doux: #fbeedb;
  --rouge: #b42318;
  --rayon: 8px;
  --ombre: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #12161d;
    --surface: #1a2029;
    --surface-2: #232b36;
    --texte: #e6e9ee;
    --discret: #9aa4b2;
    --bord: #323c49;
    --accent: #6ea2f2;
    --accent-texte: #0d1117;
    --accent-doux: #1f2f47;
    --vert: #5cc68a;
    --vert-doux: #17311f;
    --orange: #f0a64a;
    --orange-doux: #3a2a14;
    --rouge: #f97066;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--bord);
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 12px;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.principal { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); font-weight: 600; }
button.lien { border: none; background: none; color: var(--accent); padding: 0 4px; text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

select, input, textarea {
  border: 1px solid var(--bord);
  border-radius: 6px;
  background: var(--surface);
  padding: 6px 8px;
}
textarea { width: 100%; min-height: 64px; resize: vertical; }
select { max-width: 100%; }

.discret { color: var(--discret); font-size: 13px; }

/* --- Barre --- */
.barre {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--bord);
}
.marque { display: flex; flex-direction: column; line-height: 1.2; }
.identite { display: flex; gap: 8px; align-items: center; }
.progression { font-size: 13px; color: var(--discret); }
.progression strong { color: var(--texte); }

/* --- Cadre --- */
.cadre { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100vh - 56px); }

.liste {
  border-right: 1px solid var(--bord);
  background: var(--surface);
  padding: 12px 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}
.filtre { display: flex; flex-direction: column; gap: 4px; padding: 0 12px 10px; font-size: 13px; color: var(--discret); }
.liste ol { list-style: none; margin: 0; padding: 0; }
.liste li button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  border-left: 3px solid transparent;
  padding: 8px 12px;
  background: none;
}
.liste li button:hover { background: var(--surface-2); }
.liste li button[aria-current="true"] { background: var(--accent-doux); border-left-color: var(--accent); }
.liste .titre-court { font-size: 14px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.liste .meta { grid-column: 1; font-size: 12px; color: var(--discret); }
.liste .etat { grid-row: 1 / span 2; grid-column: 2; align-self: center; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12px; }

.pastille {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--discret);
}
.pastille.fait { background: var(--vert-doux); color: var(--vert); }
.pastille.accord { background: var(--vert-doux); color: var(--vert); }
.pastille.desaccord { background: var(--orange-doux); color: var(--orange); }
.pastille.accent { background: var(--accent-doux); color: var(--accent); }

/* --- Principal --- */
main { padding: 20px 24px 64px; min-width: 0; }
.vide { color: var(--discret); }

.entete-exercice { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.entete-exercice h1 { font-size: 20px; margin: 0 0 6px; line-height: 1.3; }
.metas { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--discret); }
.navigation { display: flex; gap: 6px; }

.carte {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 16px;
  margin-top: 16px;
}
.carte h2 { font-size: 16px; margin: 0 0 12px; }

.onglets { display: flex; gap: 4px; border-bottom: 1px solid var(--bord); margin: -4px 0 12px; }
.onglets button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 10px; color: var(--discret); }
.onglets button[aria-selected="true"] { color: var(--texte); border-bottom-color: var(--accent); font-weight: 600; }
.apercu iframe { width: 100%; height: 520px; border: 1px solid var(--bord); border-radius: 6px; background: #fff; }
.apercu pre { white-space: pre-wrap; word-break: break-word; margin: 0; max-height: 520px; overflow: auto; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 12px; border-radius: 6px; }
.apercu .pied { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 13px; flex-wrap: wrap; }
.apercu a { color: var(--accent); }

.deux-colonnes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.deux-colonnes > .carte { margin-top: 16px; }

fieldset { border: none; margin: 0 0 16px; padding: 0; min-width: 0; }
legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
legend .discret { font-weight: 400; margin-left: 6px; }

.ajout-capacite { display: flex; gap: 6px; }
.ajout-capacite select { flex: 1; min-width: 0; }
.case-hors-liste { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--discret); margin-top: 6px; }

.puces { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; list-style: none; padding: 0; }
.puce {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--bord);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 3px 4px 3px 8px;
  font-size: 13px;
}
.puce.hors-liste { border-style: dashed; }
.puce button { border: none; background: none; padding: 0 4px; line-height: 1; font-size: 16px; color: var(--discret); }
.puce button:hover { color: var(--rouge); }
.puce.commune { border-color: var(--vert); background: var(--vert-doux); }
.puce.differente { border-color: var(--orange); background: var(--orange-doux); }
.puce code, .version code { font-size: 11px; color: var(--discret); }

.choix { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; }
.choix label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--bord);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  cursor: pointer;
}
.choix label:has(input:checked) { border-color: var(--accent); background: var(--accent-doux); }
.choix input { margin-top: 3px; }
.choix .aide { display: block; font-size: 12px; color: var(--discret); line-height: 1.35; }

.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.message-erreur { color: var(--rouge); font-size: 13px; }

/* --- Versions --- */
.voile { text-align: center; padding: 16px 8px; color: var(--discret); }
.voile p { margin: 0 0 10px; }
.version { border: 1px solid var(--bord); border-radius: 6px; padding: 12px; margin-bottom: 10px; }
.version.ma-position { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.version header { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 6px; }
.version h3 { font-size: 14px; margin: 0; }
.version dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 10px; margin: 6px 0; font-size: 13px; }
.version dt { color: var(--discret); }
.version dd { margin: 0; }
.version .commentaire { white-space: pre-wrap; font-size: 13px; color: var(--discret); margin: 6px 0 0; }
.version .soutiens { font-size: 12px; color: var(--discret); }
.legende { font-size: 12px; color: var(--discret); display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.legende .puce { padding: 0 6px; font-size: 11px; }

/* --- Dialogues --- */
dialog {
  border: 1px solid var(--bord);
  border-radius: 12px;
  background: var(--surface);
  color: var(--texte);
  padding: 20px 24px;
  max-width: min(640px, calc(100vw - 32px));
  box-shadow: 0 20px 40px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(10 15 25 / 45%); }
dialog h2 { margin-top: 0; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; }
.guide { max-height: 75vh; overflow-y: auto; }
.guide h3 { font-size: 15px; margin: 16px 0 4px; }
.guide li { margin-bottom: 4px; }

#notification {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--texte);
  color: var(--fond);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
#notification.visible { opacity: 1; }

@media (max-width: 1100px) {
  .deux-colonnes { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .cadre { grid-template-columns: minmax(0, 1fr); }
  .liste { position: static; height: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--bord); }
  main { padding: 16px; }
  .apercu iframe { height: 420px; }
}
