:root {
  --red: #cf2030;
  --red-soft: #fde8ea;
  --ink: #1d2330;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f6f8;
  --card: #fff;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --grey-soft: #f1f2f4;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 .small, h2 .right { margin-left: auto; font-size: .85rem; font-weight: 500; }
small, .small { font-size: .82em; }
.muted { color: var(--muted); }
.red { color: var(--red); }
.right { text-align: right; }
.mt { margin-top: 1.5rem; }
.pre, pre { white-space: pre-wrap; font-family: inherit; }
code { background: var(--grey-soft); padding: 0 .3em; border-radius: 4px; }

/* En-tête */
.top { background: var(--ink); color: #fff; display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.2rem; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; }
.brand small { font-weight: 400; opacity: .7; }
.logo { background: var(--red); border-radius: 6px; width: 28px; height: 28px; display: grid; place-items: center; }
.top nav { display: flex; gap: .2rem; flex-wrap: wrap; align-items: center; }
.top nav a, .top nav .link { color: #d1d5db; padding: .4rem .65rem; border-radius: 6px; font-size: .92rem; }
.top nav a:hover, .top nav .link:hover { background: #ffffff1a; color: #fff; text-decoration: none; }
.top nav a.on { background: var(--red); color: #fff; }

main { max-width: 1200px; margin: 0 auto; padding: 1.2rem 16px 3rem; }
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Cartes et grilles */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; min-width: 0; }
.card.narrow { max-width: 640px; }
.card.scroll { overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.grid2.wide-left { grid-template-columns: 1.6fr 1fr; }
.grid2 > .card { margin-bottom: 0; }
form.grid2 > div:last-child { grid-column: 1 / -1; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; display: flex; flex-direction: column; gap: .25rem; }
.tile span { color: var(--muted); font-size: .85rem; }
.tile strong { font-size: 1.4rem; }
.tile.alert strong { color: var(--red); }
.bar { background: var(--grey-soft); border-radius: 99px; height: 8px; overflow: hidden; flex: 1; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.bar i.m-carte { background: var(--blue); }
.bar i.m-virement { background: #7c3aed; }
.bar i.m-especes { background: var(--amber); }
.mrow { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: .7rem; margin: .45rem 0; }

/* Tableaux */
table { border-collapse: collapse; width: 100%; }
table.list th, table.list td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
table.list tfoot th { color: var(--ink); text-transform: none; font-size: .95rem; border-bottom: 0; }
.num { text-align: right !important; white-space: nowrap; }
.actions { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
td.actions { display: table-cell; text-align: right; white-space: nowrap; }
td.actions > * { margin-left: .3rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafafa; }
.empty { color: var(--muted); padding: .8rem 0; }
.empty.warn { color: var(--amber); }

table.grid { font-size: .9rem; }
table.grid th, table.grid td { padding: .35rem; border-bottom: 1px solid var(--line); text-align: center; }
table.grid td:first-child, table.grid th:first-child { text-align: left; white-space: nowrap; }
.cell { display: inline-grid; place-items: center; min-width: 30px; height: 26px; border-radius: 5px; font-weight: 700; }
td.cell { display: table-cell; }
.cell a { color: inherit; display: block; }
.legend { margin-top: 1rem; color: var(--muted); font-size: .85rem; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

/* Statuts */
.chip { display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.s-paye { background: var(--green-soft); color: var(--green); }
.s-partiel { background: var(--amber-soft); color: var(--amber); }
.s-retard { background: var(--red-soft); color: var(--red); }
.s-a_payer { background: var(--blue-soft); color: var(--blue); }
.s-exonere { background: var(--grey-soft); color: var(--muted); }
.s-hors { background: transparent; color: var(--muted); }
.m-carte { background: var(--blue-soft); color: var(--blue); }
.m-virement { background: #ede9fe; color: #6d28d9; }
.m-especes { background: var(--amber-soft); color: var(--amber); }

/* Formulaires */
label { display: block; margin-bottom: .8rem; font-weight: 500; font-size: .92rem; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem; border: 1px solid #d1d5db; border-radius: 7px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #cf203040; border-color: var(--red); }
input[type=checkbox], input[type=radio] { display: inline; width: auto; margin: 0 .35rem 0 0; }
label.check { display: flex; align-items: center; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem; margin: 0 0 .9rem; }
legend { font-weight: 600; font-size: .92rem; padding: 0 .3rem; }
legend label { margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.filters { display: flex; gap: .7rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters label { margin: 0; }
.filters input, .filters select { width: auto; }
form.inline { display: inline; }
.inline-form { margin-bottom: .5rem; }
.monthnav { display: flex; gap: .3rem; align-items: center; }
.monthnav input { width: auto; margin: 0; }
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .35rem; }
.month { display: flex; align-items: center; gap: .2rem; margin: 0; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 7px; font-weight: 500; }
.month small { margin-left: auto; }
.month.done { opacity: .5; }
.month:has(input:checked) { border-color: var(--red); background: var(--red-soft); }
.methods { display: flex; gap: .5rem; flex-wrap: wrap; }
.method { margin: 0; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 7px; display: flex; align-items: center; cursor: pointer; }
.method:has(input:checked) { border-color: var(--red); background: var(--red-soft); }
.paidfields { margin-top: .6rem; }
.paidfields .methods, .payform .methods { margin-bottom: .8rem; }
.paidfields[hidden] { display: none; }

/* Boutons */
.btn { display: inline-block; background: var(--red); color: #fff; border: 1px solid var(--red); padding: .55rem 1rem; border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(.95); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--ink); border-color: #d1d5db; }
.btn.sm { padding: .3rem .65rem; font-size: .85rem; }
.btn.wa { background: #25d366; border-color: #25d366; }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
button.link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; color: var(--red); }
.top nav button.link { color: #d1d5db; }

/* Messages */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: var(--green-soft); border-color: #86efac; color: #14532d; }
.flash.err { background: var(--red-soft); border-color: #fca5a5; color: #7f1d1d; }
.flash.warn { background: var(--amber-soft); border-color: #fcd34d; color: #78350f; }

/* Relances */
.rem { border: 1px solid var(--line); border-radius: 8px; padding: .8rem .9rem; margin-bottom: .7rem; }
.remhead { display: flex; justify-content: space-between; gap: 1rem; }
.rem details { margin: .5rem 0; }
.rem summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.rem pre { background: var(--grey-soft); padding: .7rem; border-radius: 6px; font-size: .88rem; margin: .4rem 0 0; }

/* Détails paiement */
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: .45rem .8rem; margin: 0 0 1.2rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.attachments { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .7rem; }
.att { border: 1px solid var(--line); border-radius: 8px; padding: .5rem; font-size: .82rem; display: flex; flex-direction: column; gap: .3rem; }
.att a { display: flex; flex-direction: column; gap: .3rem; color: var(--ink); word-break: break-all; }
.att img { width: 100%; height: 120px; object-fit: cover; border-radius: 5px; background: var(--grey-soft); }
.fileicon { height: 120px; display: grid; place-items: center; background: var(--red-soft); color: var(--red); font-weight: 800; border-radius: 5px; }

@media (max-width: 860px) {
  .grid2, .grid2.wide-left { grid-template-columns: 1fr; }
  .grid2 > .card { margin-bottom: 0; }
}
@media (max-width: 600px) {
  .row2 { grid-template-columns: 1fr; }
  .top { gap: .5rem; padding: .5rem 16px; position: static; }
  .top nav a, .top nav .link { padding: .3rem .45rem; font-size: .85rem; }
  .card { padding: .9rem; overflow-x: auto; }
  table.list th, table.list td { padding: .45rem .3rem; }
  .remhead { flex-direction: column; gap: .3rem; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { margin-top: .4rem; }
}

/* Calendrier des réunions */
.meetings { display: flex; flex-direction: column; gap: .35rem; }
.meetings a.small { font-size: .85rem; }
.days { display: inline-flex; gap: .25rem; margin-left: .5rem; vertical-align: middle; flex-wrap: wrap; }
.day { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-size: .78rem; font-weight: 700; }
.day.held { background: var(--green-soft); color: var(--green); }
.day.off { background: var(--red-soft); color: var(--red); text-decoration: line-through; }

/* Utilisateur connecté et rôles */
.usermenu { margin-left: auto; display: flex; gap: .5rem; align-items: center; font-size: .88rem; white-space: nowrap; }
.usermenu a { color: #fff; display: flex; align-items: center; gap: .4rem; }
.usermenu a:hover { text-decoration: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #374151; display: grid; place-items: center; font-size: .72rem; font-weight: 700; }
@media (max-width: 1400px) { .usermenu .uname { display: none; } }
.usermenu .link { color: #d1d5db; }
.top nav a.admin-only { display: none; }
body.role-admin .top nav a.admin-only { display: inline-block; }
/* Lecture seule : aucune action de modification n'est proposée (le serveur les refuse aussi). */
body.role-lecture main form[method="post"]:not(.allow-ro),
body.role-lecture main a[href^="/paiements/nouveau"],
body.role-lecture main a[href^="/import"],
body.role-lecture main form[action="/relances/envoyer"],
body.role-lecture main a.btn[href^="/relances"] { display: none !important; }
tr.inactive td { opacity: .55; }
