:root {
  --fond: #f4f6f8;
  --carte: #ffffff;
  --texte: #1c2430;
  --discret: #687385;
  --bord: #e3e7ec;
  --accent: #0f8b8d;
  --accent-clair: #e3f4f4;
  --sur-accent: #ffffff;
  --ok: #1f9d55;
  --ok-clair: #e5f6ec;
  --attente: #c28a00;
  --attente-clair: #fdf4dc;
  --retard: #d64545;
  --retard-clair: #fde8e8;
  --action: #7c5cff;
  --action-clair: #efeaff;
  --nc: #a0a8b4;
  --ombre: 0 1px 3px rgba(20, 30, 45, .08);
  --rayon: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #11161c;
    --carte: #1b222b;
    --texte: #e9edf2;
    --discret: #98a2b3;
    --bord: #2b3440;
    --accent: #3cc2c4;
    --accent-clair: #163234;
    --sur-accent: #06292a;
    --ok: #4cc47f;
    --ok-clair: #16301f;
    --attente: #e8b730;
    --attente-clair: #33290f;
    --retard: #f07070;
    --retard-clair: #3a1c1c;
    --action: #a48dff;
    --action-clair: #261f40;
    --nc: #6b7380;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.discret { color: var(--discret); }

/* ---------- Structure ---------- */
.entete {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--fond);
}
.entete .titre { flex: 1; min-width: 0; }
.entete h1 { font-size: 22px; }
.etat { font-size: 12px; color: var(--discret); }
.etat.alerte { color: var(--attente); font-weight: 600; }
.icone {
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--carte); box-shadow: var(--ombre);
  font-size: 20px; display: grid; place-items: center;
}
main { padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.section { margin: 22px 0 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--discret); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: var(--carte); border-top: 1px solid var(--bord);
}
.nav button {
  border: 0; background: none; padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--discret);
}
.nav .i { font-size: 20px; line-height: 24px; }
.nav button.actif { color: var(--accent); font-weight: 600; }
.nav button.plus .i {
  width: 48px; height: 48px; margin-top: -20px; border-radius: 50%;
  background: var(--accent); color: var(--sur-accent); font-size: 30px; line-height: 46px;
  box-shadow: 0 4px 12px rgba(15, 139, 141, .35);
}

/* ---------- Cartes et tuiles ---------- */
.carte { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 16px; }
.tuiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tuile { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 14px; border: 0; text-align: left; }
.tuile .n { font-size: 28px; font-weight: 700; display: block; }
.tuile .l { font-size: 13px; color: var(--discret); }
.tuile.retard .n { color: var(--retard); }
.tuile.attente .n { color: var(--attente); }
.tuile.large { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tuile.large .n { font-size: 24px; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 14px;
  padding: 15px 18px; font-weight: 600; font-size: 17px;
  background: var(--accent); color: var(--sur-accent);
}
.btn.secondaire { background: var(--accent-clair); color: var(--accent); }
.btn.danger { background: var(--retard-clair); color: var(--retard); }
.btn.petit { display: inline-block; width: auto; padding: 9px 14px; font-size: 15px; border-radius: 10px; }
.btn-ajout { margin: 16px 0 4px; font-size: 18px; padding: 18px; }
.boutons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.lien { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 600; font-size: 14px; }

/* ---------- Avatars ---------- */
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 700; font-size: 16px;
}
.avatar.grand { width: 54px; height: 54px; font-size: 22px; }
.avatar.petit { width: 26px; height: 26px; font-size: 12px; }

/* ---------- Lignes de dépenses ---------- */
.liste { display: flex; flex-direction: column; gap: 8px; }
.ligne {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 0; text-align: left; background: var(--carte); border-radius: 14px;
  box-shadow: var(--ombre); padding: 12px;
}
.ligne-corps { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ligne-titre { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ligne-sous { font-size: 13px; color: var(--discret); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ligne-montant { text-align: right; font-weight: 700; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.ligne-montant small { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; white-space: nowrap; }
small.solde { background: var(--ok-clair); color: var(--ok); }
small.attente { background: var(--attente-clair); color: var(--attente); }
small.retard { background: var(--retard-clair); color: var(--retard); }
small.action { background: var(--action-clair); color: var(--action); }

.pastilles { display: flex; gap: 4px; margin-top: 3px; }
.pastille {
  font-size: 10px; font-weight: 700; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; background: var(--nc);
}
.pastille.ok { background: var(--ok); }
.pastille.attente { background: var(--attente); }
.pastille.retard { background: var(--retard); }
.pastille.action { background: var(--action); }
.pastille.nc { background: transparent; color: var(--nc); border: 1.5px dashed var(--nc); }

.mois { margin: 18px 0 8px; font-size: 13px; font-weight: 700; color: var(--discret); text-transform: capitalize; }
.vide { text-align: center; color: var(--discret); padding: 40px 16px; }
.vide .grand { font-size: 44px; display: block; margin-bottom: 8px; }

/* ---------- Puces (filtres, choix) ---------- */
.puces { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.puces::-webkit-scrollbar { display: none; }
.puce {
  flex: none; border: 1.5px solid var(--bord); background: var(--carte); color: var(--texte);
  border-radius: 99px; padding: 7px 14px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.puce.actif { border-color: var(--accent); background: var(--accent-clair); color: var(--accent); font-weight: 600; }

/* ---------- Formulaires ---------- */
.champ { margin: 0 0 16px; display: block; }
.champ > .etiquette { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.champ .aide { font-weight: 400; color: var(--discret); }
input[type=text], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1.5px solid var(--bord); border-radius: 12px; background: var(--carte);
  padding: 12px; font-size: 17px; min-height: 48px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--discret) 50%), linear-gradient(135deg, var(--discret) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 14px) 21px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.montant-saisie { font-size: 28px !important; font-weight: 700; text-align: center; }

.choix { display: flex; flex-wrap: wrap; gap: 10px; }
.choix input { position: absolute; opacity: 0; pointer-events: none; }
.choix label {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px;
  padding: 8px 6px; border-radius: 14px; border: 2px solid transparent; font-size: 14px;
}
.choix input:checked + label { border-color: var(--accent); background: var(--accent-clair); font-weight: 600; }
.choix input:focus-visible + label { outline: 2px solid var(--accent); }
.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bord); border-radius: 12px; padding: 3px; gap: 3px; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment label { text-align: center; padding: 10px; border-radius: 10px; font-weight: 600; color: var(--discret); }
.segment input:checked + label { background: var(--carte); color: var(--texte); box-shadow: var(--ombre); }
.bloc-sup { background: var(--accent-clair); border-radius: 14px; padding: 14px 14px 2px; margin: -6px 0 16px; }
.cache { display: none !important; }
.photo-zone {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px;
  border: 1.5px dashed var(--bord); border-radius: 12px; color: var(--discret); padding: 10px;
}
.photo-zone img { max-height: 120px; border-radius: 8px; }

/* ---------- Détail ---------- */
.detail-tete { display: flex; gap: 14px; align-items: center; }
.detail-tete h2 { font-size: 20px; }
.gros-montant { font-size: 34px; font-weight: 800; margin: 14px 0 2px; }
.barre { height: 10px; border-radius: 99px; background: var(--bord); overflow: hidden; margin: 10px 0 6px; }
.barre > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.resume { display: flex; justify-content: space-between; font-size: 14px; }
.etape { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--bord); }
.etape:first-child { border-top: 0; padding-top: 4px; }
.etape .pastille { width: 28px; height: 28px; font-size: 13px; flex: none; }
.etape-corps { flex: 1; min-width: 0; }
.etape-nom { font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.etape-texte { font-size: 15px; color: var(--discret); margin-top: 2px; }
.etape-texte b { color: var(--texte); }
.etape.retard .etape-texte b { color: var(--retard); }
.infos { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; margin-top: 12px; }
.infos dt { color: var(--discret); }
.infos dd { margin: 0; }

/* ---------- Bilan ---------- */
.barres { display: flex; flex-direction: column; gap: 14px; }
.barre-ligne .haut { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 15px; }
.barre-ligne .haut > span:first-child { display: flex; align-items: center; gap: 8px; }
.barre-ligne .bas { font-size: 12px; color: var(--discret); }
.barre-ligne .barre { margin: 6px 0 2px; height: 12px; }
.barre-ligne .barre > span { background: var(--c, var(--accent)); }
.tableau { width: 100%; border-collapse: collapse; font-size: 13px; }
.tableau th, .tableau td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--bord); white-space: nowrap; }
.tableau th:first-child, .tableau td:first-child { text-align: left; }
.tableau tfoot td { font-weight: 700; border-bottom: 0; }
.defile { overflow-x: auto; }

/* ---------- Réglages ---------- */
.reglage { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--bord); }
.reglage:first-child { border-top: 0; }
.praticien { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; text-align: left; padding: 11px 0; border-top: 1px solid var(--bord); }
.praticien:first-child { border-top: 0; }
.praticien .corps { flex: 1; min-width: 0; }
.praticien .sous { font-size: 13px; color: var(--discret); }
.praticien.inactif { opacity: .5; }

/* ---------- Écrans PIN et accueil ---------- */
.ecran-centre {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 12px; max-width: 420px; margin: 0 auto;
}
.logo {
  width: 72px; height: 72px; border-radius: 22px; background: var(--accent); color: var(--sur-accent);
  display: grid; place-items: center; font-size: 40px; font-weight: 800;
}
.points { display: flex; gap: 16px; margin: 10px 0 18px; }
.point { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); }
.point.plein { background: var(--accent); }
.secoue { animation: secoue .35s; }
@keyframes secoue { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.clavier { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.touche {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--carte);
  box-shadow: var(--ombre); font-size: 28px; font-weight: 500;
}
.touche:active { background: var(--accent-clair); }

/* ---------- Import des relevés ---------- */
.imp-groupe { margin-top: 18px; }
.imp-groupe > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.imp-groupe > summary::-webkit-details-marker { display: none; }
.imp-groupe > summary::before { content: '›'; font-size: 20px; color: var(--discret); transition: transform .15s; }
.imp-groupe[open] > summary::before { transform: rotate(90deg); }
.imp-groupe > .liste { margin-top: 8px; }
.imp-ligne { cursor: pointer; align-items: flex-start; }
.imp-ligne input[type=checkbox] { width: 22px; height: 22px; margin: 8px 0 0; accent-color: var(--accent); flex: none; }
.imp-ligne.decoche { opacity: .55; }
.imp-ligne .ligne-titre { white-space: normal; }
.imp-detail { font-size: 13px; color: var(--discret); margin-top: 4px; }
.imp-detail b { color: var(--texte); }
.imp-lien { font-size: 13px; margin-top: 4px; }
.imp-alerte { display: inline-block; margin-left: 4px; padding: 1px 7px; border-radius: 99px; background: var(--attente-clair); color: var(--attente); font-weight: 600; font-size: 11px; }
.barre-action {
  position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 4;
  display: flex; gap: 8px; align-items: center; padding: 14px 0 4px; margin-top: 12px;
  background: linear-gradient(to bottom, transparent, var(--fond) 35%);
}
.barre-action .btn:last-child { flex: 1; }

.bouton-google { min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; margin: 4px 0 8px; }
.secours { width: 100%; text-align: left; font-size: 14px; color: var(--discret); }
.secours summary { cursor: pointer; text-align: center; padding: 6px; }
.secours[open] { display: flex; flex-direction: column; gap: 10px; }
.secours[open] summary { margin-bottom: 0; }

/* ---------- Feuille du bas et toast ---------- */
.voile { position: fixed; inset: 0; z-index: 20; background: rgba(10, 15, 20, .45); display: flex; align-items: flex-end; justify-content: center; }
.feuille {
  width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto;
  background: var(--fond); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  animation: monte .2s ease-out;
}
.feuille .poignee { width: 40px; height: 5px; border-radius: 9px; background: var(--bord); margin: 0 auto 12px; }
.feuille h3 { font-size: 19px; margin-bottom: 14px; }
@keyframes monte { from { transform: translateY(40px); opacity: 0; } }
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #1c2430; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px;
  max-width: calc(100% - 32px); width: max-content; text-align: center; transition: .2s;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.erreur { background: var(--retard); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
