:root {
  color-scheme: light;
  --bg: #faf6f0;
  --card: #ffffff;
  --card-2: #efe3d3;
  --card-border: #e8ddd0;
  --text: #5c4436;
  --text-dim: #9a8a7b;
  --accent: #7a9b6e;
  --accent-dim: rgba(122, 155, 110, 0.16);
  --danger: #c1584f;
  --warn: #c98b8f;
  --warn-dim: rgba(201, 139, 143, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 22px calc(env(safe-area-inset-bottom) + 20px);
  min-height: 100vh;
}

[hidden] { display: none !important; }

h1 { font-size: 1.4rem; margin: 0; font-weight: 700; color: var(--text); }
.sous-titre { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 20px; }

.entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px 0 28px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--card-2);
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.carte {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 22px;
  margin-bottom: 20px;
}

.carte h2 { font-size: 1.25rem; margin: 0 0 14px; color: var(--text); font-weight: 700; display: flex; align-items: center; gap: 8px; }

.carte-cliquable {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
}
.carte-cliquable .chevron { color: var(--text-dim); font-size: 1.6rem; margin-left: auto; }
.carte-cliquable-contenu { flex: 1; min-width: 0; }
.carte-cliquable h2 { margin: 0 0 10px; }

.pct-mois { font-size: 2.2rem; font-weight: 700; color: var(--warn); line-height: 1.1; }
.pct-mois .montant { font-size: 1.3rem; font-weight: 600; }
.pct-mois.baisse { color: var(--accent); }

.barre-section-titre {
  font-size: 1.05rem;
  color: var(--text);
  font-weight: 700;
  margin: 20px 0 8px;
}
.barre-section-titre:first-of-type { margin-top: 4px; }

.barre-budget-h {
  position: relative;
  height: 38px;
  background: var(--card-2);
  border-radius: 9px;
  overflow: hidden;
  margin-top: 2px;
}
.barre-total {
  position: absolute;
  right: 10px;
  top: 0; bottom: 0;
  display: flex;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
}
.barre-remplissage-h {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  transition: width 0.4s ease;
}
.barre-remplissage-h.hausse { background: var(--warn); }
.barre-montant { font-size: 0.85rem; font-weight: 700; color: var(--card); white-space: nowrap; }
.barre-marqueur {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--text);
  opacity: 0.35;
}

.mois-grille {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 130px;
  overflow-x: auto;
  margin-bottom: 6px;
}
.mois-colonne {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
  min-width: 44px;
  flex: 1;
}
.mois-montant { font-size: 0.72rem; color: var(--text-dim); font-weight: 600; white-space: nowrap; }
.mois-montant.actuel { color: var(--text); }
.mois-barre {
  width: 100%;
  background: var(--accent);
  border-radius: 7px 7px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6px;
  min-height: 18px;
}
.mois-barre.hausse { background: var(--warn); }
.mois-barre-pct { color: var(--card); font-size: 0.75rem; font-weight: 700; }
.mois-label { font-size: 0.78rem; color: var(--text-dim); font-weight: 600; }
.mois-label.actuel { color: var(--text); }

.ligne-comparaison {
  padding: 10px 0;
  border-bottom: 1px solid var(--card-border);
}
.ligne-comparaison:last-of-type { border-bottom: none; }

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--card-2);
}
.badge.baisse { background: var(--accent-dim); color: var(--accent); }
.badge.hausse { background: var(--warn-dim); color: var(--warn); }

.alerte {
  padding: 10px 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 0.88rem;
}
.alerte:last-child { border-bottom: none; }
.alerte .horodatage { color: var(--text-dim); font-size: 0.72rem; }
.alerte.echec .type-badge { color: var(--danger); }
.alerte.a_corriger .type-badge { color: var(--warn); }
.alerte.resume .type-badge { color: var(--accent); }
.type-badge { font-weight: 700; text-transform: uppercase; font-size: 0.72rem; }

.vide { color: var(--text-dim); font-size: 0.88rem; padding: 8px 0; }

.ligne-case {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 0.92rem;
}
.ligne-case:last-of-type { border-bottom: none; }
.ligne-case input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
}
button.secondaire {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text);
  font-weight: 600;
}
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: 0.5; }

input[type="password"], input[type="text"], input[type="file"] {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 12px;
}

label.champ-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

#ecran-connexion {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 360px;
  margin: 0 auto;
}

.erreur { color: var(--danger); font-size: 0.88rem; margin-bottom: 12px; min-height: 1em; }
.confirmation { color: var(--accent); font-size: 0.88rem; margin-bottom: 12px; min-height: 1em; }

.maj { color: var(--text-dim); font-size: 0.8rem; margin-top: -8px; margin-bottom: 16px; }

.barre-retour {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 30px 0 18px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
}
.barre-retour .fleche { font-size: 1.4rem; }
