:root {
  color-scheme: light only;
  --p: #1d4ed8; --p-2: #2563eb; --p-pale: #eff6ff; --p-bord: #bfdbfe;
  --page: #f4f7fb; --surface: #ffffff; --bord: #e2e8f0;
  --txt: #0f172a; --txt-2: #475569; --txt-3: #94a3b8;
  --vert: #15803d; --vert-pale: #f0fdf4; --rouge: #b91c1c; --rouge-pale: #fef2f2; --ambre: #a16207; --ambre-pale: #fefce8;
  --piscine: #0284c7; --lavage: #7c3aed; --commun: #64748b;
  --r: 14px; --r-s: 10px; --ombre: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.05);
  --bas-h: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--txt); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn-p { background: var(--p); color: #fff; }
.btn-p:active { background: #1e40af; }
.btn-s { background: var(--surface); border-color: var(--bord); color: var(--txt); }
.btn-l { background: none; color: var(--p); }
.btn-d { background: var(--surface); border-color: #fecaca; color: var(--rouge); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.plein { width: 100%; }
.ico { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; background: none; border-radius: 12px; cursor: pointer; color: var(--txt-2); }
.ico:active { background: var(--p-pale); }

/* Connexion */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #eff6ff, #fff 60%); }
.login-carte { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--bord); border-radius: 20px; padding: 28px 22px; box-shadow: var(--ombre); }
.login form { display: grid; gap: 10px; margin-top: 22px; }
.login label { font-weight: 600; font-size: 14px; }
.login input { min-height: 48px; border: 1px solid var(--bord); border-radius: 12px; padding: 0 14px; background: #fff; }
.login input:focus { outline: 2px solid var(--p-bord); border-color: var(--p); }
.login input.code { font-size: 26px; letter-spacing: 10px; text-align: center; font-weight: 700; }
.marque { display: flex; align-items: center; gap: 12px; }
.marque b { display: block; font-size: 20px; }
.marque small { color: var(--txt-2); font-size: 13px; }
.marque-pastille { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--p); color: #fff; font-weight: 800; font-size: 22px; }
.aide { color: var(--txt-2); font-size: 14px; margin: 0; }
.erreur { color: var(--rouge); font-size: 14px; min-height: 20px; margin: 12px 0 0; }

/* Coquille */
.principal { min-height: 100dvh; padding-bottom: calc(var(--bas-h) + env(safe-area-inset-bottom) + 16px); }
.haut { position: sticky; top: 0; z-index: 20; background: rgba(244,247,251,.94); backdrop-filter: blur(8px); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--bord); }
.haut-l1 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.haut h1 { font-size: 20px; margin: 0; }
.base, .per-type, .seg { display: inline-flex; background: #e8eef7; border-radius: 999px; padding: 3px; }
.base button, .per-type button, .seg button { border: 0; background: none; border-radius: 999px; padding: 0 12px; min-height: 34px; font-size: 13px; font-weight: 600; color: var(--txt-2); cursor: pointer; }
.base button.on, .per-type button.on, .seg button.on { background: #fff; color: var(--p); box-shadow: 0 1px 3px rgba(15,23,42,.12); }
.periode { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 8px; min-width: 0; }
.per-type button { padding: 0 9px; }
.per-nav { display: flex; align-items: center; min-width: 0; }
.per-nav .ico { width: 36px; }
.per-nav b { min-width: 0; text-align: center; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 400px) { .per-type button[data-ptype="trimestre"] { font-size: 0; } .per-type button[data-ptype="trimestre"]::after { content: "Trim."; font-size: 13px; } }
.vue { padding: 14px 16px; max-width: 1100px; margin: 0 auto; display: grid; gap: 14px; }

.bas { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: #fff; border-top: 1px solid var(--bord); padding-bottom: env(safe-area-inset-bottom); }
.bas button { flex: 1; border: 0; background: none; height: var(--bas-h); display: grid; place-items: center; align-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--txt-3); cursor: pointer; }
.bas button.on { color: var(--p); }
.cote { display: none; }

@media (min-width: 900px) {
  #ecran-app { display: grid; grid-template-columns: 230px 1fr; }
  #ecran-app[hidden] { display: none !important; }
  .bas { display: none; }
  .principal { padding-bottom: 24px; }
  .cote { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh; padding: 18px 12px; background: #fff; border-right: 1px solid var(--bord); }
  .cote .marque { padding: 4px 8px 18px; }
  .cote button { display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left; padding: 0 12px; min-height: 42px; border-radius: 10px; font-weight: 600; color: var(--txt-2); cursor: pointer; }
  .cote button.on { background: var(--p-pale); color: var(--p); }
  .cote .sortir { margin-top: auto; }
  .vue { padding: 20px 24px; }
}

/* Cartes */
.carte { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--r); padding: 16px; box-shadow: var(--ombre); min-width: 0; }
.carte h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.carte h2 small { font-weight: 500; color: var(--txt-3); font-size: 12px; }
.heros { background: linear-gradient(135deg, #1d4ed8, #2563eb 60%, #3b82f6); color: #fff; border: 0; }
.heros .lbl { opacity: .85; font-size: 13px; font-weight: 600; }
.heros .gros { font-size: 34px; font-weight: 800; letter-spacing: -.5px; margin: 2px 0 6px; }
.heros .sous { opacity: .9; font-size: 13px; }
.grille2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--r); padding: 12px 14px; min-width: 0; }
.stat .lbl { font-size: 12px; color: var(--txt-2); font-weight: 600; }
.stat .val { font-size: 19px; font-weight: 750; margin-top: 2px; }
.stat .det { font-size: 12px; color: var(--txt-3); margin-top: 2px; }
.stat.lien { cursor: pointer; }
.neg { color: var(--rouge); }
.pos { color: var(--vert); }

.acts { display: grid; gap: 10px; }
.act { border: 1px solid var(--bord); border-radius: var(--r-s); padding: 12px; }
.act-t { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 6px; }
.pastille { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ligne { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding: 3px 0; }
.ligne span:first-child { color: var(--txt-2); }
.ligne.fort { font-weight: 700; border-top: 1px dashed var(--bord); margin-top: 4px; padding-top: 7px; }
.ligne.fort span:first-child { color: var(--txt); }
@media (min-width: 700px) { .acts { grid-template-columns: repeat(3, 1fr); } .grille4 { grid-template-columns: repeat(4, 1fr); } }

.alerte { border-radius: var(--r-s); padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alerte.ambre { background: var(--ambre-pale); color: #713f12; border: 1px solid #fde68a; }
.alerte.rouge { background: var(--rouge-pale); color: #7f1d1d; border: 1px solid #fecaca; }
.alerte.bleu { background: var(--p-pale); color: #1e3a8a; border: 1px solid var(--p-bord); }
.alerte button { margin-left: auto; }

.barres { display: grid; gap: 8px; }
.barre-l { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 13px; }
.barre-l .piste { grid-column: 1 / -1; height: 8px; background: #eef2f7; border-radius: 99px; overflow: hidden; }
.barre-l .rempli { height: 100%; border-radius: 99px; }
.graph { width: 100%; height: auto; display: block; }
.graph text { font-size: 10px; fill: var(--txt-3); }
.legende { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--txt-2); margin-top: 8px; }
.legende span { display: inline-flex; align-items: center; gap: 6px; }

/* Listes */
.filtres { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filtres::-webkit-scrollbar { display: none; }
.puce { flex: none; border: 1px solid var(--bord); background: #fff; border-radius: 999px; min-height: 36px; padding: 0 14px; font-size: 13px; font-weight: 600; color: var(--txt-2); cursor: pointer; }
.puce.on { background: var(--p); border-color: var(--p); color: #fff; }
.recherche { width: 100%; min-height: 44px; border: 1px solid var(--bord); border-radius: 12px; padding: 0 14px; background: #fff; }
.totaux { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--txt-2); }
.totaux b { color: var(--txt); }
.liste { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--r); overflow: hidden; }
.el { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px 14px; border-bottom: 1px solid #eef2f7; }
.el:last-child { border-bottom: 0; }
.el.cliquable { cursor: pointer; }
.el.cliquable:active { background: #f8fafc; }
.el-t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el-s { font-size: 12px; color: var(--txt-3); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.el-m { text-align: right; font-weight: 700; }
.el-m small { display: block; font-weight: 500; font-size: 12px; color: var(--txt-3); }
.etiq { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 700; background: #f1f5f9; color: var(--txt-2); }
.etiq.piscine { background: #e0f2fe; color: #075985; }
.etiq.lavage { background: #ede9fe; color: #5b21b6; }
.etiq.payee { background: var(--vert-pale); color: var(--vert); }
.etiq.impayee { background: var(--ambre-pale); color: var(--ambre); }
.etiq.retard { background: var(--rouge-pale); color: var(--rouge); }
.etiq.aclasser { background: var(--ambre-pale); color: var(--ambre); }
.vide { padding: 28px 16px; text-align: center; color: var(--txt-3); }
.plus { padding: 10px; text-align: center; }

/* Formulaires */
.champ { display: grid; gap: 6px; }
.champ label { font-size: 13px; font-weight: 600; color: var(--txt-2); }
.champ input, .champ select, .champ textarea { min-height: 44px; border: 1px solid var(--bord); border-radius: 12px; padding: 10px 12px; background: #fff; width: 100%; }
.champ textarea { min-height: 80px; resize: vertical; }
.coche { display: flex; gap: 10px; align-items: center; min-height: 44px; font-size: 14px; }
.coche input { width: 22px; height: 22px; accent-color: var(--p); }
.rangee { display: flex; gap: 10px; flex-wrap: wrap; }
.rangee > * { flex: 1 1 140px; }
.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cats button { text-align: left; border: 1px solid var(--bord); background: #fff; border-radius: 10px; padding: 8px 10px; min-height: 44px; font-size: 13px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.cats button.on { border-color: var(--p); background: var(--p-pale); color: var(--p); font-weight: 700; }
.seg.large { display: flex; width: 100%; }
.seg.large button { flex: 1; min-height: 40px; }

/* Feuille du bas */
.voile { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 60; }
.feuille { position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; background: #fff; border-radius: 20px 20px 0 0; max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(15,23,42,.18); }
.feuille .poignee { width: 40px; height: 5px; border-radius: 99px; background: #cbd5e1; margin: 4px auto 12px; }
#feuille-c { display: grid; gap: 14px; }
#feuille-c h3 { margin: 0; font-size: 17px; }
.feuille-bas { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: #fff; padding: 10px 0 0; display: flex; gap: 10px; }
.feuille-bas .btn { flex: 1; }
@media (min-width: 700px) { .feuille { left: 50%; right: auto; bottom: 50%; transform: translate(-50%, 50%); width: 560px; border-radius: 20px; } }

.toast { position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translate(-50%, -150%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 80; transition: transform .25s; max-width: calc(100% - 32px); }
.toast.on { transform: translate(-50%, 0); }
.toast.err { background: var(--rouge); }
.chargement { padding: 40px; text-align: center; color: var(--txt-3); }
table.tab { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tab th, table.tab td { padding: 8px 6px; border-bottom: 1px solid #eef2f7; text-align: right; }
table.tab th:first-child, table.tab td:first-child { text-align: left; }
table.tab th { font-size: 12px; color: var(--txt-2); }
.defile { overflow-x: auto; }
