/* ============================================================
   Gestion Budget — feuille de style (refonte fintech)
   Look « néobanque » : surfaces nettes, ombres douces,
   typographie financière, icônes SVG, clair/sombre auto.
   ============================================================ */

:root{
  /* Marque */
  --brand:#0a84ff;
  --brand-2:#0a5fd0;
  --gold:#ffce45;

  /* Neutres (clair) */
  --bg:#eef1f6;
  --surface:#ffffff;
  --surface-2:#f4f6fa;
  --line:rgba(17,24,39,.08);
  --txt:#0f172a;
  --txt-2:#566072;
  --txt-3:#8b93a3;

  /* Sémantique */
  --pos:#12a150;
  --neg:#e5484d;

  /* Sur l'en-tête (fond bleu) */
  --on:#ffffff;
  --on-dim:rgba(255,255,255,.74);
  --on-soft:rgba(255,255,255,.15);
  --on-soft-2:rgba(255,255,255,.24);

  /* Rayons & ombres */
  --r:18px;
  --r-lg:24px;
  --sh-sm:0 1px 2px rgba(16,24,40,.06);
  --sh:0 2px 8px rgba(16,24,40,.05), 0 14px 30px -16px rgba(16,24,40,.22);
  --sh-lg:0 28px 64px -18px rgba(16,24,40,.34);

  --safe-t:env(safe-area-inset-top);
  --safe-b:env(safe-area-inset-bottom);

  --font:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}

@media (prefers-color-scheme: dark){
  :root{
    --bg:#0a0c11;
    --surface:#161a22;
    --surface-2:#1c212b;
    --line:rgba(255,255,255,.08);
    --txt:#f3f5f8;
    --txt-2:#a3acbb;
    --txt-3:#6f7889;
    --pos:#39d27f;
    --neg:#ff5d62;
    --sh-sm:0 1px 2px rgba(0,0,0,.5);
    --sh:0 2px 10px rgba(0,0,0,.4), 0 18px 36px -16px rgba(0,0,0,.66);
    --sh-lg:0 32px 72px -20px rgba(0,0,0,.74);
  }
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;margin:0;padding:0}
html{height:100%}
body{
  font-family:var(--font);
  background:var(--bg);
  color:var(--txt);
  min-height:100vh;
  min-height:100dvh;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  font-variant-numeric:tabular-nums;
}

svg.ic{width:1em;height:1em;flex:0 0 auto}

button{font-family:inherit}
/* Focus clavier : outline (pas box-shadow, qui serait masqué par les ombres
   propres des boutons). Anneau blanc sur l'en-tête, aucun double-anneau dans
   les champs (déjà signalés par .champ:focus-within). */
:focus-visible{outline:2.5px solid var(--brand);outline-offset:2px}
.budget-pill:focus-visible{outline-color:#fff}
.champ input:focus-visible{outline:none}

/* ===================== En-tête / Hero ===================== */
header{
  position:sticky;top:0;color:var(--on);
  padding:calc(var(--safe-t) + 12px) 18px 14px;
  border-radius:0 0 var(--r-lg) var(--r-lg);
  overflow:hidden;
  background:
    radial-gradient(135% 120% at 88% -20%, rgba(255,255,255,.26), transparent 52%),
    linear-gradient(158deg,#2f9bff 0%,var(--brand) 40%,var(--brand-2) 100%);
  box-shadow:0 14px 30px -18px rgba(0,72,180,.7);
  z-index:20;
}
header::after{
  content:"";position:absolute;left:-60px;bottom:-90px;width:240px;height:240px;
  background:radial-gradient(circle,rgba(255,255,255,.12),transparent 70%);
  pointer-events:none;
}

.header-top{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  position:relative;z-index:2;
}
.logo{
  font-size:19px;font-weight:800;letter-spacing:.3px;line-height:1;color:#fff;
  text-shadow:0 1px 2px rgba(0,0,0,.18);
}
.logo .logo-euro{color:var(--gold)}
.hero{display:flex;flex-direction:column;align-items:center;margin-top:10px;position:relative;z-index:2}
.hero-label{
  font-size:10.5px;font-weight:700;letter-spacing:1px;text-transform:uppercase;
  color:var(--on-dim);
}
.hero-amount{
  font-size:clamp(28px,8.5vw,38px);font-weight:800;line-height:1.05;margin-top:3px;
  letter-spacing:-1px;
}
.budget-pill{
  display:inline-flex;align-items:center;gap:7px;cursor:pointer;white-space:nowrap;
  border:none;color:var(--on);font-size:13px;font-weight:600;letter-spacing:.2px;
  background:var(--on-soft);padding:8px 14px;border-radius:999px;
  backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);
  transition:background .18s ease, transform .12s ease;
}
.budget-pill:hover{background:var(--on-soft-2)}
.budget-pill:active{transform:scale(.96)}
.budget-pill b{font-weight:800}
.budget-pill .ic{font-size:15px;opacity:.92}
.budget-pill .ic-edit{font-size:12px;opacity:.78;margin-left:1px}

/* Alerte persistante sous le solde : orange (≥50 %) puis rouge (≥75 %) */
.solde-alerte{
  align-self:stretch;
  display:flex;align-items:center;justify-content:center;gap:8px;
  margin-top:10px;padding:9px 14px;border-radius:13px;
  font-size:13px;font-weight:700;line-height:1.3;
  box-shadow:0 10px 26px -12px rgba(0,0,0,.55);
}
.solde-alerte[hidden]{display:none}
.solde-alerte .ic{font-size:19px}
.solde-alerte.niv-50{background:#f7a325;color:#3a2400}
.solde-alerte.niv-75{background:#e0212c;color:#fff}
/* Clignotement d'appel ~3 s à l'ouverture (déclenché/arrêté par le JS) */
@keyframes clignote-alerte{0%,100%{opacity:1}50%{opacity:.18}}
.solde-alerte.clignote{animation:clignote-alerte .6s ease-in-out infinite}

.hero-stats{
  display:flex;justify-content:space-between;align-items:baseline;gap:12px;
  margin-top:10px;position:relative;z-index:2;
}
.stat{display:flex;flex-direction:row;align-items:baseline;gap:6px;min-width:0}
.stat-end{justify-content:flex-end}
.stat-k{font-size:10px;font-weight:700;letter-spacing:.5px;text-transform:uppercase;color:var(--on-dim)}
.stat-v{font-size:14px;font-weight:800;letter-spacing:-.2px}

.barre{
  height:7px;border-radius:999px;background:rgba(255,255,255,.22);
  margin-top:11px;overflow:hidden;position:relative;z-index:2;
}
.barre>i{
  display:block;height:100%;width:0;border-radius:999px;
  background:linear-gradient(90deg,#ffffff,var(--gold));
  box-shadow:0 0 10px rgba(255,255,255,.45);
  transition:width .5s cubic-bezier(.22,1,.36,1);
}

.badge-sync{
  display:none;align-items:center;justify-content:center;gap:7px;
  margin-top:10px;position:relative;z-index:2;
  font-size:12px;font-weight:600;color:var(--on);
  background:rgba(0,0,0,.24);border-radius:999px;padding:7px 14px;
}
.badge-sync.on{display:flex;animation:fade .2s ease}
.badge-sync .ic{font-size:14px;opacity:.92}

/* ===================== Bouton « Ajouter une dépense » ===================== */
.ajout-wrap{padding:14px 14px 4px;position:relative;z-index:11}
.ajout-wrap .btn{width:100%}

.champ{
  display:flex;align-items:center;gap:10px;
  background:var(--surface-2);
  border:1.5px solid transparent;
  border-radius:var(--r);
  padding:0 14px;
  transition:border-color .18s ease, background .18s ease;
}
.champ:focus-within{border-color:var(--brand);background:var(--surface)}
.champ input{
  flex:1;border:none;outline:none;background:transparent;color:var(--txt);
  font-size:16px;font-weight:600;width:100%;padding:13px 0;
}
.champ input::placeholder{color:var(--txt-3);font-weight:500}
.champ-libelle{flex:1}
.champ-libelle input{font-size:16px;font-weight:500}
.champ .eur{font-size:18px;color:var(--txt-3);font-weight:700}

.champ.secoue{animation:secousse .4s cubic-bezier(.36,.07,.19,.97)}
@keyframes secousse{
  10%,90%{transform:translateX(-2px)} 20%,80%{transform:translateX(4px)}
  30%,50%,70%{transform:translateX(-6px)} 40%,60%{transform:translateX(6px)}
}

.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:7px;
  border:none;border-radius:var(--r);font-size:16px;font-weight:700;
  padding:0 20px;min-height:50px;cursor:pointer;white-space:nowrap;
  transition:transform .12s ease, box-shadow .2s ease, filter .2s ease;
}
.btn .ic{font-size:18px}
.btn-add{
  background:linear-gradient(180deg,#2f9bff,var(--brand));color:#fff;
  box-shadow:0 8px 18px -6px rgba(10,132,255,.6);
}
.btn-add:hover{filter:brightness(1.04)}
.btn-add:active{transform:scale(.96)}

/* ===================== Liste ===================== */
main{padding:8px 14px 4px}

.liste-tete{display:flex;align-items:center;justify-content:space-between;padding:14px 6px 6px}
.liste-titre{
  display:flex;align-items:center;gap:9px;
  font-size:13px;font-weight:700;letter-spacing:.4px;text-transform:uppercase;color:var(--txt-3);
}
.count{
  display:inline-flex;align-items:center;justify-content:center;min-width:22px;height:22px;
  padding:0 7px;border-radius:999px;background:var(--surface);border:1px solid var(--line);
  color:var(--txt-2);font-size:12px;font-weight:800;letter-spacing:0;
}
.count:empty{display:none}

.ligne-titres{
  display:grid;grid-template-columns:34px 1fr auto 44px;gap:12px;align-items:center;
  padding:2px 16px 8px;color:var(--txt-3);font-size:10.5px;font-weight:700;
  text-transform:uppercase;letter-spacing:.7px;
}
.ligne-titres .t-reste{text-align:right}
.ligne-titres.cache{display:none}

ul#liste{list-style:none;display:flex;flex-direction:column;gap:10px;padding-bottom:8px}
li{
  display:grid;grid-template-columns:34px 1fr auto 44px;gap:12px;align-items:center;
  background:var(--surface);border:1px solid var(--line);
  border-radius:var(--r);padding:12px 12px 12px 14px;
  box-shadow:var(--sh-sm);cursor:pointer;
  animation:pop .28s cubic-bezier(.22,1,.36,1);
}
li.sortie{animation:out .22s ease forwards}
@keyframes pop{from{opacity:0;transform:translateY(-8px) scale(.985)}to{opacity:1;transform:none}}
@keyframes out{to{opacity:0;transform:translateX(40px)}}

li .num{
  width:34px;height:34px;border-radius:11px;
  display:flex;align-items:center;justify-content:center;
  background:linear-gradient(180deg,rgba(10,132,255,.16),rgba(10,132,255,.09));
  color:var(--brand);font-size:13px;font-weight:800;
}
@media (prefers-color-scheme: dark){
  li .num{background:rgba(10,132,255,.18);color:#62b1ff}
}
li .info{display:flex;flex-direction:column;gap:2px;min-width:0;cursor:pointer}
li .paie{font-size:20px;font-weight:800;letter-spacing:-.4px;color:var(--txt);line-height:1.15}
li .meta{
  font-size:13px;font-weight:500;color:var(--txt-2);
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
li .rest{
  display:flex;flex-direction:column;align-items:flex-end;gap:1px;
  text-align:right;white-space:nowrap;
}
li .rest b{font-size:10px;font-weight:700;color:var(--txt-3);text-transform:uppercase;letter-spacing:.5px}
li .rest .v{color:var(--pos);font-size:15px;font-weight:800}
li .rest .v.neg{color:var(--neg)}
li .sup{
  width:44px;height:44px;justify-self:end;
  border:none;border-radius:13px;cursor:pointer;
  background:transparent;color:var(--txt-3);
  display:flex;align-items:center;justify-content:center;
  transition:background .15s ease, color .15s ease, transform .12s ease;
}
li .sup svg{width:18px;height:18px;pointer-events:none}
li .sup:hover{background:rgba(229,72,77,.1);color:var(--neg)}
li .sup:active{transform:scale(.9);background:rgba(229,72,77,.18);color:var(--neg)}

/* ===================== État vide ===================== */
.vide{text-align:center;color:var(--txt-3);padding:48px 24px}
.vide-ico{
  display:inline-flex;align-items:center;justify-content:center;
  width:74px;height:74px;border-radius:22px;margin-bottom:16px;
  background:var(--surface);border:1px solid var(--line);box-shadow:var(--sh-sm);color:var(--brand);
}
.vide-ico svg{width:34px;height:34px}
.vide-titre{font-size:17px;font-weight:700;color:var(--txt);margin-bottom:4px}
.vide-sous{font-size:14px;line-height:1.5;color:var(--txt-3)}

/* ===================== Remise à zéro ===================== */
.reset-wrap{
  padding:6px 16px calc(var(--safe-b) + 18px);
}
.btn-reset{
  display:flex;align-items:center;justify-content:center;gap:11px;
  width:100%;padding:15px;border:1px solid var(--line);border-radius:var(--r);
  background:var(--surface);color:var(--neg);font-weight:700;font-size:15px;cursor:pointer;
  box-shadow:var(--sh-sm);
  transition:transform .12s ease, box-shadow .2s ease, background .2s ease;
}
.btn-reset .reset-ico{
  display:flex;align-items:center;justify-content:center;width:30px;height:30px;border-radius:50%;
  background:rgba(229,72,77,.12);color:var(--neg);
  transition:transform .55s cubic-bezier(.22,1,.36,1);
}
.btn-reset .reset-ico svg{width:17px;height:17px}
.btn-reset:hover:not(:disabled){box-shadow:var(--sh)}
.btn-reset:active:not(:disabled){transform:scale(.985)}
.btn-reset:active:not(:disabled) .reset-ico{transform:rotate(-360deg)}
.btn-reset:disabled{color:var(--txt-3);opacity:.6;cursor:default}
.btn-reset:disabled .reset-ico{background:var(--line);color:var(--txt-3)}

/* ===================== Modales ===================== */
.overlay{
  position:fixed;inset:0;z-index:50;display:none;
  align-items:center;justify-content:center;padding:26px;
  background:rgba(8,12,20,.5);
  backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);
}
.overlay.on{display:flex;animation:fade .15s ease}
@keyframes fade{from{opacity:0}to{opacity:1}}
/* Fenêtre ouverte : on fige le défilement de la page derrière
   (amélioration progressive — ignorée par les très vieux navigateurs). */
body:has(.overlay.on){overflow:hidden}
.modale{
  width:100%;max-width:340px;background:var(--surface);
  border:1px solid var(--line);border-radius:var(--r-lg);overflow:hidden;
  text-align:center;box-shadow:var(--sh-lg);
  animation:scale .24s cubic-bezier(.22,1,.36,1);
}
@keyframes scale{from{transform:scale(.9);opacity:0}to{transform:none;opacity:1}}
.modale .corps{padding:26px 24px 22px}
.modale .ico{
  display:inline-flex;align-items:center;justify-content:center;
  width:56px;height:56px;border-radius:18px;margin-bottom:14px;
}
.modale .ico svg{width:27px;height:27px}
.ico-brand{background:rgba(10,132,255,.12);color:var(--brand)}
.ico-danger{background:rgba(229,72,77,.12);color:var(--neg)}
.modale h2{font-size:19px;font-weight:800;letter-spacing:-.2px;margin-bottom:8px;color:var(--txt)}
.modale p{font-size:14px;color:var(--txt-2);line-height:1.55}

.champ-modale{margin-top:16px}
.champ-modale input{text-align:center;font-size:22px;font-weight:700}
.champ-modale.champ-libelle input{font-size:16px;font-weight:500;text-align:center}

.modale .actions{display:flex;border-top:1px solid var(--line)}
.modale .actions button{
  flex:1;border:none;background:var(--surface);padding:16px;font-size:16px;cursor:pointer;
  color:var(--txt);font-weight:600;
  transition:background .15s ease;
}
.modale .actions button + button{border-left:1px solid var(--line)}
.modale .actions button:first-child{color:var(--brand)}
.modale .actions button.ok{color:var(--brand);font-weight:800}
.modale .actions button.danger{color:var(--neg);font-weight:800}
.modale .actions button:hover{background:var(--surface-2)}
.modale .actions button:active{background:var(--surface-2)}
/* Trois boutons : Supprimer · Annuler · Enregistrer */
.modale .actions-3 button{font-size:14.5px;padding:15px 6px}
.modale .actions-3 button:nth-child(2){color:var(--brand);font-weight:600}

/* ===================== Préférence mouvement réduit ===================== */
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{
    animation-duration:.001ms !important;animation-iteration-count:1 !important;
    transition-duration:.001ms !important;scroll-behavior:auto !important;
  }
}
