/* =====================================================================
   Levier : feuille de style (fichier 2/3)
   Deux voies, deux couleurs : voie 2 (ouverte, IA) en ocre,
   voie 1 (contrôle, sans IA) en bleu, classe en vert sombre.
   ===================================================================== */

:root {
  color-scheme: light dark;
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1c2230;
  --muted: #586074;
  --line: #dcd8cc;
  --line-strong: #bdb8a8;

  --lane2: #b0480a;
  --lane2-soft: #fbe9d8;
  --lane1: #1d4f91;
  --lane1-soft: #e2ebf8;
  --lane3: #2a6553;
  --lane3-soft: #dcefe8;
  --on-accent: #ffffff;

  --ok: #1b7443;
  --ok-soft: #dcf1e4;
  --bad: #b0281f;
  --bad-soft: #fbe3e0;
  --warn: #7d5200;

  --radius: 10px;
  --shadow: 0 1px 2px rgb(20 25 40 / .06), 0 6px 18px rgb(20 25 40 / .05);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13161d;
    --surface: #1b1f29;
    --surface-2: #171a22;
    --ink: #e8eaf0;
    --muted: #a1a8b8;
    --line: #2e3442;
    --line-strong: #455066;

    --lane2: #f2a566;
    --lane2-soft: #3a2a1b;
    --lane1: #85b4f4;
    --lane1-soft: #1c2b45;
    --lane3: #7fcbb0;
    --lane3-soft: #1b3029;
    --on-accent: #10131a;

    --ok: #72c995;
    --ok-soft: #1b3326;
    --bad: #f2897f;
    --bad-soft: #3a1f1d;
    --warn: #e0b45c;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 18px rgb(0 0 0 / .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.45rem; letter-spacing: -.01em; }
h3 { font-size: 1.05rem; margin-bottom: .6rem; }
p { margin: 0 0 .6rem; }

.c-lane1 { color: var(--lane1); }
.c-lane2 { color: var(--lane2); }

/* ---------- en-tête ---------- */
.app-header {
  display: flex; flex-wrap: wrap; gap: .8rem 1.5rem; align-items: center; justify-content: space-between;
  max-width: 1180px; margin: 0 auto; padding: 1.1rem 1rem .8rem;
}
.brand h1 { font-size: 1.7rem; letter-spacing: -.02em; }
.brand p { margin: .15rem 0 0; color: var(--muted); }
.header-actions { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- onglets ---------- */
.tabs {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: .3rem; overflow-x: auto;
  padding: 0 max(1rem, calc((100% - 1180px) / 2 + 1rem));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.tab {
  --tab-color: var(--muted);
  appearance: none; font: inherit; color: var(--muted); cursor: pointer;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: .55rem; align-items: center;
  text-align: left; white-space: nowrap;
  padding: .6rem 1.1rem .55rem; margin-bottom: -1px;
  background: transparent; border: 1px solid transparent; border-top: 3px solid transparent;
  border-radius: 10px 10px 0 0;
}
#tab-voie2 { --tab-color: var(--lane2); }
#tab-voie1 { --tab-color: var(--lane1); }
#tab-classe { --tab-color: var(--lane3); }
.tab .step {
  grid-row: 1 / 3; display: grid; place-items: center;
  width: 1.7rem; height: 1.7rem; border-radius: 50%;
  border: 2px solid var(--tab-color); color: var(--tab-color); font-weight: 700; font-size: .9rem;
}
.tab .name { font-weight: 700; color: var(--ink); line-height: 1.1; }
.tab small { color: var(--muted); font-size: .8rem; line-height: 1.2; }
.tab:hover { background: var(--surface-2); }
.tab[aria-selected="true"] {
  background: var(--surface); border-color: var(--line); border-top-color: var(--tab-color); border-bottom-color: var(--surface);
}
.tab[aria-selected="true"] .step { background: var(--tab-color); color: var(--on-accent); }

:focus-visible { outline: 3px solid var(--lane1); outline-offset: 2px; border-radius: 4px; }

/* ---------- panneaux ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 1.3rem 1rem 2rem; }

.panel { display: grid; gap: 1rem; }
.lane2 { --accent: var(--lane2); --accent-soft: var(--lane2-soft); }
.lane1 { --accent: var(--lane1); --accent-soft: var(--lane1-soft); }
.lane3 { --accent: var(--lane3); --accent-soft: var(--lane3-soft); }

.panel-head { max-width: 62rem; padding-left: .9rem; border-left: 5px solid var(--accent); }
.panel-head p { color: var(--muted); margin-top: .4rem; }
.tag {
  display: inline-block; vertical-align: middle; margin-left: .4rem;
  padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 650;
  background: var(--accent-soft); color: var(--accent);
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
}
.card > :last-child { margin-bottom: 0; }

.hint { color: var(--muted); font-size: .9rem; }
.hint.warn { color: var(--warn); }
.hint:empty { display: none; }

.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 1rem; align-items: start; }

/* ---------- boutons ---------- */
.btn {
  appearance: none; font: inherit; font-weight: 600; cursor: pointer;
  padding: .5rem .95rem; border-radius: 8px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong);
}
.btn:hover:not(:disabled) { background: var(--accent-soft, var(--surface-2)); }
.btn.ghost { border-color: var(--line); color: var(--muted); font-weight: 550; background: transparent; }
.btn.ghost:hover:not(:disabled) { color: var(--ink); background: var(--surface-2); }
.btn.primary { background: var(--accent, var(--lane1)); border-color: var(--accent, var(--lane1)); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent, var(--lane1)); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.app-header .btn { font-size: .88rem; padding: .4rem .75rem; }

.icon {
  appearance: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  width: 1.9rem; height: 1.9rem; border-radius: 6px; font-size: 1.25rem; line-height: 1;
}
.icon:hover:not(:disabled) { background: var(--bad-soft); color: var(--bad); }
.icon:disabled { opacity: .3; cursor: not-allowed; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .7rem; margin-top: .8rem; }
.nav-next { display: flex; justify-content: flex-end; }

/* ---------- champs ---------- */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem 1.2rem; margin-top: .4rem; }
.fields.stack { grid-template-columns: 1fr; }
.field { display: grid; gap: .2rem; align-content: start; }
.field > span { font-weight: 600; font-size: .92rem; }
.field > small { color: var(--muted); font-size: .82rem; line-height: 1.35; }
.field.inline { display: inline-flex; align-items: center; gap: .6rem; margin: 0; }
.field.inline > span { font-weight: 550; color: var(--muted); }
input[type="text"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 7px; padding: .4rem .6rem; width: 100%; min-width: 0;
}
.field.inline input, .field.inline select { width: auto; }
input.short { width: 6rem; }
textarea { font-family: var(--mono); font-size: .88rem; resize: vertical; }
input.invalid { border-color: var(--bad); background: var(--bad-soft); }
.radio { display: inline-flex; align-items: center; gap: .35rem; }

/* ---------- tableaux ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
.table-wrap.tall { max-height: 62vh; margin-top: .9rem; border: 1px solid var(--line); border-radius: 8px; }
.short-table { max-height: 330px; margin-top: .8rem; border: 1px solid var(--line); border-radius: 8px; }

table.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: .8rem; font-weight: 650; letter-spacing: .02em; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--line-strong); padding: .5rem .6rem; white-space: nowrap;
}
.grid th small { display: block; font-weight: 500; letter-spacing: 0; }
.grid td { padding: .25rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tfoot td { border-bottom: 0; font-weight: 650; padding-top: .6rem; }
.grid .num { text-align: right; }
.grid .idx { width: 2rem; color: var(--muted); text-align: center; }
.grid .act { width: 2.4rem; text-align: center; }
.grid input[type="text"] { border-color: transparent; background: transparent; padding: .3rem .45rem; }
.grid input[type="text"]:hover { border-color: var(--line); }
.grid input[type="text"]:focus { border-color: var(--accent, var(--lane1)); background: var(--surface); }
.grid input.invalid { border-color: var(--bad); background: var(--bad-soft); }
.grid .num input[type="text"] { text-align: right; min-width: 4.2rem; }
.grid.compact td, .grid.compact th { padding: .22rem .7rem; }
.grid .is-ref td { background: var(--accent-soft); font-weight: 600; }
.grid .col-v1 { border-left: 3px solid var(--lane1); }
.grid th.col-v1 { color: var(--lane1); }
.grid .calc { padding-left: .7rem; padding-right: .7rem; white-space: nowrap; }
.grid .fin { font-weight: 750; }
.grid .fin.borne { text-decoration: underline dotted; text-underline-offset: 3px; }
.students td:first-child input { min-width: 9rem; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

.badge {
  display: inline-block; padding: .12rem .6rem; border-radius: 99px; font-weight: 700; font-size: .88rem;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- cartes de mode ---------- */
.mode-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(255px, 1fr)); gap: .9rem; }
.mode-card {
  display: grid; align-content: start; gap: .35rem; cursor: pointer;
  padding: .9rem 1rem 1rem; border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface);
  transition: border-color .12s, background .12s;
}
.mode-card:hover { border-color: var(--line-strong); }
.mode-card.selected { border-color: var(--lane1); background: var(--lane1-soft); }
.mode-card:focus-within { outline: 3px solid var(--lane1); outline-offset: 2px; }
.mode-num { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--lane1); }
.mode-title { font-size: 1.05rem; line-height: 1.25; }
.mode-sum { color: var(--muted); font-size: .92rem; }
.mode-card dl { margin: .3rem 0 0; display: grid; gap: .1rem; font-size: .88rem; }
.mode-card dt { font-weight: 700; margin-top: .4rem; font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.mode-card dd { margin: 0; }
.formule {
  display: block; margin-top: .6rem; padding: .4rem .55rem; border-radius: 6px;
  font: .8rem/1.4 var(--mono); background: var(--surface-2); border: 1px dashed var(--line-strong); color: var(--ink);
}
.mode-card.selected .formule { background: var(--surface); }

/* ---------- aperçu ---------- */
.chart-box { margin-top: .6rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1.5; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .axis-title { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart .curve { fill: none; stroke: var(--lane1); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .base-line { stroke: var(--lane2); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart .base-text { fill: var(--lane2); font-size: 12px; font-weight: 600; font-family: var(--font); }
.chart .ref-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .ref-text { fill: var(--muted); font-size: 11px; font-family: var(--font); }

.annonce { border-left: 4px solid var(--lane1); padding: .2rem 0 .2rem 1rem; max-width: 60rem; }
.annonce p { margin-bottom: .5rem; }

/* ---------- classe ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.stat {
  display: grid; gap: .05rem; padding: .7rem .9rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  border-top: 3px solid var(--lane3);
}
.stat span { font-size: .8rem; font-weight: 600; color: var(--muted); }
.stat b { font-size: 1.55rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .78rem; }
.stat-warn {
  grid-column: 1 / -1; margin: 0; padding: .6rem .9rem; border-radius: var(--radius);
  background: var(--lane2-soft); color: var(--ink); border: 1px solid var(--lane2);
}

details.paste { margin-top: .9rem; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .9rem; background: var(--surface-2); }
details.paste summary { cursor: pointer; font-weight: 650; }
details.paste[open] summary { margin-bottom: .5rem; }

/* ---------- divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.3rem; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: .6rem 1.1rem; border-radius: 8px;
  box-shadow: var(--shadow); max-width: min(90vw, 34rem); text-align: center;
}
.app-footer { max-width: 1180px; margin: 0 auto; padding: 0 1rem 2.2rem; color: var(--muted); font-size: .85rem; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  h2 { font-size: 1.25rem; }
  .tab small { display: none; }
  .tab { padding-inline: .8rem; }
  .card { padding: .9rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media print {
  .app-header .header-actions, .tabs, .toolbar, .nav-next, .toast { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
