/* Mimimondy : palette « Nuit » validée sur la maquette (docs/maquette.html).
   CSS écrit à la main, sans étape de compilation. */

@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("/static/fonts/fredoka-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/static/fonts/figtree-latin.woff2") format("woff2");
}

:root {
  --bg: #15122c;
  --stage: #0e0c20;
  --card: #221d45;
  --ink: #f4efff;
  --muted: #a79fcb;
  --line: #352e62;
  --soft: #2a2452;
  --gold: #ffc83d;
  --gold-deep: #c98f00;
  --gold-ink: #2a1c00;
  --a: #6fa8ff;   /* première personne, à gauche */
  --b: #ff7eb0;   /* seconde personne, à droite */
  --ok: #55d79c;
  --ok-soft: #173a31;
  --warn: #ffb54d;
  --warn-soft: #3a2c18;
  --danger: #ff7a7a;
  --danger-soft: #3d1c2a;
  --sky1: #2c2468;
  --sky2: #4c3e93;
  --ground3d: #3e3580;
  --display: "Fredoka", "Avenir Next Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  --body: "Figtree", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--a); outline-offset: 2px; }
code { font-size: .92em; background: var(--soft); padding: 1px 6px; border-radius: 6px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.muted { color: var(--muted); margin: 0; }

/* ---------- Marque ---------- */
.coinmark {
  width: 1.15em; height: 1.15em; border-radius: 50%; flex: none;
  background: var(--gold);
  box-shadow: inset 0 -.1em 0 var(--gold-deep), 0 0 0 .07em var(--gold-deep);
  display: inline-grid; place-items: center;
}
.coinmark::after { content: ""; width: 38%; height: 38%; border-radius: 50%; border: .08em solid var(--gold-deep); }
.coinmark.big { font-size: 46px; }

/* ---------- Structure ---------- */
.apphead {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.brand { font-family: var(--display); font-weight: 700; font-size: 20px; display: flex; align-items: center; gap: 8px; text-decoration: none; }
.me { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--muted); font-weight: 700; min-height: 40px; padding: 0 4px; border-radius: 12px; }
.me .ic { width: 22px; height: 22px; }
.me-name { display: none; }
.topnav { display: none; }
.page { padding: 4px 16px calc(120px + var(--safe-b)); display: flex; flex-direction: column; gap: 16px; }
.narrow { width: 100%; max-width: 560px; margin-inline: auto; }
.stack, .stack-lg { display: flex; flex-direction: column; gap: 14px; }
.stack-lg { gap: 18px; }
.center-page { align-items: center; text-align: center; padding-top: 12vh; gap: 14px; }
.h1 { font-family: var(--display); font-weight: 700; font-size: 30px; line-height: 1.05; margin: 0; }
.h1 small { font-size: 16px; font-weight: 500; color: var(--muted); margin-left: 8px; }
.h2 { font-family: var(--display); font-weight: 600; font-size: 21px; margin: 0; display: flex; align-items: center; gap: 8px; }
.h2 .ic { width: 20px; height: 20px; color: var(--gold); }
.pagehead { display: flex; flex-direction: column; gap: 6px; }
.card { background: var(--card); border: 2px solid var(--line); border-radius: 22px; box-shadow: 0 3px 0 var(--line); }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 700; text-decoration: none; min-height: 40px; }
.back svg { width: 16px; height: 16px; }

/* ---------- Barre d'onglets (téléphone) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px 10px calc(10px + var(--safe-b));
  background: var(--card); border-top: 2px solid var(--line);
}
.tabbar a, .topnav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11.5px; font-weight: 800; color: var(--muted); text-decoration: none; padding: 4px; border-radius: 12px;
}
.tabbar .ic { width: 24px; height: 24px; }
.tabbar a[aria-current], .topnav a[aria-current] { color: var(--ink); }
.tabbar a[aria-current] .ic, .topnav a[aria-current] .ic { color: var(--gold); }

/* ---------- Mois ---------- */
.month-grid { display: flex; flex-direction: column; gap: 18px; }
.hero-col, .list-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.monthnav-btns { display: flex; gap: 6px; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  display: inline-grid; place-items: center; color: var(--ink); flex: none; text-decoration: none; padding: 0;
}
.iconbtn svg { width: 16px; height: 16px; }
.iconbtn.off { opacity: .35; }

.hero { background: var(--card); border: 2px solid var(--line); border-radius: 26px; box-shadow: 0 4px 0 var(--line); overflow: hidden; }
.scene { height: 290px; position: relative; background: linear-gradient(180deg, var(--sky1), var(--sky2)); overflow: hidden; touch-action: manipulation; }
.scene canvas { display: block; width: 100%; height: 100%; }
.bubble {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  background: var(--gold); color: var(--gold-ink); font-family: var(--display); font-weight: 700; font-size: 16px;
  padding: 4px 11px; border-radius: 999px; box-shadow: 0 3px 0 var(--gold-deep); white-space: nowrap; pointer-events: none;
  font-variant-numeric: tabular-nums; will-change: transform;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; width: 10px; height: 10px; background: var(--gold);
  transform: translateX(-50%) rotate(45deg); border-radius: 2px; box-shadow: 3px 3px 0 var(--gold-deep); z-index: -1;
}
.bubble.even { background: var(--card); color: var(--ok); box-shadow: 0 3px 0 var(--line); }
.bubble.even::after { background: var(--card); box-shadow: 3px 3px 0 var(--line); }
.scene-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }

.tags { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 16px 0; }
.tag { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tag-b { flex-direction: row-reverse; text-align: right; }
.tag b { display: block; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 15px; }
.tag small { color: var(--muted); font-size: 12px; }
.verdict { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.verdict-title { font-family: var(--display); font-weight: 600; font-size: 25px; line-height: 1.15; margin: 0; text-wrap: balance; }
.verdict-title em { font-style: normal; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt-a { color: var(--a); } .amt-b { color: var(--b); } .amt-ok { color: var(--ok); }
.verdict-sub { margin: 0; color: var(--muted); font-size: 14px; }

.av {
  width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-size: 12px; font-weight: 800; color: var(--gold-ink); border: 2.5px solid var(--card);
}
.av-a { background: var(--a); } .av-b { background: var(--b); }
.av-lg { width: 56px; height: 56px; font-size: 18px; }

.housestrip {
  display: flex; align-items: center; gap: 12px; text-decoration: none;
  background: var(--card); border: 2px solid var(--line); border-radius: 20px; padding: 12px 14px; box-shadow: 0 3px 0 var(--line);
}
.housestrip .ic-wrap { width: 40px; height: 40px; border-radius: 13px; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; flex: none; }
.housestrip .ic-wrap svg { width: 21px; height: 21px; }
.housestrip b { display: block; font-weight: 800; font-size: 14px; }
.housestrip small { color: var(--muted); font-size: 12.5px; }
.housestrip .chev { width: 16px; height: 16px; margin-left: auto; color: var(--muted); flex: none; }

.sect-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 4px 2px -4px; }
.sect-h h2 { font-family: var(--display); font-weight: 600; font-size: 20px; margin: 0; }
.sect-h span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.day { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 800; margin: 6px 4px -6px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 2px solid var(--line); border-radius: 20px; overflow: hidden; }
.list li + li { border-top: 2px solid var(--soft); }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; text-decoration: none; min-height: 60px; }
.row:active { background: var(--soft); }
.cat { width: 38px; height: 38px; border-radius: 13px; background: var(--soft); display: grid; place-items: center; flex: none; color: var(--ink); }
.cat svg { width: 19px; height: 19px; }
.row-closing .cat { background: var(--ok-soft); color: var(--ok); }
.row-carry .cat { background: var(--warn-soft); color: var(--warn); }
.row-off { opacity: .55; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-label { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { font-size: 12.5px; color: var(--muted); }
.row-meta .chip { margin-left: 4px; vertical-align: 1px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: 0; }
.dot-a { background: var(--a); } .dot-b { background: var(--b); }
.row-amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.row-amt small { display: block; font-weight: 600; font-size: 11.5px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.chip svg { width: 11px; height: 11px; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.empty { padding: 18px; display: flex; flex-direction: column; gap: 4px; }
.empty p { margin: 0; }

/* ---------- Boutons ---------- */
.btn {
  border: 0; border-radius: 16px; padding: 13px 18px; font-weight: 800; font-size: 15.5px; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  transition: transform .08s, box-shadow .08s;
}
.btn svg { width: 17px; height: 17px; }
.btn.gold { background: var(--gold); color: var(--gold-ink); box-shadow: 0 4px 0 var(--gold-deep); }
.btn.gold:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-deep); }
.btn.ghost { background: var(--card); border: 2px solid var(--line); color: var(--ink); box-shadow: 0 3px 0 var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border: 2px solid transparent; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; } /* envoi en cours (static/app.js) */
.fab { position: fixed; right: 16px; bottom: calc(86px + var(--safe-b)); z-index: 21; }

/* ---------- Maison ---------- */
.house-grid { display: flex; flex-direction: column; gap: 18px; }
.summary { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.kpi b { font-family: var(--display); font-weight: 700; font-size: 25px; font-variant-numeric: tabular-nums; }
/* Barre à deux couleurs : la part de A (valeur) sur fond de B. Un <progress>
   plutôt qu'un style="width:…" : la Content-Security-Policy interdit les styles en ligne. */
.splitbar { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 12px; border: 0; border-radius: 999px; overflow: hidden; background: var(--b); }
.splitbar::-webkit-progress-bar { background: var(--b); border-radius: 999px; }
.splitbar::-webkit-progress-value { background: var(--a); }
.splitbar::-moz-progress-bar { background: var(--a); }
.splitlegend { display: flex; justify-content: space-between; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 6px; gap: 8px; }
.splitlegend b { color: var(--ink); font-variant-numeric: tabular-nums; }
.hint { font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: flex-start; padding: 0 4px; margin: 0; }
.hint svg { width: 16px; height: 16px; flex: none; margin-top: 2px; color: var(--gold); }
.nextgen { display: flex; align-items: center; gap: 10px; background: var(--warn-soft); color: var(--warn); border-radius: 16px; padding: 11px 14px; font-size: 13px; font-weight: 700; margin: 0; }
.nextgen svg { width: 16px; height: 16px; flex: none; }
.stopped summary { cursor: pointer; color: var(--muted); font-weight: 700; padding: 8px 4px; }
.stopped .list { margin-top: 8px; }

/* ---------- Les mois ---------- */
.monthcard { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; text-decoration: none; }
.monthcard-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.monthcard-head b { font-family: var(--display); font-weight: 600; font-size: 19px; }
.monthcard .tot { font-weight: 800; font-variant-numeric: tabular-nums; }
.monthcard-res { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.monthcard.current { border-color: var(--gold); box-shadow: 0 3px 0 var(--gold-deep); }

/* ---------- Formulaires ---------- */
.form { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.amount { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 4px 0 2px; }
.amount-input { border: 0; background: transparent; font-family: var(--display); font-weight: 700; font-size: 50px; width: 5.6ch; text-align: right; font-variant-numeric: tabular-nums; padding: 0; min-width: 0; }
.amount-input::placeholder { color: var(--line); }
.amount-input:focus { outline: none; }
.amount span { font-family: var(--display); font-size: 32px; font-weight: 600; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .fs legend { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.text { border: 2px solid var(--line); background: var(--bg); border-radius: 14px; padding: 11px 12px; min-height: 46px; width: 100%; font-size: 16px; }
.text:focus { border-color: var(--a); outline: none; }
.fs { border: 0; margin: 0; padding: 0; min-width: 0; }
.fs legend { padding: 0; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { position: relative; }
.pick input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.pick > span { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 700; color: var(--muted); background: var(--bg); min-height: 38px; }
.pick > span svg { width: 14px; height: 14px; }
.pick input:checked + span { background: var(--ink); color: var(--card); border-color: var(--ink); }
.pick input:focus-visible + span { outline: 3px solid var(--a); outline-offset: 2px; }
.pick-a input:checked + span { background: var(--a); border-color: var(--a); color: var(--gold-ink); }
.pick-b input:checked + span { background: var(--b); border-color: var(--b); color: var(--gold-ink); }
/* « Tout pour … » : le nom de l'autre, selon qui a payé (sans JavaScript). */
.for-b { display: none; }
form:has(input[name="payer"][value="b"]:checked) .for-a { display: none; }
form:has(input[name="payer"][value="b"]:checked) .for-b { display: inline; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--warn-soft); color: var(--warn); border-radius: 16px; padding: 12px 14px; font-weight: 800; font-size: 14px; cursor: pointer; }
.toggle span { display: flex; align-items: center; gap: 8px; }
.toggle svg { width: 15px; height: 15px; }
.toggle input { -webkit-appearance: none; appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .2s; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked { background: var(--warn); }
.toggle input:checked::after { transform: translateX(18px); }
/* Les options de récurrence n'apparaissent que si l'interrupteur est coché. */
.recur { display: none; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.toggle:has(input:checked) + .recur, .recur-always { display: flex; }
.recur select { border: 2px solid var(--line); background: var(--bg); border-radius: 12px; padding: 8px 10px; min-height: 42px; font-size: 15px; }
.recur .hint { width: 100%; padding: 0; }
.err { color: var(--danger); font-size: 13px; font-weight: 700; margin: -6px 0 0; }
.alert { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 12px; font-weight: 700; margin: 0; }
.note { background: var(--soft); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; color: var(--muted); margin: 0; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note a { color: var(--ink); font-weight: 700; }
.big-amount { font-family: var(--display); font-size: 36px; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; }
.login { padding-top: 12vh; gap: 22px; }
.login-head { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }

/* ---------- Feuilles (dialog natif) ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92dvh;
  background: var(--card); color: var(--ink); border-radius: 28px 28px 0 0; overflow-y: auto; overscroll-behavior: contain;
}
dialog.sheet::backdrop { background: rgba(8, 5, 20, .6); }
dialog.sheet[open] { animation: sheet-in .3s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-in { from { transform: translateY(100%); } }
.sheet-body { padding: 14px 18px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { font-family: var(--display); font-weight: 700; font-size: 23px; margin: 0; }
.transfer { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px 0; }
.transfer .arrow { display: flex; flex-direction: column; align-items: center; gap: 2px; font-family: var(--display); font-weight: 700; font-size: 23px; font-variant-numeric: tabular-nums; }
.transfer .arrow svg { width: 70px; height: 14px; color: var(--muted); }
.explain { margin: 0; color: var(--muted); font-size: 14px; text-align: center; text-wrap: balance; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(96px + var(--safe-b)); z-index: 40; margin: 0 auto; max-width: 480px;
  background: var(--ink); color: var(--bg); border-radius: 16px; padding: 12px 14px; font-size: 14px; font-weight: 700;
}

/* ---------- Ordinateur : pleine largeur, navigation en haut ---------- */
@media (min-width: 900px) {
  .apphead { padding: 14px 32px; }
  .topnav { display: flex; gap: 6px; }
  .topnav a { flex-direction: row; gap: 8px; font-size: 14.5px; padding: 8px 14px; }
  .topnav .ic { width: 20px; height: 20px; }
  .topnav a[aria-current] { background: var(--card); }
  .me-name { display: inline; }
  .tabbar { display: none; }
  .page { padding: 12px 32px 48px; }
  .fab { bottom: 32px; right: 32px; }
  .toast { bottom: 32px; }
  .month-grid { display: grid; grid-template-columns: minmax(380px, 460px) minmax(0, 1fr); gap: 32px; align-items: start; }
  .hero-col { position: sticky; top: 80px; }
  .scene { height: 340px; }
  .house-grid { display: grid; grid-template-columns: minmax(340px, 420px) minmax(0, 1fr); gap: 32px; align-items: start; }
  dialog.sheet { margin: auto; border-radius: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  dialog.sheet[open] { animation: none; }
  .btn { transition: none; }
}
