:root {
  --fond: #f5f4f0; --carte: #ffffff; --texte: #1c1f1d; --doux: #7a7f7b; --trait: #e7e5df;
  --accent: #1f6f5c; --accent-2: #2f8f76; --accent-clair: #e3f0eb; --rouge: #c2412d; --vert: #1f7a4d;
  --ombre: 0 1px 2px rgba(20, 30, 25, .05), 0 6px 20px rgba(20, 30, 25, .06);
  --rayon: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #111412; --carte: #1b1f1d; --texte: #eef1ef; --doux: #8f9692; --trait: #2a2f2c;
    --accent: #4cc39f; --accent-2: #3aa886; --accent-clair: #1d3029; --rouge: #ff7a66; --vert: #5fd29a;
    --ombre: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--fond); color: var(--texte); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  -webkit-user-select: none; user-select: none;
}
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.doux { color: var(--doux); }
.petit { font-size: 13px; }
.vert { color: var(--vert); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- code ---------- */
#v-code { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.code-boite { text-align: center; width: 100%; max-width: 320px; }
.code-logo { width: 72px; height: 72px; border-radius: 18px; box-shadow: var(--ombre); }
.code-boite h1 { margin: 14px 0 4px; font-size: 26px; letter-spacing: -.02em; }
.connexion { margin: 26px 0 8px; overflow: hidden; text-align: left; }
.connexion input { display: block; width: 100%; height: 52px; border: 0; padding: 0 16px; font-size: 17px; background: none; outline: none; }
.connexion input + input { border-top: 1px solid var(--trait); }
.btn-principal.large { width: 100%; margin-bottom: 14px; }
.deconnexion { display: block; margin: 30px auto 0; color: var(--rouge); font-size: 15px; padding: 10px; }
.points { display: flex; justify-content: center; gap: 18px; margin: 28px 0 8px; }
.points i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--accent); transition: background .15s; }
.points i.plein { background: var(--accent); }
.points.secoue { animation: secoue .35s; }
@keyframes secoue { 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.code-err { min-height: 20px; color: var(--rouge); font-size: 14px; margin: 0 0 14px; }
.pave { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 22px; padding: 0 12px; }
.pave button { aspect-ratio: 1; border-radius: 50%; font-size: 28px; font-weight: 400; background: var(--carte); box-shadow: var(--ombre); transition: transform .08s, background .1s; }
.pave button:active { transform: scale(.94); background: var(--accent-clair); }
.pave .eff { background: none; box-shadow: none; font-size: 24px; color: var(--doux); }

/* ---------- structure ---------- */
#v-app { padding: 0 16px calc(96px + env(safe-area-inset-bottom, 0px)); max-width: 640px; margin: 0 auto; }
.onglet { padding-top: 10px; animation: entre .18s ease-out; }
@keyframes entre { from { opacity: 0; transform: translateY(4px); } }
.haut { padding: 8px 2px 4px; }
.salut { margin: 6px 0 10px; font-size: 15px; color: var(--doux); }
.haut-titre h1 { margin: 10px 2px 12px; font-size: 32px; letter-spacing: -.025em; }
.carte { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); }
.titre-sec { margin: 26px 4px 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--doux); }

/* solde */
.solde {
  display: grid; padding: 18px 20px; border-radius: 20px; color: #fff;
  background: linear-gradient(135deg, #2b8a70 0%, #1f6f5c 55%, #17574a 100%);
  box-shadow: 0 10px 30px rgba(31, 111, 92, .25);
}
.solde-lib { font-size: 14px; opacity: .85; }
.solde-val { font-size: 36px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.solde-det { font-size: 13px; opacity: .85; }
.solde.avance { background: linear-gradient(135deg, #5a6a8a, #3f4c66); box-shadow: none; }

/* segment */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--trait); border-radius: 11px; padding: 3px; margin: 18px 0 12px; }
.seg button { padding: 8px 0; border-radius: 9px; font-size: 15px; font-weight: 500; color: var(--doux); transition: background .15s, color .15s; }
.seg button.actif { background: var(--carte); color: var(--texte); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* formulaire */
.formulaire { padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.champ, .champ-montant { display: block; min-width: 0; }
.lib { display: block; font-size: 13px; font-weight: 600; color: var(--doux); margin-bottom: 6px; }
.lib em { font-weight: 400; font-style: normal; }
.champ input, .ac input {
  width: 100%; min-width: 0; -webkit-appearance: none; appearance: none; height: 48px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--trait);
  background: var(--fond); font-size: 17px; outline: none; transition: border-color .15s, background .15s;
}
.champ input:focus, .ac input:focus { border-color: var(--accent); background: var(--carte); }
.montant-ligne { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--trait); padding-bottom: 4px; transition: border-color .15s; }
.montant-ligne:focus-within { border-color: var(--accent); }
#s-montant, .f-montant { flex: 1; min-width: 0; border: 0; outline: none; background: none; font-size: 44px; font-weight: 700; letter-spacing: -.02em; padding: 0; height: auto; font-variant-numeric: tabular-nums; }
.devise { font-size: 22px; font-weight: 600; color: var(--doux); }

/* autocomplétion */
.ac { position: relative; }
.ac input { padding-right: 40px; }
.ac-x { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 50%; background: var(--trait); color: var(--doux); font-size: 18px; line-height: 28px; }
.ac-liste { list-style: none; margin: 6px 0 0; padding: 4px; border-radius: 12px; background: var(--carte); border: 1px solid var(--trait); box-shadow: var(--ombre); max-height: 248px; overflow-y: auto; }
.ac-liste li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 12px; border-radius: 9px; font-size: 17px; }
.ac-liste li.sel, .ac-liste li:active { background: var(--accent-clair); }
.ac-liste li > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-liste li b { color: var(--accent); font-weight: 700; }
.ac-liste li small { color: var(--doux); font-size: 13px; }
.ac-liste li.nouveau { color: var(--accent); font-weight: 500; }
.puces { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.puces:empty { display: none; }
.puce { padding: 7px 13px; border-radius: 999px; background: var(--accent-clair); color: var(--accent); font-size: 15px; font-weight: 500; }
.puce:active { transform: scale(.96); }

/* dates */
.dates { display: flex; gap: 8px; flex-wrap: wrap; }
.puce-date { position: relative; padding: 10px 14px; border-radius: 11px; border: 1.5px solid var(--trait); font-size: 15px; font-weight: 500; overflow: hidden; }
.puce-date.actif { border-color: var(--accent); background: var(--accent-clair); color: var(--accent); }
.puce-date.autre input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; border: 0; padding: 0; }

.btn-principal { height: 54px; border-radius: 14px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; transition: opacity .15s, transform .08s; }
.btn-principal:disabled { opacity: .35; }
.btn-principal:not(:disabled):active { transform: scale(.98); }
.btn-danger { height: 50px; border-radius: 14px; color: var(--rouge); font-weight: 600; background: var(--fond); }
.btn-danger.confirme { background: var(--rouge); color: #fff; }
.btn-second { padding: 11px 14px; border-radius: 12px; background: var(--carte); box-shadow: var(--ombre); color: var(--accent); font-weight: 600; font-size: 15px; }
.btn-second:active { transform: scale(.98); }

/* listes */
.liste { overflow: hidden; }
.ligne { display: flex; align-items: center; gap: 12px; padding: 12px 16px; position: relative; }
.ligne + .ligne::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 1px solid var(--trait); }
.ligne.cliquable:active { background: var(--fond); }
.ligne .av { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; }
.ligne .milieu { flex: 1; min-width: 0; display: block; }
.ligne .nom { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne .sous { display: block; font-size: 13px; color: var(--doux); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne .mt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ligne .mt.vert { color: var(--vert); }
.ligne .attente { display: block; font-size: 12px; color: #b7791f; }
.vide { padding: 26px 16px; text-align: center; color: var(--doux); font-size: 15px; }
.jour { display: flex; justify-content: space-between; margin: 18px 4px 6px; font-size: 13px; font-weight: 600; color: var(--doux); }
.jour:first-child { margin-top: 4px; }
.barre-p { height: 6px; border-radius: 3px; background: var(--trait); margin-top: 6px; overflow: hidden; }
.barre-p i { display: block; height: 100%; border-radius: 3px; background: var(--accent-2); }

/* périodes */
.periodes { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.periodes::-webkit-scrollbar { display: none; }
.periodes button { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--carte); box-shadow: var(--ombre); font-size: 14px; font-weight: 500; position: relative; }
.periodes button.actif { background: var(--texte); color: var(--fond); }
.periodes label { flex: none; position: relative; padding: 8px 14px; border-radius: 999px; background: var(--carte); box-shadow: var(--ombre); font-size: 14px; font-weight: 500; }
.periodes label.actif { background: var(--texte); color: var(--fond); }
.periodes label input { position: absolute; inset: 0; opacity: 0; width: 100%; }
.recherche input { width: 100%; height: 42px; border-radius: 11px; border: 0; background: var(--trait); padding: 0 14px; font-size: 16px; outline: none; }
.resume { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 4px 4px; }
.resume b { font-size: 22px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.resume span { color: var(--doux); font-size: 14px; }

/* bilan */
.bilan { padding: 6px 18px 14px; }
.b-ligne { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--trait); font-variant-numeric: tabular-nums; }
.b-ligne.total { border: 0; font-size: 19px; }
.b-ligne.total b { color: var(--accent); }
.jauge { height: 8px; border-radius: 4px; background: var(--trait); overflow: hidden; margin-top: 4px; }
.jauge i { display: block; height: 100%; background: var(--vert); border-radius: 4px; transition: width .4s; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* barre du bas */
.barre {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--carte) 86%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--trait);
}
.barre button { display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--doux); font-size: 11px; font-weight: 500; }
.barre svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.barre button.actif { color: var(--accent); }

/* feuille */
.voile { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .35); animation: fondu .2s; }
@keyframes fondu { from { opacity: 0; } }
.feuille {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-height: 90dvh; overflow-y: auto; max-width: 640px; margin: 0 auto;
  background: var(--fond); border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: monte .25s cubic-bezier(.2, .8, .2, 1);
}
@keyframes monte { from { transform: translateY(100%); } }
.poignee { width: 38px; height: 5px; border-radius: 3px; background: var(--trait); margin: 2px auto 10px; }
.f-titre { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 12px; }
.f-titre h2 { margin: 0; font-size: 20px; }
.f-titre button { color: var(--accent); font-weight: 600; }
.f-actions { display: grid; gap: 10px; margin-top: 4px; }
.f-info { font-size: 12px; color: var(--doux); text-align: center; margin: 4px 0 0; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-radius: 14px; max-width: calc(100% - 32px);
  background: #1c1f1d; color: #fff; font-size: 15px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: toast .2s;
}
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } }
.toast button { color: #7fe0bf; font-weight: 600; }
.hors-ligne { position: fixed; top: env(safe-area-inset-top, 0px); left: 0; right: 0; z-index: 41; background: #b7791f; color: #fff; font-size: 13px; text-align: center; padding: 6px 12px; }
