/* ---------- Couleurs et thèmes ---------- */
:root {
  --fond: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --texte: #1c1b19;
  --texte-doux: #6b6862;
  --bordure: #e6e3dc;
  --bordure-forte: #d4d0c6;
  --accent: #4f46e5;
  --accent-texte: #ffffff;
  --accent-doux: #eceafd;
  --danger: #c2410c;
  --ombre: 0 1px 2px rgba(28, 27, 25, .06), 0 4px 16px rgba(28, 27, 25, .06);
  --ombre-forte: 0 12px 40px rgba(28, 27, 25, .18);
  --rayon: 14px;
  --lecteur-fond: #e9e7e2;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #121214;
    --surface: #1b1b1f;
    --surface-2: #24242a;
    --texte: #ededee;
    --texte-doux: #9d9da6;
    --bordure: #2c2c33;
    --bordure-forte: #3b3b44;
    --accent: #8b85ff;
    --accent-texte: #121214;
    --accent-doux: #25233f;
    --danger: #fb923c;
    --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --ombre-forte: 0 12px 40px rgba(0, 0, 0, .5);
    --lecteur-fond: #0c0c0e;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --fond: #121214;
  --surface: #1b1b1f;
  --surface-2: #24242a;
  --texte: #ededee;
  --texte-doux: #9d9da6;
  --bordure: #2c2c33;
  --bordure-forte: #3b3b44;
  --accent: #8b85ff;
  --accent-texte: #121214;
  --accent-doux: #25233f;
  --danger: #fb923c;
  --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --ombre-forte: 0 12px 40px rgba(0, 0, 0, .5);
  --lecteur-fond: #0c0c0e;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--fond);
  color: var(--texte);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

code {
  font-size: .9em;
  background: var(--surface-2);
  padding: .1em .35em;
  border-radius: 5px;
}

[hidden] { display: none !important; }

body:not(.admin) .admin-seulement { display: none !important; }

.visuellement-cache {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Boutons ---------- */
.bouton {
  display: inline-flex; align-items: center; gap: .45rem;
  height: 38px; padding: 0 .95rem;
  border: 1px solid transparent; border-radius: 10px;
  font-weight: 600; font-size: .92rem; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.bouton:active { transform: translateY(1px); }
.bouton:disabled { opacity: .45; cursor: not-allowed; }

.bouton-principal { background: var(--accent); color: var(--accent-texte); }
.bouton-principal:hover:not(:disabled) { filter: brightness(1.08); }

.bouton-discret { background: transparent; border-color: var(--bordure); }
.bouton-discret:hover { background: var(--surface-2); }

.bouton-danger { color: var(--danger); }

.bouton-icone {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border: 1px solid var(--bordure); border-radius: 10px;
  background: var(--surface);
  transition: background .15s;
}
.bouton-icone:hover { background: var(--surface-2); }

/* ---------- En-tête ---------- */
.entete {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--fond) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--bordure);
}

.entete-ligne {
  display: flex; align-items: center; gap: 1rem;
  max-width: 1200px; margin: 0 auto; padding: .85rem 1.5rem .6rem;
}

.marque {
  display: flex; align-items: center; gap: .6rem;
  color: inherit; text-decoration: none; flex: none;
}
.marque-logo {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--texte); color: var(--fond);
}
.marque-texte { font-size: 1.05rem; letter-spacing: -.01em; }

.recherche {
  flex: 1; max-width: 460px; margin-left: auto;
  display: flex; align-items: center; gap: .55rem;
  height: 40px; padding: 0 .75rem;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: 12px;
  color: var(--texte-doux);
  transition: border-color .15s, box-shadow .15s;
}
.recherche:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-doux); }
.recherche input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--texte);
}
.recherche input::-webkit-search-cancel-button { cursor: pointer; }
.recherche kbd {
  font: 500 .75rem/1 inherit; padding: .2rem .4rem;
  border: 1px solid var(--bordure); border-radius: 5px; color: var(--texte-doux);
}

.entete-actions { display: flex; gap: .5rem; flex: none; }

[data-theme-actif="dark"] .icone-lune { display: none; }
[data-theme-actif="light"] .icone-soleil { display: none; }

/* ---------- Onglets ---------- */
.onglets-conteneur {
  display: flex; align-items: center; gap: .35rem;
  max-width: 1200px; margin: 0 auto; padding: 0 1.5rem;
}

.annees {
  display: flex; flex: none; gap: 2px; padding: 3px; margin: .35rem .5rem .7rem 0;
  background: var(--surface-2); border-radius: 11px;
}
.annee {
  height: 30px; min-width: 44px; padding: 0 .6rem; border: 0; border-radius: 8px;
  background: transparent; color: var(--texte-doux); font-weight: 600; font-size: .85rem;
  transition: background .15s, color .15s;
}
.annee:hover { color: var(--texte); }
.annee[aria-checked="true"] { background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }
.annee sup { font-size: .65em; margin-left: 1px; }
.annee-vide { opacity: .55; }

.onglets {
  display: flex; gap: .35rem; overflow-x: auto; scrollbar-width: none;
  padding: .35rem 0 .7rem; min-width: 0;
  mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}
.onglets::-webkit-scrollbar { display: none; }

.onglet {
  display: inline-flex; align-items: center; gap: .45rem; flex: none;
  height: 34px; padding: 0 .8rem;
  border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: var(--texte-doux);
  font-weight: 500; font-size: .9rem;
  transition: background .15s, color .15s;
}
.onglet:hover { background: var(--surface-2); color: var(--texte); }
.onglet[aria-selected="true"] {
  background: var(--surface); color: var(--texte);
  border-color: var(--bordure); box-shadow: var(--ombre);
}
.onglet-pastille { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.onglet-compte {
  min-width: 20px; padding: 0 .35rem; border-radius: 999px;
  background: var(--surface-2); font-size: .75rem; text-align: center; line-height: 18px;
}
.onglet[aria-selected="true"] .onglet-compte { background: var(--accent-doux); color: var(--accent); }

.onglet-nouveau {
  border: 1px dashed var(--bordure-forte); margin: .35rem 0 .7rem;
}

/* ---------- Contenu ---------- */
.contenu { max-width: 1200px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }

.barre-cours {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1.4rem;
}
.barre-cours h1 { font-size: 1.6rem; letter-spacing: -.02em; line-height: 1.2; }
.sous-titre { color: var(--texte-doux); margin-top: .25rem; font-size: .92rem; }
.barre-cours-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.actions-cours { display: flex; gap: .5rem; }

.tri select {
  height: 38px; padding: 0 2rem 0 .8rem;
  border: 1px solid var(--bordure); border-radius: 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right .7rem center;
  appearance: none; -webkit-appearance: none;
}

/* ---------- Grille de cartes ---------- */
.grille {
  display: grid; gap: 1.1rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.carte {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon);
  overflow: hidden; box-shadow: var(--ombre);
  transition: transform .18s, box-shadow .18s, border-color .18s;
  animation: apparition .25s ease both;
}
.carte:hover { transform: translateY(-3px); box-shadow: var(--ombre-forte); border-color: var(--bordure-forte); }

@keyframes apparition { from { opacity: 0; transform: translateY(6px); } }

.carte-apercu {
  position: relative; aspect-ratio: 4 / 3; overflow: hidden;
  border: 0; padding: 0; width: 100%; display: block;
  background: linear-gradient(135deg, color-mix(in srgb, var(--couleur) 22%, var(--surface-2)), var(--surface-2));
}
.carte-apercu img {
  position: absolute; left: 50%; top: 14px; width: 74%; transform: translateX(-50%);
  border-radius: 4px 4px 0 0; box-shadow: 0 4px 18px rgba(0, 0, 0, .18);
  background: #fff; transition: transform .25s;
}
.carte:hover .carte-apercu img { transform: translateX(-50%) translateY(-4px); }
.carte-apercu-icone {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: color-mix(in srgb, var(--couleur) 70%, var(--texte));
}
.carte-apercu-icone span {
  font-weight: 700; font-size: .75rem; letter-spacing: .08em;
  padding: .35rem .6rem; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--bordure);
}

.carte-badge {
  position: absolute; top: 10px; left: 10px;
  font-size: .7rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px;
  background: var(--surface); color: var(--texte-doux); border: 1px solid var(--bordure);
}

.carte-corps { padding: .85rem .95rem .95rem; display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.carte-cours {
  display: flex; align-items: center; gap: .4rem;
  font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--texte-doux);
}
.carte-titre {
  font-size: .98rem; font-weight: 600; line-height: 1.35; letter-spacing: -.005em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.carte-meta { font-size: .8rem; color: var(--texte-doux); }

.carte-actions { display: flex; gap: .4rem; margin-top: auto; padding-top: .7rem; }
.carte-actions .bouton { height: 34px; padding: 0 .75rem; font-size: .85rem; flex: 1; justify-content: center; }
.carte-actions .bouton-icone { width: 34px; height: 34px; }

/* ---------- Pied de page ---------- */
.pied { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem 2rem; text-align: center; }
.lien-discret {
  border: 0; background: none; padding: .4rem .6rem; border-radius: 8px;
  color: var(--texte-doux); font-size: .82rem;
}
.lien-discret:hover { color: var(--texte); background: var(--surface-2); }

/* ---------- État vide ---------- */
.vide {
  text-align: center; padding: 4rem 1rem;
  border: 1.5px dashed var(--bordure-forte); border-radius: calc(var(--rayon) + 4px);
  background: var(--surface);
}
.vide-illustration { margin-bottom: 1rem; }
.vide h2 { font-size: 1.15rem; margin-bottom: .35rem; }
.vide p { color: var(--texte-doux); margin-bottom: 1.25rem; max-width: 420px; margin-inline: auto; }

/* ---------- Zone de dépôt plein écran ---------- */
.depot-plein-ecran {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
}
.depot-carte {
  display: grid; place-items: center; gap: .6rem;
  padding: 2.5rem 3.5rem; border-radius: 20px;
  border: 2px dashed var(--accent); background: var(--surface); color: var(--accent);
  font-weight: 600; font-size: 1.1rem; box-shadow: var(--ombre-forte);
}

/* ---------- Fenêtres ---------- */
dialog { color: var(--texte); }
dialog::backdrop { background: rgba(10, 10, 12, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.fenetre {
  width: min(520px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--bordure); border-radius: 18px;
  background: var(--surface); box-shadow: var(--ombre-forte);
}
.fenetre-petite { width: min(420px, calc(100vw - 32px)); }
.fenetre[open] { animation: entree .2s ease; }
@keyframes entree { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.fenetre form { padding: 1.4rem; display: flex; flex-direction: column; gap: 1rem; }
.fenetre h2 { font-size: 1.15rem; letter-spacing: -.01em; }

.champ { display: flex; flex-direction: column; gap: .35rem; border: 0; padding: 0; margin: 0; }
.champ > span, .champ > legend { font-size: .85rem; font-weight: 600; color: var(--texte-doux); padding: 0; margin-bottom: .35rem; }
.champ input, .champ select {
  height: 40px; padding: 0 .8rem;
  border: 1px solid var(--bordure); border-radius: 10px; background: var(--fond);
}
.champ input:focus, .champ select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-doux); }

.depot {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: 1.6rem 1rem; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--bordure-forte); border-radius: 14px;
  background: var(--fond); color: var(--texte-doux);
  transition: border-color .15s, background .15s;
}
.depot:hover, .depot.survol { border-color: var(--accent); background: var(--accent-doux); color: var(--accent); }
.depot strong { color: var(--accent); }
.depot small { font-size: .78rem; }
.depot input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.liste-fichiers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; max-height: 220px; overflow-y: auto; }
.liste-fichiers:empty { display: none; }
.liste-fichiers li {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem .4rem .4rem .7rem; border: 1px solid var(--bordure); border-radius: 10px;
}
.liste-fichiers input {
  flex: 1; min-width: 0; height: 32px; padding: 0 .5rem;
  border: 1px solid transparent; border-radius: 7px; background: transparent; font-weight: 500;
}
.liste-fichiers input:hover { border-color: var(--bordure); }
.liste-fichiers input:focus { outline: 0; border-color: var(--accent); background: var(--fond); }
.liste-fichiers li.en-cours::before {
  content: ""; position: absolute; inset: 0; width: var(--progression); z-index: -1;
  background: var(--accent-doux); transition: width .2s;
}
.liste-fichiers li.fait::before { width: 100%; }
.liste-fichiers li { isolation: isolate; }
.liste-fichiers input:disabled { opacity: 1; }
.liste-fichiers .taille { font-size: .78rem; color: var(--texte-doux); flex: none; }
.liste-fichiers button {
  width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: var(--texte-doux);
  display: grid; place-items: center; flex: none;
}
.liste-fichiers button:hover { background: var(--surface-2); color: var(--texte); }

.note { font-size: .82rem; color: var(--texte-doux); }

.fenetre-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .25rem; }
.fenetre-actions .espace { flex: 1; }
.erreur { color: var(--danger); font-size: .88rem; font-weight: 500; }

.pastilles { display: flex; flex-wrap: wrap; gap: .5rem; }
.pastilles label { position: relative; }
.pastilles input { position: absolute; opacity: 0; }
.pastilles span {
  display: block; width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  background: var(--c); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .08);
  transition: transform .12s;
}
.pastilles span:hover { transform: scale(1.1); }
.pastilles input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.pastilles input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ---------- Lecteur PDF ---------- */
.lecteur {
  width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: var(--lecteur-fond);
}
.lecteur[open] { display: flex; flex-direction: column; animation: entree .2s ease; }

.lecteur-barre {
  display: flex; align-items: center; gap: .85rem; flex: none;
  padding: .65rem 1rem; background: var(--surface); border-bottom: 1px solid var(--bordure);
}
.lecteur-infos { min-width: 0; flex: 1; }
.lecteur-infos h2 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lecteur-infos span { font-size: .8rem; color: var(--texte-doux); }
.lecteur-outils { display: flex; align-items: center; gap: .6rem; flex: none; }
.lecteur-page { font-size: .85rem; color: var(--texte-doux); font-variant-numeric: tabular-nums; }

.groupe-zoom {
  display: flex; align-items: center;
  border: 1px solid var(--bordure); border-radius: 10px; overflow: hidden;
}
.groupe-zoom .bouton-icone { border: 0; border-radius: 0; width: 34px; height: 36px; }
.zoom-valeur {
  min-width: 58px; height: 36px; border: 0; background: var(--surface);
  font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums;
  border-inline: 1px solid var(--bordure);
}
.zoom-valeur:hover { background: var(--surface-2); }

.lecteur-pages {
  flex: 1; overflow: auto; padding: 1.5rem 1rem 3rem;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.lecteur-page-conteneur {
  position: relative; flex: none; background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15); border-radius: 3px; overflow: hidden;
}
.lecteur-page-conteneur canvas { display: block; width: 100%; height: 100%; }
.lecteur[data-famille]:not([data-famille="pdf"]) .lecteur-page,
.lecteur[data-famille]:not([data-famille="pdf"]) .groupe-zoom { display: none; }
.lecteur-statut-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.lecteur-image { max-width: 100%; height: auto; flex: none; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .15); border-radius: 3px; }
.lecteur-texte {
  width: min(100%, 900px); margin: 0; padding: 1.5rem; flex: none;
  background: var(--surface); color: var(--texte); border: 1px solid var(--bordure); border-radius: 8px;
  font: .9rem/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.lecteur[data-famille="office"] .lecteur-pages { padding: 0; gap: 0; }
.lecteur-iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.lecteur-note { flex: none; padding: .5rem 1rem; font-size: .82rem; color: var(--texte-doux); text-align: center; }
.lecteur-note a { color: var(--accent); }
.lecteur-statut { margin: auto; color: var(--texte-doux); display: grid; justify-items: center; gap: 1rem; text-align: center; }
a.bouton, a.bouton-icone { color: inherit; text-decoration: none; }
a.bouton-principal { color: var(--accent-texte); }

/* ---------- Notifications ---------- */
.toasts {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none;
  width: calc(100% - 32px);
}
.toast {
  padding: .65rem 1rem; border-radius: 12px; max-width: 420px;
  background: var(--texte); color: var(--fond); font-size: .9rem; font-weight: 500;
  box-shadow: var(--ombre-forte); animation: entree .2s ease;
}

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .entete-ligne { flex-wrap: wrap; padding: .75rem 1rem .5rem; gap: .65rem; }
  .marque { flex: 1; }
  .recherche { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  .recherche kbd { display: none; }
  .onglets-conteneur { padding: 0 1rem; flex-wrap: wrap; column-gap: .35rem; }
  .annees { width: 100%; margin: .35rem 0 0; }
  .annee { flex: 1; }
  .onglets { flex: 1; }
  .onglet-nouveau span { display: none; }
  .onglet-nouveau { padding: 0 .65rem; }
  .contenu { padding: 1.25rem 1rem 3rem; }
  .barre-cours h1 { font-size: 1.35rem; }
  .grille { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
  .carte-corps { padding: .75rem .7rem .8rem; }
  .carte-actions { gap: .3rem; }
  .carte-actions .bouton { min-width: 0; padding: 0 .5rem; }
  .lecteur-barre { flex-wrap: wrap; gap: .5rem .65rem; padding: .55rem .75rem; }
  .lecteur-outils { width: 100%; justify-content: space-between; }
  .lecteur-pages { padding: .75rem .5rem 2rem; }
}
