:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #16191d; --muted: #6b7280; --line: #e5e7eb;
  --accent: #0f766e; --accent-soft: #ccfbf1; --warn: #b45309; --danger: #b91c1c; --ok: #15803d;
  --p0: #0f766e; --p1: #c2410c;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215; --card: #181c20; --text: #eef1f4; --muted: #9aa3ad; --line: #2a3036;
    --accent: #2dd4bf; --accent-soft: #134e4a; --warn: #f59e0b; --danger: #f87171; --ok: #4ade80;
    --p0: #2dd4bf; --p1: #fb923c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
.splash { padding: 40vh 16px; text-align: center; color: var(--muted); }

/* --- structure --- */
header.top { position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px; display: flex; align-items: center; gap: 10px; }
header.top h1 { font-size: 20px; margin: 0; flex: 1; }
main { max-width: 760px; margin: 0 auto; padding: 4px 16px calc(env(safe-area-inset-bottom) + 90px); }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { flex: 1; border: 0; background: none; padding: 10px 2px 8px; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
nav.tabs button .ico { font-size: 20px; line-height: 1; }
nav.tabs button.on { color: var(--accent); font-weight: 600; }
@media (min-width: 900px) {
  nav.tabs { position: sticky; top: 52px; max-width: 760px; margin: 0 auto 8px; border: 1px solid var(--line); border-radius: var(--radius); }
  main { padding-bottom: 40px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

/* --- chiffres clés --- */
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .sub { font-size: 13px; color: var(--muted); }
.person { border-left: 4px solid var(--pc, var(--accent)); }
.person h3 { margin: 0 0 8px; font-size: 18px; }
.rows .r { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.rows .r:last-child { border-bottom: 0; }
.rows .r.total { font-weight: 700; border-top: 1px solid var(--line); border-bottom: 0; margin-top: 4px; padding-top: 8px; }
.pos { color: var(--ok); } .neg { color: var(--danger); }

.bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); margin: 8px 0 4px; }
.bar > span { display: block; height: 100%; }
.legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.cat { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 8px 0; font-size: 14px; }
.cat .track { grid-column: 1 / -1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.cat .track span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* --- listes éditables --- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .lbl { flex: 1; min-width: 0; }
.list .lbl .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .lbl .c { font-size: 12px; color: var(--muted); }
.list .amt { font-weight: 600; }
.list li.tap { cursor: pointer; }
.list li.tap:active { background: var(--accent-soft); }

/* --- formulaires --- */
label.f { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
label.f input, label.f select { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062a26; } }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 14px; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
select.month { padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 6px; }

/* --- connexion --- */
.login { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12vh) 16px 40px; }
.login .logo { width: 64px; height: 64px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.qr { background: #fff; padding: 8px; border-radius: 12px; width: fit-content; margin: 10px auto; }
.qr svg { display: block; width: 200px; height: 200px; }
code.secret { display: block; text-align: center; word-break: break-all; font-size: 14px; padding: 8px; background: var(--bg); border-radius: 8px; }
input.code { text-align: center; letter-spacing: .4em; font-size: 24px !important; }

/* --- feuille modale --- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  max-height: 90vh; overflow: auto; }
@media (min-width: 600px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; } }
.sheet h3 { margin: 0 0 6px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 80px); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; }

/* --- historique --- */
table.h { width: 100%; border-collapse: collapse; font-size: 14px; }
table.h th, table.h td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
table.h th { color: var(--muted); font-weight: 600; text-align: right; }
table.h th:first-child, table.h td:first-child { text-align: left; }
.chart svg { width: 100%; height: auto; display: block; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table.h td, table.h th { white-space: nowrap; }
body { overflow-x: hidden; }
.sav { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; cursor: pointer; }
.sav:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.sav-h { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.sav-h b:first-child { color: var(--pc); }
.sav .track { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0 4px; }
.sav .track span { display: block; height: 100%; background: var(--pc); }
