:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --texte: #0b0b0b;
  --texte-2: #52514e;
  --discret: #6f6d68;
  --trait: #e1e0d9;
  --axe: #c3c2b7;
  --bord: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-texte: #ffffff;
  --succes-texte: #006300;
  --bon: #0ca30c; --attention: #fab219; --critique: #d03b3b;
  --ombre: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.04);
  --rayon: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --texte: #f0efec; --texte-2: #c3c2b7; --discret: #9a988f;
    --trait: #2c2c2a; --axe: #383835; --bord: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --succes-texte: #0ca30c;
    --ombre: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --texte: #f0efec; --texte-2: #c3c2b7; --discret: #9a988f;
  --trait: #2c2c2a; --axe: #383835; --bord: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --succes-texte: #0ca30c;
  --ombre: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--texte);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.chiffres { font-variant-numeric: tabular-nums; }
.discret { color: var(--discret); }
.secondaire { color: var(--texte-2); }
.petit { font-size: 0.85rem; }
.cache { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* En-tête et navigation */
.entete {
  position: sticky; top: 0; z-index: 10; background: var(--page);
  border-bottom: 1px solid var(--trait);
}
.entete-haut {
  max-width: 1180px; margin: 0 auto; padding: 12px 16px 0;
  display: flex; align-items: center; gap: 12px;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo img { width: 28px; height: 28px; }
.logo h1 { white-space: nowrap; }
.entete-haut .espace { flex: 1; }
.onglets {
  max-width: 1180px; margin: 0 auto; padding: 0 16px;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
}
.onglets a {
  padding: 10px 12px; color: var(--texte-2); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; font-weight: 500;
}
.onglets a[aria-current="page"] { color: var(--texte); border-bottom-color: var(--accent); }
.onglets a:hover { color: var(--texte); }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
section { margin-bottom: 28px; }

/* Boutons */
.bouton {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; min-height: 36px;
  border-radius: 8px; border: 1px solid var(--bord); background: var(--surface); cursor: pointer;
  font-weight: 500; text-decoration: none; color: var(--texte); white-space: nowrap;
}
.bouton:hover { background: var(--surface-2); }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.bouton.principal:hover { filter: brightness(1.08); }
.bouton.discret { border-color: transparent; background: transparent; }
.bouton:disabled { opacity: 0.55; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cartes */
.carte {
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 16px; box-shadow: var(--ombre);
}
.grille-tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tuile .libelle { color: var(--texte-2); font-size: 0.85rem; font-weight: 500; }
.tuile .valeur { font-size: 1.6rem; font-weight: 600; margin: 4px 0 2px; }

/* Recherche et filtres */
.barre-recherche { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.barre-recherche input[type="search"] { flex: 1 1 260px; font-size: 1rem; padding: 10px 12px; }
.puces { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.puce {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--bord); background: var(--surface);
  cursor: pointer; font-size: 0.9rem; color: var(--texte-2);
}
.puce[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.puce .compte { opacity: 0.75; margin-left: 4px; font-variant-numeric: tabular-nums; }
.filtres { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filtres select { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--axe); background: var(--surface); max-width: 100%; }
.filtres label.case { margin: 0; }
.resultat { color: var(--texte-2); font-size: 0.9rem; margin-bottom: 12px; }

/* Grille des publications */
.grille-publications {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, calc(50% - 6px)), 1fr));
}
.publication {
  all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  overflow: hidden; box-shadow: var(--ombre); min-width: 0;
}
.publication:hover { border-color: var(--axe); }
.publication:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.publication.retiree { opacity: 0.6; }
.vignette { position: relative; aspect-ratio: 4 / 5; background: var(--surface-2); overflow: hidden; }
.vignette img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vignette .sans-image {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--discret); font-size: 0.85rem;
}
.badge {
  position: absolute; top: 8px; right: 8px; padding: 2px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.62); color: #fff; font-size: 0.75rem; font-weight: 600;
}
.publication .infos { padding: 10px 12px 12px; display: grid; gap: 4px; min-width: 0; }
.publication .auteur { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.publication .extrait {
  font-size: 0.85rem; color: var(--texte-2); overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.publication .date { font-size: 0.78rem; color: var(--discret); }
.plus { display: flex; justify-content: center; margin-top: 18px; }

/* Détail d'une publication */
dialog {
  border: 1px solid var(--bord); border-radius: 14px; background: var(--surface); color: var(--texte);
  padding: 20px; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.large { width: min(860px, calc(100vw - 32px)); }
dialog h2 { margin-bottom: 8px; }
dialog .actions { justify-content: flex-end; margin-top: 16px; }
.detail { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 20px; }
.detail .vignette { border-radius: 10px; }
.detail .legende-complete { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow: auto; margin: 10px 0; }
@media (max-width: 680px) {
  .detail { grid-template-columns: 1fr; }
  .detail .vignette { max-height: 50vh; min-height: 140px; aspect-ratio: auto; }
  .detail .vignette img { max-height: 50vh; object-fit: contain; }
  dialog { padding: 16px; }
}
.liste-def { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 0.9rem; margin: 0; }
.liste-def dt { color: var(--texte-2); }
.liste-def dd { margin: 0; overflow-wrap: anywhere; }

/* Synchro */
.etapes-guide { margin: 0; padding-left: 22px; display: grid; gap: 14px; }
.etapes-guide li { padding-left: 4px; }
.etapes-guide li strong { display: block; margin-bottom: 4px; }
.cle-affichee {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 0.85rem; padding: 10px;
  border-radius: 8px; background: var(--surface-2); overflow-wrap: anywhere; user-select: all;
}
.tableau-defilant { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; color: var(--texte-2); font-weight: 500; font-size: 0.8rem; padding: 6px 10px; border-bottom: 1px solid var(--trait); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--trait); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.nombre, th.nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.etiquette {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 0.8rem; background: var(--surface-2); color: var(--texte-2); white-space: nowrap;
}
.etiquette::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--discret); }
.etiquette.bon::before { background: var(--bon); }
.etiquette.attention::before { background: var(--attention); }
.etiquette.critique::before { background: var(--critique); }

/* Formulaires */
.champ { display: grid; gap: 4px; margin-bottom: 14px; }
.champ label { font-weight: 500; font-size: 0.9rem; }
.champ .aide { font-size: 0.82rem; color: var(--discret); }
input[type="text"], input[type="password"], input[type="search"] {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--axe); background: var(--surface);
}
input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.case { display: flex; gap: 8px; align-items: center; cursor: pointer; font-size: 0.9rem; }
.case input { width: 16px; height: 16px; accent-color: var(--accent); }
input.code { font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }

/* Messages */
.message { padding: 10px 14px; border-radius: 8px; margin: 10px 0; font-size: 0.9rem; border: 1px solid var(--bord); background: var(--surface-2); }
.message.erreur { border-color: color-mix(in srgb, var(--critique) 50%, transparent); background: color-mix(in srgb, var(--critique) 10%, var(--surface)); }
.message.succes { border-color: color-mix(in srgb, var(--bon) 50%, transparent); background: color-mix(in srgb, var(--bon) 10%, var(--surface)); }
.message.alerte { border-color: color-mix(in srgb, var(--attention) 60%, transparent); background: color-mix(in srgb, var(--attention) 12%, var(--surface)); }

/* Page de connexion */
.page-connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.boite-connexion { width: min(380px, 100%); }
.boite-connexion .logo { justify-content: center; margin-bottom: 18px; }
.boite-connexion .logo img { width: 40px; height: 40px; }
.boite-connexion button { width: 100%; justify-content: center; margin-top: 6px; }

.vide { padding: 32px 16px; text-align: center; color: var(--discret); }
.chargement { color: var(--discret); padding: 24px 0; }
@media (max-width: 520px) {
  .entete-haut .bouton { padding: 6px 8px; }
  main { padding-top: 14px; }
}
