/* ================= Thème ================= */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f4f5f8;
  --surface-3: #e9ebf0;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a6;
  --line: #e7e9ee;
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #ccfbf1;
  --good: #15803d;
  --warn: #d97706;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --hero-a: #0f766e;
  --hero-b: #14b8a6;
  --hero-over-a: #b91c1c;
  --hero-over-b: #f97316;
  --chart-muted: #cfd6e1;
  --grid: #e7e9ee;
  --overlay: rgb(2 6 23 / 0.45);
  --shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 4px 14px rgb(15 23 42 / 0.05);
  --shadow-lg: 0 18px 40px -12px rgb(15 23 42 / 0.25);
  --radius: 22px;
  --radius-sm: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b0e13;
    --surface: #151a22;
    --surface-2: #1c222c;
    --surface-3: #262d39;
    --text: #e8edf4;
    --text-2: #aab4c3;
    --muted: #768297;
    --line: #242c38;
    --accent: #2dd4bf;
    --accent-strong: #14b8a6;
    --accent-ink: #042f2e;
    --accent-soft: #10302d;
    --good: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --hero-a: #0f766e;
    --hero-b: #0d9488;
    --hero-over-a: #991b1b;
    --hero-over-b: #c2410c;
    --chart-muted: #334155;
    --grid: #242c38;
    --overlay: rgb(0 0 0 / 0.6);
    --shadow: none;
    --shadow-lg: 0 18px 40px -12px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0b0e13;
  --surface: #151a22;
  --surface-2: #1c222c;
  --surface-3: #262d39;
  --text: #e8edf4;
  --text-2: #aab4c3;
  --muted: #768297;
  --line: #242c38;
  --accent: #2dd4bf;
  --accent-strong: #14b8a6;
  --accent-ink: #042f2e;
  --accent-soft: #10302d;
  --good: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --danger-soft: #3a1717;
  --hero-a: #0f766e;
  --hero-b: #0d9488;
  --hero-over-a: #991b1b;
  --hero-over-b: #c2410c;
  --chart-muted: #334155;
  --grid: #242c38;
  --overlay: rgb(0 0 0 / 0.6);
  --shadow: none;
  --shadow-lg: 0 18px 40px -12px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

/* ================= Base ================= */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 18px; height: 18px; }
svg.i.xs { width: 15px; height: 15px; }
.num { font-variant-numeric: tabular-nums; }
.press { transition: transform .12s ease, background-color .15s ease; }
.press:active { transform: scale(.97); }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 32px);
}
.app.bare { padding-bottom: 32px; }
.app.enter > * { animation: rise .28s cubic-bezier(.2, .8, .2, 1) both; }
.app.enter > *:nth-child(2) { animation-delay: .03s; }
.app.enter > *:nth-child(3) { animation-delay: .06s; }
.app.enter > *:nth-child(n+4) { animation-delay: .09s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ================= En-têtes ================= */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 16px; min-height: 52px; }
.page-head .eyebrow { color: var(--muted); font-size: 14px; font-weight: 600; }
.page-head h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; font-weight: 800; }
.page-head h1::first-letter { text-transform: uppercase; }
.page-head .titles { min-width: 0; }
.head-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); flex: none;
}
.icon-btn:active { background: var(--surface-3); }
.icon-btn.ghost { background: var(--surface-2); box-shadow: none; }
.icon-btn.danger { color: var(--danger); }
.icon-btn:disabled { opacity: .35; }

.back-head { display: flex; align-items: center; gap: 12px; margin: 2px 0 16px; min-height: 48px; }
.back-head h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.today-link {
  display: inline-flex; align-items: center; gap: 6px; margin: -6px 0 14px; padding: 6px 12px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent-strong); border: 0; font-size: 13px; font-weight: 700;
}
:root[data-theme='dark'] .today-link { color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .today-link { color: var(--accent); } }

.avatar {
  --a: var(--accent);
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--a); color: #fff; font-size: 11px; font-weight: 800; flex: none; line-height: 1;
}
.avatar.lg { width: 44px; height: 44px; font-size: 18px; box-shadow: var(--shadow); }
.avatar.xl { width: 60px; height: 60px; font-size: 26px; border-radius: 20px; }
.avatar.sys { background: var(--surface-3); color: var(--text-2); }

/* ================= Carte principale ================= */
.hero {
  position: relative; overflow: hidden; border-radius: 26px; padding: 20px 20px 18px; color: #fff;
  background: linear-gradient(140deg, var(--hero-a), var(--hero-b));
  box-shadow: 0 16px 36px -16px rgb(13 148 136 / 0.7);
  margin-bottom: 14px; touch-action: pan-y;
}
.hero.over { background: linear-gradient(140deg, var(--hero-over-a), var(--hero-over-b)); box-shadow: 0 16px 36px -16px rgb(220 38 38 / 0.6); }
.hero::before, .hero::after { content: ''; position: absolute; border-radius: 50%; background: rgb(255 255 255 / 0.08); pointer-events: none; }
.hero::before { width: 220px; height: 220px; right: -70px; top: -90px; }
.hero::after { width: 140px; height: 140px; right: 40px; bottom: -90px; }
.hero > * { position: relative; }
.hero .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hero .label { font-size: 14px; font-weight: 600; opacity: .9; }
.hero .amount { font-size: 46px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.08; margin: 6px 0 14px; }
.hero .meter { height: 8px; border-radius: 99px; background: rgb(255 255 255 / 0.25); overflow: hidden; }
.hero .meter > span { display: block; height: 100%; border-radius: inherit; background: #fff; transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.hero .figures { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; opacity: .92; }
.hero .figures b { font-weight: 700; }
.hero .pills { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 99px; font-size: 13px; font-weight: 700; background: rgb(255 255 255 / 0.18); }

/* ================= Tuiles et cartes ================= */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
:root[data-theme='dark'] .card, :root[data-theme='dark'] .list { border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .card, :root:not([data-theme='light']) .list { border: 1px solid var(--line); } }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tile { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 12px 14px; min-width: 0; }
:root[data-theme='dark'] .tile { border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .tile { border: 1px solid var(--line); } }
.tile .k { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; margin-top: 2px; white-space: nowrap; }
.tile .v.good { color: var(--good); }
.tile .v.bad { color: var(--danger); }
.tiles.three .tile .v { font-size: 16px; }

.section { display: flex; justify-content: space-between; align-items: baseline; margin: 24px 4px 10px; }
.section h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.section a, .section button { font-size: 14px; font-weight: 700; color: var(--accent-strong); background: none; border: 0; padding: 4px 0; }
:root[data-theme='dark'] .section a, :root[data-theme='dark'] .section button { color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .section a, :root:not([data-theme='light']) .section button { color: var(--accent); } }

/* ================= Listes ================= */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  width: 100%; padding: 12px 16px; background: none; border: 0; text-align: left; position: relative;
}
.row + .row::before { content: ''; position: absolute; top: 0; left: 72px; right: 0; border-top: 1px solid var(--line); }
button.row:active, a.row:active { background: var(--surface-2); }
.row .ico {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 21px;
  background: color-mix(in srgb, var(--c, var(--muted)) 15%, var(--surface));
}
.row .ico.plain { background: var(--surface-2); color: var(--text-2); }
.row .ico.solid { background: var(--c); color: #fff; }
.row .main { min-width: 0; }
.row .title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; overflow: hidden; }
.row .sub span { overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; white-space: nowrap; }
.row .amt { font-weight: 750; font-size: 15px; }
.row .amt.in { color: var(--good); }
.row .amt.neg { color: var(--danger); }
.row .end small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.row .end small.neg { color: var(--danger); }
.row .meter { grid-column: 2 / 4; margin-top: -4px; }
.row .chev { color: var(--muted); display: grid; }

.meter { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 14%, transparent); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.meter > span.warn { background: var(--warn); }
.meter > span.over { background: var(--danger); }
.meter.lg { height: 10px; }

.badge { display: inline-block; font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; vertical-align: 2px; margin-left: 4px; }
.badge.accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.day-head {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: baseline;
  padding: calc(env(safe-area-inset-top) + 10px) 6px 8px; margin: 0 -6px; font-size: 13px; font-weight: 700; color: var(--text-2);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.day-head .num { color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 32px 20px; font-size: 15px; }
.empty .e { font-size: 38px; margin-bottom: 8px; }
.empty b { color: var(--text); display: block; margin-bottom: 4px; }

/* ================= Recherche / filtres ================= */
.search { position: relative; margin-bottom: 12px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { width: 100%; height: 46px; border-radius: 14px; border: 1px solid transparent; background: var(--surface); box-shadow: var(--shadow); padding: 0 14px 0 44px; font-size: 16px; outline: none; }
.search input:focus { border-color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 14px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 99px; border: 0; background: var(--surface); box-shadow: var(--shadow); font-size: 14px; font-weight: 650; color: var(--text-2); position: relative; }
.chip.on { background: var(--text); color: var(--bg); box-shadow: none; }

/* ================= Formulaires ================= */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--text-2); margin: 0 4px 6px; }
.input {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 14px; border: 1.5px solid transparent;
  background: var(--surface-2); outline: none; font-size: 16px; appearance: none; transition: border-color .15s;
}
.input:focus { border-color: var(--accent); background: var(--surface); }
select.input { background-image: none; }
.pw { position: relative; }
.pw .input { padding-right: 50px; }
.pw button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 54px; padding: 0 20px;
  border: 0; border-radius: 16px; font-weight: 750; font-size: 16px; background: var(--surface-2); color: var(--text);
  transition: transform .12s ease, opacity .15s, background-color .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent-strong); color: #fff; box-shadow: 0 10px 22px -12px rgb(13 148 136 / 0.9); }
:root[data-theme='dark'] .btn.primary { background: var(--accent); color: var(--accent-ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .btn.primary { background: var(--accent); color: var(--accent-ink); } }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; box-shadow: none; transform: none; }
.stack > * + * { margin-top: 10px; }

.error { color: var(--danger); font-size: 14px; font-weight: 600; margin: -4px 4px 12px; }
.error:empty { display: none; }
.hint { color: var(--muted); font-size: 13px; margin: 0 4px 14px; line-height: 1.45; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 4px; margin-bottom: 10px; font-weight: 600; }
.switch-row input { width: 50px; height: 30px; appearance: none; background: var(--surface-3); border-radius: 99px; position: relative; transition: background .2s; flex: none; margin: 0; }
.switch-row input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgb(0 0 0 / .25); }
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(20px); }

.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; height: 36px; padding: 0 14px; border-radius: 9px; font-size: 14px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(15 23 42 / .12); }
.seg.block { display: grid; width: 100%; }

.swatches { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; padding: 0 3px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 0; padding: 0; min-width: 0; background: var(--c); position: relative; }
.swatch.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; margin-bottom: 14px; }
.emoji-grid button { aspect-ratio: 1; border: 0; padding: 0; min-width: 0; border-radius: 12px; background: none; font-size: 21px; display: grid; place-items: center; }
.emoji-grid button.on { background: var(--accent-soft); }

/* ================= Saisie rapide ================= */
.amount-display { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 4px 0 12px; min-height: 64px; }
.amount-display .v { font-size: 52px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.amount-display .v.empty { color: var(--muted); }
.amount-display .cur { font-size: 34px; font-weight: 700; color: var(--muted); }
.amount-display .caret { width: 3px; height: 44px; background: var(--accent); border-radius: 2px; align-self: center; animation: blink 1s steps(1) infinite; margin-left: -2px; }
@keyframes blink { 50% { opacity: 0; } }

.note-input { width: 100%; height: 46px; border: 0; border-radius: 14px; background: var(--surface-2); padding: 0 14px; font-size: 16px; outline: none; margin-bottom: 12px; text-align: center; }
.note-input:focus { box-shadow: 0 0 0 2px var(--accent); }

.cat-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.cat-chip {
  --c: var(--accent);
  border: 0; background: var(--surface-2); border-radius: 16px; padding: 8px 4px 7px; min-height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 700; line-height: 1.15; color: var(--text-2); text-align: center; position: relative;
}
.cat-chip .e { font-size: 22px; line-height: 1; }
.cat-chip .n { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 100%; }
.cat-chip.on { background: color-mix(in srgb, var(--c) 18%, var(--surface)); color: var(--text); box-shadow: inset 0 0 0 2px var(--c); }

.date-chips { display: flex; gap: 8px; margin-bottom: 12px; }
.date-chips .chip { flex: 1; justify-content: center; box-shadow: none; background: var(--surface-2); padding: 0 8px; }
.date-chips .chip.on { background: var(--text); color: var(--bg); }
.date-chips .chip input[type='date'] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; border: 0; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 12px; }
.key {
  height: 50px; border: 0; border-radius: 14px; background: var(--surface-2); font-size: 23px; font-weight: 650;
  display: grid; place-items: center; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: background-color .1s, transform .08s;
}
.key:active { background: var(--surface-3); transform: scale(.96); }
.key.fn { color: var(--text-2); }

/* ================= Feuille (bottom sheet) ================= */
.overlay { position: fixed; inset: 0; z-index: 40; background: var(--overlay); animation: fade .2s ease; }
.overlay.closing { animation: fade .2s ease reverse forwards; }
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 520px; max-height: 94dvh; overflow-y: auto;
  background: var(--surface); border-radius: 28px 28px 0 0; padding: 0 16px calc(env(safe-area-inset-bottom) + 14px);
  box-shadow: var(--shadow-lg); animation: up .32s cubic-bezier(.2, .9, .25, 1); overscroll-behavior: contain;
}
.sheet.closing { transition: transform .2s ease-in; transform: translateY(100%); }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-top { position: sticky; top: 0; z-index: 3; background: var(--surface); padding-top: 8px; margin: 0 -16px 8px; padding-left: 16px; padding-right: 16px; touch-action: none; }
.grab { width: 40px; height: 5px; border-radius: 99px; background: var(--surface-3); margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding-bottom: 6px; }
.sheet-head h3 { margin: 0; font-size: 20px; font-weight: 800; }

/* ================= Barre de navigation ================= */
.tabbar {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .inner { max-width: 520px; margin: 0 auto; height: var(--tabbar-h); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 700; color: var(--muted); padding: 6px 0; }
.tab.on { color: var(--accent-strong); }
:root[data-theme='dark'] .tab.on { color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .tab.on { color: var(--accent); } }
.tab-add { justify-self: center; width: 58px; height: 58px; border-radius: 20px; border: 0; color: #fff; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--hero-a), var(--hero-b)); box-shadow: 0 10px 24px -8px rgb(13 148 136 / .8); transform: translateY(-12px);
  transition: transform .12s ease; }
.tab-add:active { transform: translateY(-12px) scale(.94); }
.tab-add svg.i { width: 28px; height: 28px; stroke-width: 2.5; }

/* ================= Toast ================= */
.toast {
  position: fixed; z-index: 60; left: 16px; right: 16px; margin: 0 auto; max-width: 488px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #111827; color: #f9fafb; padding: 12px 12px 12px 16px; border-radius: 16px; font-weight: 600; font-size: 14px;
  box-shadow: 0 12px 30px -8px rgb(0 0 0 / .45); animation: toastIn .25s cubic-bezier(.2, .9, .25, 1);
}
:root[data-theme='dark'] .toast { background: #e8edf4; color: #0b0e13; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .toast { background: #e8edf4; color: #0b0e13; } }
.toast.err { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(10px); transition: all .2s; }
.toast button { border: 0; background: none; color: #2dd4bf; font-weight: 800; font-size: 14px; padding: 6px 8px; border-radius: 8px; flex: none; }
:root[data-theme='dark'] .toast button { color: #0f766e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .toast button { color: #0f766e; } }
.app.bare ~ .toast { bottom: calc(env(safe-area-inset-bottom) + 18px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ================= Squelettes ================= */
.sk { background: var(--surface-3); border-radius: 14px; position: relative; overflow: hidden; }
.sk::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgb(255 255 255 / .35), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

.app.dim > * { opacity: .55; transition: opacity .2s; }
.avatar svg.i { width: 12px; height: 12px; stroke-width: 2.4; }

.summary .k { color: var(--muted); font-size: 14px; font-weight: 600; }
.summary .big { font-size: 38px; font-weight: 800; letter-spacing: -0.02em; margin: 2px 0 12px; }
.summary .big.neg { color: var(--danger); }
.summary .figures { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; color: var(--text-2); }

details.more { margin-top: 8px; border-top: 1px solid var(--line); }
details.more summary { list-style: none; cursor: pointer; padding: 12px 0 2px; font-size: 14px; font-weight: 700; color: var(--text-2); display: flex; align-items: center; justify-content: center; gap: 6px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: '▾'; font-size: 12px; transition: transform .2s; }
details.more[open] summary::after { transform: rotate(180deg); }
details.more .table { margin-top: 8px; }

/* ================= Graphiques ================= */
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--chart-muted); transition: fill .2s; }
.chart .bar.sel { fill: var(--accent); }
.chart .budget { stroke: var(--text-2); stroke-width: 2; stroke-linecap: round; }
.chart .val { fill: var(--text); font-size: 11px; font-weight: 750; }
.chart .xl { fill: var(--muted); font-size: 11px; font-weight: 600; }
.chart .xl.sel { fill: var(--text); font-weight: 800; }
.chart .hit:hover .bar:not(.sel) { fill: color-mix(in srgb, var(--chart-muted) 70%, var(--text-2)); }
.chart-card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.chart-card h3 { margin: 0; font-size: 16px; font-weight: 800; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); font-weight: 600; margin-bottom: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.legend i.line { height: 2px; width: 14px; border-radius: 2px; background: var(--text-2); }
.legend i.muted { background: var(--chart-muted); }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { font-family: inherit; }
.chart .hit { cursor: pointer; }
.chart .hit:focus { outline: none; }
.chart .hit:focus-visible rect.focus-ring { stroke: var(--accent); }

.rank { padding: 4px 0; }
.rank-row { display: block; width: 100%; padding: 10px 0; border: 0; background: none; text-align: left; }
.rank-row + .rank-row { border-top: 1px solid var(--line); }
.rank-row .top { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; font-size: 14px; }
.rank-row .top .n { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row .top .v { font-weight: 750; white-space: nowrap; }
.rank-row .top .p { color: var(--muted); font-size: 12px; font-weight: 700; width: 40px; text-align: right; }
.rank-row .bar { height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 3px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: right; font-size: 12px; color: var(--muted); font-weight: 700; padding: 6px 0; }
.table th:first-child, .table td:first-child { text-align: left; }
.table td { text-align: right; padding: 9px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.table tr.sel td { font-weight: 800; }
.table td.bad { color: var(--danger); font-weight: 700; }
.table td.good { color: var(--good); font-weight: 700; }

/* ================= Connexion ================= */
.auth { min-height: calc(100dvh - 60px); display: flex; flex-direction: column; justify-content: center; padding: 20px 0; }
.auth .logo { width: 76px; height: 76px; border-radius: 24px; margin: 0 auto 18px; display: grid; place-items: center; color: #fff; font-size: 38px; font-weight: 800;
  background: linear-gradient(140deg, var(--hero-a), var(--hero-b)); box-shadow: 0 16px 32px -14px rgb(13 148 136 / .8); }
.auth h1 { text-align: center; margin: 0 0 6px; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.auth .lead { text-align: center; color: var(--muted); margin: 0 0 26px; }
.auth .card { padding: 20px; }

.profile { display: flex; align-items: center; gap: 14px; }
.profile .name { font-weight: 800; font-size: 19px; }
.profile .sub { color: var(--muted); font-size: 14px; }
.foot-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

.reorder { display: flex; flex-direction: column; gap: 4px; }
.reorder button { width: 30px; height: 22px; border: 0; border-radius: 7px; background: var(--surface-2); color: var(--text-2); display: grid; place-items: center; }
.reorder button:disabled { opacity: .3; }
.row.reorderable { grid-template-columns: 30px 44px 1fr auto; }
.row.reorderable + .row.reorderable::before { left: 114px; }

/* ================= Installation ================= */
.install { text-align: center; padding: 0 4px 4px; }
.install-icon { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 14px 30px -12px rgb(13 148 136 / .7); margin: -6px auto 14px; display: block; }
.install h3 { margin: 0 0 6px; font-size: 23px; font-weight: 800; letter-spacing: -0.01em; }
.install .lead { color: var(--text-2); margin: 0 auto 16px; max-width: 360px; font-size: 15px; line-height: 1.45; }
.perks { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; text-align: left; }
.perks li { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border-radius: 14px; padding: 11px 14px; font-weight: 650; font-size: 14px; }
.perks svg { color: var(--accent-strong); }
:root[data-theme='dark'] .perks svg { color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .perks svg { color: var(--accent); } }
.steps { list-style: none; padding: 14px; margin: 0 0 16px; text-align: left; display: grid; gap: 12px; border: 1.5px dashed var(--line); border-radius: 16px; }
.steps li { display: flex; align-items: center; gap: 12px; font-size: 14px; line-height: 1.4; }
.step-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-strong); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.kbd-ico { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--surface-3); vertical-align: middle; margin: 0 2px; }
kbd { font: 700 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace; padding: 3px 6px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); border-bottom: 2px solid var(--line); }

/* Éléments réservés à la version PC */
.tabbar .brand, .tabbar .kbd-hint, .tabbar .side-user, .tab-add .lbl, .kbd-tip { display: none; }

/* ================= Version PC ================= */
@media (min-width: 1024px) {
  :root { --side-w: 256px; }
  body.has-nav { padding-left: var(--side-w); }
  .app { max-width: 1120px; padding: 36px 40px 64px; }
  .app[data-layout='narrow'] { max-width: 800px; }
  .app.bare { max-width: 440px; padding-bottom: 40px; }
  .page-head { margin-bottom: 22px; }
  .page-head h1 { font-size: 32px; }

  /* La barre d'onglets devient un menu latéral */
  .tabbar {
    top: 0; right: auto; width: var(--side-w); padding: 22px 16px; border-top: 0; border-right: 1px solid var(--line);
    background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tabbar .inner { height: 100%; display: flex; flex-direction: column; align-items: stretch; gap: 4px; max-width: none; }
  .tabbar .brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 18px; letter-spacing: -0.01em; padding: 0 8px 22px; order: 0; }
  .brand-logo { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-size: 20px; background: linear-gradient(140deg, var(--hero-a), var(--hero-b)); }
  .tab-add {
    order: 1; width: 100%; height: 48px; border-radius: 14px; transform: none; display: flex; align-items: center; justify-content: center; gap: 8px;
    font-weight: 750; font-size: 15px; margin-bottom: 18px;
  }
  .tab-add:active { transform: scale(.98); }
  .tab-add svg.i { width: 20px; height: 20px; }
  .tab-add .lbl { display: inline; }
  .tab { order: 2; flex-direction: row; gap: 12px; font-size: 15px; font-weight: 650; padding: 11px 12px; border-radius: 12px; color: var(--text-2); }
  .tab:hover { background: var(--surface-2); color: var(--text); }
  .tab.on { background: var(--accent-soft); }
  .tabbar .kbd-hint { order: 3; display: block; margin: 18px 8px 0; font-size: 12px; color: var(--muted); line-height: 1.9; }
  .tabbar .side-user { order: 4; margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; }
  .tabbar .side-user:hover { background: var(--surface-2); }
  .side-user .who { display: flex; flex-direction: column; min-width: 0; }
  .side-user .who b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .side-user .who small { font-size: 12px; color: var(--muted); }
  .side-user .avatar.lg { width: 38px; height: 38px; font-size: 16px; box-shadow: none; }

  /* Tableau de bord sur deux colonnes */
  .home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: 'hero budgets' 'recent budgets'; grid-template-rows: auto 1fr; column-gap: 28px; align-items: start; }
  .a-hero { grid-area: hero; }
  .a-budgets { grid-area: budgets; }
  .a-recent { grid-area: recent; }
  .a-budgets > .section:first-child, .a-recent > .section:first-child { margin-top: 4px; }
  .a-hero .hero { margin-bottom: 14px; }
  .stats-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 0 24px; align-items: start; }

  /* Feuilles → fenêtres centrées */
  .sheet {
    inset: 0; margin: auto; width: 460px; height: fit-content; max-height: 88vh; border-radius: 26px;
    padding-bottom: 20px; animation: pop .2s cubic-bezier(.2, .9, .25, 1);
  }
  @keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
  .sheet-top { border-radius: 26px 26px 0 0; padding-top: 14px; }
  .grab { display: none; }
  .kbd-tip { display: block; text-align: center; color: var(--muted); font-size: 12px; margin: -6px 0 12px; }

  .toast { left: var(--side-w); right: 0; bottom: 28px; max-width: 460px; }
  .app.bare ~ .toast { left: 0; bottom: 28px; }

  .tiles.three .tile .v { font-size: 20px; }
  .hero .amount { font-size: 52px; }
}

/* Souris : retours visuels au survol */
@media (hover: hover) and (pointer: fine) {
  button.row:hover, a.row:hover, .rank-row:hover { background: var(--surface-2); }
  .chip:not(.on):hover { color: var(--text); }
  .icon-btn:hover { background: var(--surface-2); }
  .key:hover { background: var(--surface-3); }
  .cat-chip:not(.on):hover { background: var(--surface-3); }
  .btn.primary:hover { filter: brightness(1.06); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* Petits téléphones : la saisie tient sur un écran sans défiler. */
@media (max-height: 740px) {
  .sheet-top { margin-bottom: 4px; }
  .sheet-head { min-height: 40px; padding-bottom: 2px; }
  .amount-display { min-height: 48px; margin: 0 0 8px; }
  .amount-display .v { font-size: 42px; }
  .amount-display .cur { font-size: 28px; }
  .amount-display .caret { height: 36px; }
  .note-input { height: 40px; margin-bottom: 8px; }
  .cat-picker { gap: 6px; margin-bottom: 8px; }
  .cat-chip { min-height: 50px; padding: 5px 3px; gap: 2px; font-size: 10.5px; }
  .cat-chip .e { font-size: 19px; }
  .date-chips { margin-bottom: 8px; }
  .date-chips .chip { height: 34px; }
  .keypad { gap: 6px; margin-bottom: 8px; }
  .key { height: 42px; font-size: 21px; }
  .sheet .btn.primary { height: 50px; }
}
@media (max-width: 360px) {
  .hero .amount { font-size: 40px; }
  .tiles.three .tile .v { font-size: 14px; }
  .key { height: 46px; }
}
