:root {
  --ground: #EDECE7;
  --surface: #FAF9F6;
  --surface-2: #FFFFFF;
  --border: #E3E1DC;
  --border-soft: #EFEDE7;
  --ink: #16231D;
  --ink-soft: #6B7570;
  --ink-faint: #8A8F8C;
  --green-deep: #163C2E;
  --green: #1F5D45;
  --gold: #D4A73A;
  --on-deep: #FAF9F6;
  --on-deep-soft: #CFE0D5;

  --ok-bg: #E1EEE6;   --ok-fg: #1F5D45;
  --wait-bg: #FBEBC8;  --wait-fg: #8A6A1A;
  --late-bg: #F7E1DE;  --late-fg: #B23A2E;
  --soon-bg: #E6EFE9;  --soon-fg: #1F5D45;
  --idle-bg: #EDEBE5;  --idle-fg: #6B7570;

  --shadow: 0 18px 40px rgba(20, 30, 25, 0.10);
  --radius: 16px;
  --maxw: 780px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0E1F18;
    --surface: #152B22;
    --surface-2: #1A3529;
    --border: #23402F;
    --border-soft: #1F3A2C;
    --ink: #EDEFEC;
    --ink-soft: #8FA398;
    --ink-faint: #6E8479;
    --green-deep: #0A1712;
    --green: #2E7C5A;
    --gold: #E8C978;
    --on-deep: #EDEFEC;
    --on-deep-soft: #8FA398;
    --ok-bg: #16352A;  --ok-fg: #7FD9AD;
    --wait-bg: #322D18;  --wait-fg: #E8C978;
    --late-bg: #3A211E;  --late-fg: #E79B90;
    --soon-bg: #16352A;  --soon-fg: #7FD9AD;
    --idle-bg: #22332B;  --idle-fg: #8FA398;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #0E1F18;
  --surface: #152B22;
  --surface-2: #1A3529;
  --border: #23402F;
  --border-soft: #1F3A2C;
  --ink: #EDEFEC;
  --ink-soft: #8FA398;
  --ink-faint: #6E8479;
  --green-deep: #0A1712;
  --green: #2E7C5A;
  --gold: #E8C978;
  --on-deep: #EDEFEC;
  --on-deep-soft: #8FA398;
  --ok-bg: #16352A;  --ok-fg: #7FD9AD;
  --wait-bg: #322D18;  --wait-fg: #E8C978;
  --late-bg: #3A211E;  --late-fg: #E79B90;
  --soon-bg: #16352A;  --soon-fg: #7FD9AD;
  --idle-bg: #22332B;  --idle-fg: #8FA398;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px 64px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
.num { font-variant-numeric: tabular-nums; }
a { color: var(--green); }
a:hover { color: var(--gold); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

header {
  position: sticky; top: 0; z-index: 20;
  background: var(--green-deep);
  color: var(--on-deep);
}
.header-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px;
  color: var(--on-deep); text-decoration: none; }
.brand:hover { color: var(--on-deep); }
.logo {
  width: 24px; height: 24px; border-radius: 7px; background: var(--green);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo span { width: 9px; height: 9px; border-radius: 3px; background: var(--gold); display: block; }
.header-right { font-size: 12px; color: var(--on-deep-soft); text-align: right; }
.header-right a { color: var(--on-deep); }

/* Barre d'onglets admin : identique sur admin / membres / rapport / nouveau-cycle */
.header-nav {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.header-nav a {
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  color: var(--on-deep); text-decoration: none;
  padding: 6px 11px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
}
.header-nav a:hover { background: rgba(255, 255, 255, 0.18); color: var(--on-deep); }
.header-nav a.actif { background: var(--gold); color: var(--green-deep); }

/* Sommaire interne (haut de la page admin) */
.toc { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.toc a {
  font-size: 12px; font-weight: 600; text-decoration: none;
  padding: 5px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-soft);
}
.toc a:hover { color: var(--ink); border-color: var(--gold); }

section { margin-top: 32px; scroll-margin-top: 84px; }
.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 12px;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.note { font-size: 13px; color: var(--ink-soft); margin-top: 10px; }

.banner {
  background: var(--wait-bg); color: var(--wait-fg);
  border-radius: 12px; padding: 12px 16px; font-size: 13px; font-weight: 600;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex-shrink: 0; margin-top: 5px; }

.hero { padding: 26px 24px; display: flex; flex-direction: column; gap: 18px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 5px 11px; border-radius: 100px; background: var(--soon-bg); color: var(--soon-fg);
}
.hero-when { font-size: 13px; color: var(--ink-soft); }
.hero-benef { display: flex; align-items: center; gap: 16px; }
.avatar {
  width: 60px; height: 60px; border-radius: 50%; background: var(--green); color: var(--on-deep);
  font-weight: 700; font-size: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.avatar.sm { width: 38px; height: 38px; font-size: 13px; }
.hero-benef .label { font-size: 13px; color: var(--ink-soft); }
.hero-benef .name { font-size: 24px; font-weight: 700; }
.hero-benef .sub { font-size: 13px; color: var(--ink-soft); }
.hero-pot { display: flex; gap: 36px; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.hero-pot .label { font-size: 13px; color: var(--ink-soft); }
.hero-pot .big { font-size: 40px; font-weight: 800; letter-spacing: -0.01em; }

.alert {
  background: var(--wait-bg); border-radius: var(--radius); padding: 18px 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.alert-head { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--wait-fg); }
.alert-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.alert ul { margin: 0; padding-left: 26px; color: var(--ink); font-size: 14px; }
.alert li { margin: 3px 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; padding: 14px 12px; }
.stat .v { font-size: 22px; font-weight: 800; }
.stat .k { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); margin-top: 2px; }

.cal { display: flex; flex-direction: column; gap: 6px; }
.cal-row {
  display: grid; grid-template-columns: 40px 1fr auto;
  gap: 10px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
}
.cal-row.is-now { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.cal-week { font-weight: 700; color: var(--ink-soft); font-size: 13px; }
.cal-main { min-width: 0; }
.cal-name { font-weight: 600; }
.cal-meta { font-size: 12px; color: var(--ink-soft); }
.cal-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.cal-pot { font-weight: 700; font-size: 14px; }
.cal-gap { text-align: center; font-size: 12px; color: var(--ink-faint); padding: 6px 0; font-style: italic; }

.pill {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 100px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.wait { background: var(--wait-bg); color: var(--wait-fg); }
.pill.soon { background: var(--soon-bg); color: var(--soon-fg); border: 1px solid var(--green); }
.pill.idle { background: var(--idle-bg); color: var(--idle-fg); }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; min-width: 460px; }
th, td { padding: 11px 16px; text-align: right; font-size: 14px; }
th:first-child, td:first-child { text-align: left; }
thead th {
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
}
tbody tr + tr td { border-top: 1px solid var(--border-soft); }
td.pos { color: var(--ok-fg); font-weight: 700; }
td.neg { color: var(--late-fg); font-weight: 700; }
.balance-check {
  display: flex; align-items: center; gap: 10px; margin-top: 12px;
  background: var(--ok-bg); color: var(--ok-fg); border-radius: 12px; padding: 12px 16px;
  font-size: 13px; font-weight: 700;
}

.how { display: flex; flex-direction: column; gap: 20px; }
.how p { margin: 0; }
.guarantees { display: grid; gap: 10px; }
.guarantee {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px;
}
.guarantee b { color: var(--gold); font-size: 15px; }
.rules { display: grid; gap: 12px; }
.rule .t { font-weight: 700; }
.rule .d { font-size: 14px; color: var(--ink-soft); }

footer {
  margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--ink-faint);
}

/* ---- Admin ---- */
.week-nav { display: flex; align-items: center; gap: 10px; }
.week-nav select {
  flex: 1; font: inherit; font-weight: 700; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px;
}
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 10px; padding: 10px 16px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink);
}
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--green); color: var(--on-deep); border-color: var(--green); }
.btn.primary:hover { background: var(--green-deep); }
.btn.icon { padding: 10px 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.mini { padding: 4px 10px; font-size: 12px; }

.pay-row {
  display: grid; grid-template-columns: 34px 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); margin-bottom: 6px;
}
.pay-row.paid { background: var(--ok-bg); border-color: transparent; }
.pay-row.benef { opacity: 0.6; }
.pay-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--green); }
.pay-row .who { min-width: 0; }
.pay-row .who .n { font-weight: 600; }
.pay-row .who .p { font-size: 12px; color: var(--ink-soft); }
.pay-row .amt {
  width: 92px; font: inherit; text-align: right; font-variant-numeric: tabular-nums;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  background: var(--surface); color: var(--ink);
}
.progress-wrap { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.progress-line { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.progress-bar { width: 100%; height: 10px; border-radius: 100px; background: var(--border-soft); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--green); border-radius: 100px; }

.out {
  width: 100%; min-height: 130px; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace;
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  background: var(--surface-2); color: var(--ink); resize: vertical; white-space: pre;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.confirm-box { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.confirm-box input[type="date"] {
  font: inherit; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  background: var(--surface-2); color: var(--ink);
}

.gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--green-deep); color: var(--on-deep);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate form {
  background: var(--surface); color: var(--ink); border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow);
}
.gate h2 { font-size: 19px; }
.gate input {
  font: inherit; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); color: var(--ink);
}
.gate .err { color: var(--late-fg); font-size: 13px; min-height: 18px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--green-deep); color: var(--on-deep);
  padding: 10px 18px; border-radius: 100px; font-size: 13px; font-weight: 600;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 120;
}
.toast.show { opacity: 1; }

@media (max-width: 520px) {
  .hero-pot { gap: 24px; }
  .hero-benef .name { font-size: 21px; }
  .hero-pot .big { font-size: 34px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .pay-row { grid-template-columns: 30px 1fr auto; }
  .pay-row .amt { grid-column: 2 / 4; width: 100%; margin-top: 4px; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
