/* =====================================================================
   Budget — système de design
   Mobile d'abord (iPhone), clair / sombre, aucune ressource externe.
   Animations : uniquement transform + opacity (60 fps).
   ===================================================================== */

:root {
  color-scheme: light dark;
  --bg: #F3F4F7;
  --surface: #FFFFFF;
  --surface-2: #ECEEF3;
  --sheet: #F3F4F7;
  --text: #12151A;
  --text-2: #586070;
  --text-3: #636B7B;
  --line: rgba(18, 21, 26, .08);
  --line-2: rgba(18, 21, 26, .18);
  --track: #E1E4EB;
  --ok: #0A7A47;   --ok-bg: #E1F3E8;
  --warn: #9A5200; --warn-bg: #FFEFD6; --warn-bar: #B35C00;
  --over: #C0261D; --over-bg: #FDE6E4;
  --accent: #4A4FE0; --accent-bg: #ECECFC; --on-accent: #FFFFFF; --on-solid: #FFFFFF;
  --shadow: 0 1px 2px rgba(18, 21, 26, .05), 0 8px 24px rgba(18, 21, 26, .06);
  --scrim: rgba(8, 10, 14, .42);
  --glass: rgba(255, 255, 255, .78);
  --toast-bg: #12151A; --toast-fg: #F3F5F8; --toast-act: #9AA2FF;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --tab-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --ff: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --ff-num: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

/* Couleurs d'identité des enveloppes (distinctes des 3 couleurs d'état). */
.c0 { --c: #4A4FE0; --c-bg: #ECECFC; }
.c1 { --c: #0B7C9E; --c-bg: #DFF2F8; }
.c2 { --c: #8B3FD0; --c-bg: #F1E6FB; }
.c3 { --c: #BE2F7E; --c-bg: #FBE5F0; }
.c4 { --c: #566580; --c-bg: #E8EBF1; }
.c5 { --c: #8A5A2B; --c-bg: #F5EADF; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C0E12; --surface: #171A20; --surface-2: #20242C; --sheet: #12151A;
    --text: #F3F5F8; --text-2: #A6AEBB; --text-3: #7F8795;
    --line: rgba(255, 255, 255, .08); --line-2: rgba(255, 255, 255, .2); --track: #262B34;
    --ok: #4CD98A;   --ok-bg: #12301F;
    --warn: #FFB547; --warn-bg: #3A2A0C; --warn-bar: #FFB547;
    --over: #FF7A70; --over-bg: #3C1613;
    --accent: #9AA2FF; --accent-bg: #20234A; --on-accent: #0C0E12; --on-solid: #12151A;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .04);
    --scrim: rgba(0, 0, 0, .6);
    --glass: rgba(23, 26, 32, .8);
    --toast-bg: #F3F5F8; --toast-fg: #12151A; --toast-act: #4A4FE0;
  }
  :root:not([data-theme="light"]) .c0 { --c: #9AA2FF; --c-bg: #20234A; }
  :root:not([data-theme="light"]) .c1 { --c: #5CCBEA; --c-bg: #11323D; }
  :root:not([data-theme="light"]) .c2 { --c: #C79BF5; --c-bg: #2D1B42; }
  :root:not([data-theme="light"]) .c3 { --c: #F58DC0; --c-bg: #43182F; }
  :root:not([data-theme="light"]) .c4 { --c: #A9B6CE; --c-bg: #262C38; }
  :root:not([data-theme="light"]) .c5 { --c: #E0AE7A; --c-bg: #3B2A18; }
}
:root[data-theme="dark"] {
  --bg: #0C0E12; --surface: #171A20; --surface-2: #20242C; --sheet: #12151A;
  --text: #F3F5F8; --text-2: #A6AEBB; --text-3: #7F8795;
  --line: rgba(255, 255, 255, .08); --line-2: rgba(255, 255, 255, .2); --track: #262B34;
  --ok: #4CD98A;   --ok-bg: #12301F;
  --warn: #FFB547; --warn-bg: #3A2A0C; --warn-bar: #FFB547;
  --over: #FF7A70; --over-bg: #3C1613;
  --accent: #9AA2FF; --accent-bg: #20234A; --on-accent: #0C0E12; --on-solid: #12151A;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .04);
  --scrim: rgba(0, 0, 0, .6);
  --glass: rgba(23, 26, 32, .8);
  --toast-bg: #F3F5F8; --toast-fg: #12151A; --toast-act: #4A4FE0;
}
:root[data-theme="dark"] .c0 { --c: #9AA2FF; --c-bg: #20234A; }
:root[data-theme="dark"] .c1 { --c: #5CCBEA; --c-bg: #11323D; }
:root[data-theme="dark"] .c2 { --c: #C79BF5; --c-bg: #2D1B42; }
:root[data-theme="dark"] .c3 { --c: #F58DC0; --c-bg: #43182F; }
:root[data-theme="dark"] .c4 { --c: #A9B6CE; --c-bg: #262C38; }
:root[data-theme="dark"] .c5 { --c: #E0AE7A; --c-bg: #3B2A18; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 1rem/1.35 var(--ff);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none;
}
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; text-align: inherit; }
input, select { -webkit-user-select: text; user-select: text; }
h1, h2, h3, p { margin: 0; }
.ico { width: 22px; height: 22px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Structure ---------- */
#app { position: fixed; inset: 0; overflow: hidden; }
#view {
  position: absolute; inset: 0; bottom: calc(var(--tab-h) + var(--sab));
  overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch; outline: none;
}
.page { width: min(100%, 560px); margin: 0 auto; padding: calc(var(--sat) + 10px) 16px 40px; }
.view-enter { animation: viewIn .32s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

#navbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  height: calc(var(--sat) + 44px); padding-top: var(--sat);
  display: flex; align-items: center; justify-content: center;
  background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 1px solid var(--line);
  font-weight: 600; font-size: 1rem;
  opacity: 0; transform: translateY(-6px); transition: opacity .2s var(--ease), transform .2s var(--ease);
  pointer-events: none;
}
#app.scrolled #navbar { opacity: 1; transform: none; }

/* ---------- Barre d'onglets ---------- */
#tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  height: calc(var(--tab-h) + var(--sab)); padding-bottom: var(--sab);
  background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid var(--line);
}
.tabbar-in { width: min(100%, 560px); height: var(--tab-h); margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: 100%; color: var(--text-3); font-size: clamp(11px, 0.647rem, 13px); font-weight: 600; letter-spacing: .01em;
  transition: color .15s var(--ease), transform .12s var(--ease);
}
.tab .ico { width: 25px; height: 25px; transition: transform .25s var(--ease); }
.tab:active { transform: scale(.92); }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .ico { transform: translateY(-1px) scale(1.06); }
.tab-add {
  justify-self: center; width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; margin-top: -14px;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 18px rgba(74, 79, 224, .38), 0 1px 3px rgba(0, 0, 0, .12);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease);
}
.tab-add .ico { width: 28px; height: 28px; stroke-width: 2.2; }
.tab-add:active { transform: scale(.92); }

/* ---------- En-têtes ---------- */
.largehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 6px 4px 16px; }
.largehead h1 { font: 800 2rem/1.08 var(--ff); letter-spacing: -.025em; }
.eyebrow { font-size: 0.765rem; font-weight: 600; letter-spacing: .02em; color: var(--text-2); text-transform: uppercase; display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.sub { color: var(--text-2); font-size: 0.882rem; margin-top: 2px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent-bg); color: var(--accent); font-weight: 700; font-size: 0.941rem; }
.avatar.sm { width: 30px; height: 30px; font-size: 0.824rem; }
.pill { display: inline-flex; align-items: center; min-height: 22px; padding: 0 9px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); font-size: 0.647rem; font-weight: 700; letter-spacing: .02em; text-transform: none; }

/* ---------- Cartes ---------- */
.card { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); width: 100%; display: block; color: inherit; }
button.card { transition: transform .14s var(--ease); }
button.card:active { transform: scale(.985); }
.stack { display: grid; gap: 12px; }
.section { margin: 26px 4px 10px; display: flex; align-items: baseline; justify-content: space-between; }
.section h2 { font: 700 1.176rem/1.2 var(--ff); letter-spacing: -.01em; }
.link { color: var(--accent); font-weight: 600; font-size: 0.882rem; min-height: 44px; padding: 0 4px; margin: -12px -4px; }

/* ---------- Carte enveloppe ---------- */
.env { padding: 16px 16px 14px; }
.env-top { display: flex; align-items: center; gap: 10px; }
.chip-ico { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; flex: none; background: var(--c-bg); color: var(--c); }
.chip-ico .ico { width: 21px; height: 21px; }
.env-name { font-weight: 650; font-size: 1rem; }
.env-label, .big, .stat-l, .stat-v, .stat-s, .gauge { display: block; }
.state { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; min-height: 28px; padding: 0 11px 0 8px; border-radius: 999px; font-size: 0.765rem; font-weight: 650; white-space: nowrap; }
.state .ico { width: 16px; height: 16px; stroke-width: 2.1; }
.state.ok { color: var(--ok); background: var(--ok-bg); }
.state.warn { color: var(--warn); background: var(--warn-bg); }
.state.over { color: var(--over); background: var(--over-bg); }
.env-amount { margin-top: 16px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.env-label { font-size: 0.824rem; color: var(--text-2); font-weight: 500; }
.big { font: 700 min(2.588rem, 12.5vw)/1.04 var(--ff-num); letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.env.over .big { color: var(--over); }
.env-of { text-align: right; color: var(--text-2); font-size: 0.794rem; line-height: 1.4; font-variant-numeric: tabular-nums; padding-bottom: 4px; }
.gauge { position: relative; height: 11px; border-radius: 999px; background: var(--track); overflow: hidden; margin-top: 14px; }
.gauge-fill {
  position: absolute; inset: 0; border-radius: 999px; background: var(--bar);
  transform: translateX(calc((var(--p, 0) - 100) * 1%));
  transition: transform .7s var(--ease); will-change: transform;
}
.env.ok { --bar: var(--ok); } .env.warn { --bar: var(--warn-bar); } .env.over { --bar: var(--over); }
.env.over .gauge-fill { background: repeating-linear-gradient(135deg, var(--over) 0 7px, color-mix(in srgb, var(--over) 62%, var(--surface)) 7px 14px); }
.gauge-tick { position: absolute; top: 0; bottom: 0; width: 2px; left: calc(var(--t, 80) * 1%); background: var(--surface); opacity: .95; }
.env-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 11px; font-size: 0.824rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- Bandeau / stats ---------- */
.banner { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--accent-bg); color: var(--accent); box-shadow: none; }
.banner b { color: var(--text); font-weight: 650; }
.banner small { color: var(--text-2); font-size: 0.824rem; }
.banner .ico:last-child { margin-left: auto; opacity: .7; }
.banner-ico { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; background: var(--surface); flex: none; }
.stats { display: grid; grid-template-columns: 1fr 1px 1fr; gap: 16px; padding: 18px 18px; align-items: stretch; }
.vsep { background: var(--line); }
.stat-l { font-size: 0.794rem; font-weight: 600; color: var(--text-2); }
.stat-v { font: 700 min(1.647rem, 7.6vw)/1.1 var(--ff-num); letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-s { font-size: 0.765rem; color: var(--text-3); margin-top: 3px; }
.tip { display: flex; gap: 12px; padding: 14px 16px; align-items: flex-start; }
.tip p { font-size: 0.853rem; color: var(--text-2); }
.tip b { color: var(--text); }
.tip .x { margin-left: auto; color: var(--text-3); width: 44px; height: 44px; margin: -12px -10px -12px auto; display: grid; place-items: center; flex: none; }

/* ---------- Listes groupées ---------- */
.group { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.group + .group, .group + .note, .note + .group { margin-top: 12px; }
.group-title { margin: 22px 8px 8px; font-size: 0.765rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
.cell { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 10px 16px; border-top: 1px solid var(--line); text-align: left; color: inherit; }
.group > :first-child, .group > .swipe:first-child .cell { border-top: 0; }
.cell.tap { transition: background .12s; }
.cell.tap:active { background: var(--surface-2); }
.cell-t { flex: 1; min-width: 0; }
.cell-t small { display: block; color: var(--text-2); font-size: 0.794rem; }
.cell-v { color: var(--text-2); font-variant-numeric: tabular-nums; }
.cell .ico.chev { width: 18px; height: 18px; color: var(--text-3); }
.cell-ico { width: 24px; height: 24px; border-radius: 50%; border: 1.5px dashed var(--text-3); display: grid; place-items: center; flex: none; color: var(--on-solid); }
.cell-ico.done { border: 0; background: var(--ok); }
.cell-ico .ico { width: 14px; height: 14px; stroke-width: 3; }
.cell.add { color: var(--accent); font-weight: 600; }
.cell.danger { color: var(--over); font-weight: 600; }
.cell select, .cell-input { border: 0; background: none; text-align: right; color: var(--text-2); max-width: 55%; height: 36px; padding: 0 4px; border-radius: 8px; font-size: 1rem; }
.cell select { -webkit-appearance: none; appearance: none; text-align-last: right; }
.cell > .seg { flex: 1; }
.cell-input { flex: 1; text-align: left; color: var(--text); font-weight: 500; }
.cell-input:focus { outline: none; background: var(--surface-2); }
.tag { font-size: 0.706rem; font-weight: 700; color: var(--accent); background: var(--accent-bg); border-radius: 999px; padding: 2px 9px; }
.note { margin: 10px 8px 0; color: var(--text-2); font-size: 0.794rem; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.pos { color: var(--ok); }
.amt.neg { color: var(--text); }

/* ---------- Lignes d'opérations + balayage ---------- */
.daylabel { margin: 18px 8px 8px; font-size: 0.765rem; font-weight: 600; color: var(--text-2); }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 16px; text-align: left; color: inherit; transition: background .12s; }
.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-s { font-size: 0.794rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group > * + * { border-top: 1px solid var(--line); }
.swipe { position: relative; overflow: hidden; touch-action: pan-y; }
.swipe-in { position: relative; background: var(--surface); transition: transform .3s var(--ease); touch-action: pan-y; }
.swipe-in.dragging { transition: none; }
.swipe.open .swipe-in { transform: translateX(-92px); }
.swipe-del {
  position: absolute; inset: 0; padding-left: calc(100% - 92px); background: var(--over); color: var(--on-solid);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 0.706rem; font-weight: 650;
}
.swipe-del .ico { width: 21px; height: 21px; }
.new { animation: rowIn .7s var(--ease) .3s backwards; }
@keyframes rowIn { 0% { opacity: 0; transform: translateX(-14px); background: var(--accent-bg); } 40% { opacity: 1; transform: none; background: var(--accent-bg); } 100% { background: transparent; } }
.empty { text-align: center; padding: 44px 24px; color: var(--text-2); }
.empty .chip-ico { width: 56px; height: 56px; border-radius: 20px; margin: 0 auto 14px; }
.empty .chip-ico .ico { width: 28px; height: 28px; }
.empty h3 { color: var(--text); font-size: 1.118rem; margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }

/* ---------- Contrôles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 54px; border-radius: 17px;
  background: var(--accent); color: var(--on-accent); font-weight: 650; font-size: 1rem; letter-spacing: -.005em;
  transition: transform .12s var(--ease), opacity .15s, background .15s;
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .38; transform: none; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--over-bg); color: var(--over); }
.btn.sm { min-height: 46px; width: auto; padding: 0 18px; font-size: 0.941rem; }
.btn.ghost { background: transparent; color: var(--accent); }
.seg { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 13px; padding: 3px; isolation: isolate; }
.seg button { position: relative; z-index: 1; min-height: 44px; border-radius: 10px; font-weight: 600; font-size: 0.882rem; color: var(--text-2); text-align: center; transition: color .2s; }
.seg button[aria-pressed="true"] { color: var(--text); }
.seg-thumb { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 3px; border-radius: 10px; background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .14); transition: transform .3s var(--ease); }
.seg.n2 .seg-thumb { width: calc((100% - 6px) / 2); }
.seg.n3 .seg-thumb { width: calc((100% - 6px) / 3); }
.seg.i1 .seg-thumb { transform: translateX(100%); }
.seg.i2 .seg-thumb { transform: translateX(200%); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 8px; margin: 0 -16px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 15px 0 8px; border-radius: 999px;
  background: var(--surface); border: 1.5px solid transparent; font-weight: 600; font-size: 0.882rem; white-space: nowrap;
  transition: transform .12s var(--ease), border-color .15s, background .15s, color .15s;
}
.chip .chip-ico { width: 28px; height: 28px; border-radius: 50%; }
.chip .chip-ico .ico { width: 16px; height: 16px; }
.chip:active { transform: scale(.96); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.chip.plain { padding: 0 15px; min-height: 44px; }

/* ---------- Feuilles (bottom sheets) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .32s var(--ease); }
.sheet-wrap.open .scrim { opacity: var(--scrim-o, 1); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; width: min(100%, 560px); max-height: 94%;
  display: flex; flex-direction: column; background: var(--sheet); border-radius: 28px 28px 0 0;
  transform: translateY(105%); transition: transform .45s var(--ease);
  box-shadow: 0 -12px 44px rgba(0, 0, 0, .2); outline: none; padding-bottom: var(--sab);
}
.sheet-wrap.open .sheet { transform: none; }
.sheet.dragging { transition: none; }
.sheet-grab { flex: none; height: 44px; padding-top: 10px; touch-action: none; cursor: grab; }
.sheet-close { position: absolute; top: 0; right: 6px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); z-index: 2; }
.sheet-close .ico { width: 20px; height: 20px; }
.sheet-close:active { background: var(--surface-2); }
.sheet-handle { display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 0 auto; }
.sheet-body { overflow-y: auto; padding: 0 16px 18px; overscroll-behavior: contain; }
.sheet-title { font: 700 1.294rem/1.2 var(--ff); letter-spacing: -.015em; margin: 6px 4px 16px; }
.sheet-sub { color: var(--text-2); font-size: 0.882rem; margin: -8px 4px 16px; }

/* Saisie */
.amount { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin-top: 14px; min-height: 66px; }
.amount-v { font: 700 min(3.294rem, 15vw)/1.1 var(--ff-num); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.amount-cur { font: 600 1.765rem/1 var(--ff-num); color: var(--text-2); }
.amount.is-empty .amount-v { color: var(--text-3); }
.amount.long .amount-v { font-size: 2.588rem; }
.preview { text-align: center; min-height: 22px; font-size: 0.882rem; font-weight: 550; color: var(--text-2); margin: 2px 0 8px; transition: color .2s; }
.preview.ok { color: var(--ok); } .preview.warn { color: var(--warn); } .preview.over { color: var(--over); }
.opts { display: flex; gap: 8px; margin: 4px 0 12px; }
.opt { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 14px; background: var(--surface); font-size: 0.882rem; font-weight: 550; flex: none; }
.opt .ico { width: 18px; height: 18px; color: var(--text-2); }
.opt.grow { flex: 1; min-width: 0; }
.opt .note-input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 0.941rem; color: var(--text); }
.opt .note-input::placeholder { color: var(--text-3); }
.opt:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.date-ghost { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; font-size: 0.941rem; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { min-height: 54px; border-radius: 16px; background: var(--surface); font: 500 1.529rem var(--ff-num); display: grid; place-items: center; transition: transform .08s, background .12s; }
.key:active { transform: scale(.94); background: var(--surface-2); }
.key .ico { width: 26px; height: 26px; }
.add-actions { display: flex; gap: 10px; margin-top: 12px; position: sticky; bottom: 0; background: var(--sheet); padding: 8px 0 2px; }
@media (max-height: 740px) { .key { min-height: 46px; } .amount { min-height: 56px; margin-top: 4px; } .amount-v { font-size: min(2.824rem, 13vw); } }

/* Formulaires */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 0.765rem; font-weight: 600; color: var(--text-2); margin: 0 4px 7px; }
.field input, .field select, .money input {
  width: 100%; min-height: 52px; border-radius: 15px; border: 1.5px solid transparent; background: var(--surface);
  padding: 0 15px; font-size: 1rem; font-weight: 500; outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus, .money input:focus { border-color: var(--accent); }
.field select {
  -webkit-appearance: none; appearance: none; padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none' stroke='%237B8394' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1.500 1.500 5.500 5.500 5.500-5.500'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center;
}
::placeholder { color: var(--text-3); opacity: 1; }
.money { position: relative; }
.money input { padding-right: 38px; font-variant-numeric: tabular-nums; }
.money i { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--text-2); font-style: normal; font-weight: 600; }
.field.err input, .field.err select { border-color: var(--over); }
.err-msg { color: var(--over); font-size: 0.794rem; margin: -8px 4px 14px; font-weight: 550; }
.picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.pick { aspect-ratio: 1; border-radius: 12px; display: grid; place-items: center; background: var(--surface); border: 1.5px solid transparent; color: var(--text-2); transition: transform .12s var(--ease); }
.pick:active { transform: scale(.92); }
.pick[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.pick .ico { width: 21px; height: 21px; }
.swatches { display: flex; gap: 12px; padding: 2px 4px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; background: var(--c); border: 3px solid var(--sheet); box-shadow: 0 0 0 1.5px transparent; transition: box-shadow .15s, transform .12s var(--ease); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2.5px var(--c); }
.swatch:active { transform: scale(.9); }
.hint { color: var(--text-2); font-size: 0.794rem; margin: -4px 4px 16px; }
.big-code { font: 700 1.882rem/1 var(--ff-num); letter-spacing: .08em; text-align: center; padding: 22px 0; background: var(--surface); border-radius: 18px; margin-bottom: 14px; user-select: all; -webkit-user-select: all; }

/* Clôture */
.close-hero { text-align: center; padding: 8px 0 18px; }
.close-hero .big { font-size: min(3.059rem, 14vw); }
.close-hero p { color: var(--text-2); margin-bottom: 4px; }
.pos { color: var(--ok); } .negt { color: var(--over); }
.mono { font-variant-numeric: tabular-nums; }

/* Épargne */
.save-card { padding: 20px 18px; }
.save-card .big { font-size: min(2.353rem, 11vw); margin-top: 4px; }

/* ---------- Récapitulatifs ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-variant-numeric: tabular-nums; }
.kv.strong { font-weight: 700; font-size: 1.059rem; }
.kv.sep { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 13px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--sab) + 14px); z-index: 70; display: flex; justify-content: center; padding: 0 16px; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: 520px; padding: 13px 16px; border-radius: 16px;
  background: var(--toast-bg); color: var(--toast-fg); font-size: 0.882rem; font-weight: 550; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  opacity: 0; transform: translateY(16px) scale(.97); transition: opacity .25s var(--ease), transform .35s var(--ease);
}
.toast.in { opacity: 1; transform: none; }
.toast-act { color: var(--toast-act); font-weight: 700; min-height: 44px; padding: 0 12px; margin: -10px -6px -10px 0; }

/* ---------- Connexion ---------- */
#auth { display: none; position: fixed; inset: 0; z-index: 80; background: var(--bg); overflow-y: auto; }
body.locked #auth { display: block; }
body.locked #app { visibility: hidden; }
.auth { width: min(100%, 420px); margin: 0 auto; min-height: 100%; padding: calc(var(--sat) + 56px) 24px calc(var(--sab) + 32px); display: flex; flex-direction: column; }
.auth-logo { width: 84px; height: 84px; border-radius: 24px; margin: 0 auto 22px; display: block; box-shadow: 0 12px 30px rgba(74, 79, 224, .35); }
.auth h1 { text-align: center; font: 800 1.882rem/1.1 var(--ff); letter-spacing: -.025em; }
.auth .lead { text-align: center; color: var(--text-2); margin: 8px 0 30px; }
.auth form { display: grid; gap: 4px; }
.auth .foot { margin-top: auto; padding-top: 28px; text-align: center; color: var(--text-2); font-size: 0.824rem; }
.auth .foot button { color: var(--accent); font-weight: 600; }
.demo-note { margin-top: 18px; text-align: center; font-size: 0.765rem; color: var(--warn); background: var(--warn-bg); border-radius: 12px; padding: 9px 12px; }

/* ---------- Accessibilité / mouvement ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (hover: hover) {
  .cell.tap:hover, .row:hover { background: var(--surface-2); }
  .chip:hover { border-color: var(--line-2); }
}


/* ---------- Classes utilitaires (aucun style en ligne : compatible CSP stricte) ---------- */
.mt-6 { margin-top: 6px; }
.mt-12 { margin-top: 12px; }
.ml-auto { margin-left: auto; }
.muted { color: var(--text-3); }
.note-lock { margin: 6px 8px 0; }
.note-center { text-align: center; margin-top: 20px; }
.pnav { display: flex; align-items: center; gap: 8px; padding: 0 4px; min-height: 48px; margin-bottom: 6px; }
.pnav-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none; transition: background .12s; }
.pnav-btn:active { background: var(--surface-2); }
.pnav-btn:disabled { opacity: .25; pointer-events: none; }
.pnav-title { flex: 1; text-align: center; font-weight: 650; font-size: 1rem; }
.pnav-title small { display: block; color: var(--text-2); font-size: 0.765rem; font-weight: 500; }
.banner-ico.ok { color: var(--ok); }
.banner-ico.warn { color: var(--warn); }
.recap { padding: 14px 18px 16px; }
.cumul { padding: 14px 18px; margin: 14px 0; }
.cumul-v { font: 600 1.235rem/1.3 var(--ff-num); margin-top: 4px; letter-spacing: -.01em; }
.cell-flush { border-top: 0; padding-top: 0; }
.cell-input.cell-input-end { flex: none; text-align: right; color: var(--text-2); }
.noscript { padding: 24px; font-family: sans-serif; }
#boot-fallback { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; gap: 16px; padding: 32px; text-align: center; background: var(--bg); }
@media (max-height: 700px) {
  .key { min-height: 44px; }
  .amount { min-height: 48px; margin-top: 2px; }
  .preview { margin: 0 0 4px; }
}

/* ---------- Dynamic Type : les tailles de texte suivent le réglage « Taille du texte » d'iOS ---------- */
html { font-size: 1rem; }
@supports (font: -apple-system-body) { html { font: -apple-system-body; } }

/* ---------- Texte très agrandi : rien ne doit déborder de l'écran ---------- */
.stack > *, .page > * { min-width: 0; }
.env-top, .env-amount, .env-foot, .largehead { flex-wrap: wrap; }
.env-name { min-width: 0; overflow-wrap: anywhere; }
.stats { grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1fr); }
.tip p, .banner > span:not(.banner-ico), .cell-t { min-width: 0; overflow-wrap: anywhere; }

/* ---------- Correctifs de la 2e relecture ---------- */
input, select, textarea { font-size: max(16px, 1rem); }
.opt .note-input, .date-ghost { font-size: max(16px, 0.941rem); }
.opts { flex-wrap: wrap; }
.opt.grow { flex: 1 1 100px; min-width: 100px; }
.sheet-title { padding-right: 48px; }
.largehead h1, .sheet-title { overflow-wrap: anywhere; }
.picker { grid-template-columns: repeat(4, 1fr); }
.pick { aspect-ratio: auto; min-height: 48px; }
.avatar { min-width: 44px; min-height: 44px; }
.avatar.sm { min-width: 0; min-height: 0; }

/* ---------- Cartes d'enveloppe compactes (tout le budget tient sur un écran) ---------- */
.env { padding: 14px 16px 12px; }
.env-amount { margin-top: 10px; align-items: baseline; justify-content: flex-start; gap: 8px; }
.env-amount > .env-label { display: inline; }
.env .big { font-size: min(2.235rem, 10.5vw); }
.env-of { margin-left: auto; text-align: right; padding-bottom: 0; }
.env .gauge { margin-top: 10px; }
.env-foot { margin-top: 8px; font-size: 0.794rem; }

/* ---------- Guide de départ ---------- */
.guide { padding: 16px 16px 14px; }
.guide-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.guide-head b { display: block; font-size: 1.059rem; }
.guide-head small { color: var(--text-2); font-size: 0.8rem; }
.guide-steps { display: grid; gap: 2px; margin: 0 -8px 2px; }
.guide-step { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 8px; border-radius: 14px; text-align: left; transition: background .12s; }
.guide-step:active { background: var(--surface-2); }
.guide-num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent-bg); color: var(--accent); font-weight: 700; font-size: 0.8rem; }
.guide-num .ico { width: 16px; height: 16px; stroke-width: 2.6; }
.guide-step.done .guide-num { background: var(--ok); color: var(--on-solid); }
.guide-step.done .cell-t { color: var(--text-2); }
.guide .btn { margin-top: 8px; }

/* ---------- Synchronisation ---------- */
.sync-pill { display: inline-flex; align-items: center; min-height: 22px; padding: 0 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 0.647rem; font-weight: 700; letter-spacing: .02em; text-transform: none; }
.sync-pill[hidden] { display: none; }

/* ---------- Saisie : toutes les enveloppes visibles ---------- */
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 4px 0 10px; }

/* ---------- Connexion ---------- */
.pw { position: relative; }
.pw input { padding-right: 52px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; display: grid; place-items: center; color: var(--text-3); }
.field-hint { display: block; margin: 6px 4px 0; color: var(--text-3); font-size: 0.765rem; }
.opt-l { font-weight: 500; color: var(--text-3); }
.auth .foot { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.auth .foot button { min-height: 44px; padding: 0 8px; }
.auth form .err-msg { margin: 0 4px 12px; }
.auth-center { justify-content: center; text-align: center; }
.auth-center .btn { margin-top: 20px; }
.pulse { animation: pulse 1.6s var(--ease) infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.94); opacity: .75; } }
.cell .link { white-space: nowrap; font-size: 0.824rem; }

/* ---------- iOS : jamais de zoom automatique en touchant un champ ----------
   Safari zoome sur tout champ dont le texte fait moins de 16 px. Avec une taille de texte iOS réduite
   (Réglages > Luminosité et affichage > Taille du texte), 1rem peut descendre sous 16 px : la page restait
   alors zoomée après la connexion (marges coupées). On impose 16 px minimum partout, quelle que soit la règle. */
input, select, textarea,
.field input, .field select, .money input, .cell select, .cell-input, .opt .note-input, .pw input, .date-ghost {
  font-size: max(16px, 1rem) !important;
}

/* ---------- Saisie : libellé de l'opération, bien visible ---------- */
.desc { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; margin: 2px 0 8px; border-radius: 14px; background: var(--surface); }
.desc .ico { width: 18px; height: 18px; color: var(--text-2); flex: none; }
.desc-input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); font-size: max(16px, 1rem) !important; }
.desc-input::placeholder { color: var(--text-3); }
.desc:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.add .amount { margin-top: 6px; min-height: 58px; }
.add .preview { margin: 0 0 8px; }
.add .opts { margin: 0 0 10px; }
.opt [data-r="who-n"] { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Onglet Échéances : pastille ---------- */
.tab-ico { position: relative; display: grid; place-items: center; }
.tab-badge {
  position: absolute; top: -5px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--over); color: var(--on-solid); font: 700 11px/18px var(--ff); text-align: center; letter-spacing: 0;
  box-shadow: 0 0 0 2px var(--surface);
}
.tab-badge[hidden] { display: none; }

/* ---------- Relevé ouvert depuis Aujourd'hui : retour ---------- */
.back { display: inline-flex; align-items: center; gap: 1px; min-height: 44px; margin: -2px 0 -8px -10px; padding: 0 10px 0 2px; color: var(--accent); font-weight: 600; font-size: 1rem; }
.back .ico { width: 24px; height: 24px; stroke-width: 2.2; }
.back:active { opacity: .55; }

/* ---------- Échéances : avancement et lignes à pointer ---------- */
.prog { display: grid; gap: 14px; padding: 15px 16px 16px; }
.prog-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; font-size: 0.882rem; }
.prog-l { font-weight: 650; color: var(--text-2); }
.prog-v { color: var(--text-2); font-variant-numeric: tabular-nums; }
.prog-v b { color: var(--text); font-weight: 700; }
.prog .gauge { height: 8px; margin-top: 8px; }
.prog .in { --bar: var(--ok); }
.prog .out { --bar: var(--accent); }
.group-title.warn { color: var(--warn); }
.cell.due-row { gap: 2px; padding: 0 12px 0 4px; }
.due-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 8px 0; text-align: left; color: inherit; transition: opacity .12s; }
.due-main:active { opacity: .55; }
.tick { width: 46px; height: 46px; flex: none; display: grid; place-items: center; border-radius: 50%; }
.tick-c {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: transparent;
  border: 2px solid var(--line-2); transition: background .2s, border-color .2s, color .2s, transform .15s var(--ease);
}
.tick-c .ico { width: 15px; height: 15px; stroke-width: 3; }
.tick.late .tick-c { border-color: var(--warn); }
.tick.on .tick-c { background: var(--ok); border-color: var(--ok); color: var(--on-solid); }
button.tick:active .tick-c { transform: scale(.86); }
.tick.pop .tick-c { animation: tickPop .5s var(--ease); }
@keyframes tickPop { 0% { transform: scale(.55); } 55% { transform: scale(1.18); } 100% { transform: none; } }
.due-row.is-done .cell-t { color: var(--text-2); }
.done-badge { display: flex; align-items: center; gap: 8px; margin: -4px 0 16px; padding: 10px 14px; border-radius: 14px; background: var(--ok-bg); color: var(--ok); font-size: 0.882rem; font-weight: 600; }
.done-badge .ico { width: 20px; height: 20px; }
.btn.ghost { margin-top: 6px; min-height: 48px; font-size: 0.941rem; }

/* ---------- Mois : état des lignes récurrentes ---------- */
.cell-ico.late { border: 2px solid var(--warn); }
.cell-ico.off { border-style: dotted; opacity: .6; }
.cell.off .cell-t, .cell.off .amt { color: var(--text-2); }
.cell.off .amt { font-weight: 500; }
.field[hidden] { display: none; }

/* ---------- Rythme, courbe du solde, graphiques, objectif, recherche ---------- */
.env-pace { display: flex; align-items: flex-start; gap: 6px; margin-top: 10px; padding: 8px 10px; border-radius: 12px; background: var(--warn-bg); color: var(--warn); font-size: 0.765rem; font-weight: 600; text-align: left; }
.env-pace .ico { width: 15px; height: 15px; flex: none; margin-top: 1px; }
.curve, .bars { display: block; width: 100%; height: auto; margin-top: 14px; overflow: visible; }
.cv-line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.cv-zero { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 3 4; }
.cv-min { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.cv-min.neg { fill: var(--over); }
.curve-note { margin: 6px 0 0; }
.bar.pos { fill: var(--ok); } .bar.neg { fill: var(--over); }
.bar-t { fill: var(--text-3); font-size: 10px; }
.chart-card { padding: 16px 18px 12px; }
.goal-track { position: relative; height: 8px; margin: 0 16px 14px; border-radius: 999px; background: var(--track); overflow: hidden; }
.goal-fill { position: absolute; inset: 0; border-radius: 999px; background: var(--ok); transform: translateX(calc((var(--p, 0) - 100) * 1%)); transition: transform .7s var(--ease); }
.search { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; padding: 0 14px; height: 42px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); color: var(--text-3); }
.search .ico { width: 18px; height: 18px; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 1rem; -webkit-appearance: none; appearance: none; }
.check { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; padding: 12px 14px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.check[hidden] { display: none; }
.check input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--accent); flex: none; }
.check span { font-weight: 600; font-size: 0.941rem; }
.check small { display: block; font-weight: 400; color: var(--text-2); font-size: 0.765rem; margin-top: 2px; }
.sugg { margin-bottom: 4px; }
.sugg[hidden] { display: none; }
.recal { display: block; margin: 8px auto 0; font-size: 0.853rem; }
