:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1d2330; --muted: #667085; --border: #e3e6eb;
  --primary: #1f4fd1; --primary-soft: #e8eefc; --sidebar: #111827; --sidebar-text: #cbd2dc;
  --vert: #157f3b; --vert-bg: #e3f5e9; --jaune: #8a6d00; --jaune-bg: #fdf4cf;
  --orange: #b54708; --orange-bg: #fdecd9; --rouge: #b42318; --rouge-bg: #fde4e1;
  --bleu: #1f4fd1; --bleu-bg: #e8eefc; --gris: #475467; --gris-bg: #eef0f3;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a; --surface: #171c25; --text: #e6e9ef; --muted: #98a2b3; --border: #2a313d;
    --primary: #7aa2ff; --primary-soft: #1d2a48; --sidebar: #0a0d12;
    --vert: #6fd69a; --vert-bg: #13321f; --jaune: #f3d36b; --jaune-bg: #3a3112;
    --orange: #ffaf70; --orange-bg: #3d2513; --rouge: #ff8a80; --rouge-bg: #421c19;
    --bleu: #7aa2ff; --bleu-bg: #1d2a48; --gris: #c0c7d2; --gris-bg: #262d39;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
small, .muted { color: var(--muted); }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; }
.sidebar nav { position: sticky; top: 18px; }
.sidebar .logo { color: #fff; font-weight: 700; font-size: 17px; padding: 0 10px 2px; }
.sidebar .org { font-size: 12px; padding: 0 10px 18px; opacity: .7; }
.sidebar nav a { display: flex; justify-content: space-between; align-items: center; color: var(--sidebar-text); padding: 8px 10px; border-radius: 6px; margin-bottom: 2px; }
.sidebar nav a:hover, .sidebar nav a.actif { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .5; padding: 16px 10px 6px; }
.sidebar .pastille { background: #d92d20; color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.main { flex: 1; padding: 24px 28px; min-width: 0; }
.entete { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.carte { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.grille { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .val { font-size: 26px; font-weight: 700; }
.kpi .lib { color: var(--muted); font-size: 13px; }
.kpi.alerte .val { color: var(--rouge); }

.btn { display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 6px; font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primaire { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--rouge); border-color: var(--rouge); color: #fff; }
.actions-btn { display: flex; gap: 8px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--bg); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.vert { color: var(--vert); background: var(--vert-bg); }
.badge.jaune { color: var(--jaune); background: var(--jaune-bg); }
.badge.orange { color: var(--orange); background: var(--orange-bg); }
.badge.rouge { color: var(--rouge); background: var(--rouge-bg); }
.badge.bleu { color: var(--bleu); background: var(--bleu-bg); }
.badge.gris { color: var(--gris); background: var(--gris-bg); }
.retard, .etat-retard { color: var(--rouge); font-weight: 600; }
.etat-urgent { color: var(--orange); font-weight: 600; }
.etat-fait { color: var(--vert); }
.etat-fait_retard { color: var(--orange); }

.barre { height: 6px; background: var(--gris-bg); border-radius: 3px; overflow: hidden; min-width: 80px; }
.barre span { display: block; height: 100%; background: var(--primary); }

.filtres { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

.formulaire { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px 20px; }
.formulaire .champ { display: flex; flex-direction: column; gap: 4px; }
.formulaire .champ.large { grid-column: 1 / -1; }
.formulaire .champ.case { flex-direction: row; align-items: center; gap: 8px; }
.formulaire label { font-weight: 600; font-size: 13px; }
.formulaire .aide { font-size: 12px; color: var(--muted); }
.erreur, .errorlist { color: var(--rouge); font-size: 12px; margin: 0; padding: 0; list-style: none; }

.fiche { display: grid; grid-template-columns: 220px 1fr; gap: 0; }
.fiche dt, .fiche dd { padding: 8px 0; border-bottom: 1px solid var(--border); margin: 0; }
.fiche dt { color: var(--muted); }
.fiche dd { white-space: pre-wrap; }

.matrice { border-collapse: separate; border-spacing: 4px; width: auto; }
.matrice td, .matrice th { border: none; text-align: center; padding: 0; }
.matrice td.case { width: 58px; height: 46px; border-radius: 6px; font-weight: 700; font-size: 16px; }
.matrice .faible { background: var(--vert-bg); color: var(--vert); }
.matrice .modere { background: var(--jaune-bg); color: var(--jaune); }
.matrice .eleve { background: var(--orange-bg); color: var(--orange); }
.matrice .critique { background: var(--rouge-bg); color: var(--rouge); }
.matrice .vide { opacity: .45; font-weight: 400; }

.etapes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.etape { border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px; padding: 10px 12px; }
.etape.fait { border-left-color: var(--vert); }
.etape.fait_retard { border-left-color: var(--orange); }
.etape.retard { border-left-color: var(--rouge); background: var(--rouge-bg); }
.etape.urgent { border-left-color: var(--orange); background: var(--orange-bg); }
.etape.a_venir { border-left-color: var(--bleu); }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { background: var(--vert-bg); color: var(--vert); padding: 10px 14px; border-radius: 6px; }
.journal li { margin-bottom: 10px; }
.pagination { margin-top: 12px; display: flex; gap: 10px; align-items: center; }

.login { max-width: 380px; margin: 10vh auto; }
.login input { width: 100%; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .main { padding: 16px; }
  .fiche { grid-template-columns: 1fr; }
  .fiche dt { border-bottom: none; padding-bottom: 0; }
}
@media print { .sidebar, .actions-btn, .filtres { display: none; } }
