/* Gestion auto-école — interface tactile, pensée pour une tablette Surface */
:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #1c2321;
  --muted: #66706c;
  --line: #dfe3df;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e3eef6;
  --due: #b3261e;
  --due-soft: #fbe9e7;
  --credit: #2e7d4f;
  --radius: 14px;
  --tap: 52px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 14px rgb(0 0 0 / .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --surface: #1b2120; --ink: #e8ece9; --muted: #9aa5a0;
    --line: #2c3432; --accent: #6fb0e0; --accent-ink: #0d1a24; --accent-soft: #1d2d38;
    --due: #ff8a80; --due-soft: #3a1f1d; --credit: #7fd3a1;
    --shadow: none; color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.7rem; margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* Barre du haut */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar__inner { max-width: 1200px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink); text-decoration: none; }
.brand__mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: .85rem; letter-spacing: .04em; }
.brand--signe .brand__name { display: flex; flex-direction: column; line-height: 1.2; }
.brand__signature { font-size: .8rem; font-weight: 400; color: var(--muted, #666); }
.tabs__item, .brand__titre { white-space: nowrap; }
@media (max-width: 1000px) {
  .brand--signe:not(.brand--toujours) .brand__signature { display: none; }
  .tabs .tabs__item { padding: 0 10px; }
  .topbar .topbar__inner { gap: 10px; }
  .tabs { margin-left: 0; }
}
.topbar__logout { margin: 0; }

.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 22px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation; transition: filter .15s, background .15s;
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { background: var(--accent-soft); }
.btn--danger { background: var(--due); color: #fff; }
.btn--block { width: 100%; }
.btn--back { padding: 0 16px; }
.btn:focus-visible, input:focus-visible, .row__link:focus-visible, .seg__item:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Totaux */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.stat__label { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat__value { display: block; font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat--due { background: var(--due-soft); border-color: transparent; }
.stat--due .stat__value { color: var(--due); }

/* Recherche + tri */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.search { flex: 1 1 320px; }
.search input, .field input, .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
}
.search input { font-size: 1.05rem; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg__item { min-height: 44px; display: inline-flex; align-items: center; padding: 0 16px; border-radius: 9px; color: var(--ink); text-decoration: none; font-weight: 500; }
.seg__item.is-active { background: var(--accent); color: var(--accent-ink); }
#compteur { min-height: 1.4em; margin: 4px 2px 10px; font-size: .95rem; }

/* Liste des élèves */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row__link {
  display: grid; align-items: center; gap: 4px 18px;
  grid-template-columns: minmax(190px, 2fr) minmax(100px, .9fr) minmax(165px, 1.3fr) minmax(100px, .9fr) 64px 110px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; min-height: 72px; color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.row__link:hover { border-color: var(--accent); }
.row__link:active { background: var(--accent-soft); }
.row__name { display: block; font-size: 1.1rem; }
.row__sub { display: block; color: var(--muted); font-size: .9rem; }
.row__k { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.row__solde { font-weight: 600; text-align: right; }
.is-expired, .is-expired .row__k { color: var(--due); font-weight: 600; }
.row__solde.is-due { color: var(--due); }
.row__solde.is-credit { color: var(--credit); }
.row__chev { font-size: 1.6rem; color: var(--muted); text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* Tablette en portrait / téléphone : cartes */
@media (max-width: 860px) {
  .row__link { grid-template-columns: 1fr 1fr 1fr; }
  .row__main { grid-column: 1 / -1; }
  .row__solde { text-align: left; }
  .row__chev { display: none; }
}
@media (max-width: 480px) {
  .row__link { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .seg { width: 100%; } .seg__item { flex: 1; justify-content: center; }
}

/* Formulaires / connexion */
.login { max-width: 420px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.login__title { font-size: 1.5rem; }
.form { display: grid; gap: 16px; margin-top: 18px; }
.field span { display: block; font-weight: 600; margin-bottom: 6px; }
.flash { padding: 12px 16px; border-radius: 12px; margin: 0 0 16px; background: var(--accent-soft); }
.flash--err { background: var(--due-soft); color: var(--due); }
.code { white-space: pre-wrap; word-break: break-all; background: var(--bg); border: 1px solid var(--line); padding: 12px; border-radius: 10px; font-size: .85rem; user-select: all; }

/* ---------- Fiche, leçons, formulaires ---------- */
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.sub { margin: 4px 0 0; }
.small { font-size: .9rem; margin-top: -4px; }
.pagetitle { margin-bottom: 4px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn--sm { min-height: 44px; padding: 0 16px; font-size: .95rem; }
.stat--credit .stat__value { color: var(--credit); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card p { margin: 0 0 14px; }
.card p:last-child { margin-bottom: 0; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card__head h2 { margin: 0; }
.card--pos { border-left: 5px solid var(--credit); }
.card--neg { border-left: 5px solid var(--due); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 0 14px; }

.dl { display: grid; grid-template-columns: minmax(130px, 40%) 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Liste des leçons */
.lesson {
  display: grid; grid-template-columns: 48px 1fr auto 20px; align-items: center; gap: 14px;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; min-height: 68px;
  color: var(--ink); text-decoration: none; background: var(--surface);
}
.lesson:hover { border-color: var(--accent); }
.lesson:active { background: var(--accent-soft); }
.lesson__num { color: var(--muted); font-variant-numeric: tabular-nums; }
.lesson__date { display: block; font-weight: 600; }
.lesson__obj { display: block; color: var(--muted); font-size: .92rem; }
.lesson__money { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.lesson__money > span { display: block; }
.lesson__pay { font-weight: 400; font-size: .88rem; color: var(--credit); }
.lesson__pay.is-due { color: var(--due); font-weight: 600; }
.lesson__pay.muted { color: var(--muted); }
@media (max-width: 600px) {
  .lesson { grid-template-columns: 1fr auto; }
  .lesson__num, .lesson .row__chev { display: none; }
}

/* Progression */
.skills { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px 24px; }
.skills ul { list-style: none; margin: 0; padding: 0; }
.skill { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.skill__name { flex: 1; }
.skill__count { font-size: .8rem; color: var(--muted); background: var(--bg); border-radius: 99px; padding: 1px 8px; }
.skill__badge { font-size: .8rem; font-weight: 600; border-radius: 99px; padding: 3px 10px; min-width: 92px; text-align: center; color: var(--muted); }
.skill--vu .skill__badge { background: var(--accent-soft); color: var(--accent); }
.skill--auto .skill__badge { background: var(--credit); color: #fff; }
.skills--edit .skill { padding: 6px 0; }

/* Interrupteurs (cases à cocher en gros boutons) */
.toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle { position: relative; display: inline-flex; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; user-select: none; font-weight: 500;
}
.toggle input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.toggle--auto input:checked + span { background: var(--credit); border-color: var(--credit); color: #fff; }
.toggle input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Champs */
.stack { margin-top: 16px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 16px; }
.fields--1 { grid-template-columns: 1fr; }
.field textarea { padding: 12px 16px; min-height: auto; line-height: 1.45; resize: vertical; }
.field input[type=date] { padding-right: 8px; }
.field__err { display: block; color: var(--due); font-size: .9rem; margin-top: 4px; }
.field__hint { display: block; color: var(--muted); font-size: .85rem; margin-top: 4px; }
.has-err input { border-color: var(--due); }
.field--total input { font-weight: 700; }
.formbar {
  position: sticky; bottom: 0; z-index: 4; display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.formbar .btn--primary { min-width: 200px; }

/* Compétences d'une leçon */
.chips-groups { display: grid; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 4px 12px; font-size: .92rem; }

.pager { display: flex; justify-content: space-between; gap: 10px; margin: 18px 0; }
.danger { margin-top: 28px; padding-top: 18px; border-top: 1px dashed var(--line); text-align: center; }
.btn--danger-ghost { background: transparent; color: var(--due); border-color: var(--due); }
.btn--danger-ghost:hover { background: var(--due-soft); }
.mt { margin-top: 10px; }

/* ---------- Onglets de la barre du haut ---------- */
.topbar__inner { gap: 16px; }
.tabs { display: flex; gap: 4px; margin-right: auto; margin-left: 8px; }
.tabs__item { display: inline-flex; align-items: center; min-height: 48px; padding: 0 16px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.tabs__item:hover { background: var(--accent-soft); }
.tabs__item.is-active { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 760px) {
  .brand__name, .brand--signe .brand__name { display: none; }
  .brand--signe.brand--toujours .brand__name { display: flex; }
  .tabs { margin-left: 0; }
  .tabs__item { padding: 0 10px; }
}
.formbar--static { position: static; background: none; padding-bottom: 0; }

/* ---------- Support de cours ---------- */
.sc-cat { margin-bottom: 26px; }
.sc-cat__titre { font-size: 1.25rem; margin: 6px 0 12px; }
.sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.sc-card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
}
.sc-card:hover { border-color: var(--accent); }
.sc-card:active { transform: scale(.99); }
.sc-card__img { display: block; aspect-ratio: 4 / 3; background: #fff; overflow: hidden; border-bottom: 1px solid var(--line); }
.sc-card__img img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.sc-card__body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 2px; }
.sc-card__titre { font-weight: 600; line-height: 1.3; }
.sc-card__nb { color: var(--muted); font-size: .88rem; }
.sc-kicker { text-transform: uppercase; letter-spacing: .06em; font-size: .78rem; margin: 0 0 4px; }

.sc-pages { display: grid; gap: 22px; max-width: 920px; margin: 0 auto; }
.sc-page { margin: 0; text-align: center; }
.sc-page__btn { display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; cursor: zoom-in; box-shadow: var(--shadow); }
.sc-page__btn img { display: block; width: 100%; height: auto; }
.sc-page figcaption { margin-top: 6px; font-size: .9rem; }

/* Visionneuse plein écran */
.no-scroll { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 50; background: #0d0f0f; display: grid; grid-template-rows: auto 1fr; }
.viewer__bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; color: #fff; }
.viewer__count { font-variant-numeric: tabular-nums; opacity: .85; padding-left: 8px; }
.viewer__close, .viewer__nav {
  border: 0; background: rgb(255 255 255 / .12); color: #fff; border-radius: 12px; cursor: pointer;
  width: 56px; height: 56px; font-size: 1.6rem; display: grid; place-items: center; touch-action: manipulation;
}
.viewer__close:hover, .viewer__nav:hover { background: rgb(255 255 255 / .24); }
.viewer__stage { display: grid; place-items: center; overflow: auto; touch-action: pan-y pinch-zoom; padding: 0 8px 8px; }
.viewer__stage img { max-width: 100%; max-height: calc(100vh - 80px); object-fit: contain; background: #fff; border-radius: 4px; user-select: none; -webkit-user-drag: none; }
.viewer__nav { position: absolute; top: 50%; transform: translateY(-50%); width: 64px; height: 96px; font-size: 2.4rem; }
.viewer__nav--prev { left: 10px; }
.viewer__nav--next { right: 10px; }
@media (max-width: 600px) { .viewer__nav { width: 44px; height: 72px; } }

/* Progression : résumé et dernière date */
.prog-sum { margin-bottom: 10px; }
.prog-sum p { margin: 0 0 8px; }
.prog-bar { position: relative; height: 12px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.prog-bar__vu, .prog-bar__auto { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 99px; transition: width .4s ease; }
.prog-bar__vu { background: var(--accent); opacity: .35; }
.prog-bar__auto { background: var(--credit); }
.skill__last { display: block; font-size: .8rem; color: var(--muted); }

/* Archivage */
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--accent-soft); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.banner form { margin: 0; }
.archive-box { display: grid; grid-template-columns: 1fr auto; gap: 12px 20px; align-items: end; }
.archive-box h2 { margin-bottom: 6px; }
.archive-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin: 0; }
.archive-form .field input { width: 130px; }
@media (max-width: 700px) { .archive-box { grid-template-columns: 1fr; } }

/* Archives */
.chips--filter { margin: 6px 0 4px; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 99px;
  min-height: 44px; padding: 0 14px; font: inherit; font-weight: 500; cursor: pointer; }
.chip-btn.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip-btn.is-active .muted { color: inherit; opacity: .8; }
.tag { display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; font-size: .85rem; font-weight: 500; }
.tag--new { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.row__link--archive { grid-template-columns: minmax(190px, 2fr) minmax(100px, .9fr) minmax(150px, 1.2fr) 70px minmax(130px, 1fr) 20px; }
@media (max-width: 860px) { .row__link--archive { grid-template-columns: 1fr 1fr; } }
.arch-lecons { display: grid; gap: 8px; }
.arch-lecon { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.arch-lecon summary { display: grid; grid-template-columns: 48px 170px 1fr auto; gap: 12px; align-items: center;
  min-height: 56px; padding: 8px 16px; cursor: pointer; list-style: none; font-variant-numeric: tabular-nums; }
.arch-lecon summary::-webkit-details-marker { display: none; }
.arch-lecon[open] summary { border-bottom: 1px solid var(--line); }
.arch-lecon__date { font-weight: 600; }
.arch-lecon__obj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arch-lecon__money { font-weight: 600; }
.arch-lecon__body { padding: 14px 16px; }
.arch-lecon__body h3 { margin-top: 14px; }
.arch-lecon__body p { margin: 0; }
@media (max-width: 600px) { .arch-lecon summary { grid-template-columns: 1fr auto; } .arch-lecon .lesson__num, .arch-lecon__obj { display: none; } }

/* Bloc repliable (chiffres de la liste des élèves, masqués par défaut) */
.repli { margin-bottom: 14px; }
.repli__titre { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--muted); font-weight: 600; cursor: pointer; list-style: none; user-select: none; }
.repli__titre::-webkit-details-marker { display: none; }
.repli__titre::before { content: "›"; display: inline-block; font-size: 1.3rem; line-height: 1; transition: transform .15s; }
.repli[open] > .repli__titre::before { transform: rotate(90deg); }
.repli[open] > .repli__titre { margin-bottom: 10px; }

/* Bilan du mois */
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bilan-mois { margin-bottom: 16px; }
.bilan-mois__choix input { min-width: 0; width: 200px; }
.bilan-modes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -6px 0 16px; color: var(--muted); }
.bilan-titre { margin-top: 28px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.table tbody th { font-weight: 400; }
.table tbody th a { color: var(--ink); text-decoration: none; display: inline-block; min-height: 24px; }
.table tbody th a:hover { color: var(--accent); }
.table tbody tr:hover { background: var(--accent-soft); }
.table tfoot th, .table tfoot td { font-weight: 650; border-bottom: 0; background: var(--bg); }
.table .num { text-align: right; }
.table .is-due { color: var(--due); font-weight: 600; }
.table .is-credit { color: var(--credit); }
.flag { color: var(--due); font-weight: 700; cursor: help; }
.small { font-size: .88rem; }

@media print {
  .topbar, .no-print, .flash { display: none !important; }
  body { background: #fff; color: #000; }
  .page { padding: 0; max-width: none; }
  .table-wrap, .stat { box-shadow: none; border-color: #bbb; }
  .table th, .table td { padding: 5px 8px; font-size: 10pt; }
  .table tbody th a { color: #000; }
  .stats { grid-template-columns: repeat(5, 1fr); }
  .bilan-titre { break-before: auto; }
  tr { break-inside: avoid; }
  @page { size: A4 landscape; margin: 12mm; }
}
@media (max-width: 900px) { .topbar .brand--signe:not(.brand--toujours) .brand__name { display: none; } }
