/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: 'Segoe UI', Arial, sans-serif; background: #f0f2f5; color: #222; min-height: 100vh; }

/* ── Pages ────────────────────────────────────────────────────────────────── */
.page { display: none !important; }
.page.active { display: block !important; }
#page-login.active { display: flex !important; }

/* ── Boutons langue ───────────────────────────────────────────────────────── */
.lang-btn {
  background: none; border: 1px solid rgba(255,255,255,.4);
  color: rgba(255,255,255,.7); padding: 3px 9px; border-radius: 4px;
  font-size: .78rem; font-weight: 600; cursor: pointer; transition: all .15s;
}
.lang-btn.active, .lang-btn:hover {
  background: rgba(255,255,255,.2); color: white;
  border-color: rgba(255,255,255,.8);
}
.lang-bar-login {
  position: absolute; top: 18px; right: 24px;
  display: flex; align-items: center; gap: 6px;
}
.lang-bar-login .lang-btn {
  color: rgba(255,255,255,.8); border-color: rgba(255,255,255,.4);
}
.lang-bar-dash {
  display: flex; align-items: center; gap: 4px;
}

/* ── LOGIN ────────────────────────────────────────────────────────────────── */
#page-login {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0d2257 0%, #1a3a8c 60%, #0d6efd 100%);
  position: relative;
}
.login-card {
  background: white;
  border-radius: 16px;
  padding: 48px 40px 36px;
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  text-align: center;
}
.login-logo { font-size: 52px; margin-bottom: 12px; }
.login-card h1 { font-size: 1.6rem; color: #0d2257; font-weight: 700; }
.login-sub { color: #666; font-size: .9rem; margin: 4px 0 28px; }
.login-card input {
  display: block; width: 100%; padding: 13px 16px;
  border: 2px solid #dde; border-radius: 8px;
  font-size: 1rem; margin-bottom: 14px;
  transition: border-color .2s;
}
.login-card input:focus { outline: none; border-color: #0d6efd; }
.login-card button {
  width: 100%; padding: 14px; background: #0d2257;
  color: white; border: none; border-radius: 8px;
  font-size: 1.05rem; font-weight: 600; cursor: pointer;
  margin-top: 6px; transition: background .2s;
}
.login-card button:hover { background: #1a3a8c; }
.login-footer { color: #aaa; font-size: .78rem; margin-top: 20px; }
.alert-error {
  background: #fdecea; border-left: 4px solid #e53935;
  color: #c62828; padding: 10px 14px; border-radius: 6px;
  margin-bottom: 16px; font-size: .9rem; text-align: left;
}

/* ── HEADER ───────────────────────────────────────────────────────────────── */
header {
  background: #0d2257;
  color: white;
  padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-logo { font-size: 28px; }
.header-title { font-size: 1.1rem; font-weight: 700; line-height: 1.2; }
.header-sub { font-size: .78rem; color: #90caf9; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.header-right select {
  padding: 7px 10px; border-radius: 6px; border: none;
  background: #1a3a8c; color: white; font-size: .85rem; cursor: pointer;
  max-width: 200px;
}
.btn-refresh, .btn-logout {
  padding: 7px 12px; border: none; border-radius: 6px;
  font-size: 1.1rem; cursor: pointer; font-weight: 700;
}
.btn-refresh { background: #1565c0; color: white; }
.btn-refresh:hover { background: #0d47a1; }
.btn-logout { background: #c62828; color: white; }
.btn-logout:hover { background: #b71c1c; }

/* ── Onglets navigation ───────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 0;
  background: #fff;
  border-bottom: 2px solid #e0e4ef;
  padding: 0 16px;
  position: sticky; top: 56px; z-index: 10;
  overflow-x: auto;
}
.tab-btn {
  background: none; border: none; cursor: pointer;
  padding: 12px 18px; font-size: .88rem; font-weight: 600;
  color: #667; border-bottom: 3px solid transparent;
  margin-bottom: -2px; transition: color .2s, border-color .2s;
  white-space: nowrap;
}
.tab-btn:hover { color: #0d2257; }
.tab-btn.active { color: #0d2257; border-bottom-color: #0d2257; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── MAIN ─────────────────────────────────────────────────────────────────── */
main { padding: 16px 20px; max-width: 1400px; margin: 0 auto; }

/* ── Loading ──────────────────────────────────────────────────────────────── */
.loading { text-align: center; padding: 80px 20px; color: #555; }
.spinner {
  width: 48px; height: 48px; border: 5px solid #dde;
  border-top-color: #0d6efd; border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Bandeau école ────────────────────────────────────────────────────────── */
.school-banner {
  background: linear-gradient(90deg,#0d2257,#1a3a8c);
  color: white;
  padding: 10px 20px; border-radius: 10px;
  margin-bottom: 16px; font-size: .9rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.school-banner strong { font-size: 1rem; }
.school-banner .sep { opacity: .4; margin: 0 8px; }
.badge-annee {
  background: rgba(255,255,255,.2); border-radius: 20px;
  padding: 2px 12px; font-size: .82rem;
}

/* ── KPI Grid ─────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.kpi {
  border-radius: 12px; padding: 18px 14px;
  text-align: center; color: white;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  transition: transform .15s;
  position: relative; overflow: hidden;
}
.kpi::after {
  content: ''; position: absolute; top: -20px; right: -20px;
  width: 80px; height: 80px; background: rgba(255,255,255,.08);
  border-radius: 50%;
}
.kpi:hover { transform: translateY(-3px); }
.kpi-icon { font-size: 1.5rem; margin-bottom: 4px; }
.kpi-val { font-size: 1.75rem; font-weight: 800; line-height: 1.1; }
.kpi-lbl { font-size: .72rem; opacity: .9; margin-top: 5px; font-weight: 500; }
.kpi.green   { background: linear-gradient(135deg,#2e7d32,#43a047); }
.kpi.blue    { background: linear-gradient(135deg,#1565c0,#1e88e5); }
.kpi.purple  { background: linear-gradient(135deg,#6a1b9a,#8e24aa); }
.kpi.orange  { background: linear-gradient(135deg,#e65100,#fb8c00); }
.kpi.teal    { background: linear-gradient(135deg,#00695c,#00897b); }
.kpi.indigo  { background: linear-gradient(135deg,#283593,#3949ab); }
.kpi.red     { background: linear-gradient(135deg,#b71c1c,#e53935); }
.kpi.yellow  { background: linear-gradient(135deg,#f57f17,#fbc02d); }
.kpi.cyan    { background: linear-gradient(135deg,#00838f,#00acc1); }
.kpi.pink    { background: linear-gradient(135deg,#880e4f,#c2185b); }

/* ── Section titre ────────────────────────────────────────────────────────── */
.section-title {
  font-size: .95rem; font-weight: 700; color: #0d2257;
  margin: 18px 0 10px; display: flex; align-items: center; gap: 8px;
}
.section-title::after {
  content: ''; flex: 1; height: 1px; background: #e0e4ef;
}

/* ── Carte générique ──────────────────────────────────────────────────────── */
.card {
  background: white; border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  margin-bottom: 14px;
}
.card-title {
  font-weight: 700; color: #0d2257; margin-bottom: 14px;
  font-size: .92rem; display: flex; align-items: center; gap: 8px;
}

/* ── Grille 2 colonnes ────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 14px; margin-bottom: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; margin-bottom: 14px; }

/* ── Toggle Jour/Semaine/Mois ─────────────────────────────────────────────── */
.period-toggle {
  display: flex; gap: 0; border: 2px solid #0d2257;
  border-radius: 8px; overflow: hidden; width: fit-content;
  margin-bottom: 14px;
}
.period-btn {
  background: none; border: none; cursor: pointer;
  padding: 6px 16px; font-size: .82rem; font-weight: 600;
  color: #0d2257; transition: all .15s;
}
.period-btn.active { background: #0d2257; color: white; }
.period-btn:hover:not(.active) { background: #eef2ff; }

/* ── Encaissement résumé ──────────────────────────────────────────────────── */
.enc-summary {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 14px;
}
.enc-box {
  border-radius: 10px; padding: 14px 16px; text-align: center;
  border: 2px solid transparent;
}
.enc-box.recettes { background: #e8f5e9; border-color: #a5d6a7; }
.enc-box.depenses { background: #fce4ec; border-color: #f48fb1; }
.enc-box.solde    { background: #e3f2fd; border-color: #90caf9; }
.enc-box .enc-val { font-size: 1.3rem; font-weight: 800; }
.enc-box.recettes .enc-val { color: #2e7d32; }
.enc-box.depenses .enc-val { color: #b71c1c; }
.enc-box.solde    .enc-val { color: #1565c0; }
.enc-box .enc-lbl { font-size: .74rem; color: #666; margin-top: 2px; }

/* ── Graphique barre inline ───────────────────────────────────────────────── */
.bar-list { list-style: none; }
.bar-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 0; border-bottom: 1px solid #f0f0f0;
  font-size: .83rem;
}
.bar-list li:last-child { border-bottom: none; }
.bar-lbl { width: 70px; flex-shrink: 0; color: #555; font-size: .78rem; }
.bar-track { flex: 1; background: #eef; border-radius: 4px; height: 8px; }
.bar-fill { height: 8px; border-radius: 4px; background: linear-gradient(90deg,#1565c0,#42a5f5); }
.bar-fill.green { background: linear-gradient(90deg,#2e7d32,#66bb6a); }
.bar-fill.orange { background: linear-gradient(90deg,#e65100,#ffa726); }
.bar-val { width: 90px; text-align: right; font-weight: 600; color: #333; flex-shrink: 0; }

/* ── Tableau classes ──────────────────────────────────────────────────────── */
.classes-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.classes-table th {
  background: #0d2257; color: white;
  padding: 9px 12px; text-align: left; font-weight: 600;
}
.classes-table td { padding: 8px 12px; border-bottom: 1px solid #eef; vertical-align: middle; }
.classes-table tr:nth-child(even) td { background: #f7f8fc; }
.classes-table tr:hover td { background: #eef2ff; }
.progress-bar { width: 100%; background: #e0e4ef; border-radius: 20px; height: 10px; }
.progress-fill { height: 10px; border-radius: 20px; transition: width .4s; }
.progress-fill.low   { background: linear-gradient(90deg,#2e7d32,#66bb6a); }
.progress-fill.mid   { background: linear-gradient(90deg,#f57f17,#fbc02d); }
.progress-fill.high  { background: linear-gradient(90deg,#e53935,#ef9a9a); }
.taux-chip {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: .75rem; font-weight: 700; min-width: 42px; text-align: center;
}
.taux-chip.low   { background: #e8f5e9; color: #2e7d32; }
.taux-chip.mid   { background: #fff8e1; color: #f57f17; }
.taux-chip.high  { background: #fce4ec; color: #b71c1c; }

/* ── Modes de paiement ────────────────────────────────────────────────────── */
.modes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px,1fr)); gap: 12px; }
.mode-item {
  background: #f5f7fa; border-radius: 10px; padding: 14px 16px;
  border-left: 4px solid #0d6efd;
}
.mode-item .mode-name { font-weight: 700; color: #0d2257; font-size: .88rem; }
.mode-item .mode-val  { font-size: 1.25rem; font-weight: 800; color: #1565c0; }
.mode-item .mode-nb   { font-size: .76rem; color: #888; }

/* ── Comparaison ──────────────────────────────────────────────────────────── */
.cmp-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 0 8px; flex-wrap: wrap;
}
.cmp-header h2 { font-size: 1.05rem; color: #0d2257; flex: 1; font-weight: 700; }
.cmp-header select {
  padding: 7px 12px; border: 2px solid #dde; border-radius: 8px;
  font-size: .88rem; color: #333;
}
.cmp-toggle-lbl {
  display: flex; align-items: center; gap: 6px;
  font-size: .88rem; color: #555; cursor: pointer;
}
.cmp-table-wrap { overflow-x: auto; }
.cmp-table-wrap table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.cmp-table-wrap th {
  background: #0d2257; color: #fff;
  padding: 10px 14px; text-align: left; font-weight: 600;
}
.cmp-table-wrap td { padding: 9px 14px; border-bottom: 1px solid #eef; vertical-align: middle; }
.cmp-table-wrap tr:nth-child(even) td { background: #f7f8fc; }
.cmp-table-wrap tr:hover td { background: #eef2ff; }
.badge-label {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: .75rem; font-weight: 700;
}
.badge-N   { background: #e8f5e9; color: #2e7d32; }
.badge-N1  { background: #e3f2fd; color: #1565c0; }
.badge-N2  { background: #fce4ec; color: #b71c1c; }
.delta-pos { color: #2e7d32; font-weight: 600; }
.delta-neg { color: #b71c1c; font-weight: 600; }
.delta-neu { color: #888; }

/* ── Footer ───────────────────────────────────────────────────────────────── */
.dash-footer {
  text-align: center; color: #aaa; font-size: .78rem;
  padding: 24px 0 10px;
}

/* ── Responsive mobile ────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .login-card { padding: 36px 22px 28px; }
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .kpi-val { font-size: 1.4rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .enc-summary { grid-template-columns: 1fr; }
  header { padding: 8px 12px; }
  .header-right select { max-width: 130px; }
}
