:root {
  --bg: #f6f1e9;
  --card: #fffdf9;
  --ink: #1d2623;
  --muted: #6f756f;
  --line: #e6ded1;
  --brand: #1f3a34;
  --yann: #3f7f73;
  --yann-soft: #dcebe6;
  --marie: #c8693f;
  --marie-soft: #f6e1d4;
  --commun: #7a6a9a;
  --commun-soft: #e7e2f0;
  --ok: #2f7a4f;
  --danger: #b3412e;
  --radius: 16px;
  --tabbar: 64px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px);
}
body.locked { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-family: ui-serif, "New York", Georgia, serif; font-weight: 600; font-size: 1.9rem; letter-spacing: -0.01em; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.hidden { display: none !important; }
.loading { text-align: center; margin-top: 30vh; color: var(--muted); }
button { font: inherit; color: inherit; }

/* ---- en-tête et onglets ---- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-family: ui-serif, Georgia, serif; font-size: 1.15rem; }
.brand img { border-radius: 8px; }
.tabs { display: flex; gap: .25rem; margin-left: auto; }
.tab {
  display: flex; align-items: center; gap: .4rem;
  border: 0; background: none; padding: .5rem .8rem; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: .92rem;
}
.tab svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab:hover { color: var(--ink); }
.tab.on { background: var(--brand); color: #fff; }
.me {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 700;
}

main { max-width: 1040px; margin: 0 auto; padding: 1.2rem 1rem; }
.hero { margin: .6rem 0 1.2rem; }
.eyebrow { margin: 0 0 .2rem; color: var(--muted); font-weight: 600; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .6rem 0 1rem; }

/* ---- cartes ---- */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); margin-bottom: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.grid .card { margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }
.card-head h2 { margin: 0; }
.big { font-size: 1.9rem; font-weight: 700; margin: .1rem 0 .5rem; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.big-sm { font-size: 1.2rem; }
.big.ok { color: var(--ok); }
.card p { margin: .3rem 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .9rem; }
.actions.col { flex-direction: column; }
.pad { padding: 0 0 .5rem; }
.pad-x { padding-left: .6rem; padding-right: .6rem; }
.list-card .card-head { padding-top: .7rem; }
.list-card > .actions { margin: .4rem 0 .7rem; }
.notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; background: var(--yann-soft); border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; font-weight: 600; }
@media (max-width: 640px) { .notice { flex-direction: column; text-align: center; } .notice .btn { width: 100%; } }

.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 700; letter-spacing: .01em; text-transform: none; }
.chip-yann { background: var(--yann-soft); color: var(--yann); }
.chip-marie { background: var(--marie-soft); color: var(--marie); }
.chip-commun { background: var(--commun-soft); color: var(--commun); }

.split { height: 10px; border-radius: 999px; background: var(--marie); overflow: hidden; margin: .4rem 0 .45rem; }
.split-y { height: 100%; background: var(--yann); border-right: 2px solid var(--card); }
.split-legend { display: flex; justify-content: space-between; gap: .5rem; font-size: .9rem; font-variant-numeric: tabular-nums; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-top: .6rem; }
.pair > div { display: flex; flex-direction: column; gap: .25rem; align-items: flex-start; }
.pair strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.rows li:last-child { border-bottom: 0; }

.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: .45rem; }
.bars li { display: grid; grid-template-columns: minmax(80px, 9rem) 1fr auto; gap: .6rem; align-items: center; font-size: .92rem; }
.bars li > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { display: block; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar.thin { height: 5px; margin: .35rem 0 .15rem; max-width: 220px; }
.bar.thin i { background: var(--yann); }

/* ---- listes cliquables ---- */
.list-card { padding: .4rem .6rem; }
.items { list-style: none; margin: 0; padding: 0; }
.item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  background: none; border: 0; text-align: left; padding: .75rem .6rem; border-radius: 12px; cursor: pointer;
}
.item:hover { background: var(--bg); }
.item.off { opacity: .5; }
.item-main { display: flex; flex-direction: column; min-width: 0; }
.item-main strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; }
.day { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: capitalize; padding: .8rem .6rem .1rem; }
.empty { text-align: center; padding: 2rem 1rem; margin: 0; }

.month-nav { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 0 0 1rem; }
.month-nav strong { min-width: 10rem; text-align: center; font-size: 1.05rem; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 1.25rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--ink); }

/* ---- prévisionnel ---- */
.chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: .4rem; height: 160px; align-items: end; margin: .4rem 0 .3rem; }
.col { display: flex; flex-direction: column; align-items: center; height: 100%; gap: .3rem; }
.col span { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.col.now span { color: var(--ink); font-weight: 700; }
.stack { flex: 1; width: 100%; max-width: 34px; display: flex; flex-direction: column-reverse; justify-content: flex-start; }
.stack i { display: block; width: 100%; }
.stack .plan { background: var(--brand); border-radius: 6px 6px 0 0; }
.stack .real { background: var(--marie); opacity: .75; }
.col.now .stack .plan { background: var(--yann); }
.legend { display: flex; align-items: center; gap: .4rem; color: var(--muted); margin: .4rem 0 .8rem; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: .5rem; }
.dot.plan { background: var(--brand); margin-left: 0; }
.dot.real { background: var(--marie); opacity: .75; }
.months { list-style: none; padding: 0; margin: 0; }
.months > li { border-top: 1px solid var(--line); }
.months > li.now .m { font-weight: 700; }
.month-row {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: .1rem .8rem; align-items: center;
  background: none; border: 0; text-align: left; padding: .7rem .2rem; cursor: pointer;
}
.month-row .m { text-transform: capitalize; }
.month-row .per { grid-column: 1 / -1; }
.detail { list-style: none; margin: 0 0 .8rem; padding: .3rem .8rem; background: var(--bg); border-radius: 10px; font-size: .92rem; }
.detail li { display: flex; justify-content: space-between; gap: .8rem; padding: .3rem 0; }
.tag { font-style: normal; font-size: .72rem; background: var(--marie-soft); color: var(--marie); padding: 0 .4rem; border-radius: 6px; margin-left: .3rem; }

/* ---- boutons et champs ---- */
.btn {
  border: 1px solid var(--line); background: var(--card); padding: .6rem 1.1rem; border-radius: 999px; cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #142823; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.wide { width: 100%; }

.field { display: flex; flex-direction: column; gap: .3rem; margin: 0 0 .9rem; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-size: .85rem; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: .3rem; }
.field input, .field select, .field textarea, .inline input {
  font: inherit; font-size: 16px; padding: .7rem .8rem; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus, .inline input:focus { outline: 2px solid var(--yann); outline-offset: 1px; border-color: transparent; }
input[name="amount"] { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg label, .who label { position: relative; }
.seg input, .who input { position: absolute; opacity: 0; pointer-events: none; }
.seg span, .who span {
  display: inline-block; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .92rem; background: #fff;
}
.seg input:checked + span, .who input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.seg input:focus-visible + span, .who input:focus-visible + span { outline: 2px solid var(--yann); outline-offset: 2px; }
.inline { display: flex; align-items: center; gap: .5rem; margin-top: .6rem; font-size: .9rem; color: var(--muted); }
.inline input { width: 5.5rem; }
.check { display: flex; align-items: center; gap: .6rem; margin: 0 0 .9rem; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.form-error { color: var(--danger); min-height: 1.2em; margin: .2rem 0 .6rem; font-size: .9rem; }

/* ---- connexion ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; text-align: center; padding: 2rem 1.5rem; }
.login-card img { border-radius: 16px; }
.login-card h1 { margin: .8rem 0 .2rem; }
.login-card .field { text-align: left; }
.who { display: flex; justify-content: center; gap: .5rem; margin: 1.2rem 0; }

/* ---- feuille modale ---- */
.backdrop { position: fixed; inset: 0; background: rgb(20 25 23 / .4); z-index: 40; animation: fade .15s ease-out; }
.sheet {
  position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 2rem)); max-height: calc(100vh - 3rem); overflow: auto;
  background: var(--card); border-radius: 20px; padding: 1.1rem 1.3rem 1.3rem; box-shadow: 0 20px 60px rgb(0 0 0 / .25);
  animation: pop .18s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.sheet-head h2 { font-size: 1.2rem; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0; font-family: ui-serif, Georgia, serif; }
.sheet-actions { display: flex; flex-direction: column; gap: .5rem; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%); } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: .6rem 1.1rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; font-weight: 600;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }

/* ---- bureau ---- */
@media (min-width: 821px) {
  body { padding-bottom: 2rem; }
  #toast { bottom: 24px; }
}

/* ---- téléphone ---- */
@media (max-width: 820px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0;
    display: grid; grid-template-columns: repeat(6, 1fr); gap: 0;
    padding: .35rem .3rem calc(.35rem + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--card) 92%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .tab { flex-direction: column; gap: .15rem; font-size: .68rem; padding: .35rem .1rem; border-radius: 12px; }
  .tab svg { width: 22px; height: 22px; }
  .tab.on { background: none; color: var(--brand); }
  .tab.on svg { stroke-width: 2.3; }
  .me { margin-left: auto; }
  .top { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  h1 { font-size: 1.6rem; }
}
@media (max-width: 640px) {
  main { padding: .8rem .75rem; }
  .grid, .grid.two { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: stretch; text-align: center; }
  .page-head .btn { width: 100%; }
  .actions { justify-content: center; }
  .actions .btn { flex: 1 1 100%; }
  .card { padding: 1rem; }
  .bars li { grid-template-columns: 6.5rem 1fr auto; }
  .chart { height: 120px; gap: .2rem; }
  .sheet {
    left: 0; right: 0; bottom: 0; top: auto; transform: none; width: 100%;
    max-height: 92vh; border-radius: 20px 20px 0 0; padding-bottom: calc(1.3rem + env(safe-area-inset-bottom));
    animation: up .2s ease-out;
  }
  @keyframes up { from { transform: translateY(30px); opacity: 0; } }
}

.sub { font-size: .78rem; color: var(--muted); font-weight: 600; margin: .2rem 0 .5rem; }
.bars + .sub { margin-top: 1rem; }
.bars.env li.over .bar i { background: var(--danger); }
.bars.env li.over .num { color: var(--danger); }
.bars.env .bar i { background: var(--yann); }
.tags { display: flex; gap: .3rem; margin-top: .25rem; }
.tags .tag { margin-left: 0; }
.tag.env { background: var(--commun-soft); color: var(--commun); }
.bars li > .num { text-align: right; min-width: 5.5rem; }
.bars.env li { grid-template-columns: minmax(80px, 9rem) 1fr 7.5rem; }
@media (max-width: 640px) { .bars.env li { grid-template-columns: 6.5rem 1fr 7rem; } }

.card.wide { grid-column: 1 / -1; }
.commun { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1.5rem; }
.suggest { border-left: 1px solid var(--line); padding-left: 1.5rem; }
.flow { list-style: none; margin: 0 0 .6rem; padding: 0; }
.flow li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px dashed var(--line); font-size: .95rem; }
.flow li.total { border-bottom: 0; border-top: 2px solid var(--ink); margin-top: .2rem; padding-top: .55rem; font-weight: 700; }
.flow li.total .num { font-size: 1.15rem; }
.flow .tag { margin-left: .3rem; }
.rows.small li { font-size: .88rem; gap: .8rem; }
.card-head h2 { display: flex; align-items: center; gap: .5rem; }
@media (max-width: 820px) {
  .commun { grid-template-columns: 1fr; gap: .8rem; }
  .suggest { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: .8rem; }
}

.seg.filter { justify-content: center; margin: 0 0 1rem; }
.seg.filter button { border: 1px solid var(--line); background: #fff; padding: .5rem 1rem; border-radius: 999px; font-weight: 600; font-size: .92rem; cursor: pointer; min-height: 40px; }
.seg.filter button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
