/* EVM – Sujets & corrigés */
:root {
  --red: #d12f4e; --blue: #0a6eb4; --green: #5aa81a; --orange: #f2711c; --yellow: #f7b900;
  --ink: #1d2433; --muted: #5d6677; --line: #dde2ea; --bg: #f3f5f9; --card: #ffffff;
  --ui: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Noto Serif', Georgia, 'Times New Roman', serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--ui); color: var(--ink); background: var(--bg); }
button, select, input { font: inherit; }

/* ---------- En-tête / pied du site ---------- */
.site-head { background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 14px; padding: 12px 20px; max-width: 1400px; margin: 0 auto; }
.brand img { height: 54px; width: auto; }
.brand-name { font-weight: 800; font-size: 1.3rem; color: var(--blue); line-height: 1.15; }
.brand-sub { color: var(--muted); font-size: .92rem; }
.stripe { display: flex; height: 5px; }
.stripe i { flex: 1; }
.stripe i:nth-child(1) { background: var(--red); } .stripe i:nth-child(2) { background: var(--blue); }
.stripe i:nth-child(3) { background: var(--green); } .stripe i:nth-child(4) { background: var(--orange); }
.stripe i:nth-child(5) { background: var(--yellow); }
.site-foot { text-align: center; padding: 16px; color: var(--muted); font-size: .9rem; border-top: 1px solid var(--line); background: var(--card); }

/* ---------- Disposition ---------- */
.layout { display: grid; grid-template-columns: 330px 1fr; gap: 20px; padding: 20px; max-width: 1400px; margin: 0 auto; align-items: start; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; position: sticky; top: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 700; font-size: .88rem; margin-bottom: 12px; flex: 1; min-width: 0; }
.field select, .field input { font-weight: 400; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
.field select:focus, .field input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.row { display: flex; gap: 10px; }
.chapters { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 4px; max-height: 300px; overflow: auto; }
.chapters legend { padding: 0 4px; }
.chapters label { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; padding: 4px 0; font-size: .9rem; cursor: pointer; }
.chapters input { width: auto; flex: none; margin: 3px 0 0; padding: 0; accent-color: var(--blue); }
.chapters label span { flex: 1; text-align: left; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; font-weight: 700; font-size: .82rem; }
.hint { color: var(--muted); font-size: .8rem; margin: 10px 0 0; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 8px; cursor: pointer; font-weight: 700; }
.btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #085a94; color: #fff; }
.btn.accent { background: var(--green); border-color: var(--green); color: #fff; }
.btn.accent:hover:not(:disabled) { background: #4a8d14; color: #fff; }
.btn.block { width: 100%; padding: 12px; }

/* ---------- Aperçu ---------- */
.preview { min-width: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: inline-flex; background: #e6eaf1; border-radius: 10px; padding: 4px; }
.tab { border: 0; background: none; padding: 8px 18px; border-radius: 7px; cursor: pointer; font-weight: 700; color: var(--muted); }
.tab.active { background: #fff; color: var(--blue); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stage { overflow-x: auto; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 50px 20px; text-align: center; color: var(--muted); }
.empty img { width: 120px; opacity: .9; }

/* ---------- Feuille (sujet / corrigé) ---------- */
.sheet { background: #fff; width: 210mm; max-width: 100%; margin: 0 auto 20px; padding: 12mm 14mm; box-shadow: 0 2px 14px rgba(20,30,60,.10); border-radius: 4px; color: #111; font-family: var(--serif); font-size: 11.5pt; line-height: 1.55; }
.sheet-table { width: 100%; border-collapse: collapse; }
.sheet-table > thead > tr > td, .sheet-table > tfoot > tr > td, .sheet-table > tbody > tr > td { padding: 0; vertical-align: top; }
.sh-head { display: flex; align-items: center; gap: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--blue); font-family: var(--ui); }
.sh-head img { height: 58px; width: auto; }
.sh-id { flex: 1; }
.sh-school { font-weight: 800; font-size: 14pt; color: var(--blue); line-height: 1.2; }
.sh-year { font-size: 9.5pt; color: #444; }
.sh-meta { text-align: right; font-size: 9.5pt; line-height: 1.45; color: #222; }
.sh-stripe { display: flex; height: 3px; margin-bottom: 10px; }
.sh-stripe i { flex: 1; }
.sh-stripe i:nth-child(1) { background: var(--red); } .sh-stripe i:nth-child(2) { background: var(--blue); }
.sh-stripe i:nth-child(3) { background: var(--green); } .sh-stripe i:nth-child(4) { background: var(--orange); }
.sh-stripe i:nth-child(5) { background: var(--yellow); }
.sh-title { text-align: center; font-family: var(--ui); font-weight: 800; font-size: 14pt; margin: 4px 0 2px; }
.sh-subtitle { text-align: center; font-family: var(--ui); font-size: 10.5pt; color: #333; margin-bottom: 10px; }
.sh-eleve { display: flex; gap: 20px; font-family: var(--ui); font-size: 10pt; border: 1px solid #bbb; border-radius: 4px; padding: 6px 10px; margin-bottom: 12px; }
.sh-eleve span { flex: 1; white-space: nowrap; overflow: hidden; }
.sh-eleve span:first-child { flex: 2.2; }
.sh-foot { margin-top: 14px; padding-top: 6px; border-top: 1px solid #999; text-align: center; font-family: var(--ui); font-size: 9pt; color: #333; }
.corrige-badge { display: inline-block; background: var(--green); color: #fff; font-family: var(--ui); font-weight: 800; font-size: 9pt; padding: 2px 8px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }

.exo { margin: 0 0 14px; break-inside: avoid; page-break-inside: avoid; }
.exo-h { font-family: var(--ui); font-weight: 800; font-size: 11.5pt; color: var(--blue); border-left: 4px solid var(--orange); padding-left: 8px; margin-bottom: 4px; }
.exo-h small { color: #555; font-weight: 600; }
.exo p { margin: 4px 0; }
.exo ol.q { margin: 4px 0; padding-left: 24px; }
.exo ol.q > li { margin: 3px 0; }
.exo ul { margin: 4px 0; }

/* Pseudo-code */
.exo pre.algo { font-family: 'Courier New', Consolas, monospace; font-size: .92em; background: #f6f8fb; border: 1px solid #ccd; border-radius: 4px; padding: 6px 12px; margin: 6px 0; white-space: pre; line-height: 1.45; }

/* Arabe (droite à gauche) */
.rtl { direction: rtl; text-align: right; font-family: 'Noto Naskh Arabic', 'Amiri', 'Traditional Arabic', serif; font-size: 1.08em; line-height: 1.8; }
.rtl .sh-title, .rtl .sh-subtitle, .rtl .sh-eleve, .rtl .exo-h { font-family: 'Noto Kufi Arabic', 'Noto Naskh Arabic', sans-serif; }
.rtl .sh-title, .rtl .sh-subtitle { text-align: center; }
.rtl .exo-h { border-left: 0; border-right: 4px solid var(--orange); padding-left: 0; padding-right: 8px; }
.rtl ol.q { list-style: none; counter-reset: q; padding: 0; }
.rtl ol.q > li { counter-increment: q; position: relative; padding-right: 26px; }
.rtl ol.q > li::before { content: counter(q) "."; position: absolute; right: 0; top: 0; font-weight: 700; }
.rtl ul { list-style: none; padding: 0; }
.rtl ul > li { position: relative; padding-right: 18px; }
.rtl ul > li::before { content: "•"; position: absolute; right: 2px; top: 0; }
.rtl .texte { border-left: 1px solid #bbb; border-right: 4px solid var(--blue); }
.rtl .texte .src { text-align: left; }
.rtl .corrige-badge { margin-left: 0; margin-right: 6px; }

/* Texte support */
.exo .texte { border: 1px solid #bbb; border-left: 4px solid var(--blue); border-radius: 4px; padding: 6px 12px; margin: 6px 0 8px; background: #fafcff; }
.exo .texte p { margin: 4px 0; text-align: justify; }
.exo .texte .src { text-align: right; font-style: italic; font-size: .9em; color: #555; }

/* Tableaux dans les exercices */
.exo table.tb { border-collapse: collapse; margin: 6px 0; font-size: .95em; }
.exo table.tb th, .exo table.tb td { border: 1px solid #555; padding: 3px 10px; text-align: center; }
.exo table.tb th { background: #eef3f9; font-weight: 600; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* Écritures mathématiques */
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .92em; line-height: 1.15; margin: 0 .12em; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 .2em 1px; }
.frac > span:last-child { padding: 1px .2em 0; }
.rad { white-space: nowrap; }
.vec { position: relative; display: inline-block; line-height: 1.1; padding-top: .35em; }
.vec > .arr { position: absolute; left: 0; right: 0; top: -.2em; text-align: center; font-size: .75em; line-height: 1; }
.rad > span { border-top: 1px solid currentColor; padding: 0 .1em; margin-left: 1px; }
.sys { display: inline-flex; flex-direction: column; vertical-align: middle; border-left: 2px solid currentColor; padding: 2px 0 2px 8px; margin: 4px 4px; border-radius: 6px 0 0 6px; }
sup, sub { line-height: 0; }

/* ---------- Export PNG (rendu hors écran) ---------- */
.png-holder { position: absolute; left: -12000px; top: 0; width: 900px; background: #fff; }
.png-holder .sheet { width: 900px; max-width: none; margin: 0; box-shadow: none; border-radius: 0; padding: 36px 40px; font-size: 16px; }

/* ---------- Modale ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,22,40,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 1000; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 14px; width: min(520px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-box.wide { width: min(760px, 100%); }
.modal-box h3 { margin: 0; padding: 16px 20px 8px; font-size: 1.1rem; color: var(--blue); }
.modal-body { padding: 4px 20px 12px; overflow: auto; color: var(--ink); }
.modal-body .png-preview { width: 100%; border: 1px solid var(--line); border-radius: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-actions a.btn { text-decoration: none; display: inline-block; }
.spinner { width: 34px; height: 34px; border: 4px solid #e2e7ef; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

#print-root { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .panel { position: static; }
  .sheet { padding: 16px; font-size: 11pt; }
  .sh-head img { height: 44px; }
  .sh-school { font-size: 12pt; }
}

/* ---------- Impression ---------- */
@page { size: A4; margin: 10mm 12mm; }
@media print {
  body { background: #fff; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.is-printing > *:not(#print-root) { display: none !important; }
  body.is-printing #print-root { display: block !important; }
  body:not(.is-printing) .site-head, body:not(.is-printing) .site-foot,
  body:not(.is-printing) .panel, body:not(.is-printing) .toolbar, body:not(.is-printing) .empty { display: none !important; }
  body:not(.is-printing) .layout { display: block; padding: 0; }
  .sheet { width: auto; max-width: none; margin: 0; padding: 0; box-shadow: none; border-radius: 0; font-size: 11.5pt; }
  .sheet-table > thead { display: table-header-group; }
  .sheet-table > tfoot { display: table-footer-group; }
  .sh-head img { height: 52px; }
}

/* ---------- Figures géométriques (SVG) ---------- */
.fig { text-align: center; margin: 8px 0 10px; break-inside: avoid; page-break-inside: avoid; }
.fig svg { max-width: 100%; height: auto; display: inline-block; vertical-align: top; }
.fig-cap { font-size: 9.5pt; color: #555; font-style: italic; }
