:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --ink: #1D2433;
  --muted: #5B6475;
  --line: #DCE1E8;
  --accent: #2F45A6;
  --accent-ink: #FFFFFF;
  --accent-soft: #E6EAF8;
  --danger: #B42318;
  --ok: #18794E;
  --warn: #9A6700;
  --marker: #F5D90A;
  --radius: 6px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --read: "Iowan Old Style", "Charter", "Sitka Text", Cambria, Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151922;
    --surface: #1D2230;
    --ink: #E5E8EF;
    --muted: #9AA3B4;
    --line: #2F3647;
    --accent: #93A5FF;
    --accent-ink: #10142A;
    --accent-soft: #262E4D;
    --danger: #FF8A80;
    --ok: #6EDDA5;
    --warn: #F2C14E;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--ui); }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* Marque : le mot passé au surligneur */
.brand { font-family: var(--read); font-size: 1.45rem; font-weight: 600; color: var(--ink); text-decoration: none; position: relative; z-index: 0; padding: 0 .15em; }
.brand::before { content: ""; position: absolute; z-index: -1; left: -.05em; right: -.1em; top: 52%; height: .5em; background: var(--marker); border-radius: 2px 6px 3px 7px; transform: rotate(-2deg); opacity: .9; }
@media (prefers-color-scheme: dark) { .brand::before { opacity: .55; } }

/* Boutons et champs */
.btn { display: inline-flex; align-items: center; gap: .4em; border: 1px solid var(--line); background: var(--surface); padding: .45em .9em; border-radius: var(--radius); cursor: pointer; text-decoration: none; color: var(--ink); line-height: 1.3; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.sm { padding: .25em .6em; font-size: .875rem; }
.btn:disabled { opacity: .55; cursor: default; }
.field { display: grid; gap: .3em; margin-bottom: .9em; }
.field label { font-weight: 600; font-size: .9rem; }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: .55em .7em; }
textarea.input { resize: vertical; min-height: 5em; }
.row { display: flex; gap: .5em; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.notice { border-left: 3px solid var(--warn); background: var(--surface); padding: .6em .8em; border-radius: 0 var(--radius) var(--radius) 0; font-size: .9rem; margin-bottom: 1em; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 2rem 1rem; }
.login-box { width: min(420px, 100%); }
.login-box .brand { font-size: 2.6rem; display: inline-block; margin-bottom: .2em; }
.login-box .lead { color: var(--muted); margin-bottom: 2rem; font-family: var(--read); font-size: 1.1rem; }
.code-input { font-size: 1.8rem; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }

/* Structure */
.top { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top nav { display: flex; gap: .25rem; }
.top nav a { text-decoration: none; color: var(--muted); padding: .35em .7em; border-radius: var(--radius); }
.top nav a.on, .top nav a:hover { color: var(--ink); background: var(--accent-soft); }
.page { max-width: 1080px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }

/* Liste des projets */
.projects { display: grid; gap: .75rem; margin-top: 1.5rem; }
.project-row { display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; padding: 1rem 1.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; }
.project-row:hover { border-color: var(--accent); }
.project-row .name { font-weight: 650; font-size: 1.05rem; }
.project-row .stats { color: var(--muted); font-size: .875rem; text-align: right; }
.project-row .desc { color: var(--muted); font-size: .9rem; grid-column: 1 / -1; }
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 2rem; text-align: center; color: var(--muted); }

/* Espace de travail */
.work { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.work.with-panel { grid-template-columns: 270px minmax(0, 1fr) 330px; }
.side { border-right: 1px solid var(--line); background: var(--surface); padding: 1rem; overflow-y: auto; height: calc(100vh - 57px); position: sticky; top: 57px; }
.side h2 { font-size: 1rem; margin-top: 1.4rem; display: flex; align-items: center; gap: .5rem; }
.side .pname { font-size: 1.1rem; font-weight: 650; text-decoration: none; color: var(--ink); display: block; }
.side ul { list-style: none; margin: 0; padding: 0; }
.side li a { display: flex; align-items: center; gap: .5em; padding: .35em .5em; border-radius: var(--radius); text-decoration: none; color: var(--ink); font-size: .92rem; }
.side li a:hover { background: var(--accent-soft); }
.side li a.on { background: var(--accent-soft); font-weight: 600; }
.side li a .count { margin-left: auto; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.side li a .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: .8em; height: .8em; border-radius: 3px; flex: none; background: var(--c, var(--marker)); }
.dot.inherit { width: .6em; height: .6em; margin: 0 .1em; border-radius: 50%; }
.side .tree li a { padding-left: calc(.5em + var(--d, 0) * 1.1em); }
.side .tree li a.group .t { font-weight: 600; }
.side form.new-code { flex-wrap: wrap; }
.side form.new-code .input { flex: 1 1 100%; }
.side form { margin-top: .5rem; display: flex; gap: .35rem; }
.side form .input { padding: .35em .55em; font-size: .9rem; }
.main { padding: 1.5rem 2rem 4rem; min-width: 0; }
.panel { border-left: 1px solid var(--line); background: var(--surface); padding: 1rem; overflow-y: auto; height: calc(100vh - 57px); position: sticky; top: 57px; }

/* Lecture et surlignage */
.doc-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; max-width: 68ch; }
.doc-head h1 { font-family: var(--read); font-weight: 600; margin: 0; }
.doc { font-family: var(--read); font-size: 1.075rem; line-height: 1.8; white-space: pre-wrap; max-width: 68ch; overflow-wrap: anywhere; }
.doc .mark { border-radius: 2px; cursor: pointer; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.doc .mark.sel { box-shadow: 0 2px 0 var(--accent); }
.hint { color: var(--muted); font-size: .9rem; margin-bottom: 1.25rem; }
.hint .spacer { min-width: 16rem; max-width: 60ch; }

/* Bascule des couleurs */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: .3em .7em; font-size: .82rem; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }

/* Bulle de codage */
.pop { position: absolute; z-index: 50; width: 280px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 28px rgb(15 20 40 / .18); padding: .6rem; }
.pop .input { padding: .4em .6em; font-size: .9rem; margin-bottom: .5rem; }
.pop .chips { max-height: 220px; overflow-y: auto; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { display: inline-flex; align-items: center; gap: .4em; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .2em .7em .2em .5em; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--muted); }
.chip.on { background: color-mix(in srgb, var(--c) 40%, var(--surface)); border-color: color-mix(in srgb, var(--c) 70%, var(--ink)); }
.chip.new { border-style: dashed; }
.chip-groups { display: grid; gap: .45rem; }
.chip-group { display: flex; flex-wrap: wrap; gap: .35rem; padding-bottom: .45rem; border-bottom: 1px solid var(--line); }
.chip-group:last-child { border-bottom: 0; padding-bottom: 0; }
.chip-groups > .chip { justify-self: start; }
a.chip { text-decoration: none; color: var(--ink); }

/* Extraits */
.excerpt { position: relative; background: var(--surface); padding: .6rem .8rem .6rem 1rem; border-radius: var(--radius); margin-bottom: .6rem; overflow: hidden; }
.excerpt::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--stripe, var(--c, var(--marker))); }
.panel .excerpt { cursor: pointer; border: 1px solid var(--line); }
.panel .excerpt:hover, .panel .excerpt.on { border-color: var(--accent); }
.excerpt .text { font-family: var(--read); font-size: .98rem; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.excerpt .meta { font-size: .8rem; color: var(--muted); margin-top: .35rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.excerpt .note { font-size: .88rem; margin-top: .35rem; color: var(--muted); font-style: italic; }
.editor { border: 1px solid var(--accent); border-radius: 8px; padding: .8rem; margin-bottom: 1.25rem; background: var(--accent-soft); }
.editor .text { font-family: var(--read); font-size: .95rem; line-height: 1.55; max-height: 9em; overflow: auto; margin-bottom: .7rem; white-space: pre-wrap; }
.group-title { font-size: .9rem; color: var(--muted); margin: 1.5rem 0 .6rem; }
.code-head { display: grid; gap: .6rem; max-width: 640px; margin-bottom: 1.5rem; }
.code-head .colour { width: 3rem; height: 2.4rem; padding: .15rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

/* Vue d'ensemble */
.stats-line { display: flex; gap: 2rem; margin: 1rem 0 1.5rem; flex-wrap: wrap; }
.stats-line div { font-size: .9rem; color: var(--muted); }
.stats-line strong { display: block; font-size: 1.5rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; max-width: 720px; }
.drop { border: 2px dashed var(--line); border-radius: 8px; padding: 1.25rem; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* Administration */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.status { font-size: .8rem; font-weight: 600; }
.status.pending { color: var(--warn); }
.status.active { color: var(--ok); }
.status.disabled { color: var(--danger); }
tr.pending td { background: color-mix(in srgb, var(--warn) 9%, transparent); }

/* Messages */
#toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .6em 1.1em; border-radius: var(--radius); font-size: .92rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 1100px) {
  .work.with-panel { grid-template-columns: 240px minmax(0, 1fr); }
  .work.with-panel .panel { grid-column: 1 / -1; position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .work, .work.with-panel { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 1.25rem 1rem 3rem; }
  .top { flex-wrap: wrap; position: static; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
