/* Pages connexion / catalogue / administration — palette alignée sur le logo MB */
:root {
  --brand: #1a5bc8;
  --brand-hi: #4d8df5;
  --brand-soft: rgba(77, 141, 245, .14);
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1b2030;
  --line: #262c3b;
  --line-hi: #343c50;
  --fg: #eef1f7;
  --muted: #8f98ad;
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --topbar-bg: rgba(11, 13, 18, .88);
  --pop-bg: #1a1f2d;
  --btn-hover: #242a3c;
  --btn-hover-line: #414a62;
  --hover: rgba(255, 255, 255, .02);
  --inset: rgba(255, 255, 255, .04);
  --placeholder: #5f687d;
  --backdrop: rgba(4, 6, 10, .7);
  --ok-soft: rgba(74, 222, 128, .12);
  --danger-soft: rgba(248, 113, 113, .13);
  --warn-soft: rgba(251, 191, 36, .14);
  --on-danger: #1a0606;
  --shadow-sm: none;
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
  /* compat : anciens noms */
  --accent: var(--brand-hi);
}

/* Mode clair (bouton soleil/lune de la barre du haut, enregistré dans le navigateur) */
:root[data-theme="light"] {
  --brand-hi: #1a5bc8;
  --brand-soft: rgba(26, 91, 200, .09);
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f0f2f7;
  --line: #e4e7ee;
  --line-hi: #d0d6e0;
  --fg: #121826;
  --muted: #586174;
  --warn-soft: rgba(180, 83, 9, .09);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, .08);
  --ok: #15803d;
  --warn: #b45309;
  --danger: #dc2626;
  --shadow: 0 12px 36px rgba(21, 26, 36, .12);
  --topbar-bg: rgba(255, 255, 255, .88);
  --pop-bg: #ffffff;
  --btn-hover: #e6eaf2;
  --btn-hover-line: #b9c1cf;
  --hover: rgba(21, 26, 36, .03);
  --inset: rgba(255, 255, 255, .6);
  --placeholder: #8a93a5;
  --backdrop: rgba(21, 26, 36, .45);
  --ok-soft: rgba(21, 128, 61, .10);
  --danger-soft: rgba(220, 38, 38, .09);
  --on-danger: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--brand-hi); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand-hi); outline-offset: 2px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 28px 16px 80px; }
h1 { margin: 0; font-size: 26px; letter-spacing: -.01em; }
h2 { margin: 0; font-size: 19px; }
h3 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.5em; margin: 6px 0 0; }
.error:empty { min-height: 0; margin: 0; }
.pre { white-space: pre-line; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* ---------- Icônes ---------- */

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.sm { width: 15px; height: 15px; }

/* ---------- Barre du haut ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); font-weight: 700; text-decoration: none; white-space: nowrap; }
.brand img { width: 30px; height: 30px; }
.topbar nav { display: flex; align-items: center; gap: 4px; margin-left: 16px; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; text-decoration: none; white-space: nowrap; }
.topbar nav a:hover { color: var(--fg); background: var(--panel-2); }
.topbar nav a.active { color: var(--fg); background: var(--panel-2); }
.me { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.who { color: var(--muted); font-size: 14px; white-space: nowrap; }

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-hi);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line-hi);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--btn-hover); border-color: var(--btn-hover-line); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #2167dc; border-color: #2167dc; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn.small { min-height: 32px; padding: 5px 11px; font-size: 13.5px; border-radius: 9px; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--panel-2); color: var(--fg); }
.btn.dashed { width: 100%; border-style: dashed; background: none; color: var(--muted); }
.btn.dashed:hover { color: var(--fg); border-color: var(--brand-hi); background: var(--brand-soft); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--panel-2); color: var(--fg); border-color: var(--line); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.link-btn { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.link-btn:hover { color: var(--brand-hi); }

/* ---------- Formulaires ---------- */

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; align-content: start; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: 12.5px; }
.field small.warn { color: var(--warn); }
/* 16px minimum : en dessous, iOS zoome la page au focus d'un champ */
input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-hi);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 0; }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand-hi); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type="file"] { padding: 14px; border-style: dashed; cursor: pointer; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.note { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--panel-2); color: var(--muted); font-size: 13.5px; }

.search { position: relative; flex: 1; min-width: 200px; }
.search .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 38px; }

/* ---------- En-tête du tableau de bord ---------- */

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 26px; }
.stat {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.stat-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-hi); }
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat b { display: block; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

/* ---------- Onglets (segmenté) ---------- */

.tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 9px; color: var(--muted); font-weight: 600; text-decoration: none; white-space: nowrap; }
.tabs a:hover { color: var(--fg); }
.tabs a.active { background: var(--panel-2); color: var(--fg); box-shadow: 0 1px 0 var(--inset) inset; }
.count { padding: 1px 7px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600; }
.tabs a.active .count { background: var(--brand-soft); color: var(--brand-hi); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.toolbar h2 .muted { font-weight: 500; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* ---------- Cours / chapitres / vidéos ---------- */

.card {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.card.pad { padding: 18px; }
.course-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 16px 16px 12px; cursor: pointer; user-select: none; }
.course-head:hover { background: var(--hover); }
.chev { display: grid; place-items: center; flex: none; width: 28px; height: 28px; margin-top: 1px; border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; transition: transform .2s; }
.collapsed .chev { transform: rotate(-90deg); }
.course-title { flex: 1; min-width: 0; }
.course-title p { margin: 3px 0 0; font-size: 13.5px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; color: var(--muted); font-size: 13px; }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.course-body { padding: 0 16px 16px; }
.collapsed .course-body { display: none; }

.chapter { margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.chapter:first-child { margin-top: 0; }
.chapter-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--line); }
.chapter-head h3 { flex: 1; min-width: 0; font-size: 15px; }
.chapter-head { padding-left: 8px; cursor: pointer; user-select: none; }
.chapter-head .chev { margin-top: 0; }
.chapter-head .renamable h3 { flex: 0 1 auto; }
.chapter.collapsed .chapter-head { border-bottom: 0; }
.chapter.collapsed .vlist, .chapter.collapsed .empty-row { display: none; }
.chapter .empty-row { padding: 10px; }

.vlist { margin: 0; padding: 0; list-style: none; }
.vrow { display: grid; grid-template-columns: 112px 1fr auto; align-items: center; gap: 14px; padding: 10px 10px 10px 12px; border-top: 1px solid var(--line); }
.vrow:first-child { border-top: 0; }
.vrow:hover { background: var(--hover); }
/* Vidéo désactivée : miniature estompée, titre en gris lisible (contraste ≥ 4,5:1, pas d'opacité sur le texte) */
.vrow.off .thumb { opacity: .5; }
.vrow.off .thumb img { filter: grayscale(1); }
.vrow.off .vtitle { color: var(--muted); }
.vmeta button.badge { border: 0; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; min-height: 0; }
.thumb { position: relative; display: block; width: 112px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--panel-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .35); color: #fff; opacity: 0; transition: opacity .15s; }
.thumb:hover .play { opacity: 1; }
.vinfo { min-width: 0; }
.vtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* Renommage sur place */
.renamable { display: flex; align-items: center; gap: 4px; min-width: 0; }
.chapter-head .renamable { flex: 1; }
.renamable > :first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Titres de vidéos et de chapitres : jusqu'à 2 lignes avant les « … » (lisibles sur téléphone) */
.renamable > .vtitle, .chapter-head .renamable > h3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  white-space: normal;
  overflow-wrap: anywhere;
}
.renamable .rename-btn { flex: none; width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); opacity: 0; transition: opacity .15s; }
.renamable:hover .rename-btn, .rename-btn:focus-visible { opacity: 1; }
.renamable .rename-btn:hover { color: var(--fg); }
/* Écran tactile : pas de crayon permanent (il mangeait la place du titre) ; renommer via le menu ⋯ */
@media (hover: none) { .renamable .rename-btn { display: none; } }
.rename-input { flex: 1; min-width: 0; font: inherit; font-weight: 600; padding: 4px 8px; min-height: 0; }
.vmeta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 4px; color: var(--muted); font-size: 13px; }
.code { padding: 2px 7px; border-radius: 6px; background: var(--panel-2); color: var(--brand-hi); font: 600 12px ui-monospace, Consolas, monospace; letter-spacing: .03em; }
.vactions { display: flex; align-items: center; gap: 4px; }

/* Catalogue (cours.html) */
.vlink { display: flex; align-items: center; gap: 10px; padding: 4px 0; color: var(--fg); text-decoration: none; }
.vlink:hover { color: var(--brand-hi); }
.tick { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--panel-2); color: var(--brand-hi); font-size: 11px; }
.catalog .vlist li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--line); }
.catalog .vlist li:first-child { border-top: 0; }
.catalog .chapter h3 { padding: 10px 14px; border-bottom: 1px solid var(--line); }

/* États vides */
.empty { padding: 36px 20px; border: 1px dashed var(--line-hi); border-radius: var(--radius); color: var(--muted); text-align: center; }
.onboarding { padding: 28px; text-align: center; }
.onboarding h2 { margin-bottom: 6px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 22px 0; text-align: left; }
.step { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.step b { display: grid; place-items: center; width: 26px; height: 26px; margin-bottom: 8px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-hi); font-size: 13px; }
.step p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }

/* ---------- Élèves ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--line-hi);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.chip:hover { color: var(--fg); }
.chip[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--fg); }
.chip .count { background: var(--panel-2); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--hover); }
td.num { font-variant-numeric: tabular-nums; }
.person { display: flex; align-items: center; gap: 12px; }
.person small { display: block; color: var(--muted); font-size: 12px; }
.progress { display: flex; align-items: center; gap: 8px; }
.bar { width: 64px; height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand-hi); border-radius: inherit; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); }
.badge.prof { background: var(--brand-soft); color: var(--brand-hi); }
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.on::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
/* État normal d'une nouvelle vidéo : neutre, pas d'alerte rouge */
.badge.off { background: var(--panel-2); color: var(--muted); border: 1px dashed var(--line-hi); gap: 4px; }
button.badge.off:hover { color: var(--fg); border-color: var(--brand-hi); }

/* ---------- Menu « ⋯ » ---------- */

.menu {
  position: absolute;
  z-index: 200;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line-hi);
  border-radius: 12px;
  background: var(--pop-bg);
  box-shadow: var(--shadow);
  animation: pop .12s ease-out;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu-item .i { color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--panel-2); outline: none; }
.menu-item.danger, .menu-item.danger .i { color: var(--danger); }
.menu-item:disabled { opacity: .4; cursor: default; background: none; }
.menu hr { margin: 6px 4px; border: 0; border-top: 1px solid var(--line); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- Notifications ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border: 1px solid var(--line-hi);
  border-radius: 12px;
  background: var(--pop-bg);
  box-shadow: var(--shadow);
  font-weight: 550;
  transform: translateX(-50%);
  animation: toastIn .25s cubic-bezier(.2, 1.2, .4, 1);
}
.toast.ok .i { color: var(--ok); }
.toast.err .i { color: var(--danger); }
.toast.out { opacity: 0; transform: translate(-50%, 8px); transition: .3s; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ---------- Boîte de dialogue ---------- */

dialog {
  width: min(540px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 22px;
  border: 1px solid var(--line-hi);
  border-radius: 16px;
  background: var(--panel);
  color: var(--fg);
  box-shadow: var(--shadow);
}
dialog.wide { width: min(720px, calc(100vw - 24px)); }
dialog::backdrop { background: var(--backdrop); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
dialog[open] { animation: dlgIn .18s ease-out; }
@keyframes dlgIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
dialog h3 { font-size: 18px; }
.dlg-sub { margin: -8px 0 0; color: var(--muted); font-size: 13.5px; }

.qrbox { display: flex; justify-content: center; padding: 18px; border-radius: 12px; background: #fff; }
.url-row { display: flex; gap: 8px; }
.url-row input { font-size: 13px; color: var(--muted); }

.yt-preview { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.yt-preview img { width: 120px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--panel-2); }
.yt-preview b { display: block; font-size: 14px; line-height: 1.35; }
.yt-preview .status { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--danger); }
.status.wait { color: var(--muted); }

.profile { display: flex; align-items: center; gap: 14px; }
.profile h3 { font-size: 19px; }
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-stats div { padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.mini-stats b { display: block; font-size: 18px; }
.mini-stats span { color: var(--muted); font-size: 12.5px; }
.timeline { margin: 0; padding: 0; list-style: none; max-height: 320px; overflow-y: auto; }
.timeline li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline small { display: block; color: var(--muted); font-size: 12.5px; }
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn.wa:hover:not(:disabled) { background: #188f48; border-color: #188f48; }
.btn.wa .wa-done { display: none; }
tr.sent .btn.wa { background: transparent; border-color: var(--line); color: var(--ok); }
tr.sent .btn.wa .wa-done { display: inline-flex; }
td.c-act { text-align: right; white-space: nowrap; }
.qlist { display: grid; gap: 12px; }
.qedit { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.qedit-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qchoices { display: grid; gap: 8px; }
.qchoice { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; }
.qchoice input[type="radio"] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--ok); cursor: pointer; }
.qchoice.ok input[type="text"] { border-color: var(--ok); }
.qchoice .icon-btn { font-size: 20px; line-height: 1; }
.watch.q-top { color: var(--ok); }
.watch.q-mid { color: var(--warn); }
.watch.q-low { color: var(--danger); }
.errlist { margin: 8px 0 0; padding-left: 20px; color: var(--muted); font-size: 13px; }
details summary { cursor: pointer; }

/* ---------- Connexion ---------- */

/* Halo bleu du logo derrière les écrans élève (connexion, « scannez un QR code ») */
.auth, .scan-page {
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%, rgba(26, 91, 200, .28), transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 110%, rgba(63, 128, 238, .10), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}
.scan-page { min-height: 100dvh; }

.auth { display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px max(24px, env(safe-area-inset-bottom)); }
.auth .card {
  width: min(400px, 100%);
  padding: 32px 28px 28px;
  border-color: var(--line-hi);
  border-radius: 20px;
  background: rgba(20, 24, 33, .82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  animation: cardIn .4s cubic-bezier(.2, .8, .2, 1) both;
}
.auth .brand { flex-direction: column; justify-content: center; gap: 14px; margin-bottom: 6px; font-size: 22px; letter-spacing: -.01em; }
.auth .brand img { width: 64px; height: 64px; filter: drop-shadow(0 8px 24px rgba(26, 91, 200, .55)); }
.auth-sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; text-align: center; }
.auth .btn.primary { min-height: 48px; margin-top: 4px; font-size: 16px; box-shadow: 0 8px 24px rgba(26, 91, 200, .35); }
.auth .field > span { color: #b4bccd; }
.small-print { margin: 0; font-size: 13px; text-align: center; }
@keyframes cardIn { from { opacity: 0; transform: translateY(12px); } }

/* Message élève (pas de catalogue) */
.scan-only {
  max-width: 420px;
  margin: 10vh auto 0;
  padding: 36px 24px 32px;
  border-color: var(--line-hi);
  border-radius: 20px;
  background: rgba(20, 24, 33, .82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  text-align: center;
  overflow: visible;
}
.scan-only h1 { margin-bottom: 8px; }
.scan-only p { margin: 0 auto; max-width: 32ch; }
.scan-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 80px;
  height: 80px;
  margin: 0 auto 22px;
  border-radius: 22px;
  background: linear-gradient(145deg, #3f80ee, var(--brand));
  color: #fff;
  box-shadow: 0 12px 32px rgba(26, 91, 200, .45);
}
.scan-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid var(--brand-hi);
  animation: scanPulse 2.4s ease-out infinite;
}
.scan-icon .i { width: 38px; height: 38px; }
@keyframes scanPulse { from { opacity: .8; transform: scale(1); } to { opacity: 0; transform: scale(1.45); } }

/* ---------- Mobile ---------- */

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .wrap { padding-top: 20px; }
  h1 { font-size: 22px; }
  .who, .brand span { display: none; }
  .topbar { gap: 6px; padding-left: 12px; padding-right: 8px; }
  .topbar nav { margin-left: 0; gap: 2px; }
  .topbar nav a { padding: 6px 8px; }
  .me { gap: 2px; }
  .row, .steps { grid-template-columns: 1fr; }
  .stat { padding: 12px; gap: 10px; }
  .stat-icon { width: 36px; height: 36px; }
  .stat b { font-size: 20px; }
  .course-head { padding: 14px 10px 12px 6px; }
  .course-body { padding: 0 10px 12px; }
  .vrow { grid-template-columns: 84px 1fr auto; gap: 10px; padding: 10px 6px 10px 10px; }
  .thumb { width: 84px; }
  .hide-sm { display: none; }
  .tabs { display: flex; }
  .tabs a { flex: 1; justify-content: center; padding: 8px 6px; }
  .me .avatar { display: none; }

  /* Cours : moins d'imbrication, plus de place pour les titres */
  .course-body { padding: 0 6px 8px; }
  .chapter-head { gap: 6px; padding: 8px 6px 8px 4px; }
  .chapter-head .count { display: none; }
  .vrow { grid-template-columns: 72px 1fr auto; gap: 10px; padding: 10px 6px 10px 8px; }
  .thumb { width: 72px; }
  .vactions { flex-direction: column; gap: 2px; }
  .vmeta { gap: 4px 10px; }

  /* Tableau des élèves → cartes */
  .users thead { display: none; }
  .users, .users tbody { display: block; }
  .users tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 12px 12px 12px 14px; border-bottom: 1px solid var(--line); }
  .users tr:last-child { border-bottom: 0; }
  .users td { padding: 0; border: 0; white-space: normal; }
  .users td.c-who { grid-column: 1; }
  .users td.c-act { grid-column: 2; grid-row: 1; }
  .users td.c-info { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding-left: 46px; color: var(--muted); font-size: 13px; }
  .users td.c-wide { display: none; }
}

@media (min-width: 641px) {
  .users td.c-info { display: none; }
}

/* ---------- Activité (classements) ---------- */

.seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.seg button {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }

.activity-stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 26px; }
.activity-stats div { border: 1px solid var(--line); background: var(--panel); }
.activity-stats b { font-size: 20px; font-variant-numeric: tabular-nums; }

.rank-section { margin-bottom: 30px; }
.rank-section .toolbar { align-items: baseline; margin-bottom: 10px; }
.small { margin: 0; font-size: 13px; }

.ranking tbody tr { cursor: pointer; }
.ranking tr.inactive td { color: var(--muted); }
.ranking tr.inactive .avatar { background: var(--panel-2); color: var(--muted); }
.ranking .c-rank { width: 1%; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.ranking .progress { min-width: 150px; }
.ranking .bar { width: 90px; }
.ranking .progress span { font-variant-numeric: tabular-nums; font-weight: 600; }

th .sort {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
th .sort:hover { color: var(--fg); }
th .sort.on { color: var(--brand-hi); }
th .sort.on::after { content: " ↓"; }

.medal { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #1a1205; font-size: 13px; font-weight: 800; }
.medal.m1 { background: #fbbf24; }
.medal.m2 { background: #cbd5e1; }
.medal.m3 { background: #d6955b; }

.vcell { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.vcell img { flex: none; width: 72px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.vcell b { display: block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.vcell small { display: block; color: var(--muted); font-size: 12px; }

.watch { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.watch .muted { font-weight: 500; }
.bar.wide { width: 140px; height: 4px; margin-top: 6px; }

@media (max-width: 640px) {
  .activity-stats { grid-template-columns: repeat(2, 1fr); }
  .rank-section .toolbar .small { display: none; }

  /* Classements : l'essentiel à l'écran, le détail en touchant la ligne */
  .ranking .c-more { display: none; }
  .ranking .progress { min-width: 0; }
  .ranking .bar { width: 48px; }
  .ranking th, .ranking td { padding: 10px 8px; white-space: normal; }
  .vcell { min-width: 0; gap: 8px; }
  .vcell img { width: 56px; }
  .vcell b { max-width: none; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .seg { width: 100%; }
  .seg button { flex: 1; padding: 6px 4px; }
}

/* ---------- Écrans tactiles : cibles plus grandes, retour visuel à l'appui ---------- */

@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .icon-btn { width: 42px; height: 42px; }
  .chip { min-height: 38px; }
  .menu-item { padding: 12px 10px; }
}
.icon-btn:active, .chip:active, .menu-item:active { transform: scale(.96); }
.icon-btn, .chip { transition: background .15s, color .15s, transform .1s; }

/* ---------- Mouvement réduit ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .scan-icon::after { display: none; }
}

/* Import d'un cours (JSON) : aperçu de l'arborescence */
.import-preview { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.import-preview ul { margin: 0; padding-left: 18px; display: grid; gap: 2px; font-size: 14px; }
.import-preview p { margin: 0; }
/* Sections Classe / Soutien : grand intercalaire, puis niveaux à l'intérieur */
.filters-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 16px; }
.filters-row .chips { margin-bottom: 0; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.seg button .count { background: var(--panel-2); }
.seg button[aria-pressed="true"] .count { background: rgba(255, 255, 255, .22); color: #fff; }
.section-block { margin: 8px 0 30px; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; padding-bottom: 10px; border-bottom: 2px solid var(--line-hi); font-size: 20px; }
.section-title .i { color: var(--brand-hi); }
.section-block.soutien .section-title .i { color: var(--warn); }
.section-title .muted { font-size: 13.5px; font-weight: 500; }
.badge.sec-classe { background: var(--brand-soft); color: var(--brand-hi); }
.badge.sec-soutien { background: rgba(251, 191, 36, .14); color: var(--warn); }
:root[data-theme="light"] .badge.sec-soutien { background: rgba(180, 83, 9, .10); }

/* Niveaux (TC, 1BAC…) : intercalaire avec étiquette + filet */
.level-group { margin-bottom: 26px; }
.level-title { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 14px; }
.level-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.level-tag { padding: 4px 12px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-hi); font-weight: 700; letter-spacing: .03em; }
.level-title .muted { font-size: 13px; font-weight: 500; }
#course-csv-text { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; min-height: 90px; resize: vertical; }

/* =====================================================================
   Espace professeur (admin.html) : barre latérale + pages
   ===================================================================== */

.skip { position: absolute; left: -9999px; top: 8px; z-index: 999; padding: 8px 12px; border-radius: 8px; background: var(--panel); color: var(--fg); }
.skip:focus { left: 12px; }

.shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100dvh; }

/* ---------- Barre latérale ---------- */
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100dvh;
  padding: 18px 14px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.side-brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px; color: var(--fg); text-decoration: none; }
.side-brand img { width: 34px; height: 34px; flex: none; }
.side-brand b { display: block; font-size: 15px; line-height: 1.2; }
.side-brand small { display: block; color: var(--muted); font-size: 12.5px; }
.side-nav { display: grid; gap: 2px; }
.side-link {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14.5px;
  font-weight: 550;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.side-link:hover { background: var(--panel-2); color: var(--fg); }
.side-link.active { background: var(--brand-soft); color: var(--brand-hi); font-weight: 650; }
.side-link .count { margin-left: auto; }
.side-link.active .count { background: var(--panel); color: var(--brand-hi); }
.count.warn { background: var(--warn-soft); color: var(--warn); }
.side-sub { display: grid; gap: 2px; margin: 0 0 6px 21px; padding-left: 10px; border-left: 1px solid var(--line); }
.side-link.sub { min-height: 34px; padding: 6px 10px; font-size: 13.5px; }
.side-link.sub .i { width: 16px; height: 16px; }
.side-foot { display: grid; gap: 2px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px 4px 2px 6px; }
.side-user > div { flex: 1; min-width: 0; }
.side-user b, .side-user small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user b { font-size: 13.5px; }
.side-user small { color: var(--muted); font-size: 12px; }

/* ---------- Page ---------- */
.workspace { min-width: 0; }
.page { max-width: 1120px; margin: 0 auto; padding: 32px 32px 80px; outline: none; }
body.admin .page-head { align-items: flex-end; margin-bottom: 22px; }
body.admin .page-head h1 { font-size: 26px; letter-spacing: -.02em; }
body.admin .page-head .tools { gap: 8px; }
.mobile-top, .bottom-nav { display: none; }
body.admin .card { box-shadow: var(--shadow-sm); }
.card-title { margin: 0 0 14px; font-size: 16px; }
.card-sub { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.section-head h2 { font-size: 18px; }
.link { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- Accueil ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, box-shadow .2s;
}
.kpi:hover { border-color: var(--brand-hi); box-shadow: var(--shadow-md); }
.kpi-icon { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 11px; background: var(--brand-soft); color: var(--brand-hi); }
.kpi.ok .kpi-icon { background: var(--ok-soft); color: var(--ok); }
.kpi-body { min-width: 0; }
.kpi-body b { display: block; font-size: 26px; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-body span { display: block; margin-top: 3px; font-size: 14px; font-weight: 600; }
.kpi-body small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; }

.home-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; gap: 16px; margin-bottom: 30px; }
.home-grid .card { margin: 0; }
.todo { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.todo-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.todo-item p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.todo-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--panel-2); color: var(--muted); }
.todo-item.danger .todo-icon { background: var(--danger-soft); color: var(--danger); }
.todo-item.warn .todo-icon { background: var(--warn-soft); color: var(--warn); }
.all-good { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 12px; background: var(--ok-soft); }
.all-good > .i { color: var(--ok); }
.all-good p { margin: 2px 0 0; }
.quick { display: grid; gap: 4px; }
.quick-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 1px solid transparent; border-radius: 11px; background: none; color: var(--fg); font: inherit; text-align: left; cursor: pointer; transition: background .15s; }
.quick-item:hover { border-color: var(--line); background: var(--panel-2); }
.quick-icon { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-hi); }
.quick-item b { display: block; font-size: 14px; }
.quick-item small { display: block; color: var(--muted); font-size: 12.5px; }

.week { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 24px; }
.toplist { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.toplist li { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; cursor: pointer; }
.toplist li:hover, .toplist li:focus-visible { background: var(--panel-2); }
.toplist li > div { min-width: 0; }
.toplist img { width: 64px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.toplist b { display: block; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.toplist small { color: var(--muted); font-size: 12.5px; }
.week-side { display: grid; align-content: start; gap: 10px; }
.mini { padding: 12px 14px; border-radius: 12px; background: var(--panel-2); }
.mini b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.mini span { color: var(--muted); font-size: 13px; }
.mini.warn b { color: var(--warn); }

/* ---------- Barre de filtres (Cours, Élèves, Activité) ---------- */
.filterbar { display: grid; gap: 10px; margin-bottom: 22px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-sm); }
.filterbar-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.filterbar-top .search { flex: 1; min-width: 220px; }
.filterbar .search input { min-height: 40px; background: var(--bg); }
.filterbar-bottom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filterbar-bottom .chips { margin: 0; }
.filterbar-bottom > .btn.ghost { margin-left: auto; }
.chip.toggle[aria-pressed="true"] { border-color: var(--warn); background: var(--warn-soft); color: var(--fg); }
.result-count { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.result-count .link-btn { color: var(--brand-hi); font-weight: 600; }
.empty p { margin: 0 0 12px; }

/* ---------- Cours ---------- */
.section-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-hi); }
.section-icon .i { color: inherit; }
.section-block.soutien .section-icon { background: var(--warn-soft); color: var(--warn); }
.section-title { border-bottom-width: 1px; }
.meta-off { color: var(--warn); }
body.admin .chapter { background: var(--panel-2); }
body.admin .chapter .vlist { background: var(--panel); border-radius: 0 0 11px 11px; }
body.admin .chapter.collapsed .chapter-head { border-radius: 11px; }
body.admin .rank-section .toolbar h3 { font-size: 17px; }

/* ---------- Pages Classe / Soutien : en-tête ---------- */
.hero {
  --hero-accent: var(--brand-hi);
  --hero-tint: rgba(26, 91, 200, .10);
  margin-bottom: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: radial-gradient(120% 160% at 0% 0%, var(--hero-tint), transparent 55%), var(--panel);
  box-shadow: var(--shadow-sm);
}
.hero.soutien { --hero-accent: var(--warn); --hero-tint: rgba(217, 119, 6, .12); }
.hero-main { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.hero-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--hero-accent);
  color: #fff;
  box-shadow: 0 10px 24px -10px var(--hero-accent);
}
.hero-icon .i { width: 28px; height: 28px; }
.hero-kicker { margin: 0; color: var(--hero-accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.hero h1 { margin: 0; font-size: 30px; line-height: 1.15; letter-spacing: -.02em; }
.hero-sub { margin: 3px 0 0; color: var(--muted); }
.hero-actions { gap: 8px; margin-left: auto; }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 2fr); gap: 12px; margin-top: 22px; }
.hero-stat { padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.hero-stat b { display: block; font-size: 22px; line-height: 1.2; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.hero-stat span { color: var(--muted); font-size: 13px; }
.hero-stat .bar { width: 100%; height: 6px; margin-top: 8px; }
.hero-stat .bar i { background: var(--hero-accent); }

/* ---------- Niveaux déroulants (accordéons) ---------- */
.level.acc {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s;
}
.level.acc:hover { border-color: var(--line-hi); }
.level.acc.open { box-shadow: var(--shadow-md); }
.level-head {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.level-head:hover { background: var(--hover); }
.level-head:focus-visible { outline-offset: -2px; }
.level-badge {
  display: grid;
  place-items: center;
  flex: none;
  min-width: 56px;
  height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand-hi);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .02em;
  white-space: nowrap;
}
.level-badge.soutien { background: var(--warn-soft); color: var(--warn); }
.level-name { flex: 1; min-width: 0; }
.level-name b { display: block; font-size: 16px; }
.level-name small { color: var(--muted); font-size: 13px; }
.level-off { color: var(--warn); }
.level-meter { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.level-meter .bar { width: 90px; }
.level.soutien .level-meter .bar i { background: var(--warn); }
.level-chev { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 10px; color: var(--muted); transition: transform .25s ease, background .15s, color .15s; }
.level-head:hover .level-chev { background: var(--panel-2); color: var(--fg); }
.level.open .level-chev { transform: rotate(180deg); }
.level-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .28s ease; }
.level.open .level-body { grid-template-rows: 1fr; }
/* Replié : contenu masqué aussi au clavier et aux lecteurs d'écran, une fois l'animation finie */
.level-inner { min-height: 0; overflow: hidden; visibility: hidden; transition: visibility 0s .28s; }
.level.open .level-inner { visibility: visible; transition-delay: 0s; }
.level.open .level-head { border-bottom: 1px solid var(--line); }
.level-inner > .card { margin: 12px 14px 0; }
.level-inner > .card:last-child { margin-bottom: 14px; }
.level .card.course { border-radius: 14px; box-shadow: none; transition: border-color .15s; }
.level .card.course:hover { border-color: var(--line-hi); }
.level .course-title h2 { font-size: 18px; }
.btn.flip .i { transform: rotate(180deg); }
.section-block > .level.acc:last-child { margin-bottom: 0; }

/* ---------- Téléphone et tablette : barre du haut + onglets en bas ---------- */
@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .mobile-top {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) 8px 8px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--topbar-bg);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  .mobile-top .side-brand { padding: 0; }
  .mobile-top .side-brand img { width: 28px; height: 28px; }
  .mobile-top .side-brand b { font-size: 17px; }
  .mobile-top .tools { gap: 2px; }
  .bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--panel);
    box-shadow: 0 -4px 16px rgba(16, 24, 40, .06);
  }
  .bottom-nav a { display: grid; justify-items: center; gap: 2px; min-height: 52px; padding: 4px 2px; border-radius: 10px; color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: none; }
  .bottom-nav a.active { color: var(--brand-hi); }
  .bn-icon { position: relative; display: grid; place-items: center; width: 56px; height: 30px; border-radius: 999px; transition: background .2s; }
  .bottom-nav a.active .bn-icon { background: var(--brand-soft); }
  .bn-icon .dot { position: absolute; top: 3px; right: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--panel); }
  .page { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .home-grid, .week { grid-template-columns: 1fr; }
  .week-side { grid-template-columns: repeat(3, 1fr); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
  body.admin .page-head { align-items: flex-start; }
  body.admin .page-head h1 { font-size: 23px; }
  .kpi { flex-direction: column; gap: 10px; padding: 14px; }
  .kpi-body b { font-size: 22px; }
  .todo-item { grid-template-columns: auto minmax(0, 1fr); }
  .todo-item .btn { grid-column: 1 / -1; justify-self: start; }
  .toplist li { grid-template-columns: 56px minmax(0, 1fr); row-gap: 6px; }
  .toplist img { width: 56px; grid-row: span 2; }
  .toplist .progress { grid-column: 2; }
  .toplist b { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .mini { padding: 10px 12px; }
  .mini b { font-size: 17px; }
  .filterbar { padding: 10px; }
  .filterbar-top .seg { width: 100%; }
  .filterbar-top .search { min-width: 100%; }
  /* Niveaux / classes : une seule ligne qui défile au doigt */
  .filterbar-bottom .chips { flex: 1 1 100%; flex-wrap: nowrap; margin: 0 -10px; padding: 2px 10px; overflow-x: auto; scrollbar-width: none; }
  .filterbar-bottom .chips::-webkit-scrollbar { display: none; }
  .filterbar-bottom .chip { flex: none; }
  /* En-tête Classe / Soutien compact : l'essentiel au-dessus de la ligne de flottaison */
  .hero { padding: 16px; border-radius: 18px; }
  .hero-main { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 14px; }
  .hero-icon { width: 46px; height: 46px; border-radius: 13px; }
  .hero-icon .i { width: 24px; height: 24px; }
  .hero h1 { font-size: 24px; }
  .hero-sub { display: none; }
  .hero-actions { grid-column: 1 / -1; width: 100%; margin-left: 0; }
  .hero-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
  .hero-stat { padding: 8px 10px; border-radius: 12px; }
  .hero-stat b { font-size: 17px; }
  .hero-stat span { font-size: 12px; }
  .hero-stat.wide { grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 2px 10px; }
  .hero-stat.wide .bar { grid-column: 1 / -1; margin-top: 4px; }
  .level-head { gap: 12px; padding: 12px; }
  .level-badge { min-width: 48px; height: 40px; font-size: 13px; }
  .level-meter .bar { display: none; }
  .level-inner > .card { margin: 10px 8px 0; }
  .level-inner > .card:last-child { margin-bottom: 10px; }
}
