:root {
  --bg: #f5f6f2;
  --card: #ffffff;
  --fg: #19261f;
  --muted: #5b6b61;
  --line: #dde3dc;
  --primary: #14532d;
  --primary-fg: #ffffff;
  --accent: #f7c21b;
  --danger: #b42318;
  --ok: #1a7f46;
  --warn-bg: #fff4d6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1a14; --card: #17261d; --fg: #eef2ec; --muted: #9db0a3; --line: #2b4034;
    --primary: #4cc27f; --primary-fg: #0f1a14; --danger: #ff8a80; --ok: #4cc27f; --warn-bg: #3a3112;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 6px; }
p { margin: 0 0 10px; }
code { background: var(--line); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.loading { padding: 24px; text-align: center; color: var(--muted); }

/* en-tête et menu */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: var(--primary); color: var(--primary-fg); }
.brand { font-weight: 700; display: flex; flex-direction: column; line-height: 1.2; }
.brand small { font-weight: 400; opacity: .85; font-size: .8rem; }
.who { display: flex; align-items: center; gap: 12px; font-size: .9rem; flex-wrap: wrap; justify-content: flex-end; }
.who a, .who .link { color: var(--primary-fg); }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.tabs a { flex: none; padding: 10px 14px; border-radius: 999px; text-decoration: none; color: var(--fg); font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; }
.tabs a.on { background: var(--accent); color: #19261f; font-weight: 700; }
main { max-width: 960px; margin: 0 auto; padding: 16px; }

/* cartes et listes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
details.card > summary { font-weight: 600; cursor: pointer; min-height: 32px; }
details { margin: 8px 0; }
details > summary { cursor: pointer; color: var(--primary); font-weight: 500; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row-card { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--fg); min-height: 56px; }
.row-card:hover { border-color: var(--primary); }
.line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.line details { margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.toolbar label { min-width: 150px; flex: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 10px 0; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--fg); min-width: 0; }
a.stat:hover { border-color: var(--primary); }
.stat b { font-size: 1.25rem; line-height: 1.2; overflow-wrap: anywhere; }
.stat span { color: var(--muted); font-size: .85rem; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--warn-bg); color: var(--fg); vertical-align: middle; }
.badge.ok { background: #d6f0e0; color: #0f5a2f; }
.badge.bad { background: #fbd9d5; color: #8a1c12; }

/* formulaires */
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 500; }
input, select, textarea { font: inherit; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); width: 100%; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input[type=radio] { width: auto; min-height: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.inline input, .inline select { flex: 1; min-width: 140px; width: auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); margin-top: 8px; }
.btn.big { width: 100%; margin-top: 14px; min-height: 52px; }
.btn:disabled { opacity: .6; cursor: wait; }
button.link { background: none; border: 0; padding: 8px 4px; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; min-height: 44px; }
button.link.danger { color: var(--danger); }
.error-box { background: #fbd9d5; color: #8a1c12; padding: 12px; border-radius: 8px; }
.auth { max-width: 420px; margin: 8vh auto; padding: 24px 16px; }
.auth h1 { font-size: 1.8rem; }

/* tableaux */
.table-wrap { overflow-x: auto; margin: 8px 0; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.late { color: var(--danger); font-weight: 700; }
th.edit, td.edit { background: var(--warn-bg); }
input.score { width: 84px; text-align: right; min-height: 40px; }

/* présences */
.att-row { padding: 12px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.seg-group { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { flex-direction: row; align-items: center; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.seg input:checked + span { color: #fff; border-color: transparent; background: var(--ok); }
.seg.absent input:checked + span { background: var(--danger); }
.seg.late input:checked + span { background: #b26b00; }
.seg.excused input:checked + span { background: #3b5bb5; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* bulletin et reçu */
.paper { background: #fff; color: #111; border: 1px solid var(--line); border-radius: 8px; padding: 20px; margin-top: 8px; }
.paper .stat { background: #fff; border-color: #ccc; color: #111; }
.paper .stat span, .paper .muted { color: #555; }
.paper th { color: #444; }
.paper th, .paper td { border-color: #ddd; }
.paper-head { text-align: center; margin-bottom: 12px; }
.paper-head h1 { margin: 0; }
.paper-head p { margin: 0; color: #444; }
.paper-head h2 { margin-top: 10px; }
.sign { display: flex; justify-content: space-around; margin-top: 48px; gap: 12px; text-align: center; }
.sign span { border-top: 1px solid #111; padding-top: 6px; min-width: 40%; }

#toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%) translateY(120%); background: #19261f; color: #fff; padding: 12px 18px; border-radius: 10px; max-width: calc(100% - 32px); transition: transform .2s; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: #8a1c12; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

@media (min-width: 720px) {
  .att-row { flex-direction: row; align-items: center; justify-content: space-between; }
  .att-row b { flex: 1; }
  .att-row input[name^="n_"] { max-width: 220px; }
}
@media print {
  .noprint { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .paper { border: 0; padding: 0; }
}
