:root {
  --bg: #f4f7f5;
  --card: #ffffff;
  --ink: #1f2a26;
  --muted: #6b7a74;
  --line: #dde6e1;
  --brand: #1f6b52;
  --brand-dark: #15503d;
  --brand-soft: #e2f1ea;
  --pos: #1f7a4d;
  --neg: #b3262e;
  --neg-soft: #fbe6e7;
  --warn: #b7791f;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121816;
    --card: #1b2320;
    --ink: #e6eeea;
    --muted: #92a39c;
    --line: #2c3833;
    --brand: #2f8c6b;
    --brand-soft: #1d3a2f;
    --pos: #4cc38a;
    --neg: #ef6b72;
    --neg-soft: #3a1f22;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

/* ---------- barre du haut ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px; padding: 12px 20px;
  background: linear-gradient(100deg, #1f6b52, #2a7d8c);
  color: #fff;
}
.brand { color: #fff; font-weight: 700; font-size: 1.2rem; text-decoration: none; }
#nav button {
  color: #fff; background: none; border: 0; cursor: pointer; font: inherit; font-size: .95rem;
  padding: 6px 10px; border-radius: 8px;
}
#nav button:hover { background: rgba(255,255,255,.15); }

main { max-width: 900px; margin: 0 auto; padding: 20px 16px 48px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 16px 24px; }
h2 { font-size: 1.15rem; margin: 0; }
.sub { color: var(--muted); margin: 0; font-size: .9rem; }

/* ---------- cartes ---------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px;
}
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 12px; }
.panel-total { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- formulaires ---------- */
input, select, button { font: inherit; }
input[type=text], input[type=number], input[type=password], select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid transparent;
  background: var(--brand); color: #fff; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { background: var(--brand-soft); filter: none; }
.btn.small { padding: 5px 10px; font-size: .88rem; }
.icon-btn {
  background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px 6px; border-radius: 6px; font-size: 1rem;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--ink); }
.icon-btn.danger:hover { background: var(--neg-soft); color: var(--neg); }

.auth { max-width: 380px; margin: 48px auto; }
.auth h1 { font-size: 1.4rem; margin: 0 0 6px; }
.auth form { display: grid; gap: 10px; margin-top: 16px; }
.error { color: var(--neg); font-size: .9rem; min-height: 1.2em; margin: 0; }

/* ---------- navigation des mois ---------- */
.monthbar { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.monthbar h1 { font-size: 1.5rem; margin: 0; min-width: 210px; text-align: center; text-transform: capitalize; }
.monthbar .arrow { font-size: 1.3rem; width: 42px; height: 42px; padding: 0; border-radius: 50%; }

/* ---------- résumé ---------- */
.summary { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; }
.start-box label { display: block; font-weight: 600; margin-bottom: 6px; }
.money-input { position: relative; }
.money-input input { font-size: 1.5rem; font-weight: 700; padding-right: 36px; font-variant-numeric: tabular-nums; }
.money-input::after { content: "€"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1.2rem; }
.start-box .hint { margin-top: 8px; }

.calc { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.calc li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.calc li.total { border-top: 2px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 800; font-size: 1.25rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.progress { margin-top: 16px; }
.bar { height: 10px; background: var(--brand-soft); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }
.bar.over span { background: var(--neg); }
.progress .legend { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; font-size: .85rem; color: var(--muted); margin-top: 6px; }

/* ---------- listes de dépenses ---------- */
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); cursor: pointer; margin: 0; }
.row .label { min-width: 0; }
.row .label strong { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: .82rem; }
.row .amount { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.row .actions { display: flex; gap: 2px; }
.row.done .label strong, .row.done .amount { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.row.editing { display: block; background: var(--brand-soft); border-radius: 8px; padding: 10px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-form > input[name=label], .inline-title { flex: 1 1 200px; min-width: 0; }
.inline-title { display: flex; flex-direction: column; }
.inline-title .meta { color: var(--muted); font-size: .82rem; }
.money-input.small { width: 130px; }
.money-input.small input { font-size: 1rem; }
.money-input.small::after { font-size: 1rem; }
.empty { color: var(--muted); font-style: italic; padding: 8px 4px; margin: 0; }

.add-form {
  display: grid; grid-template-columns: 1fr 120px 90px auto; gap: 8px; margin-top: 14px;
  padding-top: 14px; border-top: 1px dashed var(--line);
}
.add-form.planned { grid-template-columns: 1fr 120px auto; }
.add-form .field-label { display: none; }

.cat {
  display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); margin-left: 6px; vertical-align: 1px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 40px); opacity: 0;
  background: #1f2a26; color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: .25s; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  .summary { grid-template-columns: 1fr; }
  .monthbar h1 { font-size: 1.25rem; min-width: 0; flex: 1; }
  .add-form, .add-form.planned { grid-template-columns: 1fr 1fr; }
  .add-form input[name=label] { grid-column: 1 / -1; }
  .add-form .btn { grid-column: 1 / -1; }
  .add-form.planned input[name=amount] { grid-column: 1 / -1; }
  .row { grid-template-columns: auto 1fr auto; }
  .row .actions { grid-column: 2 / -1; justify-content: flex-end; margin-top: -6px; }
}
