:root {
  --paper: #EFEAE0;
  --raised: #F7F3EA;
  --white: #FFFDF8;
  --ink: #1E2A44;
  --ink-soft: #5B6478;
  --gold: #9A7424;
  --gold-bg: #F1E6CC;
  --coral: #B8432F;
  --coral-bg: #F6E1DA;
  --sage: #4E6E50;
  --sage-bg: #DDE7DB;
  --bar: #3E5A8A;
  --line: #D8D0C0;
  --line-strong: #C4BAA4;
  --radius: 12px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --serif: 'Fraunces', Georgia, serif;
  color-scheme: light;
  accent-color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif; font-size: 15px; line-height: 1.4;
  min-height: 100vh; padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
.wrap { max-width: 560px; margin: 0 auto; }
.hide { display: none !important; }
button { font: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--sage); }
.neg { color: var(--coral); }
.muted { color: var(--ink-soft); }
.small { font-size: 12.5px; }

header.top { display: flex; justify-content: space-between; align-items: flex-end; padding: calc(18px + env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid var(--line); }
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); margin: 0 0 4px; }
h1 { font-family: var(--serif); font-weight: 600; font-size: 25px; margin: 0; letter-spacing: -0.01em; }
.icon-btn { background: var(--raised); border: 1px solid var(--line-strong); border-radius: 10px; width: 40px; height: 40px; font-size: 18px; cursor: pointer; }

.section { padding: 0 16px; }
.section-title { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); margin: 24px 16px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.link { background: none; border: none; color: var(--gold); font-weight: 600; font-size: 13px; cursor: pointer; padding: 4px 0; text-transform: none; letter-spacing: 0; font-family: 'Inter', sans-serif; }
.card { background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.empty { text-align: center; color: var(--ink-soft); font-size: 13px; padding: 18px 0; }

/* Bandeaux */
.banner { margin: 12px 16px 0; padding: 12px 14px; border-radius: 10px; font-size: 13.5px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid; }
.banner.warn { background: var(--gold-bg); border-color: var(--gold); }
.banner.alert { background: var(--coral-bg); border-color: var(--coral); color: #7A2A1C; }
.banner.info { background: var(--raised); border-color: var(--line-strong); }
.banner .btn { width: auto; padding: 8px 12px; font-size: 13px; white-space: nowrap; }

/* Chiffres principaux */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px 16px 0; }
.hero-card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 12px; }
.hero-card.main { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.hero-card .lbl { font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 6px; opacity: .8; }
.hero-card .big { font-family: var(--serif); font-weight: 700; font-size: 30px; line-height: 1.05; margin: 0; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-card .big .cents { font-size: .55em; opacity: .7; }
.hero-card .sub { font-size: 12px; margin: 6px 0 0; opacity: .85; }
.hero-card .link { font-size: 12px; }
.hero-card.main .link { color: #E7C77A; }
.summary { margin: 10px 16px 0; }
.summary .row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 13.5px; border-bottom: 1px dashed var(--line); }
.summary .row:last-child { border-bottom: none; }
.summary .row b { font-family: var(--mono); font-weight: 600; white-space: nowrap; }

/* Enveloppes */
.env { cursor: pointer; }
.env-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.env-name { font-weight: 600; font-size: 15px; margin: 0; }
.env-left { font-family: var(--mono); font-weight: 600; font-size: 18px; }
.env-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-soft); margin-top: 6px; gap: 8px; }
.track { height: 8px; background: var(--line); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.fill { height: 100%; border-radius: 4px; background: var(--sage); transition: width .3s; }
.fill.mid { background: var(--gold); }
.fill.low { background: var(--coral); }

/* Listes */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: none; }
.item .ico { flex: 0 0 34px; height: 34px; border-radius: 9px; background: var(--white); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; font-size: 14px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 12px; color: var(--ink-soft); margin: 1px 0 0; }
.item .amt { font-family: var(--mono); font-weight: 600; font-size: 14.5px; white-space: nowrap; }
.item.dim { opacity: .5; }
.day-head { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); padding: 14px 0 2px; }
.badge { display: inline-block; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .03em; padding: 2px 6px; border-radius: 4px; background: var(--line); color: var(--ink-soft); margin-left: 6px; vertical-align: 1px; }
.badge.ok { background: var(--sage-bg); color: var(--sage); }
.badge.gold { background: var(--gold-bg); color: var(--gold); }
.badge.bad { background: var(--coral-bg); color: var(--coral); }

/* Barres de navigation dans le temps / filtres */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 0; }
.pager button { background: var(--raised); border: 1px solid var(--line-strong); border-radius: 10px; width: 40px; height: 40px; font-size: 18px; cursor: pointer; }
.pager button:disabled { opacity: .3; }
.pager .lab { text-align: center; flex: 1; }
.pager .lab b { font-family: var(--serif); font-size: 16px; display: block; }
.pager .lab span { font-size: 12px; color: var(--ink-soft); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 16px 0; }
.chip { border: 1px solid var(--line-strong); background: var(--raised); border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* Analyse */
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row { cursor: pointer; padding: 8px 0; }
.bar-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.bar-head .n { font-weight: 600; }
.bar-track { height: 10px; margin-top: 6px; border-radius: 0 4px 4px 0; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-sub { padding: 4px 0 6px 12px; border-left: 2px solid var(--line); margin: 4px 0 4px 6px; }
.bar-sub .r { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; color: var(--ink-soft); }
.split { display: flex; gap: 8px; }
.split > div { flex: 1; text-align: center; }
.split b { display: block; font-family: var(--mono); font-size: 15px; }
.split span { font-size: 11.5px; color: var(--ink-soft); }

/* Tableau de prévisions */
table.fc { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.fc th { font-family: var(--mono); font-weight: 500; font-size: 10.5px; text-transform: uppercase; color: var(--ink-soft); text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--line-strong); }
table.fc th:first-child, table.fc td:first-child { text-align: left; }
table.fc td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--line); font-family: var(--mono); white-space: nowrap; }
table.fc td:first-child { font-family: 'Inter', sans-serif; text-transform: capitalize; }
details.fold > summary { cursor: pointer; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }

/* Projets */
.goal .top { display: flex; justify-content: space-between; gap: 10px; cursor: pointer; }
.goal .name { font-weight: 600; margin: 0; }
.goal .due { font-size: 12px; color: var(--ink-soft); margin: 2px 0 0; }
.goal .need { font-size: 12.5px; font-weight: 600; margin: 8px 0 10px; color: var(--gold); }
.goal .need.ok { color: var(--sage); }
.goal .need.bad { color: var(--coral); }
.btns { display: flex; gap: 8px; }
.btns .btn { padding: 9px; font-size: 13px; }

/* Formulaires */
.field { margin-bottom: 14px; }
.field > label, .label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin-bottom: 5px; font-family: var(--mono); }
.field input, .field select, .field textarea { width: 100%; padding: 12px; border: 1px solid var(--line-strong); border-radius: 10px; font-size: 16px; font-family: 'Inter', sans-serif; background: var(--white); color: var(--ink); }
.field input:focus, .field select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.field .hint { font-size: 12px; color: var(--ink-soft); margin: 6px 0 0; line-height: 1.45; }
.field.amount input { font-family: var(--serif); font-size: 32px; font-weight: 700; text-align: center; padding: 10px; }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; margin-bottom: 12px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; flex: 0 0 auto; }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.seg label { flex: 1; text-align: center; padding: 10px 4px; font-size: 13.5px; cursor: pointer; background: var(--raised); border-right: 1px solid var(--line-strong); }
.seg label:last-child { border-right: none; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--ink); color: var(--paper); }
.cat-grid { max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px 10px; background: var(--white); }
.cat-grid .fam { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; color: var(--ink-soft); margin: 10px 0 6px; }
.cat-grid .chips { padding: 0; }
.cat-grid .chip { background: var(--raised); font-size: 13px; padding: 6px 10px; }
.cat-grid .chip.on { background: var(--ink); color: var(--paper); }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 13px; border-radius: 10px; border: 1px solid transparent; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%; font-family: 'Inter', sans-serif; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-secondary { background: var(--white); border-color: var(--line-strong); color: var(--ink); }
.btn-danger { background: none; border-color: var(--coral); color: var(--coral); }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-row .btn { flex: 1; }
.error { color: var(--coral); font-size: 13px; margin: 8px 0 0; min-height: 1em; }

/* Feuille modale */
.overlay { position: fixed; inset: 0; background: rgba(30, 42, 68, .45); display: none; align-items: flex-end; justify-content: center; z-index: 50; }
.overlay.open { display: flex; }
.sheet { background: var(--paper); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; animation: up .18s ease-out; }
.sheet h2 { font-family: var(--serif); font-size: 21px; margin: 0 0 14px; font-weight: 600; }
.sheet .intro { font-size: 13.5px; color: var(--ink-soft); margin: -6px 0 16px; line-height: 1.5; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Bouton + et navigation */
.fab { position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(76px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%; background: var(--gold); color: #fff; border: none; font-size: 32px; line-height: 1; box-shadow: 0 6px 18px rgba(30, 42, 68, .3); cursor: pointer; z-index: 30; }
nav.tabbar { position: fixed; bottom: 0; left: 0; right: 0; max-width: 560px; margin: 0 auto; background: var(--raised); border-top: 1px solid var(--line-strong); display: flex; z-index: 40; padding-bottom: env(safe-area-inset-bottom); }
nav.tabbar .tab { flex: 1; padding: 9px 2px 8px; background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; color: var(--ink-soft); }
nav.tabbar .tab .glyph { font-size: 18px; line-height: 1; }
nav.tabbar .tab .lbl { font-family: var(--mono); font-size: 10px; }
nav.tabbar .tab.on { color: var(--ink); }
nav.tabbar .tab.on .lbl { color: var(--gold); font-weight: 600; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(146px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--paper); padding: 11px 14px; border-radius: 10px; font-size: 14px; z-index: 60; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); box-shadow: 0 6px 18px rgba(0, 0, 0, .25); }
.toast button { background: none; border: none; color: #E7C77A; font-weight: 700; cursor: pointer; }

/* Assistant de démarrage */
.wizard { padding: 22px 16px; }
.wizard h2 { font-family: var(--serif); font-size: 24px; margin: 0 0 8px; }
.wizard p.lead { color: var(--ink-soft); line-height: 1.55; margin: 0 0 20px; }
.steps { font-family: var(--mono); font-size: 11px; color: var(--ink-soft); margin-bottom: 10px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
main { padding-bottom: 72px; }
