:root {
  --green: #a8d5a2;
  --green-soft: #cfe8cb;
  --green-strong: #5f9e57;
  --bg: #eef1ec;
  --card: #ffffff;
  --text: #22301f;
  --muted: #6b7768;
  --line: #dde3da;
  --danger: #d0645a;
  --accent: #c3a6d6;
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.screen { min-height: 100vh; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* Barre du haut */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--green);
  padding: calc(10px + env(safe-area-inset-top)) 12px 12px;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
}
.top h1 { margin: 0; font-size: 20px; font-weight: 600; text-align: center; }
.top .sub { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.top-title { display: flex; align-items: center; justify-content: center; gap: 4px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px; line-height: 1;
}
.icon-btn:active { background: rgba(0,0,0,.06); }
.arrow { width: 36px; height: 36px; font-size: 26px; color: var(--green-strong); }
.arrow:disabled { opacity: .25; }

.content { padding: 18px 16px; max-width: 520px; margin: 0 auto; }
.label { font-size: 17px; text-align: center; margin: 4px 0 10px; }
.section-title { font-size: 17px; font-weight: 600; margin: 24px 4px 10px; }

/* Bouton + */
.add-wrap { display: flex; justify-content: center; }
.add-btn {
  width: 120px; height: 52px; border-radius: 26px; border: 0;
  background: var(--green-soft); display: grid; place-items: center;
}
.add-btn span {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  display: grid; place-items: center; font-size: 24px; color: #fff; font-weight: 600;
}
.add-btn:active { transform: scale(.97); }

.card { background: var(--green-soft); border-radius: var(--radius); padding: 16px 18px; }
.card.white { background: var(--card); }

.balance { margin-top: 18px; text-align: center; }
.balance .left { font-size: 28px; font-weight: 700; }
.balance .left.neg { color: var(--danger); }
.balance .spent { font-size: 17px; margin-top: 4px; color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.7); margin-top: 12px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green-strong); border-radius: 4px; }
.bar.over > i { background: var(--danger); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid rgba(0,0,0,.06); }
.list li:last-child { border-bottom: 0; }
.row {
  width: 100%; border: 0; background: transparent; text-align: left;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 2px;
}
.row .name { font-size: 17px; }
.row .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row .amount { font-size: 17px; font-weight: 600; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }

/* Totaux par catégorie */
.total { text-align: center; }
.total .big { font-size: 30px; font-weight: 700; }
.total .small { color: var(--muted); margin-top: 4px; }
.cat-row { display: block; width: 100%; border: 0; background: transparent; text-align: left; padding: 10px 2px; }
.cat-row .head b { white-space: nowrap; }
.cat-row .head { display: flex; justify-content: space-between; font-size: 17px; }
.cat-row .head b { font-weight: 600; }
.cat-row .bar { background: rgba(0,0,0,.06); height: 6px; margin-top: 6px; }
.cat-row .pct { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* Formulaire */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin: 0 4px 6px; }
.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 12px 14px; font-size: 17px; outline: none; -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--green-strong); }
textarea.input { min-height: 90px; resize: vertical; }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px;
}
.amount-input { position: relative; }
.amount-input .input { padding-right: 56px; }
.amount-input em { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); }
.btn {
  width: 100%; border: 0; border-radius: 14px; padding: 14px; font-size: 17px; font-weight: 600;
  background: var(--green-strong); color: #fff; margin-top: 6px;
}
.btn.secondary { background: var(--green-soft); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:disabled { opacity: .5; }
.error { color: var(--danger); text-align: center; margin: 10px 0 0; min-height: 1.2em; }
.inline { display: flex; gap: 8px; }
.inline .input { flex: 1; }
.inline .btn { width: auto; margin: 0; padding: 12px 16px; }

/* Menu latéral */
.menu-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 20;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.menu {
  position: fixed; top: 0; right: 0; bottom: 0; width: 72%; max-width: 300px; z-index: 21;
  background: var(--green); padding: calc(20px + env(safe-area-inset-top)) 12px 20px;
  transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column; gap: 4px;
}
.menu-open .menu-backdrop { opacity: 1; pointer-events: auto; }
.menu-open .menu { transform: none; }
.menu button {
  border: 0; background: transparent; text-align: left; font-size: 20px; padding: 12px 14px; border-radius: 12px;
}
.menu button.active { background: rgba(255,255,255,.55); font-weight: 600; }
.menu .sync { margin-top: auto; font-size: 13px; color: var(--muted); padding: 0 14px; }

.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--green-strong); vertical-align: middle; }
.sync-dot.pending { background: #e0b44c; }
.sync-dot.offline { background: #b9b9b9; }

/* Connexion */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login h1 { text-align: center; font-size: 28px; margin: 0 0 6px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 24px; }
