:root {
  --bg: #F4F3EF; --card: #FFFFFF; --soft: #F1EFE8; --line: #DEDCD3; --line2: #C9C6BB;
  --text: #2C2C2A; --muted: #6B6A64; --faint: #9A988F;
  --accent: #2E5E8C; --accent-bg: #E6F1FB; --accent-text: #0C447C;
  --teal: #1D9E75; --teal-bg: #E1F5EE; --teal-text: #085041;
  --violet: #534AB7; --violet-bg: #EEEDFE; --violet-text: #3C3489;
  --orange: #BA7517; --orange-bg: #FAEEDA; --orange-text: #633806;
  --absent: #444441; --absent-text: #F1EFE8;
  --NA: #CECBF6; --NA-t: #26215C; --A: #FAC775; --A-t: #412402; --M: #9FE1CB; --M-t: #04342C;
  --r: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 15px; line-height: 1.5; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 10px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }

/* Mise en page : menu à gauche, contenu à droite */
#shell { display: flex; min-height: 100vh; }
#side { width: 236px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  background: var(--card); border-right: 1px solid var(--line); padding: 16px 12px; }
#side[hidden] { display: none; }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 600; color: var(--text); text-decoration: none; padding: 4px 8px 16px; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; text-decoration: none; color: var(--muted); font-size: 15px; }
#nav a:hover { background: var(--soft); color: var(--text); }
#nav a.on { background: var(--accent-bg); color: var(--accent-text); font-weight: 600; }
#nav a.soon { opacity: .5; pointer-events: none; }
#nav a.sub { padding: 7px 12px 7px 38px; font-size: 14px; }
#nav a.sub.on { background: var(--soft); color: var(--text); }
#nav .sep { font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--faint); text-transform: uppercase; padding: 14px 12px 4px; }
#nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.who { border-top: 1px solid var(--line); padding: 12px 8px 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; font-size: 14px; color: var(--muted); }
.who button { padding: 0; height: auto; }
#content { flex: 1; min-width: 0; }
#mbar { display: none; }
#scrim { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 28px 80px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

button, .btn { font: inherit; font-size: 14px; border-radius: var(--r); border: 1px solid var(--line2); background: var(--card);
  color: var(--text); padding: 0 14px; height: 40px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
button:hover { background: var(--soft); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #244C73; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--soft); color: var(--text); }
button.small { height: 32px; padding: 0 10px; font-size: 13px; }
button.danger { color: var(--violet-text); border-color: var(--violet); }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { font: inherit; font-size: 15px; height: 40px; padding: 0 10px; border-radius: var(--r);
  border: 1px solid var(--line2); background: #fff; color: var(--text); min-width: 0; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
label.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
label.check input { width: 18px; height: 18px; }
.err { color: var(--violet-text); font-size: 14px; min-height: 1.2em; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); }
.t td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: none; }
.scroll-x { overflow-x: auto; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 16px; padding-bottom: 8px; }
.tabs a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: 14px; }
.tabs a.on { background: var(--soft); color: var(--text); font-weight: 600; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; padding: 5px 12px; border-radius: 16px;
  border: 1px solid var(--line2); background: var(--card); cursor: pointer; user-select: none; margin: 2px; }
.pill.on { background: var(--teal-bg); color: var(--teal-text); border-color: #5DCAA5; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.tag.admin { background: var(--violet-bg); color: var(--violet-text); }
.tag.lv { background: var(--soft); color: var(--text); }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: 1px; background: var(--soft); padding: 3px 8px; border-radius: 6px; font-size: 15px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; user-select: none; }
.switch i { width: 38px; height: 22px; border-radius: 11px; background: var(--line2); position: relative; transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on i { background: var(--teal); }
.switch.on i::after { left: 19px; }

.band { display: flex; height: 34px; border-radius: 8px; overflow: hidden; font-size: 13px; font-weight: 600; margin-top: 10px; }
.band div { display: flex; align-items: center; justify-content: center; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(30px); opacity: 0; background: var(--text); color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 14px; transition: all .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Écran du code */
.login { max-width: 420px; margin: 8vh auto; text-align: center; }
.login img { margin-bottom: 10px; }
.login input { width: 100%; height: 56px; font-size: 24px; text-align: center; letter-spacing: 3px; font-family: ui-monospace, Consolas, monospace; text-transform: uppercase; }
.login button { width: 100%; height: 48px; justify-content: center; margin-top: 12px; font-size: 16px; }

/* Accueil */
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; text-decoration: none; color: var(--text); }
.tile:hover { border-color: var(--accent); }
.tile b { display: block; font-size: 16px; margin-bottom: 4px; }
.tile.soon { opacity: .6; pointer-events: none; }

/* Cartons de codes à imprimer */
.print-sheet { display: none; }
@media print {
  body.print-codes * { visibility: hidden; }
  body.print-codes .print-sheet, body.print-codes .print-sheet * { visibility: visible; }
  body.print-codes .print-sheet { display: grid; position: absolute; inset: 0; grid-template-columns: 1fr 1fr; gap: 0; }
  .print-sheet .carton { border: 1px dashed #888; padding: 14px; height: 4.2cm; font-family: system-ui, sans-serif; }
  .print-sheet .carton b { font-size: 16px; }
  .print-sheet .carton .code { font-size: 22px; display: inline-block; margin: 8px 0; }
}

/* Tablette en portrait et téléphone : le menu se replie derrière un bouton */
@media (max-width: 900px) {
  #mbar:not([hidden]) { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; background: var(--card);
    border-bottom: 1px solid var(--line); padding: 6px 12px; }
  .brand-s { font-weight: 600; }
  #side { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-105%); transition: transform .2s; box-shadow: none; }
  #side.open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  #scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 30; }
}
@media (max-width: 700px) {
  main { padding: 14px 12px 80px; }
}

/* Pastilles de niveau (pas de rouge ni de vert vif) */
.lv { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.lv-P1 { background: #E6F1FB; color: #0C447C; }
.lv-P2 { background: #FBEAF0; color: #72243E; }
.lv-P3 { background: #E1F5EE; color: #085041; }
.lv-P4 { background: #FAEEDA; color: #633806; }
.lv-P5 { background: #EEEDFE; color: #3C3489; }
.lv-P6 { background: #F1EFE8; color: #444441; }
tr.sep-lv td { border-top: 2px solid var(--line2); }
.arrows { display: inline-flex; gap: 2px; }
.arrows button { width: 36px; padding: 0; justify-content: center; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: var(--r); overflow: hidden; }
.seg button { border: none; border-radius: 0; height: 36px; }
.seg button.on { background: var(--accent-bg); color: var(--accent-text); font-weight: 600; }

/* Carnet de cotes */
.carnet-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); max-height: calc(100vh - 210px); }
table.carnet { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.carnet th, .carnet td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; text-align: center; background: var(--card); }
.carnet thead th { position: sticky; top: 0; z-index: 2; }
.carnet thead tr:nth-child(2) th { top: 29px; }
.carnet .n { position: sticky; left: 0; z-index: 3; text-align: left; min-width: 170px; max-width: 230px; padding: 0 6px; }
.carnet thead .n { z-index: 4; vertical-align: bottom; padding: 8px; font-weight: 600; }
.carnet th.grp { font-size: 12px; font-weight: 600; padding: 6px; color: #1f1f1f; white-space: nowrap; height: 29px; }
.carnet th.eh { cursor: pointer; vertical-align: bottom; font-weight: 600; min-width: 50px; }
.carnet th.eh:hover { background: var(--soft); }
.carnet th.eh.off { color: var(--faint); }
.vh { writing-mode: vertical-rl; transform: rotate(180deg); height: 130px; max-height: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 6px auto 0; font-size: 12px; text-align: left; }
.em { font-size: 11px; font-weight: 400; color: var(--muted); padding: 2px 2px 6px; line-height: 1.5; }
.em .lv { font-size: 10px; padding: 1px 4px; }
.sname { border: none; background: none; height: auto; padding: 6px 0; font-size: 13px; text-align: left; display: flex; gap: 6px; align-items: center; width: 100%; white-space: nowrap; overflow: hidden; }
.sname:hover { background: none; text-decoration: underline; }
.ce { width: 50px; height: 42px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; position: relative; margin: auto; }
.ce b { font-size: 16px; font-weight: 700; }
.ce small { font-size: 11px; opacity: .85; }
.ce .ci { position: absolute; top: 1px; right: 3px; font-size: 8px; }
.ce .cf { position: absolute; top: 1px; left: 3px; font-size: 10px; color: var(--violet); }
.ce.empty { color: var(--faint); }
.ce.na { background: var(--soft); color: var(--faint); }
.L-NA { background: var(--NA); color: var(--NA-t); }
.L-A { background: var(--A); color: var(--A-t); }
.L-M { background: var(--M); color: var(--M-t); }
.abs { background: var(--absent) !important; color: var(--absent-text) !important; }
.ce.abs b { font-size: 12px; }
td.cell { cursor: pointer; }
td.cell:hover .ce { outline: 2px solid var(--accent); outline-offset: -2px; }
.carnet tr.avg td { background: var(--soft); }
.carnet tr.avg td.n { font-size: 12px; color: var(--muted); padding: 8px 6px; }
.carnet tr.sep-lv td { border-top: 2px solid var(--line2); }
.tip { min-height: 22px; margin: 10px 2px; font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; }
.ce-mini { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; margin-right: 3px; }
.ce-mini.na { background: var(--soft); color: var(--faint); }

/* Création d'évaluation : attendus */
.att { display: flex; gap: 8px; align-items: flex-start; padding: 7px 6px; border-top: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.att.on { background: var(--teal-bg); color: var(--teal-text); border-radius: 8px; border-top-color: transparent; margin-bottom: 4px; }
.att input { margin-top: 3px; width: 18px; height: 18px; flex-shrink: 0; }
.att-list { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; }

/* Encodage prénom par prénom */
.enc-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); margin: 10px 0; }
.enc-head b { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { height: 34px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.chip.cur { outline: 3px solid var(--accent); outline-offset: 1px; }
.enc .big { font-size: 30px; font-weight: 600; margin: 0; }
#val { width: 110px; height: 60px; font-size: 28px; text-align: center; }
.prev { width: 76px; height: 76px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--soft); color: var(--faint); font-size: 26px; }
.prev b { font-size: 26px; font-weight: 700; }
.prev small { font-size: 12px; }
.enc textarea { width: 100%; }

/* Notes */
.note { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: none; }
.note.new { background: var(--orange-bg); border-radius: 8px; padding: 10px; }
.new-tag { background: var(--orange); color: #fff; }
#nav .badge { margin-left: auto; background: var(--orange); color: #fff; font-size: 12px; font-weight: 700; border-radius: 10px; padding: 0 7px; }
.prev.L-NA { background: var(--NA); color: var(--NA-t); }
.prev.L-A { background: var(--A); color: var(--A-t); }
.prev.L-M { background: var(--M); color: var(--M-t); }

/* Fiche élève */
.fhead { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--teal-bg); color: var(--teal-text); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; }
.lbox { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 9px; font-weight: 700; font-size: 16px; flex-shrink: 0; }
.lbox.sm { width: 26px; height: 26px; font-size: 11px; border-radius: 6px; }
.lbox.empty { background: var(--soft); color: var(--faint); }
.lbox.abs { font-size: 11px; }
.strip { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.stag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; color: #1f1f1f; min-width: 90px; text-align: center; }
.pgroup { display: inline-flex; gap: 3px; align-items: center; padding: 2px 6px 2px 2px; border-radius: 7px; }
.pgroup .small { margin: 0 4px; }
.pgroup.on { outline: 1px solid var(--line2); }
.erow { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.erow:last-child { border-bottom: none; }
a.sname-link { color: var(--text); text-decoration: none; font-weight: 600; }
a.sname-link:hover { text-decoration: underline; }

/* Rappel d'échéance */
.remind { display: flex; align-items: center; gap: 10px; background: var(--orange-bg); color: var(--orange-text); border: 1px solid #EF9F27; border-radius: 12px; padding: 8px 14px; margin-bottom: 14px; font-size: 14px; }
.remind span { flex: 1; }
.logo-prev { width: 120px; height: 70px; border: 1px dashed var(--line2); border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #fff; }
.logo-prev img { max-width: 100%; max-height: 100%; }
a.btn { color: var(--text); }

/* Bilans : liste, aperçu */
.bil-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 14px; align-items: start; }
.bil-list { padding: 8px; max-height: calc(100vh - 160px); overflow-y: auto; position: sticky; top: 12px; }
.bil-st { width: 100%; border: none; justify-content: flex-start; height: 36px; font-size: 14px; text-align: left; }
.bil-st.on { background: var(--accent-bg); color: var(--accent-text); font-weight: 600; }
.bil-st .ok, .ok { color: var(--teal); font-weight: 700; }
.bil-preview .bpage { background: #fff; color: #1f1f1f; border: 1px solid var(--line2); border-radius: 4px; padding: 28px 32px; margin-bottom: 14px; max-width: 640px; }
@media (max-width: 900px) { .bil-grid { grid-template-columns: 1fr; } .bil-list { position: static; max-height: 220px; } }
.br-row { display: grid; grid-template-columns: 200px minmax(0, 1fr) 90px; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.br-row:last-child { border-bottom: none; }
.br-row textarea { width: 100%; }
.br-n { padding-top: 8px; font-size: 14px; }
.br-st { padding-top: 10px; }
@media (max-width: 700px) { .br-row { grid-template-columns: 1fr; } }

/* Page de bilan (aperçu et impression A4) */
.bpage { font-family: Calibri, "Segoe UI", system-ui, sans-serif; font-size: 12.5px; line-height: 1.35; }
.b-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.b-muted { color: #555; }
.b-logo { max-height: 60px; max-width: 150px; }
.b-logo-ph { font-size: 11px; color: #6a8f4e; border: 1px dashed #9cbf7e; padding: 6px 10px; border-radius: 14px; }
.b-title { font-size: 21px; font-weight: 700; text-align: center; margin: 10px 0 14px; color: #1f1f1f; }
.b-ban { background: #FFC000; border: 1px solid #333; text-align: center; font-weight: 700; font-size: 14px; padding: 5px; margin-bottom: 10px; }
.b-t { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.b-t th, .b-t td { border: 1px solid #333; padding: 4px 7px; }
.b-t th { font-weight: 700; text-align: center; color: #1f1f1f; }
.b-c { width: 68px; font-style: italic; font-weight: 400 !important; }
.b-x { text-align: center; font-weight: 700; font-size: 14px; }
.b-abs { text-align: center; font-style: italic; color: #555; }
.b-bc { margin: -6px 0 14px 18px; padding: 6px 10px; font-style: italic; font-size: 11.5px; border-left: 3px solid; border-radius: 0; }
.b-ct { font-weight: 700; text-decoration: underline; margin-top: 6px; }
.b-box { border: 1px solid #333; padding: 8px 10px; min-height: 80px; margin-top: 4px; white-space: pre-wrap; }
.b-sig-t { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.b-sig th { text-align: left; height: 80px; vertical-align: top; width: 33%; }
.b-meet { font-weight: 700; padding: 10px !important; }
.b-yn { display: flex; justify-content: space-around; margin-top: 10px; }
#printArea { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  #shell, #toast { display: none !important; }
  #printArea { display: block; }
  #printArea .bpage { page-break-after: always; break-after: page; }
  #printArea .bpage:last-child { page-break-after: auto; break-after: auto; }
  .b-t tr, .b-bc { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Accueil en deux parties */
.home-part { margin-top: 22px; }
.home-part > h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 12px; }
.admin-part > h2 { color: var(--violet-text); border-bottom-color: var(--violet-bg); }
.warn-card { background: var(--orange-bg); border-color: #EF9F27; color: var(--orange-text); }
.warn-card p { margin: 2px 0; }
