:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #14213d;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #1f4fd1;
  --red: #c4320a;
  --red-bg: #fef3f2;
  --orange: #b54708;
  --orange-bg: #fffaeb;
  --green: #067647;
  --green-bg: #ecfdf3;
  --grey-bg: #f2f4f7;
  --wa: #128c7e;
  --radius: 12px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px; line-height: 1.45;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 720px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Cartes et listes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: block; color: inherit; }
.item.retard { border-left: 4px solid var(--red); }
.item.bientot, .item.aujourdhui { border-left: 4px solid var(--orange); }
.item .titre { font-weight: 600; }
.item .actions { display: flex; gap: 8px; margin-top: 10px; }
.empty { text-align: center; color: var(--muted); padding: 20px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .valeur { font-size: 19px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.kpi.alerte .valeur { color: var(--red); }

/* Pastilles d'état */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.retard { background: var(--red-bg); color: var(--red); }
.pill.bientot, .pill.aujourdhui { background: var(--orange-bg); color: var(--orange); }
.pill.ajour { background: var(--green-bg); color: var(--green); }
.pill.gratuit, .pill.suspendu, .pill.resilie, .pill.aucun { background: var(--grey-bg); color: var(--muted); }

/* Boutons */
button, .btn {
  font: inherit; font-weight: 600; font-size: 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 9px 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:disabled { opacity: .5; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-wa { background: var(--wa); color: #fff; border-color: var(--wa); }
.btn-danger { color: var(--red); }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.actions .btn, .actions button { flex: 1; }
.fab { position: fixed; right: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); border-radius: 999px; padding: 14px 18px; box-shadow: 0 6px 16px rgba(20,33,61,.25); z-index: 5; }

/* Formulaires */
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.search { margin-bottom: 12px; }
.erreur { color: var(--red); font-size: 14px; margin-top: 10px; }

/* Fenêtre modale */
dialog { border: none; border-radius: 16px; padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); }
dialog::backdrop { background: rgba(20, 33, 61, .45); }
#modal-form { padding: 18px; }
#modal-form h3 { margin: 0 0 4px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions button { flex: 1; }

/* Navigation */
.nav[hidden] { display: none; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 10;
}
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); font-weight: 600; }
.nav a svg { width: 22px; height: 22px; fill: currentColor; }
.nav a.actif { color: var(--ink); }

/* Divers */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 24px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: 90%; }
.retour { display: inline-block; margin-bottom: 8px; font-weight: 600; }
.detail-ligne { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.detail-ligne:last-child { border-bottom: none; }
.mois { font-weight: 700; margin: 18px 0 6px; display: flex; justify-content: space-between; }
.login { max-width: 360px; margin: 18vh auto 0; }
.login .logo { width: 56px; height: 56px; margin-bottom: 8px; }

/* ---------- v0.2 ---------- */
.entete { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 14px; }
.entete h1 { margin: 0; }
.entete .sous { color: var(--muted); font-size: 13px; margin-top: 2px; }
.avatar { width: 38px; height: 38px; border-radius: 999px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }

.banniere { display: flex; gap: 12px; align-items: center; background: #eef4ff; border: 1px solid #c7d7fe; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.banniere .texte { flex: 1; font-size: 14px; }
.banniere strong { display: block; }
.banniere svg { width: 28px; height: 28px; fill: var(--accent); flex: none; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.chip.actif { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .n { opacity: .65; margin-left: 4px; font-weight: 500; }

.vide-accueil { text-align: center; padding: 28px 18px; }
.vide-accueil h3 { margin: 6px 0 6px; }
.vide-accueil p { color: var(--muted); margin: 0 0 16px; }

.onglets { display: flex; background: var(--grey-bg); border-radius: 10px; padding: 3px; margin: 10px 0 4px; }
.onglets button { flex: 1; border: none; background: transparent; color: var(--muted); }
.onglets button.actif { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(20,33,61,.12); }

.reglage { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.reglage:last-child { border-bottom: none; }
.reglage .titre { font-weight: 600; font-size: 14px; }
.reglage .desc { color: var(--muted); font-size: 13px; }
.ok-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; background: var(--green); margin-right: 6px; vertical-align: middle; }
.ko-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; background: #98a2b3; margin-right: 6px; vertical-align: middle; }
.succes { text-align: center; }
.succes .coche { width: 56px; height: 56px; border-radius: 999px; background: var(--green-bg); color: var(--green); display: flex; align-items: center; justify-content: center; margin: 4px auto 10px; font-size: 28px; font-weight: 700; }
