:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #5d6779;
  --border: #dde1e7;
  --accent: #2456d6;
  --accent-text: #ffffff;
  --ok: #1d8a4e;
  --ok-bg: #e5f5ec;
  --warn: #a36100;
  --warn-bg: #fff3dc;
  --bad: #c42b2b;
  --bad-bg: #fde8e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1d2129;
    --surface-2: #262b35;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --border: #333a47;
    --accent: #6d95ff;
    --accent-text: #0d1220;
    --ok: #4cc485;
    --ok-bg: #173325;
    --warn: #f0b04a;
    --warn-bg: #3a2c12;
    --bad: #ff7676;
    --bad-bg: #3d1c1c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
header.top .logo { font-weight: 700; text-decoration: none; color: var(--text); }
header.top .logo span { color: var(--accent); }
header.top .spacer { flex: 1; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}

button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 14px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--bad); }
button.big { padding: 12px 18px; font-size: 1.05rem; width: 100%; justify-content: center; }
button.icon { padding: 6px 9px; }

input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: .9rem; }
label.field input, label.field textarea { width: 100%; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }

.list-controles { display: grid; gap: 10px; }
.list-controles a.card { display: block; text-decoration: none; color: inherit; margin: 0; }
.list-controles a.card:hover { border-color: var(--accent); }

.bareme-row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }
.bareme-row input.q { width: 90px; }
.bareme-row input.pts { width: 80px; }

/* ------------------------------------------------------- correction */
.correction { display: grid; grid-template-columns: 1fr 330px; height: calc(100vh - 53px); }
.correction .pages-col { overflow: auto; padding: 16px; background: var(--surface-2); }
.correction .side {
  border-left: 1px solid var(--border); background: var(--surface);
  overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.toolbar {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 6px;
  align-items: center; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px; margin: 0 auto 14px; width: fit-content; max-width: 100%;
  box-shadow: var(--shadow);
}
.toolbar button { padding: 6px 10px; }
.toolbar button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; padding: 0; border: 2px solid var(--surface); outline: 1px solid var(--border); }
.swatch.active { outline: 3px solid var(--accent); }

.page-wrap {
  position: relative; margin: 0 auto 18px; background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.15); user-select: none;
}
.page-wrap img { display: block; width: 100%; height: auto; pointer-events: none; }
.page-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.pan .page-wrap canvas { pointer-events: none; }
.page-wrap .page-num {
  position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); color: #fff;
  font-size: .75rem; padding: 2px 8px; border-radius: 99px; pointer-events: none;
}
.text-input {
  position: absolute; z-index: 5; min-width: 160px; font: 16px sans-serif;
  border: 2px dashed var(--accent); background: rgba(255,255,255,.95); color: #000; padding: 3px 5px;
}

.note-row { display: grid; grid-template-columns: 1fr 72px auto; gap: 6px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border); }
.note-row input { width: 72px; text-align: right; }
.note-row input.invalid { outline: 2px solid var(--bad); }
.note-row .quick { display: flex; gap: 3px; }
.note-row .quick button { padding: 3px 7px; font-size: .8rem; }
.total-box { font-size: 1.6rem; font-weight: 700; text-align: center; padding: 10px; background: var(--surface-2); border-radius: var(--radius); }
.save-state { font-size: .8rem; color: var(--muted); text-align: right; }

@media (max-width: 800px) {
  .correction { grid-template-columns: 1fr; height: auto; }
  .correction .pages-col { max-height: none; }
  .correction .side { border-left: 0; border-top: 1px solid var(--border); }
}

/* ----------------------------------------------------- impression */
.coupons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.coupon {
  border: 1px dashed #999; padding: 10px; text-align: center; page-break-inside: avoid;
  break-inside: avoid; background: #fff; color: #000; font-size: 11px;
}
.coupon .qr { width: 120px; height: 120px; margin: 4px auto; }
.coupon .qr svg { width: 100%; height: 100%; display: block; }
.coupon .lib { font-size: 22px; font-weight: 800; letter-spacing: .05em; }
.registre { background: #fff; color: #000; }
.registre td, .registre th { border: 1px solid #999; color: #000; padding: 6px 10px; }
.registre td.nom { width: 70%; }
.print-only { display: none; }
@media print {
  header.top, .no-print { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .print-only { display: block; }
  .page-break { break-before: page; }
}

/* ------------------------------------------------------ espace eleve */
.eleve main { max-width: 640px; }
.slot {
  display: grid; grid-template-columns: 74px 1fr; gap: 12px; align-items: center;
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 10px; background: var(--surface);
}
.slot.ok { border-color: var(--ok); }
.slot.bad { border-color: var(--bad); }
.slot .thumb {
  width: 74px; height: 96px; border-radius: 6px; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden; color: var(--muted); font-weight: 700;
}
.slot .thumb img { width: 100%; height: 100%; object-fit: cover; }
.slot .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.slot .msg { font-size: .88rem; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 100;
  display: flex; flex-direction: column; padding: 10px; gap: 10px;
}
.modal .canvas-zone { flex: 1; display: grid; place-items: center; overflow: hidden; }
.modal canvas { max-width: 100%; max-height: 100%; touch-action: none; background: #fff; }
.modal .row { justify-content: center; }
.modal p { color: #fff; text-align: center; margin: 0; }

.big-note { font-size: 2.6rem; font-weight: 800; text-align: center; }
label.row { flex-wrap: nowrap; align-items: flex-start; }
label.row input[type=checkbox] { margin-top: 4px; flex: none; }
.bareme-row { flex-wrap: wrap; }
.bareme-row input.intitule { flex: 1; min-width: 140px; }
select { width: 100%; }
@media (max-width: 640px) {
  .bareme-row input.intitule { order: 10; flex-basis: 100%; margin-bottom: 6px; }
}
header.top { flex-wrap: wrap; row-gap: 6px; }
#menu { gap: 6px; justify-content: flex-end; }
#menu .btn, #menu button { padding: 5px 10px; font-size: .88rem; }
@media (max-width: 640px) {
  #fil, #menu > .muted { display: none; }
}
