/* BudgetSLC - feuille de style unique, sans dépendance externe */

:root {
  --ink:        #241c2e;
  --ink-soft:   #4a4056;
  --muted:      #6f6780;
  --line:       #d9d5e0;
  --line-soft:  #e8e5ee;
  --bg:         #eceaf1;
  --surface:    #ffffff;
  --velvet:     #b03a63;
  --velvet-dk:  #8e2c4e;
  --amber:      #b57b12;
  --amber-bg:   #fdf3dd;
  --sage:       #2f6b51;
  --sage-bg:    #e3f0e9;
  --red:        #a8323a;
  --red-bg:     #fbe7e7;
  --radius:     10px;
  --shadow:     0 1px 2px rgba(36,28,46,.08), 0 6px 18px -12px rgba(36,28,46,.35);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--velvet-dk); }
a:hover { color: var(--velvet); }

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; color: var(--ink); margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; margin-top: 1.75rem; }
h3 { font-size: 1.05rem; margin-top: 1.25rem; }

:focus-visible { outline: 3px solid var(--velvet); outline-offset: 2px; border-radius: 3px; }

/* ---------- Structure ---------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem 1rem;
  background: var(--ink);
  color: #f3f0f6;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.brand {
  font-family: var(--serif); font-size: 1.1rem; color: #fff;
  text-decoration: none; white-space: nowrap; letter-spacing: .01em;
}
.brand span { color: #d9a3b8; }
.appver {
  font-size: .68rem; color: #9b90ab; letter-spacing: .02em;
  align-self: center; white-space: nowrap;
  /* marge portée ici plutôt que par gap : rendu identique partout */
  margin-left: .5rem;
}
.topbar .spacer { flex: 1; }
.topbar select {
  background: #362c44; color: #fff; border: 1px solid #4d4160;
  border-radius: 7px; padding: .35rem .5rem; font-size: .85rem; max-width: 42vw;
}
.who { font-size: .8rem; color: #b8afc6; white-space: nowrap; }
.who b { color: #fff; font-weight: 600; }
.badge-ro {
  background: var(--amber-bg); color: #7a5209; border-radius: 999px;
  padding: .1rem .5rem; font-size: .72rem; font-weight: 600; margin-left: .35rem;
}

.menu-toggle {
  display: none; background: #362c44; color: #fff; border: 1px solid #4d4160;
  border-radius: 7px; padding: .35rem .6rem; font-size: 1.1rem; cursor: pointer; line-height: 1;
}

.shell { display: flex; min-height: calc(100vh - 48px); align-items: flex-start; }

.rail {
  width: 208px; flex: 0 0 208px; padding: 1rem .6rem 3rem;
  position: sticky; top: 48px; max-height: calc(100vh - 48px); overflow-y: auto;
}
.rail-group { margin-bottom: 1.1rem; }
.rail-group > p {
  margin: 0 0 .4rem;
  padding: .3rem .6rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--velvet);
  border-radius: 6px;
}
.rail a {
  display: block; padding: .42rem .6rem; border-radius: 7px;
  color: var(--ink-soft); text-decoration: none; font-size: .9rem;
}
.rail a:hover { background: #e2dfea; color: var(--ink); }
.rail a.on { background: var(--ink); color: #fff; font-weight: 600; }

main { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 4rem; max-width: 1180px; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Cartes & panneaux ---------- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > h3 { padding: .85rem 1.1rem 0; }

.grid { display: grid; gap: 1rem; }
/* Une grille placee directement dans la page respire comme une carte */
main > .grid { margin-bottom: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); }

/* ---------- Chiffres ---------- */

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.stat .k { font-size: .78rem; color: var(--muted); margin-bottom: .15rem; }
.stat .v { font-size: 1.5rem; font-family: var(--serif); font-variant-numeric: tabular-nums; }
.stat .n { font-size: .78rem; color: var(--muted); }
.stat.pos .v { color: var(--sage); }
.stat.neg .v { color: var(--red); }

.balance-strip {
  background: var(--ink); color: #fff; border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem;
  display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.balance-strip .b { border-left: 3px solid #55465f; padding-left: .85rem; }
.balance-strip .b:first-child { border-left: 3px solid var(--velvet); }
.balance-strip .k { font-size: .78rem; color: #b8afc6; }
.balance-strip .v {
  font-family: var(--serif); font-size: 1.75rem; font-variant-numeric: tabular-nums;
}
.balance-strip .v.pos { color: #9fd9b9; }
.balance-strip .v.neg { color: #f0a7ad; }
.balance-strip .n { font-size: .76rem; color: #a79dba; }

.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--sage); }
.neg { color: var(--red); }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--surface); }
table.data th {
  text-align: left; font-weight: 600; font-size: .78rem; color: #efeaf3;
  background: var(--ink); padding: .5rem .6rem; white-space: nowrap; position: sticky; top: 0;
}
table.data th.num, table.data td.num { text-align: right; }
table.data td { padding: .48rem .6rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.data tbody tr:nth-child(even) { background: #faf9fc; }
table.data tbody tr:hover { background: #f3eff7; }
table.data tfoot td { padding: .55rem .6rem; font-weight: 600; border-top: 2px solid var(--line); background: #f6f4f9; }
table.data td.wrap { white-space: normal; min-width: 160px; }
table.data .row-act { white-space: nowrap; text-align: right; }

.empty { padding: 1.5rem 1.1rem; color: var(--muted); text-align: center; }
.empty b { display: block; color: var(--ink); font-family: var(--serif); font-size: 1.05rem; margin-bottom: .2rem; }

/* ---------- Etiquettes de statut ---------- */

.tag {
  display: inline-block; border-radius: 999px; padding: .1rem .55rem;
  font-size: .74rem; font-weight: 600; white-space: nowrap;
}
.tag.pending   { background: var(--amber-bg); color: #7a5209; }
.tag.deposited { background: #e5ecfa; color: #2f4a86; }
.tag.cashed    { background: var(--sage-bg); color: var(--sage); }
.tag.bounced   { background: var(--red-bg); color: var(--red); }
.tag.cancelled { background: #ece9f0; color: var(--muted); text-decoration: line-through; }
.tag.neutral   { background: #ece9f0; color: var(--ink-soft); }
.tag.late      { background: var(--red-bg); color: var(--red); }
.tag.torefund  { background: var(--red-bg); color: var(--red); }
.tag.restore   { background: #efe6f2; color: #6a4b76; }

/* ---------- Formulaires ---------- */

form .field { margin-bottom: .8rem; }
label { display: block; font-size: .82rem; color: var(--ink-soft); font-weight: 600; margin-bottom: .2rem; }
label .hint { font-weight: 400; color: var(--muted); }

input[type=text], input[type=number], input[type=date], input[type=email], input[type=tel],
input[type=password], input[type=search], select, textarea {
  width: 100%; padding: .5rem .6rem; font: inherit; font-size: .92rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--velvet); }
textarea { min-height: 76px; resize: vertical; }
input[readonly], input:disabled, select:disabled { background: #f4f2f7; color: var(--muted); }

.row-fields { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.row-fields.tight { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin: 0 0 1rem; }
legend { font-family: var(--serif); font-size: 1rem; padding: 0 .4rem; color: var(--ink); }

.checkline { display: flex; align-items: center; margin-bottom: .4rem; font-size: .9rem; }
/* Marge portee par la case plutot que par gap : compatible avec tous les navigateurs */
.checkline input[type=checkbox] { width: 18px; height: 18px; flex: 0 0 auto; margin: 0 .55rem 0 0; }
.checkline label { flex: 1; margin: 0; }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: .35rem; justify-content: center;
  padding: .48rem .85rem; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-size: .88rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f5f2f8; color: var(--ink); }
.btn-primary { background: var(--velvet); border-color: var(--velvet); color: #fff; }
.btn-primary:hover { background: var(--velvet-dk); border-color: var(--velvet-dk); color: #fff; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #362c44; color: #fff; }
.btn-danger { color: var(--red); border-color: #e6c3c5; }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: .25rem .55rem; font-size: .8rem; }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

/* ---------- Messages ---------- */

.flash {
  border-radius: var(--radius); padding: .7rem 1rem; margin-bottom: 1rem;
  border: 1px solid; font-size: .9rem;
}
.flash.ok    { background: var(--sage-bg); border-color: #b9d9c8; color: #21503c; }
.flash.error { background: var(--red-bg); border-color: #e6c3c5; color: #7d2429; }
.flash.warn  { background: var(--amber-bg); border-color: #ecd9a6; color: #6f4a08; }
.flash.info  { background: #e8ecfa; border-color: #c3cee8; color: #2f4a86; }

.notice { font-size: .85rem; color: var(--muted); margin: .35rem 0 0; }

/* ---------- Fenêtres modales ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(36, 28, 46, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 1rem; overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 720px; box-shadow: 0 20px 60px -20px rgba(36,28,46,.6);
  max-height: 92vh; display: flex; flex-direction: column;
}
.modal.modal-lg { max-width: 940px; }
.modal-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; flex: 1; font-size: 1.1rem; }
.modal-body { padding: 1rem 1.1rem; overflow-y: auto; }
.modal-body > :first-child { margin-top: 0; }
.modal-foot {
  padding: .75rem 1.1rem; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end;
}
.modal-close {
  background: none; border: none; font-size: 1.5rem; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 .25rem;
}
.modal-close:hover { color: var(--ink); }

/* Carte de statistique rendue cliquable */
button.stat {
  display: block; width: 100%; text-align: left; font: inherit;
  cursor: pointer; color: inherit;
}
button.stat:hover { border-color: var(--velvet); background: #fdfbfe; }
button.stat .k::after { content: ' ›'; color: var(--velvet); font-weight: 700; }

/* Comparaison avant / après pour l'import de contacts */
.diff-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.diff-col { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; }
.diff-col h4 { margin: 0 0 .4rem; font-size: .9rem; }
.diff-col.new { border-color: var(--velvet); background: #fdf5f8; }
.diff-col dl { margin: 0; font-size: .85rem; }
.diff-col dt { color: var(--muted); font-size: .76rem; margin-top: .35rem; }
.diff-col dd { margin: 0; }

/* ---------- Filtres ---------- */

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 150px; }
.filters .field.grow { flex: 1; min-width: 200px; }

/* ---------- Onglets ---------- */

.tabs { display: flex; flex-wrap: wrap; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs a {
  padding: .45rem .8rem; text-decoration: none; color: var(--ink-soft);
  border-radius: 8px 8px 0 0; font-size: .88rem; font-weight: 600; border: 1px solid transparent;
  border-bottom: none; margin-bottom: -1px;
}
.tabs a.on { background: var(--surface); border-color: var(--line); color: var(--ink); }

/* ---------- Prise de presence (mobile d'abord) ---------- */

.att-list { display: grid; gap: .5rem; }
.att-item {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .75rem;
}
.att-item .nm { flex: 1 1 auto; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.att-item .nm small { display: block; font-weight: 400; color: var(--muted); }
.seg {
  display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  flex: 0 0 auto; max-width: 100%;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  margin: 0; padding: .5rem .7rem; font-size: .82rem; cursor: pointer; white-space: nowrap;
  background: #fff; color: var(--muted); border-left: 1px solid var(--line); min-width: 46px; text-align: center;
}
.seg label:first-of-type { border-left: none; }
.seg input:checked + label.p { background: var(--sage); color: #fff; }
.seg input:checked + label.a { background: var(--red); color: #fff; }
.seg input:checked + label.e { background: var(--amber); color: #fff; }

.sticky-save {
  position: sticky; bottom: 0; background: rgba(236,234,241,.94);
  backdrop-filter: blur(6px); padding: .7rem 0; margin-top: 1rem;
  border-top: 1px solid var(--line);
}

/* ---------- Divers ---------- */

.pill-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.small { font-size: .82rem; color: var(--muted); }
.mailbox {
  width: 100%; min-height: 180px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .82rem; white-space: pre; overflow-wrap: normal;
}
hr.sep { border: none; border-top: 1px solid var(--line); margin: 1.25rem 0; }

/* Ecran de connexion */
.login-wrap { max-width: 380px; margin: 8vh auto; padding: 0 1rem; }
.login-wrap .card { padding: 1.5rem; }
.login-wrap h1 { font-size: 1.5rem; text-align: center; }
.login-wrap .lead { text-align: center; color: var(--muted); font-size: .88rem; margin-bottom: 1.25rem; }

/* ---------- Mobile ---------- */

@media (max-width: 860px) {
  body { font-size: 16px; }
  .menu-toggle { display: block; }
  .topbar { flex-wrap: wrap; row-gap: .5rem; }
  .topbar .spacer { display: none; }
  .brand { flex: 1; font-size: 1rem; }
  /* Le selecteur de saison passe sur sa propre ligne, en pleine largeur */
  .topbar form { order: 10; flex: 1 1 100%; }
  .topbar select { width: 100%; max-width: none; }
  .who { font-size: .78rem; }
  .shell { display: block; }
  /* Tiroir glissant depuis la gauche, au-dessus du contenu */
  .rail {
    display: block; position: fixed; top: 0; left: 0; bottom: 0;
    width: 268px; max-width: 84vw; z-index: 60;
    padding: 1rem 1rem 2rem; overflow-y: auto;
    background: var(--surface); border-right: 1px solid var(--line);
    box-shadow: 4px 0 24px -8px rgba(36, 28, 46, .45);
    transform: translateX(-100%);
    transition: transform .22s ease;
    visibility: hidden;
  }
  .rail.open { transform: translateX(0); visibility: visible; }
  .rail-backdrop {
    position: fixed; inset: 0; z-index: 55;
    background: rgba(36, 28, 46, .45);
    opacity: 0; visibility: hidden; transition: opacity .22s ease;
  }
  .rail-backdrop.open { opacity: 1; visibility: visible; }
  body.rail-locked { overflow: hidden; }
  .rail-group { margin-bottom: .6rem; }
  .rail a { padding: .6rem .6rem; }
  main { padding: 1rem 1rem 3.5rem; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .page-head .actions .btn { flex: 1; }
  table.data { font-size: .85rem; }
  table.data th { position: static; }
  .balance-strip .v { font-size: 1.5rem; }
  input, select, textarea { font-size: 16px; } /* evite le zoom auto iOS */
}

@media (max-width: 860px) {
  /* Les impayes passent avant le prochain depot */
  .card-debtors  { order: 1; }
  .card-deposits { order: 2; }

  /* Le detail du depot reste plie tant qu'on ne le demande pas */
  .dep-detail { display: none; }
  .card-deposits.open .dep-detail { display: block; }
  .dep-summary { cursor: pointer; }
  .dep-hint {
    display: inline-block; margin-left: .4rem;
    color: var(--velvet-dk); font-weight: 600; white-space: nowrap;
  }
  .dep-hint::after { content: ' \25BE'; }
  .card-deposits.open .dep-hint::after { content: ' \25B4'; }
}

/* Sur grand ecran le detail est toujours visible */
@media (min-width: 861px) {
  .dep-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Impression ---------- */

@media print {
  .topbar, .rail, .page-head .actions, .btn, .filters, .no-print { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  main { padding: 0; max-width: none; }
  .card { border: 1px solid #ccc; break-inside: avoid; }
  table.data th { background: #eee !important; color: #000 !important; }
}
