:root {
  --bg: #f4f5f3; --card: #fff; --ink: #1c2321; --muted: #67706d; --line: #e2e5e2;
  --accent: #0f5c55; --accent-soft: #e3efed; --danger: #b3261e; --danger-soft: #fbe9e7;
  --owe: #9a3412; --owe-soft: #fff1e6; --ok: #166534;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { font-size: 16px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.splash { padding: 40vh 0 0; text-align: center; color: var(--muted); }

/* ---------- connexion ---------- */
.login { max-width: 360px; margin: 0 auto; padding: calc(var(--safe-t) + 15vh) 24px 24px; }
.login h1 { font-size: 26px; margin: 0 0 4px; }
.login p { margin: 0 0 28px; color: var(--muted); }
.login .field { margin-bottom: 14px; }
.login button { width: 100%; }

/* ---------- en-tête ---------- */
header.top {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(var(--safe-t) + 10px) 16px 8px; border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 8px; }
.soc-select {
  flex: 1; min-width: 0; appearance: none; -webkit-appearance: none; border: 0; background: transparent;
  font-size: 19px; font-weight: 650; padding: 4px 22px 4px 0; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 8px center, right 3px center; background-size: 5px 5px; background-repeat: no-repeat;
}
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.month-nav button { border: 0; background: var(--card); width: 38px; height: 34px; border-radius: 10px; font-size: 18px; cursor: pointer; box-shadow: 0 0 0 1px var(--line) inset; }
.month-nav .m { font-weight: 600; text-transform: capitalize; }
.month-nav .today { font-size: 12px; color: var(--accent); border: 0; background: none; cursor: pointer; padding: 0 0 0 6px; width: auto; box-shadow: none; }

main { padding: 14px 14px calc(var(--safe-b) + 90px); max-width: 720px; margin: 0 auto; }

/* ---------- barre d'onglets ---------- */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; padding: 6px 4px calc(var(--safe-b) + 6px);
}
nav.tabs button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; cursor: pointer; }
nav.tabs button svg { width: 24px; height: 24px; }
nav.tabs button.on { color: var(--accent); font-weight: 600; }

/* ---------- cartes / listes ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line); margin-bottom: 14px; overflow: hidden; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 16px 6px; gap: 10px; }
.card-h h2 { font-size: 15px; margin: 0; font-weight: 650; }
.card-h .num { font-weight: 600; }
.card-b { padding: 6px 16px 14px; }
.sec-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 4px 8px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row.tap { cursor: pointer; }
.row.tap:active { background: #f7f8f6; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 13px; color: var(--muted); margin-top: 1px; }
.row .amt { font-weight: 600; text-align: right; }
.empty { padding: 18px 16px; color: var(--muted); text-align: center; font-size: 14px; }
.total-row { display: flex; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-weight: 650; background: #fafbfa; }

/* ligne collaborateur */
.collab { padding: 12px 16px; border-top: 1px solid var(--line); }
.collab:first-child { border-top: 0; }
.collab-top { display: flex; align-items: center; gap: 10px; }
.collab-top .name { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.collab-top .name .s { font-weight: 400; }
.collab-top input.money-input { width: 140px; flex: none; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.split-line { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; background: var(--bg); border-radius: 999px; padding: 3px 9px; color: var(--muted); }
.chip b { color: var(--ink); font-weight: 600; }
.chip-btn { cursor: pointer; background: var(--accent-soft); color: var(--accent); border: 0; font-weight: 600; font-size: 12.5px; border-radius: 999px; padding: 3px 10px; }
.chip.warn { background: var(--owe-soft); color: var(--owe); }

/* ---------- formulaires ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=password], input[type=month], input[type=number], input[inputmode], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; font-size: 16px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 64px; resize: vertical; }
.btn { border: 0; border-radius: 11px; padding: 12px 16px; font-weight: 600; cursor: pointer; background: var(--accent); color: #fff; font-size: 16px; }
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: transparent; color: var(--accent); padding: 8px 4px; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.full { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 9px; }
.btns { display: flex; gap: 10px; margin-top: 16px; }
.btns .btn { flex: 1; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 8px 6px; font-size: 14px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.pct-grid { display: grid; grid-template-columns: 1fr 110px; gap: 8px 10px; align-items: center; margin-top: 10px; }
.pct-grid input { text-align: right; }
.pct-sum { font-size: 13px; margin-top: 6px; }
.pct-sum.bad { color: var(--danger); font-weight: 600; }
.err { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 0; }
.add-btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; border: 1.5px dashed #c9cfcb; background: transparent; color: var(--accent); font-weight: 600; border-radius: var(--radius); padding: 13px; cursor: pointer; margin-bottom: 14px; font-size: 15px; }

/* ---------- bilan ---------- */
.verdict { background: var(--accent); color: #fff; border-radius: 18px; padding: 18px 18px 16px; margin-bottom: 14px; }
.verdict .lbl { font-size: 13px; opacity: .85; }
.verdict .big { font-size: 24px; font-weight: 700; margin-top: 4px; line-height: 1.25; }
.verdict .big .num { font-size: 30px; }
.verdict .sub { font-size: 13px; opacity: .9; margin-top: 10px; display: flex; flex-direction: column; gap: 3px; }
.verdict.zero { background: var(--ok); }
.btable { width: 100%; border-collapse: collapse; font-size: 14px; }
.btable th, .btable td { padding: 9px 16px; text-align: right; border-top: 1px solid var(--line); }
.btable th:first-child, .btable td:first-child { text-align: left; color: var(--muted); font-weight: 400; }
.btable thead th { border-top: 0; font-weight: 650; color: var(--ink); }
.btable tr.strong td { font-weight: 650; color: var(--ink); background: #fafbfa; }
.btable .pos { color: var(--ok); }
.btable .neg { color: var(--owe); }
.explain { font-size: 13px; color: var(--muted); padding: 0 16px 14px; }

/* ---------- historique ---------- */
.h-day { font-size: 13px; font-weight: 650; color: var(--muted); margin: 18px 4px 8px; text-transform: capitalize; }
.h-item { padding: 12px 16px; border-top: 1px solid var(--line); }
.h-item:first-child { border-top: 0; }
.h-meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.h-who { font-weight: 650; color: var(--ink); }
.h-act { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg); }
.h-act.create { background: #e6f4ea; color: var(--ok); }
.h-act.update { background: #e8eefc; color: #1d4ed8; }
.h-act.delete { background: var(--danger-soft); color: var(--danger); }
.h-desc { font-size: 15px; }
.h-ch { font-size: 13px; margin-top: 5px; padding: 6px 10px; background: var(--bg); border-radius: 8px; }
.h-ch div + div { margin-top: 3px; }
.h-ch s { color: var(--muted); }

/* ---------- feuille modale ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(20,25,23,.42); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px 18px calc(var(--safe-b) + 18px); animation: up .2s ease-out; }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; } }
.sheet h3 { margin: 0 0 14px; font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 84px); background: #1c2321; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: up .2s; }
.toast.err { background: var(--danger); }
.offline { background: var(--owe-soft); color: var(--owe); font-size: 13px; padding: 6px 12px; text-align: center; }
