:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #16202e;
  --muted: #5d6878;
  --line: #e2e6ec;
  --brand: #16202e;
  --brand-ink: #ffffff;
  --accent: #f28c28;
  --paid: #1f9d55;   --paid-bg: #e6f5ec;
  --late: #d64545;   --late-bg: #fbeaea;
  --plate: #d97706;  --plate-bg: #fdf1e1;
  --pend: #2f6fed;   --pend-bg: #e8effd;
  --due: #7a8494;    --due-bg: #eef0f3;
  --pause: #a3abb8;  --pause-bg: #f2f3f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 8px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --surface: #18202b; --surface-2: #1e2734; --ink: #e9edf2; --muted: #9aa5b4; --line: #2a3442;
    --brand: #e9edf2; --brand-ink: #0f141c;
    --paid-bg: #173526; --late-bg: #3a1d1d; --plate-bg: #3a2a12; --pend-bg: #1a2a48; --due-bg: #252e3b; --pause-bg: #212935;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.no-nav { padding-bottom: 24px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px; }
.wrap.wide { max-width: 980px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.wrap-row { flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.strong { font-weight: 700; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }

/* En-tête */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--brand); color: var(--brand-ink);
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
}
.topbar .inner { max-width: 980px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { font-weight: 800; letter-spacing: .08em; }
.logo span { color: var(--accent); }

/* Cartes */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card.hero { padding: 20px; }
.card.danger { border-color: var(--late); background: var(--late-bg); }
.card.warn { border-color: var(--plate); background: var(--plate-bg); }
.card.info { border-color: var(--pend); background: var(--pend-bg); }
.card.ok { border-color: var(--paid); background: var(--paid-bg); }
.big { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi .v { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.dark { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--late); border-color: var(--late); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--pend); font-weight: 600; cursor: pointer; }

/* Formulaires */
label.f { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2);
}
textarea.input { min-height: 80px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pin { letter-spacing: .5em; text-align: center; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); }
.seg button:disabled { opacity: .45; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 1.4rem; cursor: pointer; }
.stepper .val { min-width: 90px; text-align: center; font-weight: 700; }
.err { color: var(--late); font-weight: 600; font-size: .92rem; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs a { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* Statuts */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st-paid { color: var(--paid); background: var(--paid-bg); }
.st-paid_late { color: var(--plate); background: var(--plate-bg); }
.st-late { color: var(--late); background: var(--late-bg); }
.st-pending { color: var(--pend); background: var(--pend-bg); }
.st-due, .st-not_started, .st-none { color: var(--due); background: var(--due-bg); }
.st-pause, .st-dispense { color: var(--pause); background: var(--pause-bg); }
.st-success { color: var(--paid); background: var(--paid-bg); }
.st-failed, .st-expired { color: var(--due); background: var(--due-bg); }
.pill.lg { font-size: 1rem; padding: 6px 14px; }

/* Listes */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list a.rowlink { text-decoration: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; }
.lines > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.lines > div.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 800; font-size: 1.1rem; }

/* Tableau d'équipe */
.board-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table.board { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: .9rem; }
.board th, .board td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.board th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.board th.cur { color: var(--accent); }
.board .name { position: sticky; left: 0; background: var(--surface); text-align: left; font-weight: 600; padding-left: 0; max-width: 130px; overflow: hidden; text-overflow: ellipsis; z-index: 1; }
.dot { display: inline-block; width: 22px; height: 22px; border-radius: 7px; vertical-align: middle; }
.dot.paid { background: var(--paid); }
.dot.paid_late { background: var(--plate); }
.dot.late { background: var(--late); }
.dot.pending { background: var(--pend); }
.dot.due { background: var(--due-bg); border: 2px dashed var(--due); }
.dot.pause, .dot.dispense { background: var(--pause-bg); border: 2px solid var(--pause); }
.dot.none { background: transparent; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 14px; height: 14px; border-radius: 4px; }

/* Navigation du bas */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav a { flex: 1; max-width: 120px; text-align: center; text-decoration: none; font-size: .75rem; color: var(--muted); padding: 6px 2px; border-radius: 10px; font-weight: 600; }
.nav a svg { display: block; margin: 0 auto 2px; width: 24px; height: 24px; }
.nav a.on { color: var(--accent); }

/* Fenêtre (reçu, confirmations) */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 15, 25, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-bg { align-items: center; } }
.modal { background: var(--surface); width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.receipt { border: 1px dashed var(--line); border-radius: 12px; padding: 16px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60; font-weight: 600; max-width: calc(100% - 32px); }
.spinner { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: absolute; left: 0; top: 0; width: 100%; border: 0; }
}
