:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #ebefed;
  --ink: #14211d;
  --muted: #5a6964;
  --line: #d8e0dd;
  --accent: #0f6b5c;
  --accent-soft: #dcefe9;
  --accent-ink: #ffffff;
  --bar: #2f8f7b;
  --pos: #1b7549;
  --neg: #b4363c;
  --neg-soft: #fbe3e3;
  --warn: #9a5b0c;
  --warn-soft: #fbefd9;
  --ok-soft: #dff3e8;
  --shadow: 0 1px 2px rgba(20,33,29,.06), 0 4px 16px rgba(20,33,29,.06);
  --f-display: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --f-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1412; --surface: #141f1c; --surface-2: #1b2925; --ink: #e4ece9; --muted: #96a8a2; --line: #26362f;
    --accent: #5cc7ae; --accent-soft: #173a32; --accent-ink: #08130f; --bar: #4fb39c;
    --pos: #57c592; --neg: #ff7a7f; --neg-soft: #3a1c1e; --warn: #e3a64e; --warn-soft: #36290f; --ok-soft: #173326;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1412; --surface: #141f1c; --surface-2: #1b2925; --ink: #e4ece9; --muted: #96a8a2; --line: #26362f;
  --accent: #5cc7ae; --accent-soft: #173a32; --accent-ink: #08130f; --bar: #4fb39c;
  --pos: #57c592; --neg: #ff7a7f; --neg-soft: #3a1c1e; --warn: #e3a64e; --warn-soft: #36290f; --ok-soft: #173326;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 1100px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
h1, h2, h3 { font-family: var(--f-display); font-weight: 650; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
.eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 14px; margin: 0; }
.pad { padding-block: 24px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
[hidden] { display: none !important; }

/* En-tête */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; padding-top: env(safe-area-inset-top, 0px); }
.top-in { display: flex; align-items: center; gap: 12px 20px; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.brand .eyebrow { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 36px; height: 36px; border-radius: 9px; flex: none; }
.brand h1 { font-size: 19px; line-height: 1.15; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tabs button { border: 0; background: transparent; padding: 7px 13px; border-radius: 999px; font-weight: 700; font-size: 14px; color: var(--muted); white-space: nowrap; }
.tabs button[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.account { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px 4px 4px; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; flex: none; }
.account[aria-current="page"] { border-color: var(--accent); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; }

/* Navigation du bas (téléphone) */
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(6, 1fr); padding-bottom: env(safe-area-inset-bottom, 0px); }
.bottomnav button { border: 0; background: none; padding: 7px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; font-weight: 700; color: var(--muted); min-width: 0; }
.bottomnav button svg { width: 22px; height: 22px; }
.bottomnav button[aria-current="page"] { color: var(--accent); }
.fab { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 6; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
@media (min-width: 900px) {
  .bottomnav { display: none !important; }
  .fab { bottom: 28px; right: 28px; }
}
@media (max-width: 420px) { .kpis { gap: 8px; } .kpi { padding: 10px 11px; } }
@media (max-width: 899px) {
  .tabs { display: none !important; }
  main { padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
  .account .acc-name { display: none; }
  .account { padding: 4px; }
}
main { padding-block: 20px 60px; }

/* Blocs */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .stack > * + * { margin-top: 14px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; align-items: start; }
.grid > .card + .card { margin-top: 0; }
@media (min-width: 720px) { .g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); } }
.section-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* Chiffres clés */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .v { font-size: clamp(16px, 4.4vw, 22px); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.kpi .s { font-size: 13px; color: var(--muted); }

/* Navigation de mois */
.monthnav { display: flex; align-items: center; gap: 6px; }
.monthnav strong { min-width: 130px; text-align: center; text-transform: capitalize; }

/* Boutons et champs */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 14px; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--neg); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 6px 10px; }
.btn.big { padding: 12px 18px; font-size: 16px; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
label.f { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 12px; }
label.f > span.h { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-size: 16px; min-width: 0;
}
input[type=date] { min-height: 44px; }
textarea { min-height: 70px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin-bottom: 12px; }
.check input { width: 20px; height: 20px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 8px; border-radius: 7px; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { flex: 1 1 160px; margin-top: 0 !important; }
.err { color: var(--neg); font-size: 14px; margin: 0 0 10px; }

/* Listes */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); cursor: pointer; min-width: 0; }
.list .item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--surface-2); font-size: 17px; }
.clip { width: 15px; height: 15px; vertical-align: -2px; color: var(--muted); }
.dayhead { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: capitalize; padding: 12px 4px 4px; display: flex; justify-content: space-between; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.late { background: var(--neg-soft); color: var(--neg); }
.pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--ok-soft); color: var(--pos); }
.empty { text-align: center; padding: 26px 10px; color: var(--muted); }

/* Barres par catégorie */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar-row .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; background: var(--surface-2); border-radius: 0 4px 4px 0; position: relative; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .val { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; white-space: nowrap; }
.bar-row .val small { color: var(--muted); font-weight: 400; margin-left: 4px; }
@media (max-width: 480px) { .bar-row { grid-template-columns: 1fr auto; } .bar-row .bar-track { grid-column: 1 / -1; order: 3; } }

/* Jauge (objectif, crédit) */
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.meter > div { height: 100%; background: var(--bar); border-radius: 999px; }
.meter-l { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); gap: 8px; }

/* Cartes crédit / épargne */
.tile { cursor: pointer; }
.tile:hover { border-color: var(--accent); }
.tile .big { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; margin-top: 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Papiers (justificatifs) */
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; cursor: pointer; text-align: left; padding: 0; box-shadow: var(--shadow); min-width: 0; }
.doc .thumb { aspect-ratio: 3/4; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-weight: 700; overflow: hidden; }
.doc .thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc .cap { padding: 8px 10px; font-size: 13px; }
.doc .cap b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tableau */
.table-wrap { overflow-x: auto; max-height: 50vh; border: 1px solid var(--line); border-radius: 9px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--surface-2); }
tr.past td { color: var(--muted); }

/* Feuille (fenêtre) */
.sheet-back { position: fixed; inset: 0; background: rgba(8,14,12,.45); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.sheet-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.sheet-f { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; margin-top: 8px; }
.sheet-f .btns { margin-left: auto; }
.x { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; flex: none; }
@media (max-width: 600px) {
  .sheet-back { align-items: flex-end; padding: 0; }
  .sheet { border-radius: 16px 16px 0 0; max-height: 92dvh; padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
}
.viewer img { width: 100%; border-radius: 9px; display: block; }
.attach { border: 1px dashed var(--line); border-radius: 9px; padding: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 14px; }
.attach .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Connexion */
.auth { max-width: 420px; margin: 6vh auto 0; }
.auth h2 { margin-bottom: 4px; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 22px; letter-spacing: .12em; font-weight: 700; background: var(--surface-2); padding: 6px 12px; border-radius: 8px; display: inline-block; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; font-weight: 700; font-size: 14px; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
