/* ================== École de soutien — style ================== */
:root {
  --navy: #1e3a5f;
  --navy-dark: #152b47;
  --accent: #2a9d8f;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e6ec;
  --text: #1f2933;
  --muted: #6b7785;
  --red: #c0392b;
  --red-bg: #fdecea;
  --orange: #b7650b;
  --orange-bg: #fff4e0;
  --green: #1e7d4f;
  --green-bg: #e6f5ec;
  --grey-bg: #eef0f3;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.error-text { color: var(--red); min-height: 1em; }
h1, h2, h3, h4 { margin: 0; color: var(--navy); }
h3 { font-size: 16px; }
h4 { font-size: 14px; margin: 18px 0 8px; }

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px;
  font-family: inherit; white-space: nowrap;
}
.btn:hover { background: var(--grey-bg); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: wait; }
.icon-btn { border: none; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

input, select, textarea {
  font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px;
  background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(42,157,143,.35); border-color: var(--accent); }
textarea { min-height: 60px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
.req::after { content: " *"; color: var(--red); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Connexion ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  background: var(--card); padding: 32px; border-radius: 12px; width: 100%; max-width: 380px;
  border: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px;
}

/* ---------- Mise en page ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--navy); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 18px; font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand img { width: 34px; height: 34px; object-fit: contain; background: #fff; border-radius: 6px; }
.sidebar nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; flex: 1; }
.nav-item {
  text-align: left; background: transparent; border: none; color: rgba(255,255,255,.8);
  padding: 10px 12px; border-radius: 6px; font: inherit; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.1); display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot .muted { color: rgba(255,255,255,.6); word-break: break-all; }
.sidebar-foot .btn { color: #fff; justify-content: flex-start; padding-left: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 14px 24px; display: flex; align-items: center; gap: 12px; }
.menu-btn { display: none; }
.view { padding: 22px 24px 40px; }

/* ---------- Cartes ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .label { font-size: 12px; color: var(--muted); }
.card .value { font-size: 22px; font-weight: 700; color: var(--navy); margin-top: 4px; }
.card .value.red { color: var(--red); }
.card .value.green { color: var(--green); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }

/* ---------- Barre d'outils / onglets ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.toolbar > * { width: auto; }
.toolbar input[type=search] { min-width: 220px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tab { background: none; border: none; padding: 9px 14px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }
.tab .count { background: var(--grey-bg); border-radius: 10px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #fafbfc; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f9fc; }
td.num, th.num { text-align: right; white-space: nowrap; }
td select { width: auto; padding: 4px 6px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
tfoot td { font-weight: 700; background: #fafbfc; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.grey { background: var(--grey-bg); color: var(--muted); }
.badge.blue { background: #e7eef7; color: var(--navy); }
.chip { display: inline-block; background: #e7eef7; color: var(--navy); border-radius: 4px; padding: 1px 6px; font-size: 12px; margin: 1px 2px 1px 0; }

/* ---------- Modales ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 45, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; display: flex; flex-direction: column; }
.modal.lg { max-width: 860px; }
.modal.xl { max-width: 1100px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 18px; }
.info-grid div span { display: block; font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.note { background: #f6f8fb; border-left: 3px solid var(--accent); padding: 8px 12px; font-size: 13px; color: var(--muted); margin: 8px 0; }
.alloc-input { width: 110px; text-align: right; }
.radio-row { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-row label { flex-direction: row; align-items: center; gap: 4px; color: var(--text); }
.radio-row input { width: auto; }

/* ---------- Notifications ---------- */
.toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 6px; max-width: 360px; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .menu-btn { display: block; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .form-grid, .info-grid { grid-template-columns: 1fr; }
  .toolbar > * { width: 100%; }
  .toolbar input[type=search] { min-width: 0; }
  .modal-backdrop { padding: 10px; }
}

/* ================== Impression (A4) ================== */
#print-area { display: none; }
.doc { font-size: 12px; color: #000; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--navy); padding-bottom: 10px; margin-bottom: 14px; }
.doc-head img { max-height: 60px; max-width: 120px; }
.doc-title { text-align: right; }
.doc-title h2 { font-size: 20px; }
.doc table { border: 1px solid #ccc; margin: 8px 0 14px; }
.doc th, .doc td { border: 1px solid #ccc; padding: 5px 8px; font-size: 11.5px; }
.doc th { background: #f0f2f5; color: #000; }
.doc .totals { width: 50%; margin-left: auto; }
.doc .grand td { font-weight: 700; font-size: 13px; }
.doc .two-col { display: flex; gap: 20px; }
.doc .two-col > div { flex: 1; }
.doc .sign { display: flex; justify-content: space-between; margin-top: 40px; }
.doc .sign div { width: 45%; border-top: 1px solid #000; padding-top: 6px; text-align: center; min-height: 70px; }
.doc .small-dates { font-size: 10.5px; color: #333; }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  #app, #login-screen, #modal-root, #toast-root { display: none !important; }
  #print-area { display: block; }
  .doc { page-break-inside: auto; }
  .doc tr { page-break-inside: avoid; }
}

/* Bouton d'installation (PWA) */
.sidebar-foot .btn.accent { color: #fff; justify-content: center; padding: 6px 10px; margin-bottom: 6px; }
@media (display-mode: standalone) { #install-btn { display: none !important; } }
