body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
}

/* ─── CONTENT-HEADER (barre de titre de page, fixée sous le header app) ────── */

.content-header {
  position: sticky;
  top: 60px;          /* se colle juste sous le header fixe au scroll */
  z-index: 98;        /* sous le header (150) mais au-dessus du contenu */

  background-color: #ffffff;
  border-bottom: 2px solid #dae0e8;
  padding: 0 15px;
  /* Sticky hérite la largeur du parent → pas de left/right à gérer,
     Bootstrap grid fonctionne normalement à l'intérieur */
}

.header-section {
  padding: 15px 0;
}

.page {
  padding-top: 0; /* sticky reste dans le flux, pas de compensation nécessaire */
}

/* ─── PAGE HEADER ───────────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
}

.page-header h4 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
}

/* ─── ÉTATS GÉNÉRIQUES ───────────────────────────────────────────────────────── */

.loading-text { padding: 40px; text-align: center; color: #94a3b8; }
.empty-text   { padding: 40px; text-align: center; color: #64748b; font-style: italic; }
.error-text   { padding: 20px; color: #dc2626; background: #fee2e2; border-radius: 6px; margin: 16px; }

/* ─── TABLES ─────────────────────────────────────────────────────────────────── */

.table-wrapper {
  /* Conteneur de défilement : l'en-tête reste visible lors du scroll */
  overflow: auto;
  max-height: calc(100vh - 180px);
  padding: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.data-table th {
  background: #f1f5f9;
  font-weight: 600;
  color: #64748b;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  /* En-tête figé en haut du conteneur pendant le défilement vertical */
  position: sticky;
  top: 0;
  z-index: 3;
  /* La bordure inférieure disparaît en position sticky : on la simule */
  box-shadow: inset 0 -1px 0 #e2e8f0;
}

/* En-tête sur deux lignes (sous-titres) : les deux rangées restent figées */
.data-table thead tr:nth-child(2) th { top: 38px; }

/* Pied de tableau (ligne TOTAL) figé en bas, quand présent */
.data-table tfoot td {
  position: sticky;
  bottom: 0;
  background: #f8fafc;
  z-index: 3;
  box-shadow: inset 0 1px 0 #e2e8f0;
}

@media print {
  .table-wrapper { max-height: none; overflow: visible; }
}

.data-table tbody tr:hover { background: #f8fafc; }
.data-table .text-right    { text-align: right; }
.data-table .actions       { white-space: nowrap; }

/* ─── BOUTONS ────────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}

.btn-primary   { background: #4f46e5; color: #fff; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-danger    { background: #fee2e2; color: #dc2626; }

.btn-primary:hover   { background: #4338ca; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger:hover    { background: #fecaca; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ─── BADGES ─────────────────────────────────────────────────────────────────── */

.badge-cycle, .badge-etat {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-maternelle,  .badge-cycle.maternelle  { background: #fef3c7; color: #b45309; }
.badge-primaire,    .badge-cycle.primaire    { background: #dbeafe; color: #1d4ed8; }
.badge-college,     .badge-cycle.college     { background: #dcfce7; color: #15803d; }
.badge-lycee,       .badge-cycle.lycee       { background: #cffafe; color: #0e7490; }
.badge-secondaire,  .badge-cycle.secondaire  { background: #dcfce7; color: #15803d; }
.badge-superieur,   .badge-cycle.superieur   { background: #ede9fe; color: #6d28d9; }

.badge-actif   { background: #dcfce7; color: #15803d; }
.badge-inactif { background: #f1f5f9; color: #64748b; }

/* ─── MODAL ──────────────────────────────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-16px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1);   }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}

.modal-title { margin: 0; font-size: 16px; font-weight: 600; color: #1e293b; }

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #64748b;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: #1e293b; }

.modal-body { padding: 20px; }

/* ─── FORMULAIRES ────────────────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  color: #111827;
  background: #fff;
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
  margin-top: 16px;
}

.form-error {
  padding: 10px 14px;
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}

.form-error.hidden { display: none; }

/* ─── BLOCK ─────────────────────────────────────────────────────────────────── */

.block {
  margin: 0 0 10px;
  padding: 20px 15px 1px;
  background-color: #ffffff;
  border-top-left-radius: 2px;
  border-top-right-radius: 2px;
  box-shadow: 0 2px 0 rgba(218, 224, 232, .5);
}

.block-title {
  margin: -20px -15px 20px;
  border-bottom: 2px solid #dae0e8;
  border-top-left-radius: 2px;
  border-top-right-radius: 2px;
  background: rgba(218, 224, 232, .15);
  padding: 2px 10px;
}

.block-title h2 {
  margin: 0;
  padding: 4px;
}

/* ─── NAV (dans content-header) ─────────────────────────────────────────────── */

.nav {
  margin-bottom: 0;
  padding-left: 0;
  list-style: none;
  float: right;
}

/* ─── UTILITAIRES TEXTE ───────────────────────────────────── */
.text-muted   { color: #888; }
.text-danger  { color: #e74c3c; }
.text-success { color: #27ae60; }

/* ─── STATS CARDS ─────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 160px;
  /* border-box : padding + bordure inclus dans la largeur, pour que
     min-width: 50% calcule juste sur mobile (sinon débordement à droite) */
  box-sizing: border-box;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

.stat-label {
  font-size: .78rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary, #2563eb);
}

/* ─── BADGE MOIS ──────────────────────────────────────────── */
.badge-mois {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: .8rem;
  font-weight: 600;
}

/* ─── RESUME ÉLÈVE (modal paiement) ──────────────────────── */
.resume-box {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: .85rem;
}

.resume-box span { white-space: nowrap; }

/* ─── BADGES RUBRIQUES ────────────────────────────────────── */
.badge-rubrique {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 12px;
  font-size: .8rem;
  font-weight: 600;
}
.badge-rubrique.recette { background: #dcfce7; color: #166534; }
.badge-rubrique.depense { background: #fee2e2; color: #991b1b; }

/* ─── RUBRIQUES PAGE ──────────────────────────────────────── */
.rubriques-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.rubriques-col {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 20px;
}

.rubriques-col-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid;
}
.rubriques-col-title.recette { color: #166534; border-color: #bbf7d0; }
.rubriques-col-title.depense { color: #991b1b; border-color: #fecaca; }

.rubrique-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}
.rubrique-card:last-child { border-bottom: none; }

.badge-systeme {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: .7rem;
  font-weight: 600;
  background: #eef2ff;
  color: #3730a3;
  white-space: nowrap;
}

.rubrique-actions { display: flex; gap: 6px; margin-left: auto; }

/* ─── RÉINSCRIPTION ───────────────────────────────────────── */
.reinscription-group {
  margin-bottom: 28px;
}

.reinscription-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.badge-statut {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
}
.badge-statut.ok      { background: #dcfce7; color: #166534; }
.badge-statut.attente { background: #fef9c3; color: #854d0e; }

tr.row-ok td { opacity: .7; }

/* ─── DASHBOARD ───────────────────────────────────────── */
.dash-alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #92400e;
  font-size: .9rem;
  margin-bottom: 24px;
}
.dash-alert.dash-alert-ok {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.dash-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}

/* ─── BUDGET BARRE PROGRESSION ───────────────────────────── */
.budget-bar-wrap {
  width: 60px;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.budget-bar {
  height: 100%;
  background: #4f46e5;
  border-radius: 4px;
  transition: width .3s;
}

.budget-bar.budget-bar-full {
  background: #16a34a;
}

/* ─── AVATAR CERCLE ───────────────────────────────────────── */
.avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e0e7ff;
  color: #4338ca;
  font-size: .75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

/* ─── EMPLOI DU TEMPS ─────────────────────────────────────── */
.edt-wrapper {
  overflow-x: auto;
  padding-bottom: 20px;
}

.edt-grid {
  display: grid;
  min-width: 700px;
  /* colonnes définies inline via style */
}

.edt-corner {
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  border-bottom: 2px solid #cbd5e1;
}

.edt-jour-header {
  background: #f1f5f9;
  border-bottom: 2px solid #cbd5e1;
  border-right: 1px solid #e2e8f0;
  padding: 8px 4px;
  text-align: center;
  font-size: .78rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.edt-hour-label {
  font-size: .7rem;
  color: #94a3b8;
  text-align: right;
  padding: 0 6px;
  height: 32px;
  line-height: 32px;
  border-right: 1px solid #e2e8f0;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}

.edt-cell {
  position: relative;
  height: 32px;
  border-right: 1px solid #e2e8f0;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background .1s;
}

.edt-cell:hover {
  background: #f8fafc;
}

.edt-bloc {
  position: absolute;
  left: 2px;
  right: 2px;
  top: 1px;
  border-radius: 6px;
  padding: 4px 6px;
  overflow: hidden;
  z-index: 2;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  cursor: default;
}

.edt-bloc-nom {
  font-size: .78rem;
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.edt-bloc-horaire {
  font-size: .7rem;
  color: #475569;
}

.edt-bloc-ens {
  font-size: .68rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.edt-bloc-actions {
  display: none;
  gap: 4px;
  margin-top: 4px;
}

.edt-bloc:hover .edt-bloc-actions {
  display: flex;
}

.edt-btn-edit,
.edt-btn-del {
  border: none;
  border-radius: 4px;
  font-size: .7rem;
  padding: 2px 6px;
  cursor: pointer;
  line-height: 1;
}

.edt-btn-edit { background: #e2e8f0; color: #334155; }
.edt-btn-del  { background: #fee2e2; color: #dc2626; }
.edt-btn-edit:hover { background: #cbd5e1; }
.edt-btn-del:hover  { background: #fecaca; }

/* ─── DISCIPLINE ──────────────────────────────────────────── */
.badge-disc-sanction {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ─── GRILLE NOTES ────────────────────────────────────────── */
.notes-table-wrapper {
  overflow-x: auto;
}

.notes-grid .note-input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79,70,229,.15);
}

.notes-grid td {
  padding: 6px 10px;
  vertical-align: middle;
}

/* ─── DASHBOARD PANEL TITLE ───────────────────────────────── */
.dash-panel-title {
  font-size: .85rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

/* ─── DEUX VOLETS (liste + détail) — responsive ───────────── */
.split-pane {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 768px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* En-tête de page : titre et actions empilés */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .page-header-left,
  .page-header-right { width: 100%; }
  .page-header-right,
  .page-header > div { flex-wrap: wrap; }

  /* Les champs de filtre en en-tête ne débordent plus de l'écran */
  .page-header input,
  .page-header select,
  .page-header .form-control { max-width: 100%; }

  /* Formulaires : champs et actions empilés, boutons pleine largeur */
  .form-row { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .form-actions .btn { width: 100%; }

  /* Modales : quasi plein écran, ancrées en haut */
  .modal-overlay { padding: 8px; align-items: flex-start; }
  .modal-box { max-width: 100%; max-height: 92vh; margin-top: 6px; }

  /* Tableaux : chaque .data-table devient son propre conteneur de
     défilement horizontal (même sans .table-wrapper), pour ne jamais
     être rogné par le overflow-x:hidden de la page sur mobile. */
  .table-wrapper { padding: 10px; max-height: none; }
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
    max-width: 100%;
  }
  .data-table th { position: static; box-shadow: none; }
  .data-table tfoot td { position: static; box-shadow: none; }
  .data-table th,
  .data-table td { padding: 8px 10px; white-space: nowrap; }

  /* Cartes de statistiques : 2 par ligne */
  .stat-card { min-width: calc(50% - 8px); padding: 12px 14px; }
  .stat-value { font-size: 1.25rem; }

  /* Grilles à deux colonnes → une seule sur mobile */
  .split-pane,
  .dash-grid,
  .rubriques-grid { grid-template-columns: 1fr; }
}

/* ── Très petits écrans (≤ 480px) ── */
@media (max-width: 480px) {
  .stat-card { min-width: 100%; }
  .page-header h1,
  .page-header h4 { font-size: 16px; }
}

/* Masquage des actions non autorisées (permissions par action, #/roles) */
.perm-hidden { display: none !important; }
